--- a/selectors.py Mon Oct 04 18:55:57 2010 +0200
+++ b/selectors.py Mon Oct 04 18:56:05 2010 +0200
@@ -1182,7 +1182,6 @@
"""
return ~ authenticated_user()
-
class match_user_groups(ExpectedValueSelector):
"""Return a non-zero score if request's user is in at least one of the
groups given as initializer argument. Returned score is the number of groups
@@ -1213,6 +1212,24 @@
return score
+class configuration_values(Selector):
+ """Return 1 if the instance is configured according to
+ the given value(s)"""
+
+ def __init__(self, key, values):
+ self._key = key
+ if isinstance(values, basestring):
+ values = (values,)
+ self._values = frozenset(values)
+
+ @lltrace
+ def __call__(self, cls, req, **kwargs):
+ try:
+ return self._score
+ except AttributeError:
+ self._score = req.vreg.config[self._key] in self._values
+ return self._score
+
# Web request selectors ########################################################
# XXX deprecate