a
     ÑOc)  ã                   @   sü   d dl 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mZ ddlmZ ddlmZ ddlmZ d	Zer|dd
lmZ edƒZeeeeef dœdd„Zeedœdd„Zeee	gee f Zdddedœeeeee edœdd„Zdedœdd„ZdS )é    N)ÚTYPE_CHECKINGÚ	AwaitableÚCallableÚTupleÚTypeÚTypeVaré   )ÚHandler)ÚHTTPPermanentRedirectÚ	_HTTPMove)ÚRequest)ÚStreamResponse)ÚSystemRoute)Ú
middlewareÚnormalize_path_middleware)ÚApplicationÚ_Func)ÚrequestÚpathÚreturnc                 Ã   s@   | j |d�}| jj |¡I d H }||_|jd u r8d|fS d| fS )N)Zrel_urlTF)ÚcloneÚappZrouterÚresolveZ_match_infoZhttp_exception)r   r   Zalt_requestÚ
match_info© r   úN/var/www/html/gsl.tools/lib/python3.9/site-packages/aiohttp/web_middlewares.pyÚ_check_request_resolves   s    
r   )Úfr   c                 C   s
   d| _ | S )Nr   )Z__middleware_version__)r   r   r   r   r   !   s    r   TF)Úappend_slashÚremove_slashÚmerge_slashesÚredirect_class)r   r   r    r!   r   c                    s:   ˆ oˆ }|sJ dƒ‚t tttdœ‡ ‡‡‡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 slash©r   Úhandlerr   c                 “   s0  t | jjtƒ�r"g }d| jv r:| j dd¡\}}d| }n
d}| j}ˆr\| t dd|¡¡ ˆ rz| j	 
d¡sz| |d ¡ ˆrœ| j	 
d¡rœ| |d d… ¡ ˆr¼ˆ r¼| t dd|d ¡¡ ˆräˆrät dd|¡}| |d d… ¡ |D ]8}t dd|¡}t| |ƒI d H \}} |rèˆ| j| ƒ‚qè|| ƒI d H S )Nú?r   Ú z//+ú/éÿÿÿÿz^//+)Ú
isinstancer   Zrouter   Úraw_pathÚsplitÚappendÚreÚsubr   Úendswithr   )r   r#   Zpaths_to_checkr   ÚqueryZmerged_slashesZresolves©r   r    r!   r   r   r   ÚimplO   s0    

z'normalize_path_middleware.<locals>.impl©r   r   r	   r   )r   r   r    r!   Zcorrect_configurationr1   r   r0   r   r   )   s
    #
r   r   )r   r   c                    s   t tttdœ‡ fdd„ƒ}|S )Nr"   c                 “   s>   | j  ˆ ¡� || ƒI d H W  d   ƒ S 1 s00    Y  d S )N)r   Zset_current_app)r   r#   ©r   r   r   r1   r   s    z&_fix_request_current_app.<locals>.implr2   )r   r1   r   r3   r   Ú_fix_request_current_appq   s    r4   )r,   Útypingr   r   r   r   r   r   Ztypedefsr	   Zweb_exceptionsr
   r   Zweb_requestr   Zweb_responser   Zweb_urldispatcherr   Ú__all__Zweb_appr   r   ÚstrÚboolr   r   Z_Middlewarer   r4   r   r   r   r   Ú<module>   s2    ûúH