Replace assert statements with proper control-flow
When python is run with -O assert statements are optimized away.
Replacing them with proper control-flow statements (e.g., if, else,
elif) prevents the matcher from returning an invalid match.
Closes-bug: #1414532
Co-Authored-By: Ian Cordasco <ian.cordasco@rackspace.com>
Change-Id: I60b42d5a5d71602be7adc321406ea87dfcf93f46
(cherry picked from commit 6b92b53782
)
This commit is contained in:
parent
1db07bd8c0
commit
29b282aa24
|
@ -83,16 +83,15 @@ class CacheFilter(wsgi.Middleware):
|
|||
otherwise None
|
||||
"""
|
||||
for ((version, method), pattern) in PATTERNS.items():
|
||||
match = pattern.match(request.path_info)
|
||||
try:
|
||||
assert request.method == method
|
||||
image_id = match.group(1)
|
||||
# Ensure the image id we got looks like an image id to filter
|
||||
# out a URI like /images/detail. See LP Bug #879136
|
||||
assert image_id != 'detail'
|
||||
except (AttributeError, AssertionError):
|
||||
if request.method != method:
|
||||
continue
|
||||
else:
|
||||
match = pattern.match(request.path_info)
|
||||
if match is None:
|
||||
continue
|
||||
image_id = match.group(1)
|
||||
# Ensure the image id we got looks like an image id to filter
|
||||
# out a URI like /images/detail. See LP Bug #879136
|
||||
if image_id != 'detail':
|
||||
return (version, method, image_id)
|
||||
|
||||
def _enforce(self, req, action, target=None):
|
||||
|
|
Loading…
Reference in New Issue