Skip to content
Myr

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

17 files+2 added−453 removed

deleted:flask/testsuite/test_apps/moduleapp/apps/admin/static/css/test.css-1 removed
deleted:flask/testsuite/test_apps/moduleapp/apps/admin/static/test.txt-1 removed
1Admin File
deleted:flask/testsuite/test_apps/moduleapp/apps/admin/templates/index.html-1 removed
deleted:flask/testsuite/test_apps/moduleapp/apps/admin/__init__.py-14 removed
1from flask import Module, render_template234admin = Module(__name__, url_prefix='/admin')567@admin.route('/')8def index():9 return render_template('admin/index.html')101112@admin.route('/index2')13def index2():14 return render_template('./admin/index.html')
deleted:flask/testsuite/test_apps/moduleapp/apps/frontend/templates/index.html-1 removed
deleted:flask/testsuite/test_apps/moduleapp/apps/frontend/__init__.py-9 removed
1from flask import Module, render_template234frontend = Module(__name__)567@frontend.route('/')8def 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
1from flask import Flask23app = Flask(__name__)4from moduleapp.apps.admin import admin5from moduleapp.apps.frontend import frontend6app.register_module(admin)7app.register_module(frontend)
modified:flask/testsuite/basic.py-34 removed
1303 unmodified lines
13041305 rv = c.get('/', 'http://test.localhost/')1306 self.assert_equal(rv.data, b'test index')13071308 @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()13191308 def test_subdomain_matching(self):1309 app = flask.Flask(__name__)1310 app.config['SERVER_NAME'] = 'localhost'1311 @app.route('/', subdomain='<user>')
14 unmodified lines
1326 c = app.test_client()1327 rv = c.get('/', 'http://mitsuhiko.localhost:3000/')1328 self.assert_equal(rv.data, b'index for mitsuhiko')13291342 @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'13471348 @mod.route('/test')1349 def test():1350 return 'Test'13511352 @mod.route('/outside', subdomain='xtesting')1353 def bar():1354 return 'Outside'13551356 app.register_module(mod)13571358 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')13631330 def test_multi_route_rules(self):1331 app = flask.Flask(__name__)13321333 @app.route('/')
31 unmodified lines
modified:flask/testsuite/blueprints.py+1 added-240 removed
9 unmodified lines
10"""1112import flask13import unittest14import warnings15from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning14from flask.testsuite import FlaskTestCase15from flask._compat import text_type17from werkzeug.exceptions import NotFound16from werkzeug.http import parse_cache_control_header17from jinja2 import TemplateNotFound181922# import moduleapp here because it uses deprecated features and we don't23# want to see the warnings24warnings.simplefilter('ignore', DeprecationWarning)25from moduleapp import app as moduleapp26warnings.simplefilter('default', DeprecationWarning)272829class ModuleTestCase(FlaskTestCase):3031 @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')5354 @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'), '/')6667 @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()9495 self.assert_equal(c.get('/').data, b'the index')96 self.assert_equal(catched, ['before-app', 'after-app'])97 del catched[:]9899 self.assert_equal(c.get('/admin/').data, b'the admin')100 self.assert_equal(catched, ['before-app', 'before-admin',101 'after-admin', 'after-app'])102103 @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')126127 @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')136137 @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)162163 def test_templates_and_static(self):164 app = moduleapp165 app.testing = True166 c = app.test_client()167168 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()180181 with app.test_request_context():182 self.assert_equal(flask.url_for('admin.static', filename='test.txt'),183 '/admin/static/test.txt')184185 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')192193 with flask.Flask(__name__).test_request_context():194 self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')195196 def test_safe_access(self):197 app = moduleapp198199 with app.test_request_context():200 f = app.view_functions['admin.static']201202 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')214215 # 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_path229230 @emits_module_deprecation_warning231 def test_endpoint_decorator(self):232 from werkzeug.routing import Submount, Rule233 from flask import Module234235 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__)242243 @module.endpoint('bar')244 def bar():245 return 'bar'246247 @module.endpoint('index')248 def index():249 return 'index'250251 app.register_module(module)252253 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')25625720class BlueprintTestCase(FlaskTestCase):2122 def test_blueprint_specific_error_handling(self):23 frontend = flask.Blueprint('frontend', __name__)
557 unmodified lines
581582def suite():583 suite = unittest.TestSuite()584 suite.addTest(unittest.makeSuite(BlueprintTestCase))823 suite.addTest(unittest.makeSuite(ModuleTestCase))585 return suite
modified:flask/__init__.py-1 removed
25 unmodified lines
26from .globals import current_app, g, request, session, _request_ctx_stack, \27 _app_ctx_stack28from .ctx import has_request_context, has_app_context, \29 after_this_request, copy_current_request_context30from .module import Module30from .blueprints import Blueprint31from .templating import render_template, render_template_string3233# the signals
16 unmodified lines
modified:flask/app.py-32 removed
27 unmodified lines
28from .config import ConfigAttribute, Config29from .ctx import RequestContext, AppContext, _AppCtxGlobals30from .globals import _request_ctx_stack, request, session, g31from .sessions import SecureCookieSessionInterface32from .module import blueprint_is_module32from .templating import DispatchingJinjaLoader, Environment, \33 _default_template_ctx_processor34from .signals import request_started, request_finished, got_request_exception, \35 request_tearing_down, appcontext_tearing_down
217 unmodified lines
253 #:254 #: .. versionadded:: 0.4255 logger_name = ConfigAttribute('LOGGER_NAME')256258 #: 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 = True262257 #: The JSON encoder class to use. Defaults to :class:`~flask.json.JSONEncoder`.258 #:259 #: .. versionadded:: 0.10260 json_encoder = json.JSONEncoder
625 unmodified lines
886 .. versionadded:: 0.7887 """888 return self.session_interface.make_null_session(self)889896 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.901902 .. 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)919920 self.register_blueprint(module, **options)921890 @setupmethod891 def register_blueprint(self, blueprint, **options):892 """Registers a blueprint on the application.893
986 unmodified lines
modified:flask/ctx.py-11 removed
15 unmodified lines
1617from werkzeug.exceptions import HTTPException1819from .globals import _request_ctx_stack, _app_ctx_stack20from .module import blueprint_is_module20from .signals import appcontext_pushed, appcontext_popped21from ._compat import BROKEN_PYPY_CTXMGR_EXIT, reraise2223
226 unmodified lines
250 self._after_request_functions = []251252 self.match_request()253255 # 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 = True264254 def _get_g(self):255 return _app_ctx_stack.top.g256 def _set_g(self, value):257 _app_ctx_stack.top.g = value
138 unmodified lines
deleted:flask/module.py-42 removed
1# -*- coding: utf-8 -*-2"""3 flask.module4 ~~~~~~~~~~~~56 Implements a class that represents module blueprints.78 :copyright: (c) 2014 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import os1314from .blueprints import Blueprint151617def blueprint_is_module(bp):18 """Used to figure out if something is actually a module"""19 return isinstance(bp, Module)202122class 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.2728 .. versionchanged:: 0.729 Modules were deprecated in favor for blueprints.30 """3132 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')4041 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 lines
13 TemplateNotFound1415from .globals import _request_ctx_stack, _app_ctx_stack16from .signals import template_rendered17from .module import blueprint_is_module17from ._compat import itervalues, iteritems181920def _default_template_ctx_processor():
50 unmodified lines
71 # 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 pass7778 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 lines
89 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)9495 return list(result)9697
36 unmodified lines
deleted: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
1from flask import Flask, Module, render_template, url_for234mod = Module(__name__)5mod2 = Module(__name__, 'testmod2')6mod3 = Module(__name__, name='somemod', subdomain='meh')789@app.after_request10def after_request(response):11 g.db.close()12 return response131415@app.route('/')16def index_foo():17 x1 = url_for('somemod.index')18 x2 = url_for('.index')19 return render_template('test/index.html')202122@mod.route('/')23def index():24 x1 = url_for('somemod.index')25 x2 = url_for('.index')26 return render_template('test/index.html')272829@mod2.route('/')30def mod2_index():31 return render_template('testmod2/index.html')323334@mod3.route('/')35def mod3_index():36 return render_template('something-else/index.html')373839app = Flask(__name__)40app.register_module(mod)41app.register_module(mod2)424344def handle_404(error):45 return 'Testing', 40446app.error_handlers[404] = handle_404