o
    NK&h                     @  sF  d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZ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%m&Z& d dl'm(Z(m)Z)m*Z* d dl+m,Z,m-Z-m.Z. erd dl/m0Z0 dddZ1G dd de!Z2ee2 Z3G dd de3Z4dS )    )annotationsN)defaultdict)IterableIteratorMutableSequenceSequence)deepcopy)partialwraps
isfunctionchain)SimpleNamespace)TYPE_CHECKINGAnyCallableOptionalUnionoverload)NotFound)Route)	BaseSanic)SanicException)Default_default)FutureRouteFutureSignalFutureStatic)ListenerTypeMiddlewareTypeRouteHandler)SanicTc                   s   t  fdd}|S )zDecorator to register a function to be called later.

    Args:
        func (Callable): Function to be called later.
        as_decorator (bool): Whether the function should be called
            immediately or not.
    c                   sD   dd< d } rt  d rd fdd}r|S ||S )NFapplyr   c                   sD   g R i }r|| }j r jD ]}|i  q|S N)
registeredappsregister)handlerfutureapp)argsas_decoratorbpfunckwargs C/var/www/html/venv/lib/python3.10/site-packages/sanic/blueprints.pywrapper9   s   
z(lazy.<locals>.decorator.<locals>.wrapperr   )r-   r+   r/   pass_handlerr2   r,   r.   )r+   r-   r/   r1   	decorator0   s   zlazy.<locals>.decorator)r
   )r.   r,   r5   r0   r4   r1   lazy'   s   	r6   c                      s,  e Zd ZdZdZ					dMdN fddZdOddZedPddZedQddZ	e
ejZe
ejZe
ejZe
ejZe
ejZe
ejddZdRddZeeeeed dfdSd)d*Zeddddd+d,dTd1d2Zd3d4 Zd5d6 Z	dUdd7dVd=d>Zd?d@ ZedAdB ZedWdEdFZedXdKdLZ  ZS )Y	Blueprinta  A logical collection of URLs that consist of a similar logical domain.

    A Blueprint object is the main tool for grouping functionality and similar endpoints. It allows the developer to
    organize routes, exception handlers, middleware, and other web functionalities into separate, modular groups.

    See [Blueprints](/en/guide/best-practices/blueprints) for more information.

    Args:
        name (str): The name of the blueprint.
        url_prefix (Optional[str]): The URL prefix for all routes defined on this blueprint.
        host (Optional[Union[List[str], str]]): Host or list of hosts that this blueprint should respond to.
        version (Optional[Union[int, str, float]]): Version number of the API implemented by this blueprint.
        strict_slashes (Optional[bool]): Whether or not the URL should end with a slash.
        version_prefix (str): Prefix for the version. Default is "/v".
    )_apps_future_commands_future_routes_future_statics_future_middleware_future_listeners_future_exceptions_future_signals_allow_route_overwritecopied_fromctx
exceptionshost	listenersmiddlewaresroutesstaticsstrict_slashes
url_prefixversionversion_prefixwebsocket_routesN/vnamestrrJ   Optional[str]rD   Optional[Union[list[str], str]]rK    Optional[Union[int, str, float]]rI   Optional[bool]rL   c                   sf   t  j|d |   d| _d| _t | _|| _|| _|r(|	dr(|d d n|| _
|| _|| _d S )NrO   F /)super__init__resetr@   rA   r   rB   rD   rI   endswithrJ   rK   rL   )selfrO   rJ   rD   rK   rI   rL   	__class__r0   r1   rZ   s   s   	
zBlueprint.__init__returnc                   s$   d  fdddD }d| dS )Nz, c                   sF   g | ]}t t |tr| d t | dn	| dt | qS )z=""=)
isinstancegetattrrP   ).0attrr]   r0   r1   
<listcomp>   s    z&Blueprint.__repr__.<locals>.<listcomp>)rO   rJ   rD   rK   rI   z
Blueprint())join)r]   r+   r0   rg   r1   __repr__   s   
zBlueprint.__repr__
set[Sanic]c                 C  s   | j s
t|  d| j S )a  Get the set of apps that this blueprint is registered to.

        Returns:
            Set[Sanic]: Set of apps that this blueprint is registered to.

        Raises:
            SanicException: If the blueprint has not yet been registered to
                an app.
        z& has not yet been registered to an app)r8   r   rg   r0   r0   r1   r&      s
   zBlueprint.appsboolc                 C  
   t | jS )zCheck if the blueprint has been registered to an app.

        Returns:
            bool: `True` if the blueprint has been registered to an app,
                `False` otherwise.
        )rm   r8   rg   r0   r0   r1   r%      s   
