HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/aiohttp/__pycache__/web_urldispatcher.cpython-310.pyc
o

���g1��@sfUddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZddl
mZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z+ddl,m-Z-dd	lm.Z.m/Z/m0Z0dd
l1m2Z2ddl3m4Z4ddl5m6Z6m7Z7dd
l8m9Z9m:Z:m;Z;m<Z<m=Z=ddl>m?Z?ddl@mAZAddlBmCZCmDZDddlEmFZFdZGer�ddlHmIZIeeJeJfZKneLZKe
jMdkr�e
jN�Od�r�ePfn	e
jMdkr�eQfndZReSeTeUe+�Vd�dd���ZWee#eUdfeXd<e	�Yd�ZZee eJeXd<e	�Yd�Z[ee eJeXd<e	�\d �Z]eeJeXd!<eeAgeeeDfZ^e#ed"e!eJfZ_ej`ej\d#d$�ZaGd%d&�d&e%d'd(�ZbGd)d*�d*e"ed+�ZcGd,d+�d+ejd�ZeGd-d"�d"eKe.�ZfGd.d/�d/ef�Zgd0eAd1dfd2d3�ZhGd4d5�d5ec�ZiGd6d7�d7ei�ZjGd8d9�d9ei�ZkGd:d;�d;ec�ZlGd<d=�d=el�ZmGd>d?�d?el�ZnGd@dA�dAejd�ZoGdBdC�dCeo�ZpGdDdE�dEep�ZqGdFdG�dGen�ZrGdHdI�dIee�ZsGdJdK�dKee�ZtGdLdM�dMe0�ZuGdNdO�dOe"eeceec�ZvGdPdQ�dQe"eeeeee�ZwGdRdS�dSe/eeJecf�ZxdTeJd1eJfdUdV�ZydTeJd1eJfdWdX�ZzdTeJd1eJfdYdZ�Z{dS)[�N)�wraps)�Path)�MappingProxyType)�
TYPE_CHECKING�Any�	Awaitable�Callable�	Container�Dict�Final�	Generator�Iterable�Iterator�List�Mapping�NoReturn�Optional�Pattern�Set�Sized�Tuple�Type�	TypedDict�Union�cast)�URL�__version__�)�hdrs)�AbstractMatchInfo�AbstractRouter�AbstractView)�DEBUG)�
HttpVersion11)�Handler�PathLike)�
HTTPException�HTTPExpectationFailed�
HTTPForbidden�HTTPMethodNotAllowed�HTTPNotFound)�FileResponse)�Request)�Response�StreamResponse)�AbstractRouteDef)
�
UrlDispatcher�UrlMappingMatchInfo�AbstractResource�Resource�
PlainResource�DynamicResource�
AbstractRoute�
ResourceRoute�StaticResource�View)�Application)��
�win32)r;�
��.�.�YARL_VERSIONz$^[0-9A-Za-z!#\$%&'\*\+\-\.\^_`\|~]+$�HTTP_METHOD_REz*(\{[_a-zA-Z][^{}]*(?:\{[^{}]*\}[^{}]*)*\})�ROUTE_RE�/�PATH_SEPr1T)�quotec@sjeZdZUeed<eed<eeed<eed<eed<eedfed<ded	<eed
<ded<eed
<dS)�	_InfoDict�path�	formatter�pattern�	directory�prefixr6�routesr:�app�domain�AbstractRuleMatching�rule�http_exceptionN)	�__name__�
__module__�__qualname__�str�__annotations__rrrr&r?r?r?�D/usr/local/lib/python3.10/dist-packages/aiohttp/web_urldispatcher.pyrHhs
rHF)�totalc@s�eZdZdd�deeddfdd�Zedeefdd��Zeej	defd	d
���Z
ej	dedefdd
��Zej	de
defdd��Zej	deddfdd��Zej	defdd��Zddd�Zej	dedefdd��ZdS)r2N��namer\�returncC�
||_dS�N��_name��selfr\r?r?rY�__init__|�
zAbstractResource.__init__cC�|jSr_r`�rcr?r?rYr\�zAbstractResource.namecC�dS)zWExposes the resource's canonical path.

        For example '/foo/bar/{name}'

        Nr?rgr?r?rY�	canonical��zAbstractResource.canonical�kwargscKri)z2Construct url for resource with additional params.Nr?)rcrlr?r?rY�url_for�rkzAbstractResource.url_for�requestc���dS)zWResolve resource.

        Return (UrlMappingMatchInfo, allowed_methods) pair.
        Nr?�rcrnr?r?rY�resolve��zAbstractResource.resolverMcCri)zWAdd a prefix to processed URLs.

        Required for subapplications support.
        Nr?�rcrMr?r?rY�
add_prefix�rkzAbstractResource.add_prefixcCri�z;Return a dict with additional info useful for introspectionNr?rgr?r?rY�get_info�rkzAbstractResource.get_infocC�dSr_r?rgr?r?rY�freeze��zAbstractResource.freezerIcCri)z Perform a raw match against pathNr?�rcrIr?r?rY�	raw_match�rkzAbstractResource.raw_match�r]N)rTrUrVrrWrd�propertyr\�abc�abstractmethodrjrrmr,�_ResolverqrtrHrvrx�boolr{r?r?r?rYr2{s$
r2r6c@s�eZdZddd�dedeeeefdee	dee
ddf
dd	�Zedefd
d��Z
edefdd
��Zeejdeefdd���Zedee
fdd��Zejdefdd��Zejdededefdd��Zdedeefdd�ZdS)r6N��expect_handler�resource�method�handlerr�r�r]cs�|durt}t�|�sJd|����|��}t�|�s"t|�d���t|�s*J|��t�|�r0n0t�	|�r<t
�dt�n$t
|t�rGt|t�rGnt
�dt�t|�dtdtf�fdd��}|�|}||_||_||_||_dS)	NzCoroutine is expected, got z is not allowed HTTP methodz6Bare generators are deprecated, use @coroutine wrapperz-Bare functions are deprecated, use async onesrnr]c�s0��|�}t�|�r|IdH}t|t�sJ�|Sr_)�asyncio�iscoroutine�
isinstancer.)rn�result��old_handlerr?rY�handler_wrapper�s�

z/AbstractRoute.__init__.<locals>.handler_wrapper)�_default_expect_handlerr��iscoroutinefunction�upperrC�match�
ValueError�callable�inspect�isgeneratorfunction�warnings�warn�DeprecationWarningr��type�
issubclassr!rr,r.�_method�_handler�_expect_handler�	_resource)rcr�r�r�r�r�r?r�rYrd�s>	��


��
zAbstractRoute.__init__cCrfr_)r�rgr?r?rYr��rhzAbstractRoute.methodcCrfr_)r�rgr?r?rYr��rhzAbstractRoute.handlercCri)z8Optional route's name, always equals to resource's name.Nr?rgr?r?rYr\�rkzAbstractRoute.namecCrfr_)r�rgr?r?rYr��rhzAbstractRoute.resourcecCrirur?rgr?r?rYrv�rkzAbstractRoute.get_info�argsrlcOri�z/Construct url for route with additional params.Nr?�rcr�rlr?r?rYrm�rkzAbstractRoute.url_forrnc�s�|�|�IdHSr_)r�rpr?r?rY�handle_expect_header���z"AbstractRoute.handle_expect_header)rTrUrVrWrr$rr!r�_ExpectHandlerr2rdr}r�r�r~rr\r�rHrvrrmr,r.r�r?r?r?rYr6�s8�����
�3cs�eZdZdZdeeefdeddf�fdd�Zede	fdd	��Z
edefd
d��Zedefdd
��Z
edeefdd��Zdefdd�Zededfdd��Zd dd�Zed!dd��Zejd dd��Zd"dd�Zdef�fdd�Z�ZS)#r1)�_route�_apps�_current_app�_frozen�
match_dict�router]Ncs(t��|�||_g|_d|_d|_dS�NF)�superrdr�r�r�r�)rcr�r���	__class__r?rYrd�s

zUrlMappingMatchInfo.__init__cC�|jjSr_)r�r�rgr?r?rYr��zUrlMappingMatchInfo.handlercCrfr_)r�rgr?r?rYr�
rhzUrlMappingMatchInfo.routecCr�r_)r�r�rgr?r?rYr�r�z"UrlMappingMatchInfo.expect_handlercCrwr_r?rgr?r?rYrS�z"UrlMappingMatchInfo.http_exceptioncCs
|j��Sr_)r�rvrgr?r?rYrvrezUrlMappingMatchInfo.get_info)r:.cC�
t|j�Sr_)�tupler�rgr?r?rY�appss
zUrlMappingMatchInfo.appsrOr:cCs0|jrtd��|jdur||_|j�d|�dS)Nz-Cannot change apps stack after .freeze() callr)r��RuntimeErrorr�r��insert�rcrOr?r?rY�add_apps

zUrlMappingMatchInfo.add_appcCs|j}|dus	J�|Sr_)r�r�r?r?rY�current_app$szUrlMappingMatchInfo.current_appcCs*tr||jvrtd�|j|���||_dS)Nz1Expected one of the following apps {!r}, got {!r})r"r�r��formatr�r�r?r?rYr�*s
��
cCs
d|_dS)NT)r�rgr?r?rYrx5rezUrlMappingMatchInfo.freezecsdt����d|j�d�S)Nz<MatchInfo z: �>)r��__repr__r�rgr�r?rYr�8szUrlMappingMatchInfo.__repr__)rOr:r]N)r]r:r|)rTrUrV�	__slots__r
rWr6rdr}r$r�r�r�r�rr&rSrHrvrr�r�r��setterrxr��
__classcell__r?r?r�rYr1�s*"


csJeZdZdZdeddf�fdd�Zedefdd��Zdefd	d
�Z	�Z
S)�MatchInfoError��
_exceptionrSr]Ncs||_t��it|j��dSr_)r�r�rd�SystemRoute�rcrSr�r?rYrd@szMatchInfoError.__init__cCrfr_r�rgr?r?rYrSDrhzMatchInfoError.http_exceptioncCsd�|jj|jj�S)Nz<MatchInfoError {}: {}>)r�r��status�reasonrgr?r?rYr�Hs�zMatchInfoError.__repr__)rTrUrVr�r&rdr}rSrWr�r�r?r?r�rYr�<sr�rnr]c�sX�|j�tjd�}|jtkr*|��dkr#|j�d�IdHd|j_	dSt
d|d��dS)z�Default handler for Expect header.

    Just send "100 Continue" to client.
    raise HTTPExpectationFailed if value of header is not "100-continue"
    �z100-continuesHTTP/1.1 100 Continue

NrzUnknown Expect: %s)�text)�headers�getr�EXPECT�versionr#�lower�writer�write�output_sizer')rn�expectr?r?rYr�Ns�
�r�c	s�eZdZdd�deeddf�fdd�Zdd�ded	eeee	fd
ee
ddfdd
�Zddd�Zde
defdd�Zejdedeeeeffdd��Zdefdd�Zdedfdd�Z�ZS)r3Nr[r\r]cs&t�j|d�i|_d|_t�|_dS)Nr[)r�rd�_routes�
_any_route�set�_allowed_methodsrbr�r?rYrd_szResource.__init__�r�r�r�r�r7cCsD|j�||j�}rtd|j�d���t||||d�}|�|�|S)Nz+Added route will never be executed, method z is already registeredr�)r�r�r�r�r�r7�register_route)rcr�r�r�r��	route_objr?r?rY�	add_routees��
zResource.add_router�cCsHt|t�sJd|����|jtjkr||_|j�|j�||j|j<dS)Nz)Instance of Route class is required, got )	r�r7r�r�METH_ANYr�r��addr��rcr�r?r?rYr�ws��zResource.register_routernc�sR�|�|jj�}durdt�fS|j�|j|j�}r$t||�|j	fSd|j	fSr_)
�_match�rel_url�	path_safer�r�r�r�r�r1r�)rcrnr�r�r?r?rYrq�s�

zResource.resolverIcCrwr_r?rzr?r?rYr��r�zResource._matchcCr�r_��lenr�rgr?r?rY�__len__�rezResource.__len__cC�t|j���Sr_��iterr��valuesrgr?r?rY�__iter__��zResource.__iter__)r�r7r]N)rTrUrVrrWrdrrr!r$r�r�r�r,r�rqr~rr
r��intr�rr�r�r?r?r�rYr3^s$ ����
�
	 r3cs�eZdZdd�dedeeddf�fdd�Zedefdd	��Zdd
d�Zdeddfd
d�Z	dedee
eeffdd�Zdedefdd�Z
defdd�Zdefdd�Zdefdd�Z�ZS)r4Nr[rIr\r]cs*t�j|d�|r|�d�sJ�||_dS)Nr[rE)r�rd�
startswith�_path)rcrIr\r�r?rYrd�s
zPlainResource.__init__cCrfr_�r�rgr?r?rYrj�rhzPlainResource.canonicalcCs|jsd|_dSdS)NrEr�rgr?r?rYrx�s
�zPlainResource.freezerMcCs<|�d�sJ�|�d�rJ�t|�dksJ�||j|_dS�NrEr)r��endswithr�r�rsr?r?rYrt�szPlainResource.add_prefixcCs|j|kriSdSr_r�rzr?r?rYr��s
zPlainResource._matchcC�
|j|kSr_r�rzr?r?rYr{�rezPlainResource.raw_matchcC�
d|jiS)NrIr�rgr?r?rYrv�rezPlainResource.get_infocCstj|jdd�S)NT�rI�encoded)r�buildr�rgr?r?rYrm��zPlainResource.url_forcCs0|jdurd|jdnd}d|�d|j�d�S)N�'�' r�z<PlainResource � r�)r\r�rbr?r?rYr��szPlainResource.__repr__r|)rTrUrVrWrrdr}rjrxrtr
r�r�r{rHrvrrmr�r�r?r?r�rYr4�s$
r4cs�eZdZe�d�Ze�d�ZdZdd�dede	eddf�fd	d
�Z
edefdd��Zd
eddfdd�Z
dede	eeeffdd�Zdedefdd�Zdefdd�Zdedefdd�Zdefdd�Z�ZS)r5z#\{(?P<var>[_a-zA-Z][_a-zA-Z0-9]*)\}z.\{(?P<var>[_a-zA-Z][_a-zA-Z0-9]*):(?P<re>.+)\}z[^{}/]+Nr[rIr\r]c	
s^t�j|d�||_d}d}t�|�D]d}|j�|�}|r5|d�|�d�|j	�7}|d|�d�d7}q|j
�|�}|rU|djdi|����7}|d|�d�d7}qd|vs]d|vrhtd|�d	|�d
���t
|�}||7}|t�|�7}qzt�|�}Wntjy�}ztd|�d|���d�d}~ww|j�t�s�J�|�d
�s�J�||_||_dS)Nr[r�z
(?P<{}>{})�var�{�}z(?P<{var}>{re})zInvalid path 'z'['z']z
Bad pattern 'z': rEr?)r�rd�
_orig_pathrD�split�DYN�	fullmatchr��group�GOOD�DYN_WITH_RE�	groupdictr��
_requote_path�re�escape�compile�errorrKr�rF�_pattern�
_formatter)	rcrIr\rKrJ�partr��compiled�excr�r?rYrd�s<��
zDynamicResource.__init__cCrfr_)r	rgr?r?rYrj�rhzDynamicResource.canonicalrMcCsV|�d�sJ�|�d�rJ�t|�dksJ�t�t�|�|jj�|_||j|_dSr�)	r�r�r�rrrrrKr	rsr?r?rYrt�s
zDynamicResource.add_prefixcCs.|j�|�}|durdSdd�|����D�S)NcS�i|]	\}}|t|��qSr?)�_unquote_path_safe)�.0�key�valuer?r?rY�
<dictcomp>�s�z*DynamicResource._match.<locals>.<dictcomp>)rr�r�items)rcrIr�r?r?rYr��s
�zDynamicResource._matchcCr�r_)r�rzr?r?rYr{�rezDynamicResource.raw_matchcC�|j|jd�S)N)rJrK)r	rrgr?r?rYrv�r�zDynamicResource.get_info�partscKs(|j�dd�|��D��}tj|dd�S)NcSr
r?)�_quote_path)r�k�vr?r?rYr�sz+DynamicResource.url_for.<locals>.<dictcomp>Tr�)r	�
format_maprrr�)rcr�urlr?r?rYrm�szDynamicResource.url_forcCs,|jdurd|jdnd}dj||jd�S)Nr�r�r�z$<DynamicResource {name} {formatter}>)r\rJ)r\r�r	rbr?r?rYr�s�zDynamicResource.__repr__)rTrUrVrrr�rrrWrrdr}rjrtr
r�r�r{rHrvrrmr�r�r?r?r�rYr5�s

$"r5csjeZdZdd�dedeeddf�fdd�Zedefdd	��Zdeddfd
d�Zdede	fdd
�Z
�ZS)�PrefixResourceNr[rMr\r]csX|r|�d�sJ|��|dvs|�d�rJ|��t�j|d�t|�|_|jd|_dS)NrE)r�rEr[)r�r�r�rdr�_prefix�_prefix2)rcrMr\r�r?rYrd	s

zPrefixResource.__init__cCrfr_)rrgr?r?rYrjrhzPrefixResource.canonicalcCsH|�d�sJ�|�d�rJ�t|�dksJ�||j|_|jd|_dSr�)r�r�r�rrrsr?r?rYrts
zPrefixResource.add_prefixcCrir�r?rsr?r?rYr{ryzPrefixResource.raw_match)rTrUrVrWrrdr}rjrtr�r{r�r?r?r�rYrs$rcs*eZdZdZddddddd�dededeed	eed
ede	de	d
e	ddf�fdd�Z
dd�ded
ee	defdd�Ze
dedefdd��Zdefdd�Zdeddfdd�Zdedefdd�Zdefd d!�Zdeefd"d#�Zdedefd$d%�Zd&edefd'd(�Zd)edefd*d+�Zdefd,d-�Z �Z!S).r8rN�F�r\r��
chunk_size�
show_index�follow_symlinks�append_versionrMrLr\r�r r!r"r#r]c

s�t�j||d�zt|���jdd�}Wnty)}	z	td|�d��|	�d}	~	ww|��s6td|�d���||_||_	||_
||_||_||_
td|j||d�td	|j||d�d
�|_t|j�|_dS)Nr[T)�strictr�z' does not existz' is not a directory�GETr��HEAD)r%r&)r�rdr�
expanduserrq�FileNotFoundErrorr��is_dir�
_directory�_show_index�_chunk_size�_follow_symlinksr��_append_versionr7�_handler�r�r�)
rcrMrLr\r�r r!r"r#rr�r?rYrd$s.��
�
��zStaticResource.__init__)r#�filenamec
	Cs|dur|j}t|��d�}tj|jdd�}tdkr#||�dd�}n||}|r�|j�	|�}z"|j
rFttj
�|��}|�|j�|��}n
|��}|�|j�Wn
ttfy^|YSw|��r�|�d��}|��}Wd�n1swwY|�|�}	|�|j|	i�}|S|S)NrETr��r��%�%25�rb)r.rW�lstriprr�rrB�replacer*�joinpathr-r�osrI�normpath�relative_torqr�r(�is_file�open�read�_get_file_hash�
with_query�VERSION_KEY)
rcr0r#r�unresolved_path�normalized_path�filepath�f�
file_bytes�hr?r?rYrmHs8
��
�
zStaticResource.url_for�
byte_arraycCs*t��}|�|�t�|���}|�d�S)N�ascii)�hashlib�sha256�update�base64�urlsafe_b64encode�digest�decode)rH�m�b64r?r?rYr?qs

zStaticResource._get_file_hashcCs|j|j|jd�S)N)rLrMrN)r*rr�rgr?r?rYrvxs�zStaticResource.get_infor�cCs:d|jvr	td��td|||jd�|jd<|j�d�dS)N�OPTIONSzOPTIONS route was set alreadyr�)r�r�r7r�r�r�)rcr�r?r?rY�set_options_routes

�z StaticResource.set_options_routernc�sx�|jj}|j}|�|j�s||jkrdt�fS|j}||vr#d|fSdt|t	|j�dd��i}t
||j|�|fS)Nr0r)r�r�r�r�rrr�r�rr�r1r�)rcrnrIr��allowed_methodsr�r?r?rYrq�s�
zStaticResource.resolvecCr�r_r�rgr?r?rYr��rezStaticResource.__len__cCr�r_r�rgr?r?rYr��r�zStaticResource.__iter__c�sJ�|jd}t|�}|jrt��|j�|�}t��}|�d|j	|�IdHS)Nr0)
�
match_infor�anchorr(r*r8r��get_running_loop�run_in_executor�_resolve_path_to_response)rcrnr�r0rB�loopr?r?rYr/�s�

�zStaticResource._handlerBc
Cs�z"|jrttj�|��}|�|j�|��}n
|��}|�|j�Wntgt	�Ry6}zt
�|�d}~wwz|��rL|jrIt
|�|�dd�WSt��Wnty]}zt�|�d}~wwt||jd�S)zFTake the unresolved path and query the file system to form a response.Nz	text/html)r��content_type)r )r-rr9rIr:r;r*rqr��CIRCULAR_SYMLINK_ERRORr*r)r+r-�_directory_as_htmlr(�PermissionErrorr+r,)rcrBrC�	file_pathrr?r?rYrZ�s4
�������z(StaticResource._resolve_path_to_response�dir_pathcCs�|��sJ�|�|j���}dt|���}d|�d�}g}|��}t|�D]0}|�|j���}t|j�d|���}	|��rD|j	�d�}
n|j	}
|�
d|	�dt|
��d��q%d�d	�|��}d
|�d	|�d�}d|�d
�}
d|
�d	|�d�}|S)z"returns directory's index as html.z
Index of /z<h1>z</h1>rEz
<li><a href="z">z	</a></li>z
<ul>
{}
</ul>�
z<body>
z
</body>z<head>
<title>z</title>
</head>z<html>
z
</html>)
r)r;r*�as_posix�html_escape�iterdir�sortedrrr\�appendr��join)rcra�relative_path_to_dir�index_of�h1�
index_list�	dir_index�_file�rel_path�quoted_file_url�	file_name�ul�body�head_str�htmlr?r?rYr^�s(�z!StaticResource._directory_as_htmlcCs0|jdurd|jdnd}dj||j|jd�S)Nr�r�z/<StaticResource {name} {path} -> {directory!r}>)r\rIrL)r\r�rr*rbr?r?rYr��s
�zStaticResource.__repr__)"rTrUrVrArWr%rr�r�r�rdrrm�staticmethod�bytesr?rHrvr$rTr,r�rqr�rr6r�r.r/rrZr^r�r�r?r?r�rYr8!s\�������	�
��(���
�)
# r8cs�eZdZdeddddf�fdd�Zdeddf�fdd	�Zdeddfd
d�Zded
edefdd�Zde	fdd�Z
dedefdd�Z
defdd�Zdeefdd�Zdefdd�Z�ZS)�PrefixedSubAppResourcerMrOr:r]Ncs t��|�||_|�|�dSr_)r�rd�_app�_add_prefix_to_resources)rcrMrOr�r?rYrd�szPrefixedSubAppResource.__init__cst��|�|�|�dSr_)r�rtrzrsr�r?rYrt�sz!PrefixedSubAppResource.add_prefixcCs8|jj}|��D]}|�|�|�|�|�|�qdSr_)ry�router�	resources�unindex_resourcert�index_resource)rcrMr{r�r?r?rYrz�s

�z/PrefixedSubAppResource._add_prefix_to_resourcesr�rlcO�td��)Nz3.url_for() is not supported by sub-application root�r�r�r?r?rYrm�zPrefixedSubAppResource.url_forcCr)N)rOrM)ryrrgr?r?rYrv	r�zPrefixedSubAppResource.get_infornc�sL�|jj�|�IdH}|�|j�t|jt�r|jj}||fSt�}||fSr_)	ryr{rqr�r�rSr)rUr��rcrnrV�methodsr?r?rYrqs��zPrefixedSubAppResource.resolvecC�t|jj���Sr_)r�ryr{rNrgr?r?rYr�r�zPrefixedSubAppResource.__len__cCr�r_)r�ryr{rNrgr?r?rYr�r�zPrefixedSubAppResource.__iter__cCsdj|j|jd�S)Nz,<PrefixedSubAppResource {prefix} -> {app!r}>)rMrO)r�rryrgr?r?rYr�s�zPrefixedSubAppResource.__repr__)rTrUrVrWrdrtrzrrmrHrvr,r�rqr�r�rr6r�r�r�r?r?r�rYrx�s		rxc@sPeZdZejdedefdd��Zejdefdd��Z	e
ejdefdd���Zd	S)
rQrnr]c�ro)z1Return bool if the request satisfies the criteriaNr?rpr?r?rYr�"rrzAbstractRuleMatching.matchcCrirur?rgr?r?rYrv&rkzAbstractRuleMatching.get_infocCri)zReturn a strNr?rgr?r?rYrj*rkzAbstractRuleMatching.canonicalN)
rTrUrVr~rr,r�r�rHrvr}rWrjr?r?r?rYrQ!srQcs�eZdZe�d�Zdeddf�fdd�Zedefdd��Z	dedefd	d
�Z
dedefdd
�Z
dedefdd�Zdefdd�Z�ZS)�Domainz(?!-)[a-z\d-]{1,63}(?<!-)rPr]Ncst���|�|�|_dSr_)r�rd�
validation�_domain)rcrPr�r?rYrd3s
zDomain.__init__cCrfr_�r�rgr?r?rYrj7rhzDomain.canonicalcs�t|t�s	td��|�d���}|std��d|vrtd��td|�}|jdus+J�t�fdd�|j�	d�D��s>td	��|j
d
krF|jS|j�d|j
��S)NzDomain must be strr@zDomain cannot be emptyz://zScheme not supportedzhttp://c3s�|]	}�j�|�VqdSr_)�re_partr�)r�xrgr?rY�	<genexpr>Es�z$Domain.validation.<locals>.<genexpr>zDomain not valid�P�:)r�rW�	TypeError�rstripr�r�r�raw_host�allr��port)rcrPrr?rgrYr�;s

zDomain.validationrnc�s"�|j�tj�}|sdS|�|�Sr�)r�r�r�HOST�match_domain)rcrn�hostr?r?rYr�Ks
�
zDomain.matchr�cCs|��|jkSr_)r�r��rcr�r?r?rYr�Qr�zDomain.match_domaincCr�)NrPr�rgr?r?rYrvTrezDomain.get_info)rTrUrVrrr�rWrdr}rjr�r,r�r�r�rHrvr�r?r?r�rYr�0s
r�csTeZdZe�d�Zdeddf�fdd�Zedefdd��Z	d	ede
fd
d�Z�ZS)�
MaskDomainz(?!-)[a-z\d\*-]{1,63}(?<!-)rPr]Ncs2t��|�|j�dd��dd�}t�|�|_dS)Nr@z\.�*z.*)r�rdr�r7rr�_mask)rcrP�maskr�r?rYrd[szMaskDomain.__init__cCr�r_)r�rKrgr?r?rYrj`r�zMaskDomain.canonicalr�cCs|j�|�duSr_)r�r�r�r?r?rYr�dr�zMaskDomain.match_domain)
rTrUrVrrr�rWrdr}rjr�r�r�r?r?r�rYr�Xs
r�c@sbeZdZdeddddfdd�Zedefdd	��Zdefd
d�Z	de
defd
d�Zdefdd�Z
dS)�MatchedSubAppResourcerRrOr:r]NcCs t�|�d|_||_||_dS)Nr�)r2rdrry�_rule)rcrRrOr?r?rYrdis

