관리-도구
편집 파일: web_middlewares.cpython-37.pyc
B �k�a) � @ s� d dl Z d dlmZmZmZmZmZmZ ddlm Z ddl mZmZ ddl mZ ddlmZ ddlmZ d Zer|dd lmZ ed�Zeeeeef d�d d�Zeed�dd�Zeee gee f Zddded�eeeee ed�dd�Zded�dd�ZdS )� 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�}| jj�|�I d H }||_|jd kr8d|fS d| fS )N)Zrel_urlTF)�clone�appZrouter�resolveZ_match_infoZhttp_exception)r r Zalt_request� match_info� r �J/opt/alt/python37/lib64/python3.7/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� }|st d��ttttd�� ���fdd��}|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 � s4 t | jjt��r&g }d| jkr:| j�dd�\}}d| }n d}| j}�r\|�t�dd|�� � rz| j � d�sz|�|d � �r�| j � d�r�|�|d d� � �r�� r�|�t�dd|d �� �r�r�t�dd|�}|�|d d� � x@|D ]8}t�dd|�}t| |�I d H \}} |r�| j| ��q�W || �I d H S )N�?r � z//+�/���z^//+)� isinstancer Zrouter Zraw_path�split�append�re�subr �endswithr )r r"