summaryrefslogtreecommitdiff
path: root/src/mailman/rest/wsgiapp.py
diff options
context:
space:
mode:
authorJ08nY2017-06-01 02:38:38 +0200
committerJ08nY2017-06-01 02:38:38 +0200
commit5b2df8d6cd6a6241e044126b020b8a8ebbc9230b (patch)
treea81d8ffe4ee13180c5affde92388c0b0e1b68aca /src/mailman/rest/wsgiapp.py
parent28dbc044a0d0c464c6800df6b5e27e2b25025b8d (diff)
downloadmailman-precompile-rest-matchers.tar.gz
mailman-precompile-rest-matchers.tar.zst
mailman-precompile-rest-matchers.zip
Precompile the REST path regex matchers.precompile-rest-matchers
Diffstat (limited to 'src/mailman/rest/wsgiapp.py')
-rw-r--r--src/mailman/rest/wsgiapp.py26
1 files changed, 13 insertions, 13 deletions
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