diff options
| author | J08nY | 2017-06-01 02:38:38 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-01 02:38:38 +0200 |
| commit | 5b2df8d6cd6a6241e044126b020b8a8ebbc9230b (patch) | |
| tree | a81d8ffe4ee13180c5affde92388c0b0e1b68aca | |
| parent | 28dbc044a0d0c464c6800df6b5e27e2b25025b8d (diff) | |
| download | mailman-precompile-rest-matchers.tar.gz mailman-precompile-rest-matchers.tar.zst mailman-precompile-rest-matchers.zip | |
| -rw-r--r-- | src/mailman/rest/helpers.py | 4 | ||||
| -rw-r--r-- | src/mailman/rest/wsgiapp.py | 26 |
2 files changed, 17 insertions, 13 deletions
diff --git a/src/mailman/rest/helpers.py b/src/mailman/rest/helpers.py index b8b602dea..b532b330b 100644 --- a/src/mailman/rest/helpers.py +++ b/src/mailman/rest/helpers.py @@ -17,6 +17,7 @@ """Web service helpers.""" +import re import json import falcon import hashlib @@ -26,6 +27,7 @@ from datetime import datetime, timedelta from email.header import Header from email.message import Message from enum import Enum + from lazr.config import as_boolean from mailman.config import config from pprint import pformat @@ -233,6 +235,8 @@ def child(matcher=None): def decorator(func): if matcher is None: func.__matcher__ = func.__name__ + elif isinstance(matcher, str) and matcher.startswith('^'): + func.__matcher__ = re.compile(matcher) else: func.__matcher__ = matcher return func diff --git a/src/mailman/rest/wsgiapp.py b/src/mailman/rest/wsgiapp.py index 70d756405..0be96d42c 100644 --- a/src/mailman/rest/wsgiapp.py +++ b/src/mailman/rest/wsgiapp.py @@ -131,21 +131,21 @@ class ObjectRouter: if matcher is MISSING: continue result = None + + # Is the matcher a regular expression or plain + # string? if isinstance(matcher, str): - # Is the matcher string a regular expression or plain - # string? If it starts with a caret, it's a regexp. - if matcher.startswith('^'): - cre = re.compile(matcher) - # Search against the entire remaining path. - tmp_segments = segments[:] - tmp_segments.insert(0, this_segment) - remaining_path = SLASH.join(tmp_segments) - mo = cre.match(remaining_path) - if mo: - result = attribute( - context, segments, **mo.groupdict()) - elif matcher == this_segment: + if matcher == this_segment: result = attribute(context, segments) + elif isinstance(matcher, re._pattern_type): + # Search against the entire remaining path. + tmp_segments = segments[:] + tmp_segments.insert(0, this_segment) + remaining_path = SLASH.join(tmp_segments) + mo = matcher.match(remaining_path) + if mo: + result = attribute( + context, segments, **mo.groupdict()) else: # The matcher is a callable. It returns None if it # doesn't match, and if it does, it returns a 3-tuple |