zMatchedSubAppResource.__init__cCr�r_)r�rjrgr?r?rYrjor�zMatchedSubAppResource.canonicalcCr)N)rOrR)ryr�rgr?r?rYrvsr�zMatchedSubAppResource.get_infornc�sh�|j�|�IdHsdt�fS|jj�|�IdH}|�|j�t|jt	�r-|jj
}||fSt�}||fSr_)r�r�r�ryr{rqr�r�rSr)rUr�r?r?rYrqvs�
�zMatchedSubAppResource.resolvecCsd|j�d�S)Nz<MatchedSubAppResource -> r�)ryrgr?r?rYr��r�zMatchedSubAppResource.__repr__)rTrUrVrQrdr}rWrjrHrvr,r�rqr�r?r?r?rYr�hsr�cs�eZdZdZdd�dedeeeefde	de
eddf
�fd	d
�Zdefdd�Z
ede
efd
d��Zdededefdd�Zdefdd�Z�ZS)r7zA route with resourceNr�r�r�r�r�r]cst�j||||d�dS)Nr�)r�rd)rcr�r�r�r�r�r?rYrd�s
�zResourceRoute.__init__cCsdj|j|j|jd�S)Nz3<ResourceRoute [{method}] {resource} -> {handler!r})r�r�r�)r�r�r�r�rgr?r?rYr��s�zResourceRoute.__repr__cCs|jdurdS|jjSr_)r�r\rgr?r?rYr\�s
zResourceRoute.namer�rlcOs |jdusJ�|jj|i|��Sr�)r�rmr�r?r?rYrm�szResourceRoute.url_forcCs|jdusJ�|j��Sr_)r�rvrgr?r?rYrv�s
zResourceRoute.get_info)rTrUrV�__doc__rWrr$rr!r2rr�rdr�r}r\rrmrHrvr�r?r?r�rYr7�s&������r7cs�eZdZdeddf�fdd�Zdededefdd	�Zede	efd
d��Z
defdd
�Zde
defdd�Zedefdd��Zedefdd��Zdefdd�Z�ZS)r�rSr]Ncst��tj|j�||_dSr_)r�rdrr�r/�_http_exceptionr�r�r?rYrd�s
zSystemRoute.__init__r�rlcOr)Nz).url_for() is not allowed for SystemRouter�r�r?r?rYrm�r�zSystemRoute.url_forcCrwr_r?rgr?r?rYr\�r�zSystemRoute.namecCr�)NrS�r�rgr?r?rYrv�rezSystemRoute.get_infornc�s�|j�r_r�rpr?r?rYr/�s�zSystemRoute._handlecCr�r_)r�r�rgr?r?rYr��r�zSystemRoute.statuscCr�r_)r�r�rgr?r?rYr��r�zSystemRoute.reasoncCsdj|d�S)Nz*<SystemRoute {self.status}: {self.reason}>rg)r�rgr?r?rYr���zSystemRoute.__repr__)rTrUrVr&rdrWrrmr}rr\rHrvr,r.r/r�r�r�r�r�r?r?r�rYr��sr�c@s@eZdZdefdd�Zdeedeffdd�Zdefdd�Z	dS)	r9r]c�sZ�|jjtjvr|��t||jj��d�}|dur|��|�IdH}t|t�s+J�|Sr_)	rnr�r�METH_ALL�_raise_allowed_methods�getattrr�r�r.)rcr��retr?r?rY�_iter�s�z
View._iterNcCs|����Sr_)r��	__await__rgr?r?rYr��r�zView.__await__cs"�fdd�tjD�}t�jj|��)Ncsh|]}t�|���r|�qSr?)�hasattrr�)rrQrgr?rY�	<setcomp>�sz.View._raise_allowed_methods.<locals>.<setcomp>)rr�r)rnr�)rcrUr?rgrYr��szView._raise_allowed_methods)
rTrUrVr.r�rrr�rr�r?r?r?rYr9�sr9c@sTeZdZdeeddfdd�Zdefdd�Zdeefdd	�Z	d
e
defdd�ZdS)
�
ResourcesViewr|r]NcCr^r_��
_resources)rcr|r?r?rYrd�rezResourcesView.__init__cCr�r_)r�r�rgr?r?rYr��rezResourcesView.__len__cc��|jEdHdSr_r�rgr?r?rYr��r�zResourcesView.__iter__r�cC�
||jvSr_r��rcr�r?r?rY�__contains__�rezResourcesView.__contains__)
rTrUrVrr2rdr�r�rr��objectr�r�r?r?r?rYr��s
r�c@sPeZdZdeefdd�Zdefdd�Zdee	fdd�Z
d	edefd
d�Z
dS)
�
RoutesViewr|cCs*g|_|D]
}|D]}|j�|�q	qdSr_)r�rg)rcr|r�r�r?r?rYrd�s��zRoutesView.__init__r]cCr�r_r�rgr?r?rYr��rezRoutesView.__len__ccr�r_�r�rgr?r?rYr��r�zRoutesView.__iter__r�cCr�r_r�r�r?r?rYr��rezRoutesView.__contains__N)rTrUrVrr2rdr�r�rr6r�r�r�r�r?r?r?rYr��s
r�cs�eZdZe�d�ZdN�fdd�Zdedefdd�Z	de
efd	d
�Zde
fdd�Zd
edefdd�Zdedefdd�Zdefdd�Zdefdd�Zdeeeffdd�Zd
eddfdd�Zd
edefdd�Zd
eddfdd�Zd
eddfdd �Zdd!�d"edeedefd#d$�Z ddd%�d&ed"ed'e!e"e#e$fdeed(ee%de&fd)d*�Z'ddd+d,d,d,d-�d.ed"e(deed(ee%d/e
d0ed1ed2edefd3d4�Z)d"ed'e"d5e*de&fd6d7�Z+d"ed'e"d5e*de&fd8d9�Z,dd:d;�d"ed'e"deed<ed5e*de&fd=d>�Z-d"ed'e"d5e*de&fd?d@�Z.d"ed'e"d5e*de&fdAdB�Z/d"ed'e"d5e*de&fdCdD�Z0d"ed'e"d5e*de&fdEdF�Z1d"ed'e#e$d5e*de&fdGdH�Z2dN�fdIdJ�Z3dKe4e5de6e&fdLdM�Z7�Z8S)Or0z[.:-]r]Ncs&t���g|_i|_i|_g|_dSr_)r�rdr��_named_resources�_resource_index�_matched_sub_app_resourcesrgr�r?rYrd�s


zUrlDispatcher.__init__rnc	�s��|j}t�}|jj}|r<|�|d�D]}|�|�IdH\}}|dur'|S||O}q|dkr1n|�d�dp9d}|s
|jD]}|�|�IdH\}}|durS|S||O}q?|rbtt	|j
|��Stt��S)Nr?rEr)r�r�r�r�r�rq�
rpartitionr�r�r)r�r*)	rcrn�resource_indexrU�url_part�	candidater��allowedr�r?r?rYrqs,�
�


zUrlDispatcher.resolvecCr�r_)r�r�rgr?r?rYr�.rezUrlDispatcher.__iter__cCr�r_)r�r�rgr?r?rYr�1rezUrlDispatcher.__len__r�cCr�r_�r�r�r?r?rYr�4rezUrlDispatcher.__contains__r\cCs
|j|Sr_r�rbr?r?rY�__getitem__7rezUrlDispatcher.__getitem__cCr�r_)r�r�rgr?r?rYr|:rezUrlDispatcher.resourcescCr�r_)r�r�rgr?r?rYrN=rezUrlDispatcher.routescCr�r_)rr�rgr?r?rY�named_resources@rezUrlDispatcher.named_resourcescCs�t|t�sJd|����|jrtd��|j}|durR|j�|�}|D]}t�|�r1t	d|�d���|�
�s<t	d�|���q"||jvrMt	d�||j|���||j|<|j
�|�t|t�re|j�|�dS|�|�dS)Nz4Instance of AbstractResource class is required, got z.Cannot register a resource into frozen router.zIncorrect route name z/, python keywords cannot be used for route namezoIncorrect route name {!r}, the name should be a sequence of python identifiers separated by dash, dot or columnz'Duplicate {!r}, already handled by {!r})r�r2�frozenr�r\�
NAME_SPLIT_REr��keyword�	iskeywordr��isidentifierr�r�r�rgr�r�r~)rcr�r\rr
r?r?rY�register_resourceCs>��

���
�

zUrlDispatcher.register_resourcecCs4d|j}vr|�d�d�d�d}|�d�pdS)z9Return a key to index the resource in the resource index.r�rrE)rj�	partitionr�r�)rcr��	index_keyr?r?rY�_get_resource_index_keyjsz%UrlDispatcher._get_resource_index_keycCs"|�|�}|j�|g��|�dS)z%Add a resource to the resource index.N)r�r��
setdefaultrg�rcr��resource_keyr?r?rYr~us
zUrlDispatcher.index_resourcecCs|�|�}|j|�|�dS)z*Remove a resource from the resource index.N)r�r��remover�r?r?rYr}}s
zUrlDispatcher.unindex_resourcer[rIcCs�|r|�d�std��|jr"|jd}|j|kr"|�|�r"tt|�Sd|vs<d|vs<t�|�s<t	||d�}|�
|�|St||d�}|�
|�|S)NrEz)path should be started with / or be empty���r�r�r[)r�r�r�r\r{rr3rD�searchr4r�r5)rcrIr\r�r?r?rY�add_resource�s



zUrlDispatcher.add_resource)r\r�r�r�r�cCs|j||d�}|j|||d�S)Nr[r�)r�r�)rcr�rIr�r\r�r�r?r?rYr��s	zUrlDispatcher.add_routerFrrMr r!r"r#c

CsJ|�d�sJ�|�d�r|dd�}t||||||||d�}	|�|	�|	S)z^Add static files view.

        prefix - url prefix
        path - folder with files

        rENr�r)r�r�r8r�)
rcrMrIr\r�r r!r"r#r�r?r?rY�
add_static�s
�

zUrlDispatcher.add_staticrlcK�|jtj||fi|��S)z(Shortcut for add_route with method HEAD.)r�r�	METH_HEAD�rcrIr�rlr?r?rY�add_head��zUrlDispatcher.add_headcKr�)z+Shortcut for add_route with method OPTIONS.)r�r�METH_OPTIONSr�r?r?rY�add_options�r�zUrlDispatcher.add_optionsT)r\�
allow_headr�cKs>|j||d�}|r|jtj|fi|��|jtj|fi|��S)z�Shortcut for add_route with method GET.

        If allow_head is true, another
        route is added allowing head requests to the same endpoint.
        r[)r�r�rr��METH_GET)rcrIr�r\r�rlr�r?r?rY�add_get�szUrlDispatcher.add_getcKr�)z(Shortcut for add_route with method POST.)r�r�	METH_POSTr�r?r?rY�add_post�r�zUrlDispatcher.add_postcKr�)z'Shortcut for add_route with method PUT.)r�r�METH_PUTr�r?r?rY�add_put�r�zUrlDispatcher.add_putcKr�)z)Shortcut for add_route with method PATCH.)r�r�
