B `a@sddlZddlmZmZmZmZmZmZddlm Z m Z ddl m Z ddl mZddlmZdZerpdd lmZed Ze eeee fd d d ZeedddZee geefZee egeefZddde deeeee edddZdedddZdS)N) TYPE_CHECKING AwaitableCallableTupleTypeTypeVar)HTTPPermanentRedirect _HTTPMove)Request)StreamResponse) SystemRoute) middlewarenormalize_path_middleware) Application_Func)requestpathreturncs@|j|d}|jj|IdH}||_|jdkr8d|fSd|fS)N)Zrel_urlTF)cloneappZrouterresolveZ _match_infoZhttp_exception)rrZ alt_request match_inforr/private/var/folders/7j/8686xlfs15q3tgljmghtvg0r0000gn/T/pip-target-isidps9b/lib/python/aiohttp/web_middlewares.py_check_request_resolvess   r)frcCs d|_|S)Nr)Z__middleware_version__)rrrrr srTF) append_slash remove_slash merge_slashesredirect_class)rrrr rcs:o }|stdttttdfdd }|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)rhandlerrcs4t|jjtr&g}d|jkr:|jdd\}}d|}n d}|j}r\|tdd|rz|j dsz||dr|j dr||ddrr|tdd|drrtdd|}||ddx@|D]8}tdd|}t ||IdH\}}|r|j|qW||IdHS)N?rz//+/z^//+) isinstancerZrouter raw_pathsplitappendresubrendswithr)rr!Zpaths_to_checkrqueryZmerged_slashesZresolves)rrr rrrimplQs0   z'normalize_path_middleware..impl)AssertionErrorrr _Handlerr )rrrr Zcorrect_configurationr.r)rrr rrr)s %  rr)rrcsttttdfdd }|S)N)rr!rc s&|j||IdHSQRXdS)N)rZset_current_app)rr!)rrrr.tsz&_fix_request_current_app..impl)rr r0r )rr.r)rr_fix_request_current_appssr1)r*typingrrrrrrZweb_exceptionsr r Z web_requestr Z web_responser Zweb_urldispatcherr __all__Zweb_apprrstrboolrrr0Z _Middlewarerr1rrrrs&      D