Merge pull request #2394 from davidism/remove-deprecated
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Remove deprecated code
authored by David Lord · committed by GitHub · parents c5d3f80, 89c8724 · Browse files · 6 files·+61 added−96 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+61 added−96 removed
- tests:+0 added−26 removed
- other:+61 added−70 removed
Provenance
- Commit
4c56477- Tree
871d6c1- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
c5d3f80- Parent 2
89c8724
6 files changed+61 added−96 removed
modified:flask/app.py+31 added-34 removed
347 unmodified lines348 #: Absolute path to the package on the filesystem. Used to look up349 #: resources contained in the package.350 root_path = None351 352- def __init__(self, import_name, static_path=None, static_url_path=None,353- static_folder='static', static_host=None,354- host_matching=False, template_folder='templates',355- instance_path=None, instance_relative_config=False,356- root_path=None):357- _PackageBoundObject.__init__(self, import_name,358- template_folder=template_folder,359- root_path=root_path)360- if static_path is not None:361- from warnings import warn362- warn(DeprecationWarning('static_path is now called '363- 'static_url_path'), stacklevel=2)364- static_url_path = static_path352+ def __init__(353+ self,354+ import_name,355+ static_url_path=None,356+ static_folder='static',357+ static_host=None,358+ host_matching=False,359+ template_folder='templates',360+ instance_path=None,361+ instance_relative_config=False,362+ root_path=None363+ ):364+ _PackageBoundObject.__init__(365+ self,366+ import_name,367+ template_folder=template_folder,368+ root_path=root_path369+ )370 371 if static_url_path is not None:372 self.static_url_path = static_url_path373+374 if static_folder is not None:375 self.static_folder = static_folder376+377 if instance_path is None:378 instance_path = self.auto_find_instance_path()379 elif not os.path.isabs(instance_path):373- raise ValueError('If an instance path is provided it must be '374- 'absolute. A relative path was given instead.')380+ raise ValueError(381+ 'If an instance path is provided it must be absolute.'382+ ' A relative path was given instead.'383+ )384 385 #: Holds the path to the instance folder.386 #:387 #: .. versionadded:: 0.813 unmodified lines401 #: the values are the function objects themselves.402 #: To register a view function, use the :meth:`route` decorator.403 self.view_functions = {}404 396- # support for the now deprecated `error_handlers` attribute. The397- # :attr:`error_handler_spec` shall be used now.398- self._error_handlers = {}399-405 #: A dictionary of all registered error handlers. The key is ``None``406 #: for error handlers active on the application, otherwise the key is407 #: the name of the blueprint. Each key points to another dictionary408 #: where the key is the status code of the http exception. The2 unmodified lines411 #: function.412 #:413 #: To register an error handler, use the :meth:`errorhandler`414 #: decorator.410- self.error_handler_spec = {None: self._error_handlers}415+ self.error_handler_spec = {}416 417 #: A list of functions that are called when :meth:`url_for` raises a418 #: :exc:`~werkzeug.routing.BuildError`. Each function registered here419 #: is called with `error`, `endpoint` and `values`. If a function135 unmodified lines555 # For one, it might be created while the server is running (e.g. during556 # development). Also, Google App Engine stores static files somewhere557 if self.has_static_folder:558 assert bool(static_host) == host_matching, 'Invalid static_host/host_matching combination'554- self.add_url_rule(self.static_url_path + '/<path:filename>',555- endpoint='static', host=static_host,556- view_func=self.send_static_file)559+ self.add_url_rule(560+ self.static_url_path + '/<path:filename>',561+ endpoint='static',562+ host=static_host,563+ view_func=self.send_static_file564+ )565 566 #: The click command line context for this application. Commands567 #: registered here show up in the :command:`flask` command once the568 #: application has been discovered. The default commands are1 unmodified line570 #:571 #: This is an instance of a :class:`click.Group` object.572 self.cli = cli.AppGroup(self.name)573 566- def _get_error_handlers(self):567- from warnings import warn568- warn(DeprecationWarning('error_handlers is deprecated, use the '569- 'new error_handler_spec attribute instead.'), stacklevel=1)570- return self._error_handlers571- def _set_error_handlers(self, value):572- self._error_handlers = value573- self.error_handler_spec[None] = value574- error_handlers = property(_get_error_handlers, _set_error_handlers)575- del _get_error_handlers, _set_error_handlers576-574 @locked_cached_property575 def name(self):576 """The name of the application. This is usually the import name577 with the difference that it's guessed from the run file if the1606 unmodified linesmodified:flask/helpers.py+19 added-19 removed
266 unmodified lines267 :param _method: if provided this explicitly specifies an HTTP method.268 """269 appctx = _app_ctx_stack.top270 reqctx = _request_ctx_stack.top271+272 if appctx is None:272- raise RuntimeError('Attempted to generate a URL without the '273- 'application context being pushed. This has to be '274- 'executed when application context is available.')273+ raise RuntimeError(274+ 'Attempted to generate a URL without the application context being'275+ ' pushed. This has to be executed when application context is'276+ ' available.'277+ )278 279 # If request specific information is available we have some extra280 # features that support "relative" URLs.281 if reqctx is not None:282 url_adapter = reqctx.url_adapter283 blueprint_name = request.blueprint281- if not reqctx.request._is_old_module:282- if endpoint[:1] == '.':283- if blueprint_name is not None:284- endpoint = blueprint_name + endpoint285- else:286- endpoint = endpoint[1:]287- else:288- # TODO: get rid of this deprecated functionality in 1.0289- if '.' not in endpoint:290- if blueprint_name is not None:291- endpoint = blueprint_name + '.' + endpoint292- elif endpoint.startswith('.'):284+285+ if endpoint[:1] == '.':286+ if blueprint_name is not None:287+ endpoint = blueprint_name + endpoint288+ else:289 endpoint = endpoint[1:]290+291 external = values.pop('_external', False)292 293 # Otherwise go with the url adapter from the appctx and make294 # the URLs external by default.295 else:296 url_adapter = appctx.url_adapter297+298 if url_adapter is None:301- raise RuntimeError('Application was not able to create a URL '302- 'adapter for request independent URL generation. '303- 'You might be able to fix this by setting '304- 'the SERVER_NAME config variable.')299+ raise RuntimeError(300+ 'Application was not able to create a URL adapter for request'301+ ' independent URL generation. You might be able to fix this by'302+ ' setting the SERVER_NAME config variable.'303+ )304+305 external = values.pop('_external', True)306 307 anchor = values.pop('_anchor', None)308 method = values.pop('_method', None)711 unmodified linesmodified:flask/wrappers.py-17 removed
139 unmodified lines140 #: usually a :exc:`~werkzeug.exceptions.NotFound` exception or141 #: something similar.142 routing_exception = None143 144- # Switched by the request context until 1.0 to opt in deprecated145- # module functionality.146- _is_old_module = False147-144 @property145 def max_content_length(self):146 """Read-only view of the ``MAX_CONTENT_LENGTH`` config key."""147 if current_app:9 unmodified lines157 if self.url_rule is not None:158 return self.url_rule.endpoint159 160 @property165- def module(self):166- """The name of the current module if the request was dispatched167- to an actual module. This is deprecated functionality, use blueprints168- instead.169- """170- from warnings import warn171- warn(DeprecationWarning('modules were deprecated in favor of '172- 'blueprints. Use request.blueprint '173- 'instead.'), stacklevel=2)174- if self._is_old_module:175- return self.blueprint176-177- @property161 def blueprint(self):162 """The name of the current blueprint"""163 if self.url_rule and '.' in self.url_rule.endpoint:164 return self.url_rule.endpoint.rsplit('.', 1)[0]34 unmodified linesmodified:tests/test_basic.py-13 removed
1351 unmodified lines1352 '/static/index.html'1353 rv.close()1354 1355 1356-def test_static_path_deprecated(recwarn):1357- app = flask.Flask(__name__, static_path='/foo')1358- recwarn.pop(DeprecationWarning)1359-1360- app.testing = True1361- rv = app.test_client().get('/foo/index.html')1362- assert rv.status_code == 2001363- rv.close()1364-1365- with app.test_request_context():1366- assert flask.url_for('static', filename='index.html') == '/foo/index.html'1367-1368-1356 def test_static_url_path():1357 app = flask.Flask(__name__, static_url_path='/foo')1358 app.testing = True1359 rv = app.test_client().get('/foo/index.html')493 unmodified linesmodified:tests/test_deprecations.py-13 removed
7 unmodified lines8 :copyright: (c) 2015 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-import pytest13-12 import flask13 14 15 class TestRequestDeprecation(object):7 unmodified lines23 return 'OK'24 25 client.post('/', data='{"spam": 42}', content_type='application/json')26 recwarn.pop(DeprecationWarning)29-30- def test_request_module(self, recwarn, app, client):31- """Request.module is deprecated"""32-33- @app.route('/')34- def index():35- assert flask.request.module is None36- return 'OK'37-38- client.get('/')39- recwarn.pop(DeprecationWarning)modified:CHANGES+11 added
80 unmodified lines81 exception if you don't want to traverse the MRO. (`#2362`_)82 - Fix incorrect JSON encoding of aware, non-UTC datetimes. (`#2374`_)83 - Template auto reloading will honor the ``run`` command's ``debug`` flag even84 if ``app.jinja_env`` was already accessed. (`#2373`_)85+- The following old deprecated code was removed. (`#2385`_)86 87+ - ``Flask.init_jinja_globals`` - extend ``Flask.create_jinja_environment``88+ instead.89+ - ``Flask.error_handlers`` - tracked by ``Flask.error_handler_spec``,90+ use ``@app.errorhandler`` to register handlers.91+ - ``Flask.request_globals_class`` - use ``Flask.app_ctx_globals_class``92+ instead.93+ - ``Flask.static_path`` - use ``Flask.static_url_path`` instead.94+ - ``Request.module`` - use ``Request.blueprint`` instead.95+96 .. _#1489: https://github.com/pallets/flask/pull/148997 .. _#1621: https://github.com/pallets/flask/pull/162198 .. _#1898: https://github.com/pallets/flask/pull/189899 .. _#1936: https://github.com/pallets/flask/pull/193616 unmodified lines116 .. _#2358: https://github.com/pallets/flask/pull/2358117 .. _#2362: https://github.com/pallets/flask/pull/2362118 .. _#2374: https://github.com/pallets/flask/pull/2374119 .. _#2373: https://github.com/pallets/flask/pull/2373120+.. _#2385: https://github.com/pallets/flask/issues/2385121 122 Version 0.12.2123 --------------124 617 unmodified lines