zBlueprint.registeredF)r,   Nonec                 C  s6   t  | _d| _g | _i | _g | _g | _g | _g | _dS )z)Reset the blueprint to its initial state.FN)	setr8   r@   rC   rE   rF   rG   rH   rM   rg   r0   r0   r1   r[      s   
zBlueprint.resetTOptional[Union[str, Default]])Optional[Union[int, str, float, Default]]Union[str, Default]allow_route_overwriteUnion[bool, Default]Optional[Union[bool, Default]]with_registrationwith_ctxc	                 C  s   | j | j| j| j| j| j| jd}	|   t| }
||
_	| j	|
_
t|ts(||
_t|ts0||
_t|ts8||
_t|ts@||
_t|tsH||
_|	 D ]
\}}t| || qL|rn| j rn|
jrctd| j D ]}||
 qf|stt |
_|
S )a  Copy a blueprint instance with some optional parameters to override the values of attributes in the old instance.

        Args:
            name (str): Unique name of the blueprint.
            url_prefix (Optional[Union[str, Default]]): URL to be prefixed before all route URLs.
            version (Optional[Union[int, str, float, Default]]): Blueprint version.
            version_prefix (Union[str, Default]): The prefix of the version number shown in the URL.
            allow_route_overwrite (Union[bool, Default]): Whether to allow route overwrite or not.
            strict_slashes (Optional[Union[bool, Default]]): Enforce the API URLs are requested with a trailing "/*".
            with_registration (bool): Whether to register the new blueprint instance with Sanic apps that were registered with the old instance or not. Default is `True`.
            with_ctx (bool): Whether the ``ctx`` will be copied or not. Default is `False`.

        Returns:
            Blueprint: A new Blueprint instance with the specified attributes.
        )r8   rG   rM   rF   rC   rE   rH   zUStatic routes registered with the old blueprint instance, cannot be registered again.)r8   rG   rM   rF   rC   rE   rH   r[   r   rO   rA   rc   r   rJ   rK   rI   rL   r@   itemssetattrr;   r   	blueprintr   rB   )r]   rO   rJ   rK   rL   rt   rI   rw   rx   attrs_backupnew_bpkeyvaluer*   r0   r0   r1   copy   sD   







