
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    '7`a                     @   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	m
Z
 ddlmZ ddlmZ ddlmZ dZerpd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gee f 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   )HTTPPermanentRedirect	_HTTPMove)Request)StreamResponse)SystemRoute)
middlewarenormalize_path_middleware)Application_Func)requestpathreturnc                    s@   | j |d}| jj|I d H }||_|jd k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   J/opt/alt/python38/lib64/python3.8/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t dttttd fdd}|S )a  
    Middleware factory which produces a middleware that normalizes
    the path of a request. By normalizing it 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k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rt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   Zraw_pathsplitappendresubr   endswithr   )r   r"   Zpaths_to_checkr   queryZmerged_slashesZresolvesr   r   r    r   r   r   implQ   s0    

z'normalize_path_middleware.<locals>.impl)AssertionErrorr   r   _Handlerr   )r   r   r   r    Zcorrect_configurationr/   r   r.   r   r   )   s
    %
r   r   )r   r   c                    s   t tttd fdd}|S )Nr!   c              
      s2   | j   || I d H W  5 Q R  S Q R X d S )N)r   Zset_current_app)r   r"   r   r   r   r/   t   s    z&_fix_request_current_app.<locals>.impl)r   r   r1   r   )r   r/   r   r2   r   _fix_request_current_apps   s    r3   )r*   typingr   r   r   r   r   r   Zweb_exceptionsr	   r
   Zweb_requestr   Zweb_responser   Zweb_urldispatcherr   __all__Zweb_appr   r   strboolr   r   r1   Z_Middlewarer   r3   r   r   r   r   <module>   s2    J