o
    g=`                     @  sZ  d dl mZ d dlZd dlZd dlmZ d dlmZ ddl	mZ
 ddlmZ dd	lmZ dd
lmZ ddlmZ ejrAddlmZ ejdgdf Zejde
jej dZejde
jdZejde
jdZejde
jdZejde
jdZ ejde
j!dZ"ejde
j#dZ$ejde
j%dZ&ejde
j'dZ(ejde
j)dZ*G dd dZ+G dd deZ,dS )    )annotationsN)defaultdict)update_wrapper   )typing   )_endpoint_from_view_func)	_sentinel)Scaffold)setupmethod)AppBlueprintSetupStateT_after_request)boundT_before_requestT_error_handler
T_teardownT_template_context_processorT_template_filterT_template_globalT_template_testT_url_defaultsT_url_value_preprocessorc                   @  s*   e Zd ZdZdddZ		ddddZdS )r   zTemporary 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.
    	blueprint	Blueprintappr   optionst.Anyfirst_registrationboolreturnNonec                 C  s   || _ || _|| _|| _| jd}|d u r| jj}|| _| jd}|d u r+| jj}|| _| jd|j| _| jdd| _t	| jj
| _| j| jdd d S )N	subdomain
url_prefixnamename_prefix url_defaults )r   r   r   r   getr"   r#   r$   r%   dicturl_values_defaultsr'   update)selfr   r   r   r   r"   r#   r(   r(   Y/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/flask/sansio/blueprints.py__init__)   s    zBlueprintSetupState.__init__Nrulestrendpoint
str | None	view_funcft.RouteCallable | Nonec                 K  s   | j dur|rd| j d|df}n| j }|d| j |du r(t|}| j}d|v r:t|fi |	d}| j
j|| j d| j d| d|fd|i| dS )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/r"   defaults.)r#   joinrstriplstrip
setdefaultr"   r   r'   r*   popr   add_url_ruler%   r$   )r-   r0   r2   r4   r   r7   r(   r(   r.   r>   W   s&   

z BlueprintSetupState.add_url_rule)
r   r   r   r   r   r   r   r   r    r!   )NN)
r0   r1   r2   r3   r4   r5   r   r   r    r!   )__name__
__module____qualname____doc__r/   r>   r(   r(   r(   r.   r   "   s    
1c                      sr  e Zd ZdZdZdddddddefdb fddZdcddZeddddZ	eddddZ
	dedfd&d'Zedgd*d+Zdhd,d-Zdid.d/Ze			djdkd6d7Ze	dldmd9d:Ze	dldnd=d>Ze	dldod@dAZe	dldpdCdDZe	dldqdFdGZe	dldrdIdJZedsdLdMZedtdOdPZedudRdSZedvdUdVZedwdZd[Zedxd]d^Zedyd`daZ  ZS )zr   a	  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
    FNr$   r1   import_namestatic_folderstr | os.PathLike[str] | Nonestatic_url_pathr3   template_folderr#   r"   r'   dict[str, t.Any] | None	root_path	cli_groupc                   sl   t  j|||||	d |stdd|v rtd|| _|| _|| _g | _|d u r+i }|| _|
| _g | _	d S )N)rC   rD   rF   rG   rI   z'name' may not be empty.r8   z+'name' may not contain a dot '.' character.)
superr/   
ValueErrorr$   r#   r"   deferred_functionsr+   rJ   _blueprints)r-   r$   rC   rD   rF   rG   r#   r"   r'   rI   rJ   	__class__r(   r.   r/      s(   
zBlueprint.__init__f_namer    r!   c                 C  s"   | j rtd| d| j dd S )NzThe setup method 'z,' can no longer be called on the blueprint 'z'. It has already been registered at least once, any changes will not be applied consistently.
Make sure all imports, decorators, functions, etc. needed to set up the blueprint are done before registering it.)_got_registered_onceAssertionErrorr$   )r-   rQ   r(   r(   r.   _check_setup_finished   s   zBlueprint._check_setup_finishedfuncDeferredSetupFunctionc                 C  s   | j | dS )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.
        N)rM   append)r-   rU   r(   r(   r.   record   s   zBlueprint.recordc                   s"   d fdd}|  t|  d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.
        stater   r    r!   c                   s   | j r	 |  d S d S N)r   rY   rU   r(   r.   wrapper   s   z&Blueprint.record_once.<locals>.wrapperNrY   r   r    r!   )rX   r   )r-   rU   r]   r(   r\   r.   record_once   s   zBlueprint.record_oncer   r   r   dict[str, t.Any]r   r   r   c                 C  s   t | |||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-   r   r   r   r(   r(   r.   make_setup_state   s   zBlueprint.make_setup_stater   r   c                 K  s$   || u rt d| j||f dS )a  Register 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)rL   rN   rW   )r-   r   r   r(   r(   r.   register_blueprint   s   zBlueprint.register_blueprintc                   s  | dd}| d j}| d| d}||jv rA|j|  u r%dnd}||kr1d| dnd}td	| d
