forked from orbit-oss/flask
make_default_options_response now tries to use Werkzeug 0.7 functionality before falling back.
This commit is contained in:
parent
d49221bf2e
commit
b256e9f36c
1 changed files with 12 additions and 11 deletions
23
flask/app.py
23
flask/app.py
|
|
@ -1305,17 +1305,18 @@ class Flask(_PackageBoundObject):
|
||||||
|
|
||||||
.. versionadded:: 0.7
|
.. versionadded:: 0.7
|
||||||
"""
|
"""
|
||||||
# This would be nicer in Werkzeug 0.7, which however currently
|
adapter = _request_ctx_stack.top.url_adapter
|
||||||
# is not released. Werkzeug 0.7 provides a method called
|
if hasattr(adapter, 'allowed_methods'):
|
||||||
# allowed_methods() that returns all methods that are valid for
|
methods = adapter.allowed_methods()
|
||||||
# a given path.
|
else:
|
||||||
methods = []
|
# fallback for Werkzeug < 0.7
|
||||||
try:
|
methods = []
|
||||||
_request_ctx_stack.top.url_adapter.match(method='--')
|
try:
|
||||||
except MethodNotAllowed, e:
|
adapter.match(method='--')
|
||||||
methods = e.valid_methods
|
except MethodNotAllowed, e:
|
||||||
except HTTPException, e:
|
methods = e.valid_methods
|
||||||
pass
|
except HTTPException, e:
|
||||||
|
pass
|
||||||
rv = self.response_class()
|
rv = self.response_class()
|
||||||
rv.allow.update(methods)
|
rv.allow.update(methods)
|
||||||
return rv
|
return rv
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue