forked from orbit-oss/flask
remove deprecated Request.module
This commit is contained in:
parent
d63c2bc417
commit
723e665004
3 changed files with 19 additions and 49 deletions
|
|
@ -268,40 +268,40 @@ def url_for(endpoint, **values):
|
||||||
"""
|
"""
|
||||||
appctx = _app_ctx_stack.top
|
appctx = _app_ctx_stack.top
|
||||||
reqctx = _request_ctx_stack.top
|
reqctx = _request_ctx_stack.top
|
||||||
|
|
||||||
if appctx is None:
|
if appctx is None:
|
||||||
raise RuntimeError('Attempted to generate a URL without the '
|
raise RuntimeError(
|
||||||
'application context being pushed. This has to be '
|
'Attempted to generate a URL without the application context being'
|
||||||
'executed when application context is available.')
|
' pushed. This has to be executed when application context is'
|
||||||
|
' available.'
|
||||||
|
)
|
||||||
|
|
||||||
# If request specific information is available we have some extra
|
# If request specific information is available we have some extra
|
||||||
# features that support "relative" URLs.
|
# features that support "relative" URLs.
|
||||||
if reqctx is not None:
|
if reqctx is not None:
|
||||||
url_adapter = reqctx.url_adapter
|
url_adapter = reqctx.url_adapter
|
||||||
blueprint_name = request.blueprint
|
blueprint_name = request.blueprint
|
||||||
if not reqctx.request._is_old_module:
|
|
||||||
if endpoint[:1] == '.':
|
if endpoint[:1] == '.':
|
||||||
if blueprint_name is not None:
|
if blueprint_name is not None:
|
||||||
endpoint = blueprint_name + endpoint
|
endpoint = blueprint_name + endpoint
|
||||||
else:
|
else:
|
||||||
endpoint = endpoint[1:]
|
|
||||||
else:
|
|
||||||
# TODO: get rid of this deprecated functionality in 1.0
|
|
||||||
if '.' not in endpoint:
|
|
||||||
if blueprint_name is not None:
|
|
||||||
endpoint = blueprint_name + '.' + endpoint
|
|
||||||
elif endpoint.startswith('.'):
|
|
||||||
endpoint = endpoint[1:]
|
endpoint = endpoint[1:]
|
||||||
|
|
||||||
external = values.pop('_external', False)
|
external = values.pop('_external', False)
|
||||||
|
|
||||||
# Otherwise go with the url adapter from the appctx and make
|
# Otherwise go with the url adapter from the appctx and make
|
||||||
# the URLs external by default.
|
# the URLs external by default.
|
||||||
else:
|
else:
|
||||||
url_adapter = appctx.url_adapter
|
url_adapter = appctx.url_adapter
|
||||||
|
|
||||||
if url_adapter is None:
|
if url_adapter is None:
|
||||||
raise RuntimeError('Application was not able to create a URL '
|
raise RuntimeError(
|
||||||
'adapter for request independent URL generation. '
|
'Application was not able to create a URL adapter for request'
|
||||||
'You might be able to fix this by setting '
|
' independent URL generation. You might be able to fix this by'
|
||||||
'the SERVER_NAME config variable.')
|
' setting the SERVER_NAME config variable.'
|
||||||
|
)
|
||||||
|
|
||||||
external = values.pop('_external', True)
|
external = values.pop('_external', True)
|
||||||
|
|
||||||
anchor = values.pop('_anchor', None)
|
anchor = values.pop('_anchor', None)
|
||||||
|
|
|
||||||
|
|
@ -141,10 +141,6 @@ class Request(RequestBase, JSONMixin):
|
||||||
#: something similar.
|
#: something similar.
|
||||||
routing_exception = None
|
routing_exception = None
|
||||||
|
|
||||||
# Switched by the request context until 1.0 to opt in deprecated
|
|
||||||
# module functionality.
|
|
||||||
_is_old_module = False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_content_length(self):
|
def max_content_length(self):
|
||||||
"""Read-only view of the ``MAX_CONTENT_LENGTH`` config key."""
|
"""Read-only view of the ``MAX_CONTENT_LENGTH`` config key."""
|
||||||
|
|
@ -161,19 +157,6 @@ class Request(RequestBase, JSONMixin):
|
||||||
if self.url_rule is not None:
|
if self.url_rule is not None:
|
||||||
return self.url_rule.endpoint
|
return self.url_rule.endpoint
|
||||||
|
|
||||||
@property
|
|
||||||
def module(self):
|
|
||||||
"""The name of the current module if the request was dispatched
|
|
||||||
to an actual module. This is deprecated functionality, use blueprints
|
|
||||||
instead.
|
|
||||||
"""
|
|
||||||
from warnings import warn
|
|
||||||
warn(DeprecationWarning('modules were deprecated in favor of '
|
|
||||||
'blueprints. Use request.blueprint '
|
|
||||||
'instead.'), stacklevel=2)
|
|
||||||
if self._is_old_module:
|
|
||||||
return self.blueprint
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def blueprint(self):
|
def blueprint(self):
|
||||||
"""The name of the current blueprint"""
|
"""The name of the current blueprint"""
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@
|
||||||
:license: BSD, see LICENSE for more details.
|
:license: BSD, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -26,14 +24,3 @@ class TestRequestDeprecation(object):
|
||||||
|
|
||||||
client.post('/', data='{"spam": 42}', content_type='application/json')
|
client.post('/', data='{"spam": 42}', content_type='application/json')
|
||||||
recwarn.pop(DeprecationWarning)
|
recwarn.pop(DeprecationWarning)
|
||||||
|
|
||||||
def test_request_module(self, recwarn, app, client):
|
|
||||||
"""Request.module is deprecated"""
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def index():
|
|
||||||
assert flask.request.module is None
|
|
||||||
return 'OK'
|
|
||||||
|
|
||||||
client.get('/')
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue