make_default_options_response now tries to use Werkzeug 0.7 functionality before falling back.

This commit is contained in:
Armin Ronacher 2011-08-26 14:05:08 +01:00
parent d49221bf2e
commit b256e9f36c

View file

@ -1305,13 +1305,14 @@ 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:
# fallback for Werkzeug < 0.7
methods = [] methods = []
try: try:
_request_ctx_stack.top.url_adapter.match(method='--') adapter.match(method='--')
except MethodNotAllowed, e: except MethodNotAllowed, e:
methods = e.valid_methods methods = e.valid_methods
except HTTPException, e: except HTTPException, e: