Removed deprecated module functionality
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 84ad89f · Browse files · 17 files·+2 added−453 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
17 files+2 added−453 removed
- other:+2 added−453 removed
Provenance
- Commit
817b72d- Tree
fcb1e98- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
84ad89f
17 files changed+2 added−453 removed
deleted:flask/testsuite/test_apps/moduleapp/apps/admin/static/css/test.css-1 removed
1/* nested file */deleted:flask/testsuite/test_apps/moduleapp/apps/admin/static/test.txt-1 removed
1-Admin Filedeleted:flask/testsuite/test_apps/moduleapp/apps/admin/templates/index.html-1 removed
1Hello from the Admindeleted:flask/testsuite/test_apps/moduleapp/apps/admin/__init__.py-14 removed
1-from flask import Module, render_template2-3-4-admin = Module(__name__, url_prefix='/admin')5-6-7-@admin.route('/')8-def index():9- return render_template('admin/index.html')10-11-12-@admin.route('/index2')13-def index2():14- return render_template('./admin/index.html')deleted:flask/testsuite/test_apps/moduleapp/apps/frontend/templates/index.html-1 removed
1Hello from the Frontenddeleted:flask/testsuite/test_apps/moduleapp/apps/frontend/__init__.py-9 removed
1-from flask import Module, render_template2-3-4-frontend = Module(__name__)5-6-7-@frontend.route('/')8-def index():9- return render_template('frontend/index.html')deleted:flask/testsuite/test_apps/moduleapp/apps/__init__.py
deleted:flask/testsuite/test_apps/moduleapp/__init__.py-7 removed
1-from flask import Flask2-3-app = Flask(__name__)4-from moduleapp.apps.admin import admin5-from moduleapp.apps.frontend import frontend6-app.register_module(admin)7-app.register_module(frontend)modified:flask/testsuite/basic.py-34 removed
1303 unmodified lines1304 1305 rv = c.get('/', 'http://test.localhost/')1306 self.assert_equal(rv.data, b'test index')1307 1308- @emits_module_deprecation_warning1309- def test_module_static_path_subdomain(self):1310- app = flask.Flask(__name__)1311- app.config['SERVER_NAME'] = 'example.com'1312- from subdomaintestmodule import mod1313- app.register_module(mod)1314- c = app.test_client()1315- rv = c.get('/static/hello.txt', 'http://foo.example.com/')1316- rv.direct_passthrough = False1317- self.assert_equal(rv.data.strip(), b'Hello Subdomain')1318- rv.close()1319-1308 def test_subdomain_matching(self):1309 app = flask.Flask(__name__)1310 app.config['SERVER_NAME'] = 'localhost'1311 @app.route('/', subdomain='<user>')14 unmodified lines1326 c = app.test_client()1327 rv = c.get('/', 'http://mitsuhiko.localhost:3000/')1328 self.assert_equal(rv.data, b'index for mitsuhiko')1329 1342- @emits_module_deprecation_warning1343- def test_module_subdomain_support(self):1344- app = flask.Flask(__name__)1345- mod = flask.Module(__name__, 'test', subdomain='testing')1346- app.config['SERVER_NAME'] = 'localhost'1347-1348- @mod.route('/test')1349- def test():1350- return 'Test'1351-1352- @mod.route('/outside', subdomain='xtesting')1353- def bar():1354- return 'Outside'1355-1356- app.register_module(mod)1357-1358- c = app.test_client()1359- rv = c.get('/test', 'http://testing.localhost/')1360- self.assert_equal(rv.data, b'Test')1361- rv = c.get('/outside', 'http://xtesting.localhost/')1362- self.assert_equal(rv.data, b'Outside')1363-1330 def test_multi_route_rules(self):1331 app = flask.Flask(__name__)1332 1333 @app.route('/')31 unmodified linesmodified:flask/testsuite/blueprints.py+1 added-240 removed
9 unmodified lines10 """11 12 import flask13 import unittest14-import warnings15-from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning14+from flask.testsuite import FlaskTestCase15 from flask._compat import text_type17-from werkzeug.exceptions import NotFound16 from werkzeug.http import parse_cache_control_header17 from jinja2 import TemplateNotFound18 19 22-# import moduleapp here because it uses deprecated features and we don't23-# want to see the warnings24-warnings.simplefilter('ignore', DeprecationWarning)25-from moduleapp import app as moduleapp26-warnings.simplefilter('default', DeprecationWarning)27-28-29-class ModuleTestCase(FlaskTestCase):30-31- @emits_module_deprecation_warning32- def test_basic_module(self):33- app = flask.Flask(__name__)34- admin = flask.Module(__name__, 'admin', url_prefix='/admin')35- @admin.route('/')36- def admin_index():37- return 'admin index'38- @admin.route('/login')39- def admin_login():40- return 'admin login'41- @admin.route('/logout')42- def admin_logout():43- return 'admin logout'44- @app.route('/')45- def index():46- return 'the index'47- app.register_module(admin)48- c = app.test_client()49- self.assert_equal(c.get('/').data, b'the index')50- self.assert_equal(c.get('/admin/').data, b'admin index')51- self.assert_equal(c.get('/admin/login').data, b'admin login')52- self.assert_equal(c.get('/admin/logout').data, b'admin logout')53-54- @emits_module_deprecation_warning55- def test_default_endpoint_name(self):56- app = flask.Flask(__name__)57- mod = flask.Module(__name__, 'frontend')58- def index():59- return 'Awesome'60- mod.add_url_rule('/', view_func=index)61- app.register_module(mod)62- rv = app.test_client().get('/')63- self.assert_equal(rv.data, b'Awesome')64- with app.test_request_context():65- self.assert_equal(flask.url_for('frontend.index'), '/')66-67- @emits_module_deprecation_warning68- def test_request_processing(self):69- catched = []70- app = flask.Flask(__name__)71- admin = flask.Module(__name__, 'admin', url_prefix='/admin')72- @admin.before_request73- def before_admin_request():74- catched.append('before-admin')75- @admin.after_request76- def after_admin_request(response):77- catched.append('after-admin')78- return response79- @admin.route('/')80- def admin_index():81- return 'the admin'82- @app.before_request83- def before_request():84- catched.append('before-app')85- @app.after_request86- def after_request(response):87- catched.append('after-app')88- return response89- @app.route('/')90- def index():91- return 'the index'92- app.register_module(admin)93- c = app.test_client()94-95- self.assert_equal(c.get('/').data, b'the index')96- self.assert_equal(catched, ['before-app', 'after-app'])97- del catched[:]98-99- self.assert_equal(c.get('/admin/').data, b'the admin')100- self.assert_equal(catched, ['before-app', 'before-admin',101- 'after-admin', 'after-app'])102-103- @emits_module_deprecation_warning104- def test_context_processors(self):105- app = flask.Flask(__name__)106- admin = flask.Module(__name__, 'admin', url_prefix='/admin')107- @app.context_processor108- def inject_all_regular():109- return {'a': 1}110- @admin.context_processor111- def inject_admin():112- return {'b': 2}113- @admin.app_context_processor114- def inject_all_module():115- return {'c': 3}116- @app.route('/')117- def index():118- return flask.render_template_string('{{ a }}{{ b }}{{ c }}')119- @admin.route('/')120- def admin_index():121- return flask.render_template_string('{{ a }}{{ b }}{{ c }}')122- app.register_module(admin)123- c = app.test_client()124- self.assert_equal(c.get('/').data, b'13')125- self.assert_equal(c.get('/admin/').data, b'123')126-127- @emits_module_deprecation_warning128- def test_late_binding(self):129- app = flask.Flask(__name__)130- admin = flask.Module(__name__, 'admin')131- @admin.route('/')132- def index():133- return '42'134- app.register_module(admin, url_prefix='/admin')135- self.assert_equal(app.test_client().get('/admin/').data, b'42')136-137- @emits_module_deprecation_warning138- def test_error_handling(self):139- app = flask.Flask(__name__)140- app.config['LOGGER_HANDLER_POLICY'] = 'never'141- admin = flask.Module(__name__, 'admin')142- @admin.app_errorhandler(404)143- def not_found(e):144- return 'not found', 404145- @admin.app_errorhandler(500)146- def internal_server_error(e):147- return 'internal server error', 500148- @admin.route('/')149- def index():150- flask.abort(404)151- @admin.route('/error')152- def error():153- 1 // 0154- app.register_module(admin)155- c = app.test_client()156- rv = c.get('/')157- self.assert_equal(rv.status_code, 404)158- self.assert_equal(rv.data, b'not found')159- rv = c.get('/error')160- self.assert_equal(rv.status_code, 500)161- self.assert_equal(b'internal server error', rv.data)162-163- def test_templates_and_static(self):164- app = moduleapp165- app.testing = True166- c = app.test_client()167-168- rv = c.get('/')169- self.assert_equal(rv.data, b'Hello from the Frontend')170- rv = c.get('/admin/')171- self.assert_equal(rv.data, b'Hello from the Admin')172- rv = c.get('/admin/index2')173- self.assert_equal(rv.data, b'Hello from the Admin')174- rv = c.get('/admin/static/test.txt')175- self.assert_equal(rv.data.strip(), b'Admin File')176- rv.close()177- rv = c.get('/admin/static/css/test.css')178- self.assert_equal(rv.data.strip(), b'/* nested file */')179- rv.close()180-181- with app.test_request_context():182- self.assert_equal(flask.url_for('admin.static', filename='test.txt'),183- '/admin/static/test.txt')184-185- with app.test_request_context():186- try:187- flask.render_template('missing.html')188- except TemplateNotFound as e:189- self.assert_equal(e.name, 'missing.html')190- else:191- self.assert_true(0, 'expected exception')192-193- with flask.Flask(__name__).test_request_context():194- self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')195-196- def test_safe_access(self):197- app = moduleapp198-199- with app.test_request_context():200- f = app.view_functions['admin.static']201-202- try:203- f('/etc/passwd')204- except NotFound:205- pass206- else:207- self.assert_true(0, 'expected exception')208- try:209- f('../__init__.py')210- except NotFound:211- pass212- else:213- self.assert_true(0, 'expected exception')214-215- # testcase for a security issue that may exist on windows systems216- import os217- import ntpath218- old_path = os.path219- os.path = ntpath220- try:221- try:222- f('..\\__init__.py')223- except NotFound:224- pass225- else:226- self.assert_true(0, 'expected exception')227- finally:228- os.path = old_path229-230- @emits_module_deprecation_warning231- def test_endpoint_decorator(self):232- from werkzeug.routing import Submount, Rule233- from flask import Module234-235- app = flask.Flask(__name__)236- app.testing = True237- app.url_map.add(Submount('/foo', [238- Rule('/bar', endpoint='bar'),239- Rule('/', endpoint='index')240- ]))241- module = Module(__name__, __name__)242-243- @module.endpoint('bar')244- def bar():245- return 'bar'246-247- @module.endpoint('index')248- def index():249- return 'index'250-251- app.register_module(module)252-253- c = app.test_client()254- self.assert_equal(c.get('/foo/').data, b'index')255- self.assert_equal(c.get('/foo/bar').data, b'bar')256-257-20 class BlueprintTestCase(FlaskTestCase):21 22 def test_blueprint_specific_error_handling(self):23 frontend = flask.Blueprint('frontend', __name__)557 unmodified lines581 582 def suite():583 suite = unittest.TestSuite()584 suite.addTest(unittest.makeSuite(BlueprintTestCase))823- suite.addTest(unittest.makeSuite(ModuleTestCase))585 return suitemodified:flask/__init__.py-1 removed
25 unmodified lines26 from .globals import current_app, g, request, session, _request_ctx_stack, \27 _app_ctx_stack28 from .ctx import has_request_context, has_app_context, \29 after_this_request, copy_current_request_context30-from .module import Module30 from .blueprints import Blueprint31 from .templating import render_template, render_template_string32 33 # the signals16 unmodified linesmodified:flask/app.py-32 removed
27 unmodified lines28 from .config import ConfigAttribute, Config29 from .ctx import RequestContext, AppContext, _AppCtxGlobals30 from .globals import _request_ctx_stack, request, session, g31 from .sessions import SecureCookieSessionInterface32-from .module import blueprint_is_module32 from .templating import DispatchingJinjaLoader, Environment, \33 _default_template_ctx_processor34 from .signals import request_started, request_finished, got_request_exception, \35 request_tearing_down, appcontext_tearing_down217 unmodified lines253 #:254 #: .. versionadded:: 0.4255 logger_name = ConfigAttribute('LOGGER_NAME')256 258- #: Enable the deprecated module support? This is active by default259- #: in 0.7 but will be changed to False in 0.8. With Flask 1.0 modules260- #: will be removed in favor of Blueprints261- enable_modules = True262-257 #: The JSON encoder class to use. Defaults to :class:`~flask.json.JSONEncoder`.258 #:259 #: .. versionadded:: 0.10260 json_encoder = json.JSONEncoder625 unmodified lines886 .. versionadded:: 0.7887 """888 return self.session_interface.make_null_session(self)889 896- def register_module(self, module, **options):897- """Registers a module with this application. The keyword arguments898- of this function are the same as the ones for the constructor of the899- :class:`Module` class and will override the values of the module if900- provided.901-902- .. versionchanged:: 0.7903- The module system was deprecated in favor for the blueprint904- system.905- """906- assert blueprint_is_module(module), 'register_module requires ' \907- 'actual module objects. Please upgrade to blueprints though.'908- if not self.enable_modules:909- raise RuntimeError('Module support was disabled but code '910- 'attempted to register a module named %r' % module)911- else:912- from warnings import warn913- warn(DeprecationWarning('Modules are deprecated. Upgrade to '914- 'using blueprints. Have a look into the documentation for '915- 'more information. If this module was registered by a '916- 'Flask-Extension upgrade the extension or contact the author '917- 'of that extension instead. (Registered %r)' % module),918- stacklevel=2)919-920- self.register_blueprint(module, **options)921-890 @setupmethod891 def register_blueprint(self, blueprint, **options):892 """Registers a blueprint on the application.893 986 unmodified linesmodified:flask/ctx.py-11 removed
15 unmodified lines16 17 from werkzeug.exceptions import HTTPException18 19 from .globals import _request_ctx_stack, _app_ctx_stack20-from .module import blueprint_is_module20 from .signals import appcontext_pushed, appcontext_popped21 from ._compat import BROKEN_PYPY_CTXMGR_EXIT, reraise22 23 226 unmodified lines250 self._after_request_functions = []251 252 self.match_request()253 255- # XXX: Support for deprecated functionality. This is going away with256- # Flask 1.0257- blueprint = self.request.blueprint258- if blueprint is not None:259- # better safe than sorry, we don't want to break code that260- # already worked261- bp = app.blueprints.get(blueprint)262- if bp is not None and blueprint_is_module(bp):263- self.request._is_old_module = True264-254 def _get_g(self):255 return _app_ctx_stack.top.g256 def _set_g(self, value):257 _app_ctx_stack.top.g = value138 unmodified linesdeleted:flask/module.py-42 removed
1-# -*- coding: utf-8 -*-2-"""3- flask.module4- ~~~~~~~~~~~~5-6- Implements a class that represents module blueprints.7-8- :copyright: (c) 2014 by Armin Ronacher.9- :license: BSD, see LICENSE for more details.10-"""11-12-import os13-14-from .blueprints import Blueprint15-16-17-def blueprint_is_module(bp):18- """Used to figure out if something is actually a module"""19- return isinstance(bp, Module)20-21-22-class Module(Blueprint):23- """Deprecated module support. Until Flask 0.6 modules were a different24- name of the concept now available as blueprints in Flask. They are25- essentially doing the same but have some bad semantics for templates and26- static files that were fixed with blueprints.27-28- .. versionchanged:: 0.729- Modules were deprecated in favor for blueprints.30- """31-32- def __init__(self, import_name, name=None, url_prefix=None,33- static_path=None, subdomain=None):34- if name is None:35- assert '.' in import_name, 'name required if package name ' \36- 'does not point to a submodule'37- name = import_name.rsplit('.', 1)[1]38- Blueprint.__init__(self, name, import_name, url_prefix=url_prefix,39- subdomain=subdomain, template_folder='templates')40-41- if os.path.isdir(os.path.join(self.root_path, 'static')):42- self._static_folder = 'static'modified:flask/templating.py+1 added-11 removed
12 unmodified lines13 TemplateNotFound14 15 from .globals import _request_ctx_stack, _app_ctx_stack16 from .signals import template_rendered17-from .module import blueprint_is_module17 from ._compat import itervalues, iteritems18 19 20 def _default_template_ctx_processor():50 unmodified lines71 # blueprint that is an old style module72 try:73 module, local_name = posixpath.normpath(template).split('/', 1)74 blueprint = self.app.blueprints[module]76- if blueprint_is_module(blueprint):77- loader = blueprint.jinja_loader78- if loader is not None:79- yield loader, local_name75 except (ValueError, KeyError):76 pass77 78 for blueprint in itervalues(self.app.blueprints):84- if blueprint_is_module(blueprint):85- continue79 loader = blueprint.jinja_loader80 if loader is not None:81 yield loader, template82 6 unmodified lines89 for name, blueprint in iteritems(self.app.blueprints):90 loader = blueprint.jinja_loader91 if loader is not None:92 for template in loader.list_templates():100- prefix = ''101- if blueprint_is_module(blueprint):102- prefix = name + '/'103- result.add(prefix + template)93+ result.add(template)94 95 return list(result)96 97 36 unmodified linesdeleted:scripts/testproj/templates/index.html-2 removed
1-{{ url_for('static', filename='test.css') }}2-{{ url_for('foo.static', filename='test.css') }}deleted:scripts/testproj/test.py-46 removed
1-from flask import Flask, Module, render_template, url_for2-3-4-mod = Module(__name__)5-mod2 = Module(__name__, 'testmod2')6-mod3 = Module(__name__, name='somemod', subdomain='meh')7-8-9-@app.after_request10-def after_request(response):11- g.db.close()12- return response13-14-15-@app.route('/')16-def index_foo():17- x1 = url_for('somemod.index')18- x2 = url_for('.index')19- return render_template('test/index.html')20-21-22-@mod.route('/')23-def index():24- x1 = url_for('somemod.index')25- x2 = url_for('.index')26- return render_template('test/index.html')27-28-29-@mod2.route('/')30-def mod2_index():31- return render_template('testmod2/index.html')32-33-34-@mod3.route('/')35-def mod3_index():36- return render_template('something-else/index.html')37-38-39-app = Flask(__name__)40-app.register_module(mod)41-app.register_module(mod2)42-43-44-def handle_404(error):45- return 'Testing', 40446-app.error_handlers[404] = handle_404