METH_PATCHr�r?r?rY�	add_patch�r�zUrlDispatcher.add_patchcKr�)z*Shortcut for add_route with method DELETE.)r�r�METH_DELETEr�r?r?rY�
add_delete�r�zUrlDispatcher.add_deletecKr�)z?Shortcut for add_route with ANY methods for a class-based view.)r�rr�r�r?r?rY�add_view�szUrlDispatcher.add_viewcs"t���|jD]}|��qdSr_)r�rxr�r�r�r?rYrx�s


�zUrlDispatcher.freezerNcCs"g}|D]
}|�|�|��q|S)z�Append routes to route table.

        Parameter should be a sequence of RouteDef objects.

        Returns a list of registered AbstractRoute instances.
        )�extend�register)rcrN�registered_routes�	route_defr?r?rY�
add_routes�szUrlDispatcher.add_routesr|)9rTrUrVrrr�rdr,r1rqrrWr�r�r�r�r�r�r2r�r�r|r�rNrr�r�r�r~r}rr3r�rr$rr!r�r6r�r%r�rr�r�r�r�r�r�r�r�rxr
r/rr�r�r?r?r�rYr0�s�
)' ������
��������	�
�
�"	������
����
�"r0rcCs$tdkr
|�dd�}tj|dd�jS)Nr1r3r4Fr�)rBr7rr��raw_path�rr?r?rYrsrcCs d|vr|S|�dd��dd�S)Nr3z%2FrEr4)r7r�r?r?rYr	srcCs t|�}d|vr|�dd�}|S)Nr3r4)rr7)rr�r?r?rYrsr)|r~r�rM�	functoolsrJrur�r�r9r�sysr�r�pathlibr�typesr�typingrrrrr	r
rrr
rrrrrrrrrrrrr�yarlrr�yarl_versionr�rrr r!�helpersr"�httpr#�typedefsr$r%�web_exceptionsr&r'r(r)r*�web_fileresponser+�web_requestr,�web_responser-r.�web_routedefr/�__all__�web_appr:rW�BaseDict�dict�version_info�platformr��OSErrorr�r]r��mapr�r�rBrXrrCrDrrFr�r��partialrdrHr2�ABCr6r1r�r�r3r4r5rr8rxrQr�r�r�r7r�r9r�r�r0rrrr?r?r?rY�<module>s�
`��0��/QA6(LS.($