Skip to content
Myr

Latest iteration of the blueprint code. Far from being done

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 673fa18 · Browse files · 8 files+304 added−274 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+304 added−274 removed

  • tests:+1 added−0 removed
  • other:+303 added−274 removed

8 files+304 added−274 removed

modified:flask/app.py+42 added-41 removed
26 unmodified lines
27from .config import ConfigAttribute, Config28from .ctx import RequestContext29from .globals import _request_ctx_stack, request30from .session import Session, _NullSession31from .module import _ModuleSetupState31from .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
66 unmodified lines
102 #: The class that is used for response objects. See103 #: :class:`~flask.Response` for more information.104 response_class = Response105106 #: Path for the static files. If you don't want to use static files107 #: you can set this value to `None` in which case no URL rule is added108 #: and the development server will no longer serve any static files.109 #:110 #: This is the default used for application and modules unless a111 #: different value is passed to the constructor.112 static_path = '/static'113106 #: The debug flag. Set this to `True` to enable debugging of the107 #: application. In debug mode the debugger will kick in when an unhandled108 #: exception ocurrs and the integrated server will automatically reload109 #: the application if changes in the code are detected.
94 unmodified lines
204 #:205 #: .. versionadded:: 0.7206 test_client_class = None207216 def __init__(self, import_name, static_path=None):208 def __init__(self, import_name, static_path=None, static_url_path=None,209 static_folder='static'):210 _PackageBoundObject.__init__(self, import_name)211 if static_path is not None:212 from warnings import warn213 warn(DeprecationWarning('static_path is now called '214 'static_url_path'), stacklevel=2)219 self.static_path = static_path215 static_url_path = static_path216217 if static_url_path is not None:218 self.static_url_path = static_url_path219 if static_folder is not None:220 self.static_folder = static_folder221222 #: The configuration dictionary as :class:`Config`. This behaves223 #: exactly like a regular dictionary but supports additional methods224 #: to load a config from files.225 self.config = Config(self.root_path, self.default_config)
16 unmodified lines
242 self.error_handlers = {}243244 #: A dictionary with lists of functions that should be called at the245 #: beginning of the request. The key of the dictionary is the name of245 #: the module this function is active for, `None` for all requests.246 #: the blueprint this function is active for, `None` for all requests.247 #: This can for example be used to open database connections or248 #: getting hold of the currently logged in user. To register a249 #: function here, use the :meth:`before_request` decorator.250 self.before_request_funcs = {}251252 #: A dictionary with lists of functions that should be called after252 #: each request. The key of the dictionary is the name of the module253 #: each request. The key of the dictionary is the name of the blueprint254 #: this function is active for, `None` for all requests. This can for255 #: example be used to open database connections or getting hold of the256 #: currently logged in user. To register a function here, use the257 #: :meth:`after_request` decorator.258 self.after_request_funcs = {}259260 #: A dictionary with lists of functions that are called after261 #: each request, even if an exception has occurred. The key of the261 #: dictionary is the name of the module this function is active for,262 #: dictionary is the name of the blueprint this function is active for,263 #: `None` for all requests. These functions are not allowed to modify264 #: the request, and their return values are ignored. If an exception265 #: occurred while processing the request, it gets passed to each266 #: teardown_request function. To register a function here, use the
3 unmodified lines
270 self.teardown_request_funcs = {}271272 #: A dictionary with list of functions that are called without argument273 #: to populate the template context. The key of the dictionary is the273 #: name of the module this function is active for, `None` for all274 #: name of the blueprint this function is active for, `None` for all275 #: requests. Each returns a dictionary that the template context is276 #: updated with. To register a function here, use the277 #: :meth:`context_processor` decorator.278 self.template_context_processors = {279 None: [_default_template_ctx_processor]280 }281281 #: all the loaded modules in a dictionary by name.282 #:283 #: .. versionadded:: 0.5284 self.modules = {}285282 #: all the attached blueprints in a directory by name. Blueprints283 #: can be attached multiple times so this dictionary does not tell284 #: you how often they got attached.285 #:
37 unmodified lines
323 # if the folder does not exist. First of all it might be created324 # while the server is running (usually happens during development)325 # but also because google appengine stores static files somewhere326 # else when mapped with the .yml file.327 if self.has_static_folder:331 self.add_url_rule(self.static_path + '/<path:filename>',332 endpoint='static',333 view_func=self.send_static_file)328 self.add_url_rule(self.static_url_path + '/<path:filename>',329 endpoint='static',330 view_func=self.send_static_file)331332 @property333 def propagate_exceptions(self):334 """Returns the value of the `PROPAGATE_EXCEPTIONS` configuration
117 unmodified lines
452 :param context: the context as a dictionary that is updated in place453 to add extra variables.454 """455 funcs = self.template_context_processors[None]459 mod = _request_ctx_stack.top.request.module460 if mod is not None and mod in self.template_context_processors:461 funcs = chain(funcs, self.template_context_processors[mod])456 bp = _request_ctx_stack.top.request.blueprint457 if bp is not None and bp in self.template_context_processors:458 funcs = chain(funcs, self.template_context_processors[bp])459 orig_ctx = context.copy()460 for func in funcs:461 context.update(func())462 # make sure the original values win. This makes it possible to
98 unmodified lines
561 .. versionchanged:: 0.7562 The module system was deprecated in favor for the blueprint563 system.564 """565 assert blueprint_is_module(module), 'register_module requires ' \566 'actual module objects. Please upgrade to blueprints though.'567 if not self.enable_modules:568 raise RuntimeError('Module support was disabled but code '569 'attempted to register a module named %r' % module)570 else:
4 unmodified lines
575 'Flask-Extension upgrade the extension or contact the author '576 'of that extension instead. (Registered %r)' % module),577 stacklevel=2)578580 options.setdefault('url_prefix', module.url_prefix)581 options.setdefault('subdomain', module.subdomain)582 self.view_functions.update(module.view_functions)583 state = _ModuleSetupState(self, **options)584 for func in module._register_events:585 func(state)579 self.register_blueprint(module, **options)580581 def register_blueprint(self, blueprint, **options):582 """Registers a blueprint on the application.583
396 unmodified lines
980 if it was the return value from the view and further981 request handling is stopped.982 """983 funcs = self.before_request_funcs.get(None, ())990 mod = request.module991 if mod and mod in self.before_request_funcs:992 funcs = chain(funcs, self.before_request_funcs[mod])984 bp = request.blueprint985 if bp is not None and bp in self.before_request_funcs:986 funcs = chain(funcs, self.before_request_funcs[bp])987 for func in funcs:988 rv = func()989 if rv is not None:990 return rv
11 unmodified lines
1002 :return: a new response object or the same, has to be an1003 instance of :attr:`response_class`.1004 """1005 ctx = _request_ctx_stack.top1012 mod = ctx.request.module1006 bp = ctx.request.blueprint1007 if not isinstance(ctx.session, _NullSession):1008 self.save_session(ctx.session, response)1009 funcs = ()1016 if mod and mod in self.after_request_funcs:1017 funcs = reversed(self.after_request_funcs[mod])1010 if bp is not None and bp in self.after_request_funcs:1011 funcs = reversed(self.after_request_funcs[bp])1012 if None in self.after_request_funcs:1013 funcs = chain(funcs, reversed(self.after_request_funcs[None]))1014 for handler in funcs:1015 response = handler(response)
6 unmodified lines
1022 triggered when the request context is popped. That way we have a1023 tighter control over certain resources under testing environments.1024 """1025 funcs = reversed(self.teardown_request_funcs.get(None, ()))1032 mod = request.module1033 if mod and mod in self.teardown_request_funcs:1034 funcs = chain(funcs, reversed(self.teardown_request_funcs[mod]))1026 bp = request.blueprint1027 if bp is not None and bp in self.teardown_request_funcs:1028 funcs = chain(funcs, reversed(self.teardown_request_funcs[bp]))1029 exc = sys.exc_info()[1]1030 for func in funcs:1031 rv = func(exc)1032 if rv is not None:
80 unmodified lines
1113 except Exception, e:1114 response = self.make_response(self.handle_exception(e))1115 return response(environ, start_response)11161117 @property1118 def modules(self):1119 from warnings import warn1120 warn(DeprecationWarning('Flask.modules is deprecated, use '1121 'Flask.blueprints instead'), stacklevel=2)1122 return self.blueprints11231124 def __call__(self, environ, start_response):1125 """Shortcut for :attr:`wsgi_app`."""1126 return self.wsgi_app(environ, start_response)
added:flask/blueprints.py+172 added
1# -*- coding: utf-8 -*-2"""3 flask.blueprints4 ~~~~~~~~~~~~~~~~56 Blueprints are the recommended way to implement larger or more7 pluggable applications in Flask 0.7 and later.89 :copyright: (c) 2011 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""12import os1314from .helpers import _PackageBoundObject, _endpoint_from_view_func151617class BlueprintSetupState(object):18 """Temporary holder object for registering a blueprint with the19 application.20 """2122 def __init__(self, blueprint, app, options):23 self.app = app24 self.blueprint = blueprint25 self.options = options2627 subdomain = self.options.get('subdomain')28 if subdomain is None:29 subdomain = self.blueprint.subdomain30 self.subdomain = subdomain3132 url_prefix = self.options.get('url_prefix')33 if url_prefix is None:34 url_prefix = self.blueprint.url_prefix35 self.url_prefix = url_prefix3637 def add_url_rule(self, rule, endpoint=None, view_func=None, **options):38 if self.url_prefix:39 rule = self.url_prefix + rule40 options.setdefault('subdomain', self.subdomain)41 if endpoint is None:42 endpoint = _endpoint_from_view_func(view_func)43 self.app.add_url_rule(rule, '%s.%s' % (self.blueprint.name, endpoint),44 view_func, **options)454647class Blueprint(_PackageBoundObject):48 """Represents a blueprint.4950 .. versionadded:: 0.751 """5253 def __init__(self, name, import_name, static_folder=None,54 static_url_path=None, url_prefix=None,55 subdomain=None):56 _PackageBoundObject.__init__(self, import_name)57 self.name = name58 self.url_prefix = url_prefix59 self.subdomain = subdomain60 self.static_folder = static_folder61 self.static_url_path = static_url_path62 self.deferred_functions = []6364 def _record(self, func):65 self.deferred_functions.append(func)6667 def make_setup_state(self, app, options):68 return BlueprintSetupState(self, app, options)6970 def register(self, app, options):71 """Called by :meth:`Flask.register_blueprint` to register a blueprint72 on the application. This can be overridden to customize the register73 behavior. Keyword arguments from74 :func:`~flask.Flask.register_blueprint` are directly forwarded to this75 method in the `options` dictionary.76 """77 state = self.make_setup_state(app, options)78 if self.has_static_folder:79 state.add_url_rule(self.static_url_path + '/<path:filename>',80 view_func=self.send_static_file,81 endpoint='static')8283 for deferred in self.deferred_functions:84 deferred(state)8586 def route(self, rule, **options):87 """Like :meth:`Flask.route` but for a module. The endpoint for the88 :func:`url_for` function is prefixed with the name of the module.89 """90 def decorator(f):91 self.add_url_rule(rule, f.__name__, f, **options)92 return f93 return decorator9495 def add_url_rule(self, rule, endpoint=None, view_func=None, **options):96 """Like :meth:`Flask.add_url_rule` but for a module. The endpoint for97 the :func:`url_for` function is prefixed with the name of the module.98 """99 def register_rule(state):100 state.add_url_rule(rule, endpoint, view_func, **options)101 self._record(register_rule)102103 def endpoint(self, endpoint):104 """Like :meth:`Flask.endpoint` but for a module. This does not105 prefix the endpoint with the module name, this has to be done106 explicitly by the user of this method.107 """108 def decorator(f):109 def register_endpoint(state):110 state.app.view_functions[endpoint] = f111 self._record(register_endpoint)112 return f113 return decorator114115 def before_request(self, f):116 """Like :meth:`Flask.before_request` but for a module. This function117 is only executed before each request that is handled by a function of118 that module.119 """120 self._record(lambda s: s.app.before_request_funcs121 .setdefault(self.name, []).append(f))122 return f123124 def before_app_request(self, f):125 """Like :meth:`Flask.before_request`. Such a function is executed126 before each request, even if outside of a module.127 """128 self._record(lambda s: s.app.before_request_funcs129 .setdefault(None, []).append(f))130 return f131132 def after_request(self, f):133 """Like :meth:`Flask.after_request` but for a module. This function134 is only executed after each request that is handled by a function of135 that module.136 """137 self._record(lambda s: s.app.after_request_funcs138 .setdefault(self.name, []).append(f))139 return f140141 def after_app_request(self, f):142 """Like :meth:`Flask.after_request` but for a module. Such a function143 is executed after each request, even if outside of the module.144 """145 self._record(lambda s: s.app.after_request_funcs146 .setdefault(None, []).append(f))147 return f148149 def context_processor(self, f):150 """Like :meth:`Flask.context_processor` but for a module. This151 function is only executed for requests handled by a module.152 """153 self._record(lambda s: s.app.template_context_processors154 .setdefault(self.name, []).append(f))155 return f156157 def app_context_processor(self, f):158 """Like :meth:`Flask.context_processor` but for a module. Such a159 function is executed each request, even if outside of the module.160 """161 self._record(lambda s: s.app.template_context_processors162 .setdefault(None, []).append(f))163 return f164165 def app_errorhandler(self, code):166 """Like :meth:`Flask.errorhandler` but for a module. This167 handler is used for all requests, even if outside of the module.168 """169 def decorator(f):170 self._record(lambda s: s.app.errorhandler(code)(f))171 return f172 return decorator
modified:flask/ctx.py+11 added
11 unmodified lines
12from werkzeug.exceptions import HTTPException1314from .globals import _request_ctx_stack15from .session import _NullSession16from .module import blueprint_is_module171819class _RequestGlobals(object):20 pass
75 unmodified lines
96 self.request.url_rule = url_rule97 except HTTPException, e:98 self.request.routing_exception = e99100 # Support for deprecated functionality. This is doing away with101 # Flask 1.0102 blueprint = self.request.blueprint103 if blueprint is not None:104 # better safe than sorry, we don't want to break code that105 # already worked106 bp = app.blueprints.get(blueprint)107 if bp is not None and blueprint_is_module(bp):108 self.request._is_old_module = True109110 def push(self):111 """Binds the request context to the current context."""112 _request_ctx_stack.push(self)113
28 unmodified lines
modified:flask/helpers.py+41 added-21 removed
154 unmodified lines
155156157def url_for(endpoint, **values):158 """Generates a URL to the given endpoint with the method provided.159 The endpoint is relative to the active module if modules are in use.159161 Here are some examples:162163 ==================== ======================= =============================164 Active Module Target Endpoint Target Function165 ==================== ======================= =============================166 `None` ``'index'`` `index` of the application167 `None` ``'.index'`` `index` of the application168 ``'admin'`` ``'index'`` `index` of the `admin` module169 any ``'.index'`` `index` of the application170 any ``'admin.index'`` `index` of the `admin` module171 ==================== ======================= =============================172160 Variable arguments that are unknown to the target endpoint are appended161 to the generated URL as query arguments. If the value of a query argument162 is `None`, the whole pair is skipped.163
3 unmodified lines
167 :param values: the variable arguments of the URL rule168 :param _external: if set to `True`, an absolute URL is generated.169 """170 ctx = _request_ctx_stack.top171 if not ctx.request._is_old_module:172 if endpoint[:1] == '.':173 endpoint = request.blueprint + endpoint174 else:175 # TODO: get rid of this deprecated functionality in 1.0184 if '.' not in endpoint:185 mod = ctx.request.module186 if mod is not None:187 endpoint = mod + '.' + endpoint188 elif endpoint.startswith('.'):189 endpoint = endpoint[1:]176 if '.' not in endpoint:177 mod = ctx.request.blueprint178 if mod is not None:179 endpoint = mod + '.' + endpoint180 elif endpoint.startswith('.'):181 endpoint = endpoint[1:]182 external = values.pop('_external', False)183 return ctx.url_adapter.build(endpoint, values, force_external=external)184185
294 unmodified lines
480481482class _PackageBoundObject(object):483484 template_folder = 'templates'485486 def __init__(self, import_name):487 #: The name of the package or module. Do not change this once488 #: it was set by the constructor.489 self.import_name = import_name490491 #: Where is the app root located?492 self.root_path = _get_package_path(self.import_name)493494 self._static_folder = None495 self._static_url_path = None496497 def _get_static_folder(self):498 if self._static_folder is not None:499 return os.path.join(self.root_path, self._static_folder)500 def _set_static_folder(self, value):501 self._static_folder = value502 static_folder = property(_get_static_folder, _set_static_folder)503 del _get_static_folder, _set_static_folder504505 def _get_static_url_path(self):506 if self._static_url_path is None:507 if self.static_folder is None:508 return None509 return '/' + os.path.basename(self.static_folder)510 return self._static_url_path511 def _set_static_url_path(self, value):512 self._static_url_path = value513 static_url_path = property(_get_static_url_path, _set_static_url_path)514 del _get_static_url_path, _set_static_url_path515516 @property517 def has_static_folder(self):518 """This is `True` if the package bound object's container has a519 folder named ``'static'``.520521 .. versionadded:: 0.5522 """507 return os.path.isdir(os.path.join(self.root_path, 'static'))523 return self.static_folder is not None524525 @locked_cached_property526 def jinja_loader(self):527 """The Jinja loader for this package bound object.528529 .. versionadded:: 0.5530 """531 if self.template_folder is not None:515 return FileSystemLoader(os.path.join(self.root_path, 'templates'))532 return FileSystemLoader(os.path.join(self.root_path,533 self.template_folder))534535 def send_static_file(self, filename):536 """Function used internally to send static files from the static537 folder to the browser.538539 .. versionadded:: 0.5540 """541 if not self.has_static_folder:542 raise RuntimeError('No static folder for this object')543 return send_from_directory(os.path.join(self.root_path, 'static'),544 filename)545546 def open_resource(self, resource):
22 unmodified lines
modified:flask/module.py+17 added-204 removed
7 unmodified lines
8 :copyright: (c) 2010 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import os1314from .helpers import _PackageBoundObject, _endpoint_from_view_func15from .blueprints import Blueprint161715def _register_module(module, static_path):16 """Internal helper function that returns a function for recording17 that registers the `send_static_file` function for the module on18 the application if necessary. It also registers the module on19 the application.20 """21 def _register(state):22 state.app.modules[module.name] = module23 # do not register the rule if the static folder of the24 # module is the same as the one from the application.25 if state.app.root_path == module.root_path:26 return27 path = static_path28 if path is None:29 path = state.app.static_path30 if state.url_prefix:31 path = state.url_prefix + path32 state.app.add_url_rule(path + '/<path:filename>',33 endpoint='%s.static' % module.name,34 view_func=module.send_static_file,35 subdomain=state.subdomain)36 return _register18def blueprint_is_module(bp):19 """Used to figure out if something is actually a module"""20 return isinstance(bp, Module)212239class _ModuleSetupState(object):23class Module(Blueprint):24 """Deprecated module support. Until Flask 0.6 modules were a different25 name of the concept now available as blueprints in Flask. They are26 essentially doing the same but have some bad semantics for templates and27 static files that were fixed with blueprints.2841 def __init__(self, app, url_prefix=None, subdomain=None):42 self.app = app43 self.url_prefix = url_prefix44 self.subdomain = subdomain454647class Module(_PackageBoundObject):48 """Container object that enables pluggable applications. A module can49 be used to organize larger applications. They represent blueprints that,50 in combination with a :class:`Flask` object are used to create a large51 application.5253 A module is like an application bound to an `import_name`. Multiple54 modules can share the same import names, but in that case a `name` has55 to be provided to keep them apart. If different import names are used,56 the rightmost part of the import name is used as name.5758 Here's an example structure for a larger application::5960 /myapplication61 /__init__.py62 /views63 /__init__.py64 /admin.py65 /frontend.py6667 The `myapplication/__init__.py` can look like this::6869 from flask import Flask70 from myapplication.views.admin import admin71 from myapplication.views.frontend import frontend7273 app = Flask(__name__)74 app.register_module(admin, url_prefix='/admin')75 app.register_module(frontend)7677 And here's an example view module (`myapplication/views/admin.py`)::7879 from flask import Module8081 admin = Module(__name__)8283 @admin.route('/')84 def index():85 pass8687 @admin.route('/login')88 def login():89 pass9091 For a gentle introduction into modules, checkout the92 :ref:`working-with-modules` section.9394 .. versionadded:: 0.595 The `static_path` parameter was added and it's now possible for96 modules to refer to their own templates and static files. See97 :ref:`modules-and-resources` for more information.9899 .. versionadded:: 0.6100 The `subdomain` parameter was added.101102 :param import_name: the name of the Python package or module103 implementing this :class:`Module`.104 :param name: the internal short name for the module. Unless specified105 the rightmost part of the import name106 :param url_prefix: an optional string that is used to prefix all the107 URL rules of this module. This can also be specified108 when registering the module with the application.109 :param subdomain: used to set the subdomain setting for URL rules that110 do not have a subdomain setting set.111 :param static_path: can be used to specify a different path for the112 static files on the web. Defaults to ``/static``.113 This does not affect the folder the files are served114 *from*.29 .. versionchanged:: 0.730 Modules were deprecated in favor for blueprints.31 """3233 def __init__(self, import_name, name=None, url_prefix=None,34 static_path=None, subdomain=None):35 if name is None:36 assert '.' in import_name, 'name required if package name ' \37 'does not point to a submodule'38 name = import_name.rsplit('.', 1)[1]123 _PackageBoundObject.__init__(self, import_name)124 self.name = name125 self.url_prefix = url_prefix126 self.subdomain = subdomain127 self.view_functions = {}128 self._register_events = [_register_module(self, static_path)]39 Blueprint.__init__(self, name, import_name, url_prefix=url_prefix,40 subdomain=subdomain)41130 def route(self, rule, **options):131 """Like :meth:`Flask.route` but for a module. The endpoint for the132 :func:`url_for` function is prefixed with the name of the module.133 """134 def decorator(f):135 self.add_url_rule(rule, f.__name__, f, **options)136 return f137 return decorator138139 def add_url_rule(self, rule, endpoint=None, view_func=None, **options):140 """Like :meth:`Flask.add_url_rule` but for a module. The endpoint for141 the :func:`url_for` function is prefixed with the name of the module.142143 .. versionchanged:: 0.6144 The `endpoint` argument is now optional and will default to the145 function name to consistent with the function of the same name146 on the application object.147 """148 def register_rule(state):149 the_rule = rule150 if state.url_prefix:151 the_rule = state.url_prefix + rule152 options.setdefault('subdomain', state.subdomain)153 the_endpoint = endpoint154 if the_endpoint is None:155 the_endpoint = _endpoint_from_view_func(view_func)156 state.app.add_url_rule(the_rule, '%s.%s' % (self.name,157 the_endpoint),158 view_func, **options)159 self._record(register_rule)160161 def endpoint(self, endpoint):162 """Like :meth:`Flask.endpoint` but for a module."""163 def decorator(f):164 self.view_functions[endpoint] = f165 return f166 return decorator167168 def before_request(self, f):169 """Like :meth:`Flask.before_request` but for a module. This function170 is only executed before each request that is handled by a function of171 that module.172 """173 self._record(lambda s: s.app.before_request_funcs174 .setdefault(self.name, []).append(f))175 return f176177 def before_app_request(self, f):178 """Like :meth:`Flask.before_request`. Such a function is executed179 before each request, even if outside of a module.180 """181 self._record(lambda s: s.app.before_request_funcs182 .setdefault(None, []).append(f))183 return f184185 def after_request(self, f):186 """Like :meth:`Flask.after_request` but for a module. This function187 is only executed after each request that is handled by a function of188 that module.189 """190 self._record(lambda s: s.app.after_request_funcs191 .setdefault(self.name, []).append(f))192 return f193194 def after_app_request(self, f):195 """Like :meth:`Flask.after_request` but for a module. Such a function196 is executed after each request, even if outside of the module.197 """198 self._record(lambda s: s.app.after_request_funcs199 .setdefault(None, []).append(f))200 return f201202 def context_processor(self, f):203 """Like :meth:`Flask.context_processor` but for a module. This204 function is only executed for requests handled by a module.205 """206 self._record(lambda s: s.app.template_context_processors207 .setdefault(self.name, []).append(f))208 return f209210 def app_context_processor(self, f):211 """Like :meth:`Flask.context_processor` but for a module. Such a212 function is executed each request, even if outside of the module.213 """214 self._record(lambda s: s.app.template_context_processors215 .setdefault(None, []).append(f))216 return f217218 def app_errorhandler(self, code):219 """Like :meth:`Flask.errorhandler` but for a module. This220 handler is used for all requests, even if outside of the module.221222 .. versionadded:: 0.4223 """224 def decorator(f):225 self._record(lambda s: s.app.errorhandler(code)(f))226 return f227 return decorator228229 def _record(self, func):230 self._register_events.append(func)42 if os.path.isdir(os.path.join(self.root_path, 'static')):43 self._static_folder = 'static'
modified:flask/templating.py+4 added-1 removed
12 unmodified lines
13 TemplateNotFound1415from .globals import _request_ctx_stack16from .signals import template_rendered17from .module import blueprint_is_module181920def _default_template_ctx_processor():21 """Default template context processor. Injects `request`,
52 unmodified lines
74 # and try that before we go with the real deal.75 loader = None76 try:77 module, name = posixpath.normpath(template).split('/', 1)77 loader = self.app.modules[module].jinja_loader78 blueprint = self.app.blueprints[module]79 if blueprint_is_module(blueprint):80 loader = blueprint.jinja_loader81 except (ValueError, KeyError, TemplateNotFound):82 pass83 try:84 if loader is not None:
59 unmodified lines
modified:flask/wrappers.py+16 added-7 removed
40 unmodified lines
41 #: usually a :exc:`~werkzeug.exceptions.NotFound` exception or42 #: something similar.43 routing_exception = None4445 # switched by the request context until 1.0 to opt in deprecated46 # module functionality47 _is_old_module = False4849 @property50 def max_content_length(self):51 """Read-only view of the `MAX_CONTENT_LENGTH` config key."""52 ctx = _request_ctx_stack.top
11 unmodified lines
64 return self.url_rule.endpoint6566 @property67 def module(self):64 """The name of the current module"""65 if self.url_rule and \66 ':' not in self.url_rule.endpoint and \67 '.' in self.url_rule.endpoint:68 return self.url_rule.endpoint.rsplit('.', 1)[0]68 """The name of the current module if the request was dispatched69 to an actual module. This is deprecated functionality, use blueprints70 instead.71 """72 from warnings import warn73 warn(DeprecationWarning('modules were deprecated in favor of '74 'blueprints. Use request.blueprint '75 'instead.'), stacklevel=2)76 if self._is_old_module:77 return self.blueprint7879 @property80 def blueprint(self):81 """The name of the current blueprint"""73 if self.url_rule and ':' in self.url_rule.endpoint:74 return self.url_rule.endpoint.split(':', 1)[0]82 if self.url_rule and '.' in self.url_rule.endpoint:83 return self.url_rule.endpoint.split('.', 1)[0]8485 @cached_property86 def json(self):87 """If the mimetype is `application/json` this will contain the
24 unmodified lines
modified:tests/flask_tests.py+1 added
1190 unmodified lines
1191 from werkzeug.routing import Submount, Rule1192 from flask import Module11931194 app = flask.Flask(__name__)1195 app.testing = True1196 app.url_map.add(Submount('/foo', [1197 Rule('/bar', endpoint='bar'),1198 Rule('/', endpoint='index')1199 ]))
450 unmodified lines