o
    4˜Žj8  ã                   @   sì   d dl Z d dlmZmZ ddlmZ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	Zer8dd
lmZ edƒZdededeeef fdd„Zdedefdd„Zddde	dœdedededee def
dd„Zdddefdd „ZdS )!é    N)ÚTYPE_CHECKINGÚTypeVaré   )ÚHandlerÚ
Middleware)ÚHTTPMoveÚHTTPPermanentRedirect)ÚRequest)ÚStreamResponse)ÚSystemRoute)Ú
middlewareÚnormalize_path_middleware)ÚApplicationÚ_FuncÚrequestÚpathÚreturnc                 Ã   sB   �| j |d�}| jj |¡I d H }||_|jd u rd|fS d| fS )N)Úrel_urlTF)ÚcloneÚappÚrouterÚresolveÚ_match_infoÚhttp_exception)r   r   Úalt_requestÚ
match_info© r   úT/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/aiohttp/web_middlewares.pyÚ_check_request_resolves   s   €
r   Úfc                 C   s
   d| _ | S )Nr   )Ú__middleware_version__)r   r   r   r   r   !   s   r   TF)Úappend_slashÚremove_slashÚmerge_slashesÚredirect_classr!   r"   r#   r$   c                    s>   ˆ oˆ }|sJ dƒ‚t dtdtdtf‡ ‡‡‡fdd„ƒ}|S )a€  Factory for producing a middleware that normalizes the path of a request.

    Normalizing means:
        - Add or remove a trailing slash to the path.
        - Double slashes are replaced by one.

    The middleware returns as soon as it finds a path that resolves
    correctly. The order if both merge and append/remove are enabled is
        1) merge slashes
        2) append/remove slash
        3) both merge slashes and append/remove slash.
    If the path resolves with at least one of those conditions, it will
    redirect to the new path.

    Only one of `append_slash` and `remove_slash` can be enabled. If both
    are `True` the factory will raise an assertion error

    If `append_slash` is `True` the middleware will append a slash when
    needed. If a resource is defined with trailing slash and the request
    comes without it, it will append it automatically.

    If `remove_slash` is `True`, `append_slash` must be `False`. When enabled
    the middleware will remove trailing slashes and redirect if the resource
    is defined

    If merge_slashes is True, merge multiple consecutive slashes in the
    path into one.
    z#Cannot both remove and append slashr   Úhandlerr   c                 “   s0  �t | jjtƒr‘g }d| jv r| j dd¡\}}d| }nd}| j}ˆr.| t dd|¡¡ ˆ r=| j	 
d¡s=| |d ¡ ˆrN| j	 
d¡rN| |d d… ¡ ˆr^ˆ r^| t dd|d ¡¡ ˆrrˆrrt dd|¡}| |d d… ¡ |D ]}t dd|¡}t| |ƒI d H \}} |r�ˆ| j| ƒ‚qt|| ƒI d H S )Nú?r   Ú z//+ú/éÿÿÿÿz^//+)Ú
isinstancer   Úrouter   Úraw_pathÚsplitÚappendÚreÚsubr   Úendswithr   )r   r%   Úpaths_to_checkr   ÚqueryÚmerged_slashesÚresolves©r!   r#   r$   r"   r   r   ÚimplL   s4   €

ÿz'normalize_path_middleware.<locals>.impl©r   r	   r   r
   )r!   r"   r#   r$   Úcorrect_configurationr7   r   r6   r   r   &   s
   
#"r   r   r   c                    s"   t dtdtdtf‡ fdd„ƒ}|S )Nr   r%   r   c                 “   s4   �| j }|j}ˆ |_z|| ƒI d H W ||_S ||_w )N)r   Úcurrent_app)r   r%   r   Úprev©r   r   r   r7   o   s   €z&_fix_request_current_app.<locals>.implr8   )r   r7   r   r<   r   Ú_fix_request_current_appn   s   	r=   )r/   Útypingr   r   Útypedefsr   r   Úweb_exceptionsr   r   Úweb_requestr	   Úweb_responser
   Úweb_urldispatcherr   Ú__all__Úweb_appr   r   ÚstrÚtupleÚboolr   r   Útyper   r=   r   r   r   r   Ú<module>   s:    ûþýüû
úH