zBlueprint.copyrV   rJ   rK   rI   rL   name_prefix
blueprints Union[Blueprint, BlueprintGroup]r   BlueprintGroupc                   s<   d fdd t | ||||d} |D ]}|| q|S )aP  Group multiple blueprints (or other blueprint groups) together.

        Gropuping blueprings is a method for modularizing and organizing
        your application's code. This can be a powerful tool for creating
        reusable components, logically structuring your application code,
        and easily maintaining route definitions in bulk.

        This is the preferred way to group multiple blueprints together.

        Args:
            blueprints (Union[Blueprint, BlueprintGroup]): Blueprints to be
                registered as a group.
            url_prefix (Optional[str]): URL route to be prepended to all
                sub-prefixes. Default is `None`.
            version (Optional[Union[int, str, float]]): API Version to be
                used for Blueprint group. Default is `None`.
            strict_slashes (Optional[bool]): Indicate strict slash
                termination behavior for URL. Default is `None`.
            version_prefix (str): Prefix to be used for the version in the
                URL. Default is "/v".
            name_prefix (Optional[str]): Prefix to be used for the name of
                the blueprints in the group. Default is an empty string.

        Returns:
            BlueprintGroup: A group of blueprints.

        Example:
            The resulting group will have the URL prefixes
            `'/v2/bp1'` and `'/v2/bp2'` for bp1 and bp2, respectively.
            ```python
            bp1 = Blueprint('bp1', url_prefix='/bp1')
            bp2 = Blueprint('bp2', url_prefix='/bp2')
            group = group(bp1, bp2, version=2)
            ```
        r`   Iterable[Blueprint]c                 3  s4    | D ]}t |ttfr |E dH  q|V  qdS )z!Iterate through nested blueprintsN)rc   listtuple)nestedir   r0   r1   r   <  s   zBlueprint.group.<locals>.chainr   N)r`   r   )r   append)rJ   rK   rI   rL   r   r   bpsr-   r0   r   r1   group  s   -zBlueprint.groupc                 C  s  | j | |d| j}|dd}|dd}|d| j}|dd}|d|jj}g }	g }
g }tt}t	 }| j
D ]}| |j|}|jrM|jn|}| j}|j|fD ]}|rc|dkrc|} nqW| |j|| j}| |j|| j}|j}|r| d	|j }||}|jp| j}t|trt|}t|j||j|||j|||j|j|j|j|j|||j}| |f|j v rq>|| |j!|| j"d
}| j#r|D ]}|j$| j#| j|_|j%j&$| j#| j|j%_&qt|tr|	j'n|	j(}|| q>| j)D ]-}| |j|}t*|g|dd R  }| |f|j v rq|| |+|}|	(| qdd |	D }|re| j,D ]}| |f|j v r@q4|
(|-|| q4| j.D ]}| |f|j v rZqN|(|/|| qN| j0D ]}| |f|j v rtqh||j1 (|2| qh| j3D ]%}| |f|j v rq|j45d| ji |6t7|j|j1|j4d|j8 q|  j9dd |	D 7  _9|  j:dd | j9D 7  _:|  j;|
7  _;|  j<|7  _<| j=5t>| | j?r| @| jA| tB|| j,| j.| j0| j3 | jCrtDddS )zRegister the blueprint to the sanic app.

        Args:
            app (Sanic): Sanic app to register the blueprint to.
            options (dict): Options to be passed to the blueprint.
        rJ   rK   NrI   rL   r   error_formatrN   _)	overwrite   c                 S  s   g | ]}|r|j qS r0   rU   re   router0   r0   r1   rh     s    z&Blueprint.register.<locals>.<listcomp>__blueprint__Fc                 S  s   g | ]	}t |tr|qS r0   )rc   r   r   r0   r0   r1   rh         c                 S  s   g | ]}|j jr|qS r0   )extra	websocketr   r0   r0   r1   rh     s
    z6Registering commands with blueprints is not supported.)Er8   addgetrJ   rL   configFALLBACK_ERROR_FORMATr   r   rp   r:   
_setup_uriurir   _extract_valuerK   rI   rO   generate_namerD   rc   r   r   r(   methodsstreamignore_bodyr   subprotocolsunquotestaticroute_context_future_registry_apply_router@   rA   replacer   identextendr   r;   r   _apply_staticr<   _apply_middlewarer>   _apply_exception_handlerr=   event_apply_listenerr?   	conditionupdate_apply_signalr   priorityrG   rM   rF   rC   rE   dictr%   register_futuresr&   r   r9   r   )r]   r*   optionsrJ   opt_versionopt_strict_slashesopt_version_prefixopt_name_prefixr   rG   
middlewareexception_handlersrE   r%   r)   r   route_error_formatrL   prefixrK   rI   rO   rD   apply_router   r	operationroute_namesr0   r0   r1   r'   O  s
  

















