U
'7`a @ s d dl Z d dlmZmZmZmZmZmZ ddlm Z m
Z
ddlmZ ddl
mZ ddlmZ dZerpdd lmZ ed
Zeeeeef ddd
ZeedddZeegee f Zeeegee f Zddde deeeee
edddZdedddZdS ) N)
TYPE_CHECKING AwaitableCallableTupleTypeTypeVar )HTTPPermanentRedirect _HTTPMove)Request)StreamResponse)SystemRoute)
middlewarenormalize_path_middleware)Application_Func)requestpathreturnc s@ | j |d}| jj|I d H }||_|jd kr8d|fS d| fS )N)Zrel_urlTF)ZcloneappZrouterZresolveZ_match_infoZhttp_exception)r r Zalt_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_slashremove_slash
merge_slashesredirect_class)r r r r r c s: o }|st dttttd fdd}|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 slashr handlerr c s0 t | jjtr"g }d| jkr:| jdd\}}d| }n
d}| j}r\|tdd| rz| j
dsz||d r| j
dr||d d r r|tdd|d rrtdd|}||d d |D ]8}tdd|}t| |I d H \}} |r| j| q|| I d H S )N?r z//+/z^//+)
isinstancer Zrouter
Zraw_pathsplitappendresubr endswithr )r r Zpaths_to_checkr ZqueryZmerged_slashesZresolvesr r r r r r implQ s0
z'normalize_path_middleware.<locals>.impl)AssertionErrorr r _Handlerr )r r r r Zcorrect_configurationr, r r+ r r ) s
%
r r )r r c s t tttd fdd}|S )Nr c
s2 | j || I d H W 5 Q R S Q R X d S )N)r Zset_current_app)r r r r r r, t s z&_fix_request_current_app.<locals>.impl)r r r. r )r r, r r/ r _fix_request_current_apps s r0 )r( typingr r r r r r Zweb_exceptionsr r
Zweb_requestr Zweb_responser Zweb_urldispatcherr
__all__Zweb_appr r strboolr r r. Z_Middlewarer r0 r r r r <module> s2 J