Comments (5)
It's a good idea. I had considered this, but there is the problem of how to include the decorators in the blacklist file. If the decorator definition wasn't embedded directly into the focus_blacklist.py, it would need to be imported from somewhere obvious. It makes the learning curve a little steeper for writing rules.
One thing I should probably document better is that this:
def domain_somedomain_com(dt): return True
would match *.somedomain.com. You can write more specific subdomain functions to whitelist/blacklist specific subdomains, and then have a catch-all function for the entire domain. The way I had figured it, regexes would be mainly for matching subdomains, so doing this would eliminate the need for 99% of the regexes.
from focus.
Can't you just run the blacklist code in the scope of the main program? I'm not too experienced with execfile, but wouldn't this work?
#Define the decorator
allRules = {}
def domainfilter(regex):
def decorator(f):
allRules[regex] = f
return f
def loadConfig():
allRules.clear()
execfile('focus_blacklist.py', {"domainfilter": domainfilter})
from focus.
Yeah that would. I still think that the learning curve cost / benefit ratio of adding it is high though, since the current implementation handles most of what regexes would be used for. I'll leave this issue open though and see if anyone else wants to weigh in.
from focus.
Perhaps have two decorators? I agree that forcing users to use regex isn't the right way to go. A solution would be to have one decorator for your current behaviour:
@focus.filter("facebook.com")
def stopMeFacebooking(dt):
return 12 >= dt.hour >= 14
And then something like one of these for regex behaviour:
@focus.filter.regex(r".*\.co.uk")
def ignoreEngland(dt, groups):
return dt.hour % 2 == 0
@focus.filter(regex = r".*\.co.uk")
def ignoreEngland(dt, groups):
return dt.hour % 2 == 0
@focus.regexFilter(r".*\.co.uk")
def ignoreEngland(dt, groups):
return dt.hour % 2 == 0
from focus.
As it stands, I'll have to vote no. Regexes aren't necessary in the current scheme (for most of the uses), so the regex decorators are out. That leaves the regular focus.filter
decorator, which, to me, seems to be just another step that doesn't gain much. The gains of the decorator is that it allows for arbitrary domain names easily...domains with weird characters, etc, that would have to be filtered out of a function name. The drawbacks are that it's another piece for users to learn and it's another line to write that feels redundant.
from focus.
Related Issues (10)
- HTTPS HOT 3
- Use Interface Name for Fail IP HOT 2
- IPv6/AAAA records
- s
- runtime error in most recent build HOT 1
- Does anyone still use this? HOT 1
- windows support HOT 6
- Navigation Scrolling HOT 1
- /etc/resolv.conf not used on Mac OS X HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from focus.