zBlueprint.registerc                   sH    di }|d| ji |d< tj fdd| jD  I dH S )zDispatch a signal event

        Args:
            *args: Arguments to be passed to the signal event.
            **kwargs: Keyword arguments to be passed to the signal event.
        r   r   c                   s   g | ]
}|j  i qS r0   )dispatch)re   r*   r+   r/   r0   r1   rh   
  s    z&Blueprint.dispatch.<locals>.<listcomp>N)popr   rO   asynciogatherr&   )r]   r+   r/   r   r0   r   r1   r     s   
zBlueprint.dispatch)r   r   timeoutOptional[Union[int, float]]r   Optional[dict[str, Any]]c                C  sd   |du ri }| d| ji g }| jD ]}|jj||dd}|s&td| || q| ||S )a  Wait for a signal event to be dispatched.

        Args:
            event (str): Name of the signal event.
            timeout (Optional[Union[int, float]]): Timeout for the event to be
                dispatched.
            condition: If provided, method will only return when the signal
                is dispatched with the given condition.

        Returns:
            Awaitable: Awaitable for the event to be dispatched.
        Nr   F)	exclusivezCould not find signal %s)r   rO   r&   signal_router
get_waiterr   r   _event)r]   r   r   r   waitersr*   waiterr0   r0   r1   r     s   
zBlueprint.eventc                   sR   t jdd |D t j|dI d H \}}|D ]}|  q|s"t |\}| S )Nc                 S  s   g | ]	}t | qS r0   )r   create_taskwait)re   r   r0   r0   r1   rh   1  r   z$Blueprint._event.<locals>.<listcomp>)return_whenr   )r   r   FIRST_COMPLETEDcancelTimeoutErrorresult)r]   r   r   donependingtaskfinished_taskr0   r0   r1   r   /  s   
zBlueprint._eventc                  G  s(   | d }| D ]}|d ur|} |S q|S )NrX   r0   )valuesr   vr0   r0   r1   r   <  s   zBlueprint._extract_valuebaser   c                 C  sT   | }|r|}|  dr|dr|| dd  7 }n|| 7 }| dr(|dd  S |S )NrW   r   z//)
startswithr\   )r   r   r   r0   r0   r1   r   E  s   zBlueprint._setup_urir&   r-   futuresSequence[tuple[Any, ...]]c                   s(   | D ]}|j  fdd|D  qdS )a%  Register futures to the apps.

        Args:
            apps (Set[Sanic]): Set of apps to register the futures to.
            bp (Blueprint): Blueprint that the futures belong to.
            futures (Sequence[Tuple[Any, ...]]): Sequence of futures to be
                registered.
        c                   s   h | ]} |fqS r0   r0   )re   itemr-   r0   r1   	<setcomp>_  s    z-Blueprint.register_futures.<locals>.<setcomp>N)r   r   )r&   r-   r   r*   r0   r   r1   r   Q  s   zBlueprint.register_futures)NNNNrN   )rO   rP   rJ   rQ   rD   rR   rK   rS   rI   rT   rL   rP   r`   rP   )r`   rl   )r`   rm   )r`   ro   )rO   rP   rJ   rq   rK   rr   rL   rs   rt   ru   rI   rv   rw   rm   rx   rm   )r   r   rJ   rQ   rK   rS   rI   rT   rL   rP   r   rQ   r`   r   r$   )r   rP   r   r   r   r   )r   rP   r   rQ   )r&   rl   r-   r7   r   r   )__name__
__module____qualname____doc__	__slots__rZ   rk   propertyr&   r%   r6   r   	exceptionlistenerr   r   signalr   r[   r   r   staticmethodr   r'   r   r   r   r   r   r   __classcell__r0   r0   r^   r1   r7   I   sd    

	




F? 1"
r7   c                   @  s>  e Zd ZdZdZ					dLdMddZedNddZedOddZedPddZ	edQddZ
edRddZedSddZdTd!d"ZedUd&d'ZedVd*d'ZdWd-d'ZedXd0d1ZedYd3d1ZdZd5d1Zed[d6d7Zed\d8d7Zd]d9d7Zd^d:d;Zd_d=d>Zd`dBdCZdXdDdEZdFdG ZdadHdIZdadJdKZdS )br   a  This class provides a mechanism to implement a Blueprint Group.

    The `BlueprintGroup` class allows grouping blueprints under a common
    URL prefix, version, and other shared attributes. It integrates with
    Sanic's Blueprint system, offering a custom iterator to treat an
    object of this class as a list/tuple.

    Although possible to instantiate a group directly, it is recommended
    to use the `Blueprint.group` method to create a group of blueprints.

    Args:
        url_prefix (Optional[str]): URL to be prefixed before all the
            Blueprint Prefixes. Default is `None`.
        version (Optional[Union[int, str, float]]): API Version for the
            blueprint group, inherited by each Blueprint. Default is `None`.
        strict_slashes (Optional[bool]): URL Strict slash behavior
            indicator. Default is `None`.
        version_prefix (str): Prefix for the version in the URL.
            Default is `"/v"`.
        name_prefix (Optional[str]): Prefix for the name of the blueprints
            in the group. Default is an empty string.

    Examples:
        ```python
        bp1 = Blueprint("bp1", url_prefix="/bp1")
        bp2 = Blueprint("bp2", url_prefix="/bp2")

        bp3 = Blueprint("bp3", url_prefix="/bp4")
        bp4 = Blueprint("bp3", url_prefix="/bp4")


        group1 = Blueprint.group(bp1, bp2)
        group2 = Blueprint.group(bp3, bp4, version_prefix="/api/v", version="1")


        @bp1.on_request
        async def bp1_only_middleware(request):
            print("applied on Blueprint : bp1 Only")


        @bp1.route("/")
        async def bp1_route(request):
            return text("bp1")


        @bp2.route("/<param>")
        async def bp2_route(request, param):
            return text(param)


        @bp3.route("/")
        async def bp3_route(request):
            return text("bp3")


        @bp4.route("/<param>")
        async def bp4_route(request, param):
            return text(param)


        @group1.on_request
        async def group_middleware(request):
            print("common middleware applied for both bp1 and bp2")


        # Register Blueprint group under the app
        app.blueprint(group1)
        app.blueprint(group2)
        ```
    )_blueprints_url_prefix_version_strict_slashes_version_prefix_name_prefixNrN   rV   rJ   rQ   rK   rS   rI   rT   rL   rP   r   c                 C  s(   g | _ || _|| _|| _|| _|| _d S r$   )r   r   r   r   r   r   )r]   rJ   rK   rI   rL   r   r0   r0   r1   rZ     s   
zBlueprintGroup.__init__r`   c                 C     | j S )zThe URL prefix for the Blueprint Group.

        Returns:
            Optional[Union[int, str, float]]: URL prefix for the Blueprint
                Group.
        )r   rg   r0   r0   r1   rJ        zBlueprintGroup.url_prefixlist[Blueprint]c                 C  r   )zA list of all the available blueprints under this group.

        Returns:
            List[Blueprint]: List of all the available blueprints under
                this group.
        r   rg   r0   r0   r1   r     r   zBlueprintGroup.blueprints Optional[Union[str, int, float]]c                 C  r   )zAPI Version for the Blueprint Group, if any.

        Returns:
            Optional[Union[str, int, float]]: API Version for the Blueprint
        )r   rg   r0   r0   r1   rK        zBlueprintGroup.versionc                 C  r   )zWhether to enforce strict slashes for the Blueprint Group.

        Returns:
            Optional[bool]: Whether to enforce strict slashes for the
        )r   rg   r0   r0   r1   rI     r   zBlueprintGroup.strict_slashesc                 C  r   )z{Version prefix for the Blueprint Group.

        Returns:
            str: Version prefix for the Blueprint Group.
        )r   rg   r0   r0   r1   rL     r   zBlueprintGroup.version_prefixc                 C  r   )zName prefix for the Blueprint Group.

        This is mainly needed when blueprints are copied in order to
        avoid name conflicts.

        Returns:
            Optional[str]: Name prefix for the Blueprint Group.
        )r   rg   r0   r0   r1   r     s   
zBlueprintGroup.name_prefixIterator[Blueprint]c                 C  rn   )zIterate over the list of blueprints in the group.

        Returns:
            Iterator[Blueprint]: Iterator for the list of blueprints in
        )iterr   rg   r0   r0   r1   __iter__      
zBlueprintGroup.__iter__r   intr7   c                 C     d S r$   r0   r]   r   r0   r0   r1   __getitem__     zBlueprintGroup.__getitem__sliceMutableSequence[Blueprint]c                 C  r  r$   r0   r  r0   r0   r1   r    r  Union[int, slice],Union[Blueprint, MutableSequence[Blueprint]]c                 C  s
   | j | S )a%  Get the Blueprint object at the specified index.

        This method returns a blueprint inside the group specified by
        an index value. This will enable indexing, splice and slicing
        of the blueprint group like we can do with regular list/tuple.

        This method is provided to ensure backward compatibility with
        any of the pre-existing usage that might break.

        Returns:
            Blueprint: Blueprint object at the specified index.

        Raises:
            IndexError: If the index is out of range.
        r   r  r0   r0   r1   r    s   
indexro   c                 C  r  r$   r0   r]   r  r   r0   r0   r1   __setitem__"  r  zBlueprintGroup.__setitem__r   c                 C  r  r$   r0   r  r0   r0   r1   r  %  r  %Union[Blueprint, Iterable[Blueprint]]c                 C  s`   t |trt |tstd|| j|< dS t |tr,t |ts#tdt|| j|< dS td)a  Set the Blueprint object at the specified index.

        Abstract method implemented to turn the `BlueprintGroup` class
        into a list like object to support all the existing behavior.

        This method is used to perform the list's indexed setter operation.

        Args:
            index (int): Index to use for removing a new Blueprint item
            item (Blueprint): New `Blueprint` object.

        Returns:
            None

        Raises:
            IndexError: If the index is out of range.
        zExpected a Blueprint instancez+Expected an iterable of Blueprint instanceszIndex must be int or sliceN)rc   r  r7   	TypeErrorr   r  r   r   r  r0   r0   r1   r  (  s   



c                 C  r  r$   r0   r]   r  r0   r0   r1   __delitem__I  r  zBlueprintGroup.__delitem__c                 C  r  r$   r0   r  r0   r0   r1   r  L  r  c                 C  s   | j |= dS )a  Delete the Blueprint object at the specified index.

        Abstract method implemented to turn the `BlueprintGroup` class
        into a list like object to support all the existing behavior.

        This method is used to delete an item from the list of blueprint
        groups like it can be done on a regular list with index.

        Args:
            index (int): Index to use for removing a new Blueprint item

        Returns:
            None

        Raises:
            IndexError: If the index is out of range.
        Nr   r  r0   r0   r1   r  O  s   c                 C  rn   )zGet the Length of the blueprint group object.

        Returns:
            int: Length of the blueprint group object.
        )lenr   rg   r0   r0   r1   __len__c  r  zBlueprintGroup.__len__r   c                 C  s   | j | dS )a  Add a new Blueprint object to the group.

        The Abstract class `MutableSequence` leverages this append method to
        perform the `BlueprintGroup.append` operation.

        Args:
            value (Blueprint): New `Blueprint` object.

        Returns:
            None
        N)r   r   )r]   r   r0   r0   r1   r   k  s   zBlueprintGroup.appendrC   	Exceptionr   c                   s    fdd}|S )a  Decorate a function to handle exceptions for all blueprints in the group.

        In case of nested Blueprint Groups, the same handler is applied
        across each of the Blueprints recursively.

        Args:
            *exceptions (Exception): Exceptions to handle
            **kwargs (dict): Optional Keyword arg to use with Middleware

        Returns:
            Partial function to apply the middleware

        Examples:
            ```python
            bp1 = Blueprint("bp1", url_prefix="/bp1")
            bp2 = Blueprint("bp2", url_prefix="/bp2")
            group1 = Blueprint.group(bp1, bp2)

            @group1.exception(Exception)
            def handler(request, exception):
                return text("Exception caught")
            ```
        c                   s$   j D ]}|j i |  qd S r$   )r   r   fnr{   rC   r/   r]   r0   r1   )register_exception_handler_for_blueprints  s   