| d| dt fdd|j D  }||jv}	 |j|< d _ |||}
 j	rt|
j
 j d jdd |sx|	r~ ||  jD ]}||
 q| d j} jjr|du r|jj jj n|tu r| j_|j j n| j_|j j  jD ]\}}| }| d}| d}|du r|j}|
jdur|dur|d |
j |d< n|dur||d< n
|
jdur|
j|d< |du r|j}|
jdur!|dur!|
jdd |d |d< n|dur+||d< n|
jdur6|
j|d< ||d< ||| qd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.3
            Nested blueprints now correctly apply subdomains.

        .. versionchanged:: 2.1
            Registering the same blueprint with the same name multiple
            times is an error.

        .. 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``.
        r%   r&   r$   r8   thisza differentz ''z
The name 'z' is already registered for z
 blueprintz'. Use 'name=' to provide a unique name.c                 3  s    | ]}| u V  qd S rZ   r(   ).0bpr-   r(   r.   	<genexpr><  s    z%Blueprint.register.<locals>.<genexpr>Tz/<path:filename>static)r4   r2   rJ   Nr#   r"   r6   )r)   r$   r;   
blueprintsrL   anyvaluesrR   ra   has_static_folderr>   rF   send_static_file_merge_blueprint_funcsrM   rJ   clicommandsr,   r	   add_commandrN   copyr"   r#   r:   register)r-   r   r   r%   	self_namer$   bp_descexisting_atfirst_bp_registrationfirst_name_registrationrY   deferredcli_resolved_groupr   
bp_optionsbp_url_prefixbp_subdomainr(   rg   r.   rt     sz   














zBlueprint.registerc                   s   d fdd}| j  D ]"\}}|d u r n  d| }ttd	d
 | D }||j |< q| j D ]	\}}||j|< q4|| j|j || j|j || j|j || j|j || j	|j	 || j
|j
 d S )Nbp_dict'dict[ft.AppOrBlueprintKey, list[t.Any]]parent_dictr    r!   c                   s>   |   D ]\}}|d u r n  d| }|| | qd S )Nr8   )itemsextend)r   r   keyrl   r$   r(   r.   r   |  s   z0Blueprint._merge_blueprint_funcs.<locals>.extendr8   c                 S  s$   i | ]\}}|d d |  D qS )c                 S  s   i | ]\}}||qS r(   r(   )re   	exc_classrU   r(   r(   r.   
