o
    NK&h                     @  s~   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
 d dlmZmZ d dlmZ G dd	 d	eZG d
d dZdS )    )annotationsdeque)Sequence)IntEnumauto)count)DequeUnion)MiddlewareTypec                   @  s   e Zd Ze Ze ZdS )MiddlewareLocationN)__name__
__module____qualname__r   REQUESTRESPONSE r   r   C/var/www/html/venv/lib/python3.10/site-packages/sanic/middleware.pyr      s    
r   c                   @  sx   e Zd ZU dZe Zded< dZ	d!d"ddZdd Z	d#ddZ
d$ddZed%ddZed&ddZed'ddZd S )(
Middlewarea  Middleware object that is used to encapsulate middleware functions.

    This should generally not be instantiated directly, but rather through
    the `sanic.Sanic.middleware` decorator and its variants.

    Args:
        func (MiddlewareType): The middleware function to be called.
        location (MiddlewareLocation): The location of the middleware.
        priority (int): The priority of the middleware.
    intr   )funcprioritylocation
definitionr   r   r   r   r   r   returnNonec                 C  s"   || _ || _|| _ttj| _d S N)r   r   r   nextr   _counterr   )selfr   r   r   r   r   r   __init__"   s   zMiddleware.__init__c                 O  s   | j |i |S r   )r   )r   argskwargsr   r   r   __call__-   s   zMiddleware.__call__c                 C  s
   t | jS r   )hashr   r   r   r   r   __hash__0   s   
zMiddleware.__hash__strc                 C  s*   | j j d| jj d| j d| jj dS )Nz(func=<function z>, priority=z, location=))	__class__r   r   r   r   namer%   r   r   r   __repr__3   s   
zMiddleware.__repr__tuple[int, int]c                 C  s   | j | j fS )zReturn a tuple of the priority and definition order.

        This is used to sort the middleware.

        Returns:
            tuple[int, int]: The priority and definition order.
        )r   r   r%   r   r   r   order;   s   	zMiddleware.ordermiddleware_collections+Sequence[Union[Middleware, MiddlewareType]]Deque[Middleware]c                  s   t  fdd|D S )ax  Convert middleware collections to a deque of Middleware objects.

        Args:
            *middleware_collections (Sequence[Union[Middleware, MiddlewareType]]):
                The middleware collections to convert.
            location (MiddlewareLocation): The location of the middleware.

        Returns:
            Deque[Middleware]: The converted middleware.
        c                   s.   g | ]}|D ]}t |tr|nt| qqS r   )
isinstancer   ).0
collection
middlewarer   r   r   
<listcomp>W   s    z&Middleware.convert.<locals>.<listcomp>r   )clsr   r.   r   r5   r   convertF   s
   
zMiddleware.convertc                 C  s   t  | _t| j| _ dS )zReset the counter for the middleware definition order.

        This is used for testing.

        Returns:
            None
        N)r   r   r   )r7   r   r   r   reset_count`   s   	zMiddleware.reset_countN)r   )r   r   r   r   r   r   r   r   )r   r   )r   r'   )r   r,   )r.   r/   r   r   r   r0   )r   r   )r   r   r   __doc__r   r   __annotations__	__slots__r    r#   r&   r+   propertyr-   classmethodr8   r9   r   r   r   r   r      s    
 


r   N)
__future__r   collectionsr   collections.abcr   enumr   r   	itertoolsr   typingr	   r
   sanic.models.handler_typesr   r   r   r   r   r   r   <module>   s    