zKBlueprintGroup.exception.<locals>.register_exception_handler_for_blueprintsr0   )r]   rC   r/   r  r0   r  r1   r   y  s   zBlueprintGroup.exceptionc                 C  s   | j || dS )a  Insert a new Blueprint object to the group at the specified index.

        The Abstract class `MutableSequence` leverages this insert method to
        perform the `BlueprintGroup.append` operation.

        Args:
            index (int): Index to use for removing a new Blueprint item
            item (Blueprint): New `Blueprint` object.

        Returns:
            None
        N)r   insertr  r0   r0   r1   r    s   zBlueprintGroup.insertc                   sD    fdd} r t  d r  d }t dd  ||S |S )a  A decorator that can be used to implement a Middleware for all blueprints in the group.

        In case of nested Blueprint Groups, the same middleware is applied
        across each of the Blueprints recursively.

        Args:
            *args (Optional): Optional positional Parameters to be use middleware
            **kwargs (Optional): Optional Keyword arg to use with Middleware

        Returns:
            Partial function to apply the middleware
        c                   s(   j D ]}|j| g R i  qd S r$   )r   r   r  r+   r/   r]   r0   r1   "register_middleware_for_blueprints  s   
zEBlueprintGroup.middleware.<locals>.register_middleware_for_blueprintsr   r   N)callabler   )r]   r+   r/   r  r  r0   r  r1   r     s   zBlueprintGroup.middlewarec                 C  "   t |r
| |dS t| jddS )a
  Convenience method to register a request middleware for all blueprints in the group.

        Args:
            middleware (Optional): Optional positional Parameters to be use middleware

        Returns:
            Partial function to apply the middleware
        request	attach_tor  r   r	   r]   r   r0   r0   r1   
