U a[@sddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZejrddlmZejdgejfZGdddZGddde ZdS)N) defaultdict)update_wrapper)_endpoint_from_view_func) _sentinel)Scaffold)AfterRequestCallable)BeforeRequestCallableErrorHandlerCallable)TeardownCallable) TemplateContextProcessorCallableTemplateFilterCallableTemplateGlobalCallableTemplateTestCallable)URLDefaultCallable)URLValuePreprocessorCallable)FlaskBlueprintSetupStatec@sPeZdZdZddejeddddZd eej eej ej ejddd d Z dS) rzTemporary holder object for registering a blueprint with the application. An instance of this class is created by the :meth:`~flask.Blueprint.make_setup_state` method and later passed to all register callback functions. BlueprintrN) blueprintappoptionsfirst_registrationreturncCs||_||_||_||_|jd}|dkr4|jj}||_|jd}|dkrV|jj}||_|jd|j|_|jdd|_t |jj |_ |j |jdddS)N subdomain url_prefixname name_prefix url_defaults) rrrrgetrrr r!dicturl_values_defaultsr#update)selfrrrrrrr$r$QC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-e702oxwa\flask\blueprints.py__init__ s   zBlueprintSetupState.__init__)ruleendpoint view_funcrrcKs|jdk r2|r,d|jd|df}n|j}|d|j|dkrPt|}|j}d|krpt|f| d}|j j ||j d|j d|d|fd|i|dS)zA helper method to register a rule (and optionally a view function) to the application. The endpoint is automatically prefixed with the blueprint's name. N/rdefaults.)rjoinrstriplstrip setdefaultrrr#r&popr add_url_ruler!r )r)r,r-r.rr0r$r$r*r7Ns& z BlueprintSetupState.add_url_rule)NN) __name__ __module__ __qualname____doc__tAnyboolr+strOptionalCallabler7r$r$r$r*rs  1 c steZdZdZdZdZdZdZdddddddefe e e j e e j e e j e e j e e j e e j e e j e e j e d fdd Z eddd Ze jdd d d Ze jdd d dZde j e e jegefdddZd?ee j e ddd d!Zd@e j e e jegefdd"d#ZdAee j e ddd$d%ZdBe j e e jegefdd&d'Z dCee j e ddd(d)Z!e"e"d*d+d,Z#e"e"d*d-d.Z$e%e%d*d/d0Z&e'e'd*d1d2Z(e)e)d*d3d4Z*e j+e j,e-e.fe jd5d6d7Z/e0e0d*d8d9Z1e2e2d*d:d;Z3Z4S)Dra Represents a blueprint, a collection of routes and other app-related functions that can be registered on a real application later. A blueprint is an object that allows defining application functions without requiring an application object ahead of time. It uses the same decorators as :class:`~flask.Flask`, but defers the need for an application by recording them for later registration. Decorating a function with a blueprint creates a deferred function that is called with :class:`~flask.blueprints.BlueprintSetupState` when the blueprint is registered on an application. See :doc:`/blueprints` for more information. :param name: The name of the blueprint. Will be prepended to each endpoint name. :param import_name: The name of the blueprint package, usually ``__name__``. This helps locate the ``root_path`` for the blueprint. :param static_folder: A folder with static files that should be served by the blueprint's static route. The path is relative to the blueprint's root path. Blueprint static files are disabled by default. :param static_url_path: The url to serve static files from. Defaults to ``static_folder``. If the blueprint does not have a ``url_prefix``, the app's static route will take precedence, and the blueprint's static files won't be accessible. :param template_folder: A folder with templates that should be added to the app's template search path. The path is relative to the blueprint's root path. Blueprint templates are disabled by default. Blueprint templates have a lower precedence than those in the app's templates folder. :param url_prefix: A path to prepend to all of the blueprint's URLs, to make them distinct from the rest of the app's routes. :param subdomain: A subdomain that blueprint routes will match on by default. :param url_defaults: A dict of default values that blueprint routes will receive by default. :param root_path: By default, the blueprint will automatically set this based on ``import_name``. In certain situations this automatic detection can fail, so the path can be specified manually instead. .. versionchanged:: 1.1.0 Blueprints have a ``cli`` group to register nested CLI commands. The ``cli_group`` parameter controls the name of the group under the ``flask`` command. .. versionadded:: 0.7 FN) r import_name static_folderstatic_url_pathtemplate_folderrrr# root_path cli_groupc s`tj||||| dd|kr&td||_||_||_g|_|dkrJi}||_| |_g|_ dS)N)rBrCrDrErFr1z+'name' may not contain a dot '.' character.) superr+ ValueErrorr rrdeferred_functionsr'rG _blueprints) r)r rBrCrDrErrr#rFrG __class__r$r*r+s$ zBlueprint.__init__)rcCs |jo |jSN)warn_on_modifications_got_registered_oncer)r$r$r*_is_setup_finishedszBlueprint._is_setup_finished)funcrcCs4|jr$|jr$ddlm}|td|j|dS)zRegisters a function that is called when the blueprint is registered on the application. This function is called with the state as argument as returned by the :meth:`make_setup_state` method. r)warnzfThe blueprint was already registered once but is getting modified now. These changes will not show up.N)rPrOwarningsrTWarningrJappend)r)rSrTr$r$r*records  zBlueprint.recordcs$tddfdd }|t|S)zWorks like :meth:`record` but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called. Nstatercs|jr|dSrN)rrZrSr$r*wrappersz&Blueprint.record_once..wrapper)rrXr)r)rSr]r$r\r* record_onceszBlueprint.record_oncer)rrrrcCst||||S)zCreates an instance of :meth:`~flask.blueprints.BlueprintSetupState` object that is later passed to the register callback functions. Subclasses can override this to return a subclass of the setup state. )r)r)rrrr$r$r*make_setup_stateszBlueprint.make_setup_state)rrrcKs$||krtd|j||fdS)aRegister a :class:`~flask.Blueprint` on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint. .. versionchanged:: 2.0.1 The ``name`` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for ``url_for``. .. versionadded:: 2.0 z%Cannot register a blueprint on itselfN)rIrKrW)r)rrr$r$r*register_blueprints zBlueprint.register_blueprint)rrrcstfdd|jD }|dd}|dj}|d|d|jkr|krjddnd}|jk rtd |d |d n$d d l}|jd |d|ddd|j<d_  |||}j r|j j djdd|rЇfdd} jD]H\} } | d kr(n d| } ttdd| D} | |j| <qjD]\} } | |j| <qf| j|j| j|j| j|j| j|j| j|j| j|jjD]}||q|dj}jjrT|d kr|jjjjn8|tkr>j_|j jn|j_|j jj!D]\}}|"}|d}|d kr|j#}|j#d k r|d k r|j#$dd|d|d<n*|d k r||d<n|j#d k r|j#|d<|d<|%||qZd S)a\Called by :meth:`Flask.register_blueprint` to register all views and callbacks registered on the blueprint with the application. Creates a :class:`.BlueprintSetupState` and calls each :meth:`record` callback with it. :param app: The application this blueprint is being registered with. :param options: Keyword arguments forwarded from :meth:`~Flask.register_blueprint`. .. versionchanged:: 2.0.1 Nested blueprints are registered with their dotted name. This allows different blueprints with the same name to be nested at different locations. .. versionchanged:: 2.0.1 The ``name`` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for ``url_for``. .. versionchanged:: 2.0.1 Registering the same blueprint with the same name multiple times is deprecated and will become an error in Flask 2.1. c3s|]}|kVqdSrNr$).0ZbprQr$r* 'sz%Blueprint.register..r!r"r r1z ''z The name 'z1' is already registered for a different blueprintz'. Use 'name=' to provide a unique name.rNz*' is already registered for this blueprintzO. Use 'name=' to provide a unique name. This will become an error in Flask 2.1.) stacklevelTz/Zstatic)r.r-cs>|D]0\}}|dkrn d|}|||qdS)Nr1)itemsextend)Zbp_dictZ parent_dictkeyvaluesr r$r*rgNsz"Blueprint.register..extendcSs$i|]\}}|dd|DqS)cSsi|]\}}||qSr$r$)ra exc_classrSr$r$r* Xsz1Blueprint.register...)rf)racodeZ code_valuesr$r$r*rlWs z&Blueprint.register..rGrr/)&anyZ blueprintsrir%r r4rIrUrTrPr_Zhas_static_folderr7rDZsend_static_fileZerror_handler_specrfrr&Zview_functionsbefore_request_funcsafter_request_funcsteardown_request_funcsurl_default_functionsurl_value_preprocessorstemplate_context_processorsrJrGclicommandsr(rZ add_commandrKcopyrr3register)r)rrrr!Z self_nameZ existing_atrUrZrgrhvaluer-rSdeferredZcli_resolved_grouprZ bp_optionsZ bp_url_prefixr$r r)r*rx s                 zBlueprint.register)r,r-r.provide_automatic_optionsrrc sRrdkrtdr4tdr4djkr4td|fdddS)zLike :meth:`Flask.add_url_rule` but for a blueprint. The endpoint for the :func:`url_for` function is prefixed with the name of the blueprint. r1z/'endpoint' may not contain a dot '.' character.r8z5'view_func' name may not contain a dot '.' character.cs|jfdiS)Nr|)r7sr-rr|r,r.r$r*sz(Blueprint.add_url_rule..N)rIhasattrr8rX)r)r,r-r.r|rr$rr*r7s zBlueprint.add_url_rule)r rcsttdfdd }|S)zRegister a custom template filter, available application wide. Like :meth:`Flask.template_filter` but for a blueprint. :param name: the optional name of the filter, otherwise the function name will be used. frcsj|d|SNrj)add_app_template_filterrr{r$r* decoratorsz0Blueprint.app_template_filter..decoratorrr)r rr$r{r*app_template_filters zBlueprint.app_template_filter)rr rcs$tddfdd }||dS)aIRegister a custom template filter, available application wide. Like :meth:`Flask.add_template_filter` but for a blueprint. Works exactly like the :meth:`app_template_filter` decorator. :param name: the optional name of the filter, otherwise the function name will be used. NrYcs|jjjpj<dSrN)r jinja_envfiltersr8r[rr r$r*register_templatesz.register_templaterr^r)rr rr$rr*rs z!Blueprint.add_app_template_filtercsttdfdd }|S)aRegister a custom template test, available application wide. Like :meth:`Flask.template_test` but for a blueprint. .. versionadded:: 0.10 :param name: the optional name of the test, otherwise the function name will be used. rcsj|d|Sr)add_app_template_testrr{r$r*rsz.Blueprint.app_template_test..decoratorrrr$r{r*app_template_tests zBlueprint.app_template_testcs$tddfdd }||dS)aaRegister a custom template test, available application wide. Like :meth:`Flask.add_template_test` but for a blueprint. Works exactly like the :meth:`app_template_test` decorator. .. versionadded:: 0.10 :param name: the optional name of the test, otherwise the function name will be used. NrYcs|jjjpj<dSrN)rrtestsr8r[rr$r*rsz:Blueprint.add_app_template_test..register_templaterrr$rr*rs zBlueprint.add_app_template_testcsttdfdd }|S)aRegister a custom template global, available application wide. Like :meth:`Flask.template_global` but for a blueprint. .. versionadded:: 0.10 :param name: the optional name of the global, otherwise the function name will be used. rcsj|d|Sr)add_app_template_globalrr{r$r*rsz0Blueprint.app_template_global..decoratorrrr$r{r*app_template_globals zBlueprint.app_template_globalcs$tddfdd }||dS)aiRegister a custom template global, available application wide. Like :meth:`Flask.add_template_global` but for a blueprint. Works exactly like the :meth:`app_template_global` decorator. .. versionadded:: 0.10 :param name: the optional name of the global, otherwise the function name will be used. NrYcs|jjjpj<dSrN)rrglobalsr8r[rr$r*r sz.register_templaterrr$rr*rs z!Blueprint.add_app_template_globalrcs|fddS)zLike :meth:`Flask.before_request`. Such a function is executed before each request, even if outside of a blueprint. cs|jjdgSrN)rror5rWr}rr$r*rz.Blueprint.before_app_request..r^r)rr$rr*before_app_requests zBlueprint.before_app_requestcs|fddS)zLike :meth:`Flask.before_first_request`. Such a function is executed before the first request to the application. cs|jjSrN)rZbefore_first_request_funcsrWr}rr$r*r!rz4Blueprint.before_app_first_request..rrr$rr*before_app_first_requestsz"Blueprint.before_app_first_requestcs|fddS)zLike :meth:`Flask.after_request` but for a blueprint. Such a function is executed after each request, even if outside of the blueprint. cs|jjdgSrN)rrpr5rWr}rr$r*r)rz-Blueprint.after_app_request..rrr$rr*after_app_request$s zBlueprint.after_app_requestcs|fddS)zLike :meth:`Flask.teardown_request` but for a blueprint. Such a function is executed when tearing down each request, even if outside of the blueprint. cs|jjdgSrN)rrqr5rWr}rr$r*r3rz0Blueprint.teardown_app_request..rrr$rr*teardown_app_request-s zBlueprint.teardown_app_requestcs|fddS)zLike :meth:`Flask.context_processor` but for a blueprint. Such a function is executed each request, even if outside of the blueprint. cs|jjdgSrN)rrtr5rWr}rr$r*r>rz1Blueprint.app_context_processor..rrr$rr*app_context_processor7s zBlueprint.app_context_processor)rmrcsttdfdd }|S)zLike :meth:`Flask.errorhandler` but for a blueprint. This handler is used for all requests, even if outside of the blueprint. rcsfddS)Ncs|jSrN)rZ errorhandlerr})rmrr$r*rHrz?Blueprint.app_errorhandler..decorator..rrrmr)rr*rGsz-Blueprint.app_errorhandler..decoratorr )r)rmrr$rr*app_errorhandlerBszBlueprint.app_errorhandlercs|fddS)z.rrr$rr*app_url_value_preprocessorMs z$Blueprint.app_url_value_preprocessorcs|fddS)z2Same as :meth:`url_defaults` but application wide.cs|jjdgSrN)rrrr5rWr}rr$r*rYrz,Blueprint.app_url_defaults..rrr$rr*app_url_defaultsVs zBlueprint.app_url_defaults)F)NNN)N)N)N)N)N)N)5r8r9r:r;rOrPZ json_encoderZ json_decoderrr?r<r@r&r+r>rRrArXr^rr_r=r`rxr7rrrrrrrrrr rrrrr rr rUnionType Exceptionintrrrrr __classcell__r$r$rLr*rns4$              "  r)typingr< collectionsr functoolsrZscaffoldrrrrr r r r rrrrr TYPE_CHECKINGrrrAZDeferredSetupFunctionrrr$r$r$r*s(                U