<dictcomp>      z?Blueprint._merge_blueprint_funcs.<locals>.<dictcomp>.<dictcomp>)r   )re   codecode_valuesr(   r(   r.   r     s    z4Blueprint._merge_blueprint_funcs.<locals>.<dictcomp>)r   r   r   r   r    r!   )error_handler_specr   r   r*   view_functionsbefore_request_funcsafter_request_funcsteardown_request_funcsurl_default_functionsurl_value_preprocessorstemplate_context_processors)r-   r   r$   r   r   valuer2   rU   r(   r   r.   ro   {  s*   z Blueprint._merge_blueprint_funcsr0   r2   r4   r5   provide_automatic_optionsbool | Nonec                   sR    r
d v r
t drtdrdjv rt d|  fdd dS )a  Register a URL rule with the blueprint. See :meth:`.Flask.add_url_rule` for
        full documentation.

        The URL rule is prefixed with the blueprint's URL prefix. The endpoint name,
        used with :func:`url_for`, is prefixed with the blueprint's name.
        r8   z/'endpoint' may not contain a dot '.' character.r?   z5'view_func' name may not contain a dot '.' character.c                   s   | j  fdiS )Nr   )r>   sr2   r   r   r0   r4   r(   r.   <lambda>  s    z(Blueprint.add_url_rule.<locals>.<lambda>N)rL   hasattrr?   rX   )r-   r0   r2   r4   r   r   r(   r   r.   r>     s   zBlueprint.add_url_rule2t.Callable[[T_template_filter], T_template_filter]c                      d fdd}|S )a  Register a template filter, available in any template rendered by the
        application. Equivalent to :meth:`.Flask.template_filter`.

        :param name: the optional name of the filter, otherwise the
                     function name will be used.
        fr   r    c                      j |  d | S Nr   )add_app_template_filterr   r$   r-   r(   r.   	decorator     z0Blueprint.app_template_filter.<locals>.decoratorN)r   r   r    r   r(   r-   r$   r   r(   r   r.   app_template_filter  s   zBlueprint.app_template_filterr   ft.TemplateFilterCallablec                      d fdd}|  | dS )	aI  Register a template filter, available in any template rendered by the
        application. Works like the :meth:`app_template_filter` decorator. Equivalent to
        :meth:`.Flask.add_template_filter`.

        :param name: the optional name of the filter, otherwise the
                     function name will be used.
        rY   r   r    r!   c                       | j jjp	 j< d S rZ   )r   	jinja_envfiltersr?   r[   r   r$   r(   r.   register_template     z<Blueprint.add_app_template_filter.<locals>.register_templateNr^   r_   r-   r   r$   r   r(   r   r.   r     s   z!Blueprint.add_app_template_filter.t.Callable[[T_template_test], T_template_test]c                   r   )a!  Register a template test, available in any template rendered by the
        application. Equivalent to :meth:`.Flask.template_test`.

        .. versionadded:: 0.10

        :param name: the optional name of the test, otherwise the
                     function name will be used.
        r   r   r    c                   r   r   )add_app_template_testr   r   r(   r.   r     r   z.Blueprint.app_template_test.<locals>.decoratorN)r   r   r    r   r(   r   r(   r   r.   app_template_test     zBlueprint.app_template_testft.TemplateTestCallablec                   r   )	aa  Register a template test, available in any template rendered by the
        application. Works like the :meth:`app_template_test` decorator. Equivalent to
        :meth:`.Flask.add_template_test`.

        .. versionadded:: 0.10

        :param name: the optional name of the test, otherwise the
                     function name will be used.
        rY   r   r    r!   c                   r   rZ   )r   r   testsr?   r[   r   r(   r.   r     r   z:Blueprint.add_app_template_test.<locals>.register_templateNr^   r   r   r(   r   r.   r        zBlueprint.add_app_template_test2t.Callable[[T_template_global], T_template_global]c                   r   )a'  Register a template global, available in any template rendered by the
        application. Equivalent to :meth:`.Flask.template_global`.

        .. versionadded:: 0.10

        :param name: the optional name of the global, otherwise the
                     function name will be used.
        r   r   r    c                   r   r   )add_app_template_globalr   r   r(   r.   r     r   z0Blueprint.app_template_global.<locals>.decoratorN)r   r   r    r   r(   r   r(   r   r.   app_template_global  r   zBlueprint.app_template_globalft.TemplateGlobalCallablec                   r   )	ai  Register a template global, available in any template rendered by the
        application. Works like the :meth:`app_template_global` decorator. Equivalent to
        :meth:`.Flask.add_template_global`.

        .. versionadded:: 0.10

        :param name: the optional name of the global, otherwise the
                     function name will be used.
        rY   r   r    r!   c                   r   rZ   )r   r   globalsr?   r[   r   r(   r.   r   $  r   z<Blueprint.add_app_template_global.<locals>.register_templateNr^   r   r   r(   r   r.   r     r   z!Blueprint.add_app_template_globalr   c                      |   fdd  S )zLike :meth:`before_request`, but before every request, not only those handled
        by the blueprint. Equivalent to :meth:`.Flask.before_request`.
        c                      | j jd g  S rZ   )r   r   r<   rW   r   r   r(   r.   r   /  r   z.Blueprint.before_app_request.<locals>.<lambda>r   r-   r   r(   r   r.   before_app_request)     
zBlueprint.before_app_requestr   c                   r   )zLike :meth:`after_request`, but after every request, not only those handled
        by the blueprint. Equivalent to :meth:`.Flask.after_request`.
        c                   r   rZ   )r   r   r<   rW   r   r   r(   r.   r   9  r   z-Blueprint.after_app_request.<locals>.<lambda>r   r   r(   r   r.   after_app_request3  r   zBlueprint.after_app_requestr   c                   r   )zLike :meth:`teardown_request`, but after every request, not only those
        handled by the blueprint. Equivalent to :meth:`.Flask.teardown_request`.
        c                   r   rZ   )r   r   r<   rW   r   r   r(   r.   r   C  r   z0Blueprint.teardown_app_request.<locals>.<lambda>r   r   r(   r   r.   teardown_app_request=  r   zBlueprint.teardown_app_requestr   c                   r   )zLike :meth:`context_processor`, but for templates rendered by every view, not
        only by the blueprint. Equivalent to :meth:`.Flask.context_processor`.
        c                   r   rZ   )r   r   r<   rW   r   r   r(   r.   r   O  r   z1Blueprint.app_context_processor.<locals>.<lambda>r   r   r(   r   r.   app_context_processorG     
zBlueprint.app_context_processorr   type[Exception] | int.t.Callable[[T_error_handler], T_error_handler]c                   r   )zLike :meth:`errorhandler`, but for every request, not only those handled by
        the blueprint. Equivalent to :meth:`.Flask.errorhandler`.
        r   r   r    c                   s   d fdd} |  S )NrY   r   r    r!   c                   s   | j   d S rZ   )r   errorhandlerr[   )r   r   r(   r.   from_blueprint\  s   zEBlueprint.app_errorhandler.<locals>.decorator.<locals>.from_blueprintr^   r   )r   r   r   r-   r   r.   r   [  s   
z-Blueprint.app_errorhandler.<locals>.decoratorN)r   r   r    r   r(   )r-   r   r   r(   r   r.   app_errorhandlerS  s   zBlueprint.app_errorhandlerr   c                   r   )zLike :meth:`url_value_preprocessor`, but for every request, not only those
        handled by the blueprint. Equivalent to :meth:`.Flask.url_value_preprocessor`.
        c                   r   rZ   )r   r   r<   rW   r   r   r(   r.   r   l  r   z6Blueprint.app_url_value_preprocessor.<locals>.<lambda>r   r   r(   r   r.   app_url_value_preprocessord  r   z$Blueprint.app_url_value_preprocessorr   c                   r   )zLike :meth:`url_defaults`, but for every request, not only those handled by
        the blueprint. Equivalent to :meth:`.Flask.url_defaults`.
        c                   r   rZ   )r   r   r<   rW   r   r   r(   r.   r   v  r   z,Blueprint.app_url_defaults.<locals>.<lambda>r   r   r(   r   r.   app_url_defaultsp  r   zBlueprint.app_url_defaults)r$   r1   rC   r1   rD   rE   rF   r3   rG   rE   r#   r3   r"   r3   r'   rH   rI   r3   rJ   r3   )rQ   r1   r    r!   )rU   rV   r    r!   )F)r   r   r   r`   r   r   r    r   )r   r   r   r   r    r!   )r   r   r   r`   r    r!   )r   r   r$   r1   r    r!   )NNN)r0   r1   r2   r3   r4   r5   r   r   r   r   r    r!   rZ   )r$   r3   r    r   )r   r   r$   r3   r    r!   )r$   r3   r    r   )r   r   r$   r3   r    r!   )r$   r3   r    r   )r   r   r$   r3   r    r!   )r   r   r    r   )r   r   r    r   )r   r   r    r   )r   r   r    r   )r   r   r    r   )r   r   r    r   )r   r   r    r   )r?   r@   rA   rB   rR   r	   r/   rT   r   rX   r_   ra   rb   rt   ro   r>   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r(   r(   rO   r.   r   w   sx    4
'
	

j!			r   )-
__future__r   osr   tcollectionsr   	functoolsr   r&   ftscaffoldr   r	   r
   r   TYPE_CHECKINGr   r   CallablerV   TypeVarAfterRequestCallableAnyr   BeforeRequestCallabler   ErrorHandlerCallabler   TeardownCallabler    TemplateContextProcessorCallabler   TemplateFilterCallabler   TemplateGlobalCallabler   TemplateTestCallabler   URLDefaultCallabler   URLValuePreprocessorCallabler   r   r   r(   r(   r(   r.   <module>   s:    U