on_request     	zBlueprintGroup.on_requestc                 C  r  )a  Convenience method to register a response middleware for all blueprints in the group.

        Args:
            middleware (Optional): Optional positional Parameters to be use middleware

        Returns:
            Partial function to apply the middleware
        responser  r!  r"  r0   r0   r1   on_response  r$  zBlueprintGroup.on_response)NNNrN   rV   )
rJ   rQ   rK   rS   rI   rT   rL   rP   r   rQ   )r`   rS   )r`   r   )r`   r   )r`   rT   r   )r`   rQ   )r`   r   )r   r  r`   r7   )r   r  r`   r  )r   r	  r`   r
  )r  r  r   r7   r`   ro   )r  r  r   r   r`   ro   )r  r	  r   r  r`   ro   )r  r  r`   ro   )r  r  r`   ro   )r  r	  r`   ro   )r`   r  )r   r7   r`   ro   )rC   r  r`   r   r$   )r   r   r   r   r   rZ   r   rJ   r   rK   rI   rL   r   r   r   r  r  r  r  r   r   r  r   r#  r&  r0   r0   r0   r1   r   e  sX    G		


!





r   )T)5
__future__r   r   collectionsr   collections.abcr   r   r   r   r   r   	functoolsr	   r
   inspectr   	itertoolsr   typesr   typingr   r   r   r   r   r   sanic_routing.exceptionsr   sanic_routing.router   sanic.base.rootr   sanic.exceptionsr   sanic.helpersr   r   sanic.models.futuresr   r   r   sanic.models.handler_typesr   r    r!   sanicr"   r6   r7   bpg_baser   r0   r0   r0   r1   <module>   s6     	
"    