Skip to content

Commit b256e9f

Browse files
committed
make_default_options_response now tries to use Werkzeug 0.7 functionality before falling back.
1 parent d49221b commit b256e9f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

flask/app.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,17 +1305,18 @@ def make_default_options_response(self):
13051305
13061306
.. versionadded:: 0.7
13071307
"""
1308-
# This would be nicer in Werkzeug 0.7, which however currently
1309-
# is not released. Werkzeug 0.7 provides a method called
1310-
# allowed_methods() that returns all methods that are valid for
1311-
# a given path.
1312-
methods = []
1313-
try:
1314-
_request_ctx_stack.top.url_adapter.match(method='--')
1315-
except MethodNotAllowed, e:
1316-
methods = e.valid_methods
1317-
except HTTPException, e:
1318-
pass
1308+
adapter = _request_ctx_stack.top.url_adapter
1309+
if hasattr(adapter, 'allowed_methods'):
1310+
methods = adapter.allowed_methods()
1311+
else:
1312+
# fallback for Werkzeug < 0.7
1313+
methods = []
1314+
try:
1315+
adapter.match(method='--')
1316+
except MethodNotAllowed, e:
1317+
methods = e.valid_methods
1318+
except HTTPException, e:
1319+
pass
13191320
rv = self.response_class()
13201321
rv.allow.update(methods)
13211322
return rv

0 commit comments

Comments
 (0)