2011-05-20 11:08:13 +02:00
|
|
|
Index: Config.py
|
|
|
|
===================================================================
|
|
|
|
--- Config.py.orig
|
2011-04-27 15:22:17 +02:00
|
|
|
+++ Config.py
|
2011-05-20 11:08:13 +02:00
|
|
|
@@ -116,12 +116,23 @@ def getOption(name, default = ""):
|
2011-04-27 15:22:17 +02:00
|
|
|
_filters = []
|
|
|
|
_filters_re = None
|
2011-05-20 11:08:13 +02:00
|
|
|
|
|
|
|
+_filters_non_except = []
|
|
|
|
+_filters_non_except_re = None
|
|
|
|
+
|
2011-04-27 15:22:17 +02:00
|
|
|
+_filters_except = []
|
|
|
|
+_filters_except_re = None
|
2011-05-20 11:08:13 +02:00
|
|
|
+
|
2011-04-27 15:22:17 +02:00
|
|
|
def addFilter(s):
|
|
|
|
global _filters
|
2011-05-20 11:08:13 +02:00
|
|
|
global _filters_re
|
|
|
|
+ global _filters_except
|
|
|
|
|
|
|
|
- _filters.append(s)
|
|
|
|
- _filters_re = None
|
|
|
|
+ if len(_filters_except):
|
|
|
|
+ _filters.append(s)
|
|
|
|
+ _filters_re = None
|
|
|
|
+ else:
|
|
|
|
+ _filters_non_except.append(s)
|
|
|
|
+ _filters_non_except_re = None
|
|
|
|
|
|
|
|
def removeFilter(s):
|
|
|
|
global _filters
|
|
|
|
@@ -137,8 +148,14 @@ def removeFilter(s):
|
2011-04-27 15:22:17 +02:00
|
|
|
_scoring = {}
|
|
|
|
|
|
|
|
def setBadness(s, score):
|
|
|
|
+ global _scoring
|
|
|
|
_scoring[s] = score
|
|
|
|
|
|
|
|
+def setFilterException(s):
|
|
|
|
+ global _filters_except
|
|
|
|
+
|
|
|
|
+ _filters_except.append(s)
|
|
|
|
+
|
|
|
|
def badness(s):
|
|
|
|
return _scoring.get(s, 0)
|
|
|
|
|
2011-05-20 11:08:13 +02:00
|
|
|
@@ -146,11 +163,24 @@ _non_named_group_re = re.compile('[^\\](
|
2011-04-27 15:22:17 +02:00
|
|
|
def isFiltered(s):
|
|
|
|
global _filters
|
|
|
|
global _filters_re
|
|
|
|
+ global _filters_except
|
|
|
|
+ global _filters_except_re
|
2011-05-20 11:08:13 +02:00
|
|
|
+ global _filters_non_except
|
|
|
|
+ global _filters_non_except_re
|
|
|
|
|
|
|
|
- if _filters_re == None:
|
|
|
|
- # no filter
|
|
|
|
- if len(_filters) == 0:
|
|
|
|
- return False
|
|
|
|
+ if _filters_non_except_re == None and len(_filters_non_except):
|
|
|
|
+ _filters_non_except_re = '(?:' + _filters_non_except[0] + ')'
|
|
|
|
+
|
|
|
|
+ for idx in range(1, len(_filters_non_except)):
|
|
|
|
+ # to prevent named group overflow that happen when there is too
|
|
|
|
+ # many () in a single regexp: AssertionError: sorry, but this
|
|
|
|
+ # version only supports 100 named groups
|
|
|
|
+ if '(' in _filters_non_except[idx]:
|
|
|
|
+ _non_named_group_re.subn('(:?', _filters_non_except[idx])
|
|
|
|
+ _filters_non_except_re = _filters_non_except_re + '|(?:' + _filters_non_except[idx] +')'
|
|
|
|
+ _filters_non_except_re = re.compile(_filters_non_except_re)
|
|
|
|
+
|
|
|
|
+ if _filters_re == None and len(_filters):
|
|
|
|
_filters_re = '(?:' + _filters[0] + ')'
|
2011-04-27 15:22:17 +02:00
|
|
|
|
2011-05-20 11:08:13 +02:00
|
|
|
for idx in range(1, len(_filters)):
|
2011-05-20 11:10:47 +02:00
|
|
|
@@ -162,9 +192,27 @@ def isFiltered(s):
|
2011-04-27 15:22:17 +02:00
|
|
|
_filters_re = _filters_re + '|(?:' + _filters[idx] +')'
|
|
|
|
_filters_re = re.compile(_filters_re)
|
|
|
|
|
|
|
|
+ if _filters_except_re == None and len(_filters_except):
|
|
|
|
+ _filters_except_re = '(?:' + _filters_except[0] + ')'
|
|
|
|
+
|
|
|
|
+ for idx in range(1, len(_filters_except)):
|
|
|
|
+ # to prevent named group overflow that happen when there is too
|
|
|
|
+ # many () in a single regexp: AssertionError: sorry, but this
|
|
|
|
+ # version only supports 100 named groups
|
|
|
|
+ if '(' in _filters_except[idx]:
|
|
|
|
+ _non_named_group_re.subn('(:?', _filters_except[idx])
|
|
|
|
+ _filters_except_re = _filters_except_re + '|(?:' + _filters_except[idx] +')'
|
|
|
|
+ _filters_except_re = re.compile(_filters_except_re)
|
|
|
|
+
|
|
|
|
if not no_exception:
|
2011-05-20 11:10:47 +02:00
|
|
|
- if _filters_re.search(s):
|
2011-05-20 11:08:13 +02:00
|
|
|
+
|
|
|
|
+ if _filters_non_except_re and _filters_non_except_re.search(s):
|
2011-05-20 11:10:47 +02:00
|
|
|
return True
|
2011-04-27 15:22:17 +02:00
|
|
|
+ if _filters_except_re and _filters_except_re.search(s):
|
|
|
|
+ return False
|
2011-05-20 11:10:47 +02:00
|
|
|
+ if _filters_re and _filters_re.search(s):
|
|
|
|
+ return True
|
|
|
|
+
|
2011-04-27 15:22:17 +02:00
|
|
|
return False
|
2011-05-20 11:10:47 +02:00
|
|
|
|
|
|
|
# Config.py ends here
|