only extend on first registration
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent ef52e3e · Browse files · 1 file·+42 added−47 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+42 added−47 removed
- other:+42 added−47 removed
Provenance
- Commit
3dfc12e- Tree
ffe7404- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
ef52e3e
1 file changed+42 added−47 removed
modified:src/flask/blueprints.py+42 added-47 removed
88 unmodified lines89 when the blueprint is registered on an application.90 91 See :doc:`/blueprints` for more information.92 93- .. versionchanged:: 1.1.094- Blueprints have a ``cli`` group to register nested CLI commands.95- The ``cli_group`` parameter controls the name of the group under96- the ``flask`` command.97-98- .. versionadded:: 0.799-93 :param name: The name of the blueprint. Will be prepended to each94 endpoint name.95 :param import_name: The name of the blueprint package, usually96 ``__name__``. This helps locate the ``root_path`` for the16 unmodified lines113 :param subdomain: A subdomain that blueprint routes will match on by114 default.115 :param url_defaults: A dict of default values that blueprint routes116 will receive by default.124- :param root_path: By default, the blueprint will automatically set this125- based on ``import_name``. In certain situations this automatic126- detection can fail, so the path can be specified manually127- instead.117+ :param root_path: By default, the blueprint will automatically set118+ this based on ``import_name``. In certain situations this119+ automatic detection can fail, so the path can be specified120+ manually instead.121+122+ .. versionchanged:: 1.1.0123+ Blueprints have a ``cli`` group to register nested CLI commands.124+ The ``cli_group`` parameter controls the name of the group under125+ the ``flask`` command.126+127+ .. versionadded:: 0.7128 """129 130 warn_on_modifications = False131 _got_registered_once = False28 unmodified lines160 self.name = name161 self.url_prefix = url_prefix162 self.subdomain = subdomain163 self.deferred_functions = []164+165 if url_defaults is None:166 url_defaults = {}167+168 self.url_values_defaults = url_defaults169 self.cli_group = cli_group170 171 def _is_setup_finished(self):9 unmodified lines181 from warnings import warn182 183 warn(184 Warning(183- "The blueprint was already registered once "184- "but is getting modified now. These changes "185- "will not show up."185+ "The blueprint was already registered once but is"186+ " getting modified now. These changes will not show"187+ " up."188 )189 )190 self.deferred_functions.append(func)191 17 unmodified lines209 """210 return BlueprintSetupState(self, app, options, first_registration)211 212 def register(self, app, options, first_registration=False):211- """Called by :meth:`Flask.register_blueprint` to register all views212- and callbacks registered on the blueprint with the application. Creates213- a :class:`.BlueprintSetupState` and calls each :meth:`record` callback214- with it.213+ """Called by :meth:`Flask.register_blueprint` to register all214+ views and callbacks registered on the blueprint with the215+ application. Creates a :class:`.BlueprintSetupState` and calls216+ each :meth:`record` callbackwith it.217 216- :param app: The application this blueprint is being registered with.218+ :param app: The application this blueprint is being registered219+ with.220 :param options: Keyword arguments forwarded from221 :meth:`~Flask.register_blueprint`.222 :param first_registration: Whether this is the first time this223 blueprint has been registered on the application.7 unmodified lines231 view_func=self.send_static_file,232 endpoint="static",233 )234 232- # Merge app and self dictionaries.233- def merge_dict_lists(self_dict, app_dict):234- """Merges self_dict into app_dict. Replaces None keys with self.name.235- Values of dict must be lists.236- """237- for key, values in self_dict.items():238- key = self.name if key is None else f"{self.name}.{key}"239- app_dict[key].extend(values)235+ # Merge blueprint data into parent.236+ if first_registration:237 241- def merge_dict_nested(self_dict, app_dict):242- """Merges self_dict into app_dict. Replaces None keys with self.name.243- Values of dict must be dict.244- """245- for key, value in self_dict.items():246- key = self.name if key is None else f"{self.name}.{key}"247- app_dict[key] = value238+ def extend(bp_dict, parent_dict):239+ for key, values in bp_dict.items():240+ key = self.name if key is None else f"{self.name}.{key}"241+ parent_dict[key].extend(values)242 249- app.view_functions.update(self.view_functions)243+ def update(bp_dict, parent_dict):244+ for key, value in bp_dict.items():245+ key = self.name if key is None else f"{self.name}.{key}"246+ parent_dict[key] = value247 251- merge_dict_lists(self.before_request_funcs, app.before_request_funcs)252- merge_dict_lists(self.after_request_funcs, app.after_request_funcs)253- merge_dict_lists(self.teardown_request_funcs, app.teardown_request_funcs)254- merge_dict_lists(self.url_default_functions, app.url_default_functions)255- merge_dict_lists(self.url_value_preprocessors, app.url_value_preprocessors)256- merge_dict_lists(257- self.template_context_processors, app.template_context_processors258- )248+ app.view_functions.update(self.view_functions)249+ extend(self.before_request_funcs, app.before_request_funcs)250+ extend(self.after_request_funcs, app.after_request_funcs)251+ extend(self.teardown_request_funcs, app.teardown_request_funcs)252+ extend(self.url_default_functions, app.url_default_functions)253+ extend(self.url_value_preprocessors, app.url_value_preprocessors)254+ extend(self.template_context_processors, app.template_context_processors)255+ update(self.error_handler_spec, app.error_handler_spec)256 260- merge_dict_nested(self.error_handler_spec, app.error_handler_spec)261-257 for deferred in self.deferred_functions:258 deferred(state)259 265- cli_resolved_group = options.get("cli_group", self.cli_group)266-260 if not self.cli.commands:261 return262 263+ cli_resolved_group = options.get("cli_group", self.cli_group)264+265 if cli_resolved_group is None:266 app.cli.commands.update(self.cli.commands)267 elif cli_resolved_group is _sentinel:268 self.cli.name = self.name177 unmodified lines