Created
October 29, 2013 04:25
-
-
Save goodwillcoding/7209158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExactRequestParamPredicate(object): | |
def __init__(self, val, config): | |
val = _as_sorted_tuple(val) | |
reqs = [] | |
for p in val: | |
k = p | |
v = None | |
if '=' in p: | |
k, v = p.split('=', 1) | |
k, v = k.strip(), v.strip() | |
reqs.append((k, v)) | |
self.val = val | |
self.reqs = reqs | |
def text(self): | |
return 'request_param %s' % ','.join( | |
['%s=%s' % (x,y) if y else x for x, y in self.reqs] | |
) | |
phash = text | |
def __call__(self, context, request): | |
# predicate params count and request params count must be the same | |
if len(self.reqs) != len(request.params): | |
return False | |
for k, v in self.reqs: | |
actual = request.params.get(k) | |
if actual is None: | |
return False | |
if v is not None and actual != v: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment