Browse Source

Merge pull request #2394 from davidism/remove-deprecated

Remove deprecated code
pull/2395/head
David Lord 7 years ago committed by GitHub
parent
commit
4c564779d1
  1. 11
      CHANGES
  2. 65
      flask/app.py
  3. 38
      flask/helpers.py
  4. 17
      flask/wrappers.py
  5. 13
      tests/test_basic.py
  6. 13
      tests/test_deprecations.py

11
CHANGES

@ -82,6 +82,16 @@ Major release, unreleased
- Fix incorrect JSON encoding of aware, non-UTC datetimes. (`#2374`_) - Fix incorrect JSON encoding of aware, non-UTC datetimes. (`#2374`_)
- Template auto reloading will honor the ``run`` command's ``debug`` flag even - Template auto reloading will honor the ``run`` command's ``debug`` flag even
if ``app.jinja_env`` was already accessed. (`#2373`_) if ``app.jinja_env`` was already accessed. (`#2373`_)
- The following old deprecated code was removed. (`#2385`_)
- ``Flask.init_jinja_globals`` - extend ``Flask.create_jinja_environment``
instead.
- ``Flask.error_handlers`` - tracked by ``Flask.error_handler_spec``,
use ``@app.errorhandler`` to register handlers.
- ``Flask.request_globals_class`` - use ``Flask.app_ctx_globals_class``
instead.
- ``Flask.static_path`` - use ``Flask.static_url_path`` instead.
- ``Request.module`` - use ``Request.blueprint`` instead.
.. _#1489: https://github.com/pallets/flask/pull/1489 .. _#1489: https://github.com/pallets/flask/pull/1489
.. _#1621: https://github.com/pallets/flask/pull/1621 .. _#1621: https://github.com/pallets/flask/pull/1621
@ -107,6 +117,7 @@ Major release, unreleased
.. _#2362: https://github.com/pallets/flask/pull/2362 .. _#2362: https://github.com/pallets/flask/pull/2362
.. _#2374: https://github.com/pallets/flask/pull/2374 .. _#2374: https://github.com/pallets/flask/pull/2374
.. _#2373: https://github.com/pallets/flask/pull/2373 .. _#2373: https://github.com/pallets/flask/pull/2373
.. _#2385: https://github.com/pallets/flask/issues/2385
Version 0.12.2 Version 0.12.2
-------------- --------------

65
flask/app.py

@ -349,29 +349,38 @@ class Flask(_PackageBoundObject):
#: resources contained in the package. #: resources contained in the package.
root_path = None root_path = None
def __init__(self, import_name, static_path=None, static_url_path=None, def __init__(
static_folder='static', static_host=None, self,
host_matching=False, template_folder='templates', import_name,
instance_path=None, instance_relative_config=False, static_url_path=None,
root_path=None): static_folder='static',
_PackageBoundObject.__init__(self, import_name, static_host=None,
template_folder=template_folder, host_matching=False,
root_path=root_path) template_folder='templates',
if static_path is not None: instance_path=None,
from warnings import warn instance_relative_config=False,
warn(DeprecationWarning('static_path is now called ' root_path=None
'static_url_path'), stacklevel=2) ):
static_url_path = static_path _PackageBoundObject.__init__(
self,
import_name,
template_folder=template_folder,
root_path=root_path
)
if static_url_path is not None: if static_url_path is not None:
self.static_url_path = static_url_path self.static_url_path = static_url_path
if static_folder is not None: if static_folder is not None:
self.static_folder = static_folder self.static_folder = static_folder
if instance_path is None: if instance_path is None:
instance_path = self.auto_find_instance_path() instance_path = self.auto_find_instance_path()
elif not os.path.isabs(instance_path): elif not os.path.isabs(instance_path):
raise ValueError('If an instance path is provided it must be ' raise ValueError(
'absolute. A relative path was given instead.') 'If an instance path is provided it must be absolute.'
' A relative path was given instead.'
)
#: Holds the path to the instance folder. #: Holds the path to the instance folder.
#: #:
@ -393,10 +402,6 @@ class Flask(_PackageBoundObject):
#: To register a view function, use the :meth:`route` decorator. #: To register a view function, use the :meth:`route` decorator.
self.view_functions = {} self.view_functions = {}
# support for the now deprecated `error_handlers` attribute. The
# :attr:`error_handler_spec` shall be used now.
self._error_handlers = {}
#: A dictionary of all registered error handlers. The key is ``None`` #: A dictionary of all registered error handlers. The key is ``None``
#: for error handlers active on the application, otherwise the key is #: for error handlers active on the application, otherwise the key is
#: the name of the blueprint. Each key points to another dictionary #: the name of the blueprint. Each key points to another dictionary
@ -407,7 +412,7 @@ class Flask(_PackageBoundObject):
#: #:
#: To register an error handler, use the :meth:`errorhandler` #: To register an error handler, use the :meth:`errorhandler`
#: decorator. #: decorator.
self.error_handler_spec = {None: self._error_handlers} self.error_handler_spec = {}
#: A list of functions that are called when :meth:`url_for` raises a #: A list of functions that are called when :meth:`url_for` raises a
#: :exc:`~werkzeug.routing.BuildError`. Each function registered here #: :exc:`~werkzeug.routing.BuildError`. Each function registered here
@ -551,9 +556,12 @@ class Flask(_PackageBoundObject):
# development). Also, Google App Engine stores static files somewhere # development). Also, Google App Engine stores static files somewhere
if self.has_static_folder: if self.has_static_folder:
assert bool(static_host) == host_matching, 'Invalid static_host/host_matching combination' assert bool(static_host) == host_matching, 'Invalid static_host/host_matching combination'
self.add_url_rule(self.static_url_path + '/<path:filename>', self.add_url_rule(
endpoint='static', host=static_host, self.static_url_path + '/<path:filename>',
view_func=self.send_static_file) endpoint='static',
host=static_host,
view_func=self.send_static_file
)
#: The click command line context for this application. Commands #: The click command line context for this application. Commands
#: registered here show up in the :command:`flask` command once the #: registered here show up in the :command:`flask` command once the
@ -563,17 +571,6 @@ class Flask(_PackageBoundObject):
#: This is an instance of a :class:`click.Group` object. #: This is an instance of a :class:`click.Group` object.
self.cli = cli.AppGroup(self.name) self.cli = cli.AppGroup(self.name)
def _get_error_handlers(self):
from warnings import warn
warn(DeprecationWarning('error_handlers is deprecated, use the '
'new error_handler_spec attribute instead.'), stacklevel=1)
return self._error_handlers
def _set_error_handlers(self, value):
self._error_handlers = value
self.error_handler_spec[None] = value
error_handlers = property(_get_error_handlers, _set_error_handlers)
del _get_error_handlers, _set_error_handlers
@locked_cached_property @locked_cached_property
def name(self): def name(self):
"""The name of the application. This is usually the import name """The name of the application. This is usually the import name

38
flask/helpers.py

@ -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)

17
flask/wrappers.py

@ -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"""

13
tests/test_basic.py

@ -1353,19 +1353,6 @@ def test_static_files(app, client):
rv.close() rv.close()
def test_static_path_deprecated(recwarn):
app = flask.Flask(__name__, static_path='/foo')
recwarn.pop(DeprecationWarning)
app.testing = True
rv = app.test_client().get('/foo/index.html')
assert rv.status_code == 200
rv.close()
with app.test_request_context():
assert flask.url_for('static', filename='index.html') == '/foo/index.html'
def test_static_url_path(): def test_static_url_path():
app = flask.Flask(__name__, static_url_path='/foo') app = flask.Flask(__name__, static_url_path='/foo')
app.testing = True app.testing = True

13
tests/test_deprecations.py

@ -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…
Cancel
Save