o
    5׾gǪ                     @   sf  U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!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.m/Z/m0Z0 dd
l1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZCmDZD ddlEmFZF dZGerddlHmIZI eeJeJf ZKneLZKe
jMdk re
jNOdrePfn	e
jMdk reQfndZReSeTeUe+Vddd ZWee#eUdf  eXd< e	YdZZee eJ  eXd< e	YdZ[ee eJ  eXd< e	\d Z]eeJ eXd!< eeAgeeeD  f Z^e#ed" e!eJ f Z_ej`ej\d#d$ZaG d%d& d&e%d'd(ZbG d)d* d*e"ed+ ZcG d,d+ d+e jdZeG d-d" d"eKe.ZfG d.d/ d/efZgd0eAd1dfd2d3ZhG d4d5 d5ecZiG d6d7 d7eiZjG d8d9 d9eiZkG d:d; d;ecZlG d<d= d=elZmG d>d? d?elZnG d@dA dAe jdZoG dBdC dCeoZpG dDdE dEepZqG dFdG dGenZrG dHdI dIeeZsG dJdK dKeeZtG dLdM dMe0ZuG dNdO dOe"eec eec ZvG dPdQ dQe"eee eee ZwG dRdS dSe/eeJecf ZxdTeJd1eJfdUdVZydTeJd1eJfdWdXZzdTeJd1eJfdYdZZ{dS )[    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_SEPr1   T)quotec                   @   sj   e Zd ZU eed< eed< ee ed< eed< eed< eedf ed< ded	< eed
< ded< eed< dS )	_InfoDictpath	formatterpattern	directoryprefixr6   routesr:   appdomainAbstractRuleMatchingrulehttp_exceptionN)	__name__
__module____qualname__str__annotations__r   r   r   r&   r?   r?   r?   c/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/aiohttp/web_urldispatcher.pyrH   h   s   
 rH   F)totalc                   @   s   e Zd Zdddee ddfddZedee fddZeej	defd	d
Z
ej	dedefddZej	dedefddZej	deddfddZej	defddZdddZej	dedefddZdS )r2   Nnamer\   returnc                C   
   || _ d S N_nameselfr\   r?   r?   rY   __init__|      
zAbstractResource.__init__c                 C      | j S r_   r`   rc   r?   r?   rY   r\         zAbstractResource.namec                 C      dS )zWExposes the resource's canonical path.

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

        Nr?   rg   r?   r?   rY   	canonical       zAbstractResource.canonicalkwargsc                 K   ri   )z2Construct url for resource with additional params.Nr?   )rc   rl   r?   r?   rY   url_for   rk   zAbstractResource.url_forrequestc                       dS )zWResolve resource.

        Return (UrlMappingMatchInfo, allowed_methods) pair.
        Nr?   rc   rn   r?   r?   rY   resolve       zAbstractResource.resolverM   c                 C   ri   )zWAdd a prefix to processed URLs.

        Required for subapplications support.
        Nr?   rc   rM   r?   r?   rY   
add_prefix   rk   zAbstractResource.add_prefixc                 C   ri   z;Return a dict with additional info useful for introspectionNr?   rg   r?   r?   rY   get_info   rk   zAbstractResource.get_infoc                 C      d S r_   r?   rg   r?   r?   rY   freeze      zAbstractResource.freezerI   c                 C   ri   )z Perform a raw match against pathNr?   rc   rI   r?   r?   rY   	raw_match   rk   zAbstractResource.raw_matchr]   N)rT   rU   rV   r   rW   rd   propertyr\   abcabstractmethodrj   r   rm   r,   _Resolverq   rt   rH   rv   rx   boolr{   r?   r?   r?   rY   r2   {   s$    
r2   r6   c                   @   s   e Zd Zddddedeeee f dee	 dee
 ddf
dd	Zedefd
dZedefddZeejdee fddZedee
 fddZejdefddZejdededefddZdedee fddZdS )r6   Nexpect_handlerresourcemethodhandlerr   r   r]   c                   s   |d u rt }t|sJ d|| }t|s"t| dt|s*J |t|r0n0t	|r<t
dt n$t|trGt|trGnt
dt t|dtdtf fdd}| |}|| _|| _|| _|| _d S )	NzCoroutine is expected, got z is not allowed HTTP methodz6Bare generators are deprecated, use @coroutine wrapperz-Bare functions are deprecated, use async onesrn   r]   c                    s0    | }t |r|I d H }t|tsJ |S r_   )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!   r   r,   r.   _method_handler_expect_handler	_resource)rc   r   r   r   r   r   r?   r   rY   rd      s>   	



zAbstractRoute.__init__c                 C   rf   r_   )r   rg   r?   r?   rY   r      rh   zAbstractRoute.methodc                 C   rf   r_   )r   rg   r?   r?   rY   r      rh   zAbstractRoute.handlerc                 C   ri   )z8Optional route's name, always equals to resource's name.Nr?   rg   r?   r?   rY   r\      rk   zAbstractRoute.namec                 C   rf   r_   )r   rg   r?   r?   rY   r      rh   zAbstractRoute.resourcec                 C   ri   ru   r?   rg   r?   r?   rY   rv      rk   zAbstractRoute.get_infoargsrl   c                 O   ri   z/Construct url for route with additional params.Nr?   rc   r   rl   r?   r?   rY   rm      rk   zAbstractRoute.url_forrn   c                    s   |  |I d H S r_   )r   rp   r?   r?   rY   handle_expect_header      z"AbstractRoute.handle_expect_header)rT   rU   rV   rW   r   r$   r   r!   r   _ExpectHandlerr2   rd   r}   r   r   r~   r   r\   r   rH   rv   r   rm   r,   r.   r   r?   r?   r?   rY   r6      s8    
3c                       s   e Zd Zdeeef def fddZedefddZ	edefdd	Z
edefd
dZedee fddZdefddZeded fddZdddZed ddZejdddZd!ddZdef fddZ  ZS )"r1   
match_dictroutec                    s(   t  | || _g | _d | _d| _d S NF)superrd   _route_apps_current_app_frozen)rc   r   r   	__class__r?   rY   rd      s
   
zUrlMappingMatchInfo.__init__r]   c                 C      | j jS r_   )r   r   rg   r?   r?   rY   r        zUrlMappingMatchInfo.handlerc                 C   rf   r_   )r   rg   r?   r?   rY   r     rh   zUrlMappingMatchInfo.routec                 C   r   r_   )r   r   rg   r?   r?   rY   r     r   z"UrlMappingMatchInfo.expect_handlerc                 C   rw   r_   r?   rg   r?   r?   rY   rS        z"UrlMappingMatchInfo.http_exceptionc                 C   s
   | j  S r_   )r   rv   rg   r?   r?   rY   rv     re   zUrlMappingMatchInfo.get_info)r:   .c                 C   
   t | jS r_   )tupler   rg   r?   r?   rY   apps  s   
zUrlMappingMatchInfo.appsrO   r:   Nc                 C   s0   | j rtd| jd u r|| _| jd| d S )Nz-Cannot change apps stack after .freeze() callr   )r   RuntimeErrorr   r   insertrc   rO   r?   r?   rY   add_app  s
   
zUrlMappingMatchInfo.add_appc                 C   s   | j }|d us	J |S r_   )r   r   r?   r?   rY   current_app!  s   zUrlMappingMatchInfo.current_appc                 C   s*   t r|| jvrtd| j||| _d S )Nz1Expected one of the following apps {!r}, got {!r})r"   r   r   formatr   r   r?   r?   rY   r   '  s   

c                 C   s
   d| _ d S )NT)r   rg   r?   r?   rY   rx   2  re   zUrlMappingMatchInfo.freezec                    s   dt    d| j dS )Nz<MatchInfo z: >)r   __repr__r   rg   r   r?   rY   r   5  s   zUrlMappingMatchInfo.__repr__)rO   r:   r]   N)r]   r:   r|   )rT   rU   rV   r
   rW   r6   rd   r}   r$   r   r   r   r   r   r&   rS   rH   rv   r   r   r   r   setterrx   r   __classcell__r?   r?   r   rY   r1      s(    


c                       sF   e Zd Zdeddf fddZedefddZdefdd	Z  Z	S )
MatchInfoErrorrS   r]   Nc                    s   || _ t i t| j  d S r_   )
_exceptionr   rd   SystemRouterc   rS   r   r?   rY   rd   :  s   zMatchInfoError.__init__c                 C   rf   r_   )r   rg   r?   r?   rY   rS   >  rh   zMatchInfoError.http_exceptionc                 C   s   d | jj| jjS )Nz<MatchInfoError {}: {}>)r   r   statusreasonrg   r?   r?   rY   r   B  s   zMatchInfoError.__repr__)
rT   rU   rV   r&   rd   r}   rS   rW   r   r   r?   r?   r   rY   r   9  s
    r   rn   r]   c                    sX   | j tjd}| jtkr*| dkr#| jdI dH  d| j_	dS t
d| ddS )zDefault handler for Expect header.

    Just send "100 Continue" to client.
    raise HTTPExpectationFailed if value of header is not "100-continue"
     z100-continues   HTTP/1.1 100 Continue

Nr   zUnknown Expect: %s)text)headersgetr   EXPECTversionr#   lowerwriterwriteoutput_sizer'   )rn   expectr?   r?   rY   r   H  s   
r   c                	       s   e Zd Zdddee ddf fddZddded	eee e	f d
ee
 ddfddZdddZdedefddZejdedeeeef  fddZdefddZded fddZ  ZS )r3   Nr[   r\   r]   c                   s   t  j|d g | _d S )Nr[   )r   rd   _routesrb   r   r?   rY   rd   Y     
zResource.__init__r   r   r   r   r7   c                C   sP   | j D ]}|j|ks|jtjkrtdj|dqt||| |d}| | |S )NzOAdded route will never be executed, method {route.method} is already registered)r   r   )r   r   r   METH_ANYr   r   r7   register_route)rc   r   r   r   	route_objr?   r?   rY   	add_route]  s   

zResource.add_router   c                 C   s(   t |tsJ d|| j| d S )Nz)Instance of Route class is required, got )r   r7   r   appendrc   r   r?   r?   rY   r   q  s   zResource.register_routern   c                    sp   t  }| |jj}|d u rd |fS | jD ]}|j}|| ||jks*|tjkr3t	|||f  S qd |fS r_   )
set_matchrel_url	path_safer   r   addr   r   r1   )rc   rn   allowed_methodsr   r   route_methodr?   r?   rY   rq   w  s   

zResource.resolverI   c                 C   rw   r_   r?   rz   r?   r?   rY   r     r   zResource._matchc                 C   r   r_   lenr   rg   r?   r?   rY   __len__  re   zResource.__len__c                 C   r   r_   )iterr   rg   r?   r?   rY   __iter__  re   zResource.__iter__)r   r7   r]   N)rT   rU   rV   r   rW   rd   r   r   r!   r$   r   r   r   r,   r   rq   r~   r   r
   r   intr   r   r   r   r?   r?   r   rY   r3   X  s$     	

 r3   c                       s   e Zd Zdddedee ddf fddZedefdd	Zdd
dZdeddfddZ	dedee
eef  fddZdedefddZdefddZdefddZdefddZ  ZS )r4   Nr[   rI   r\   r]   c                   s*   t  j|d |r|dsJ || _d S )Nr[   rE   )r   rd   
startswith_path)rc   rI   r\   r   r?   rY   rd     s   
zPlainResource.__init__c                 C   rf   r_   r   rg   r?   r?   rY   rj     rh   zPlainResource.canonicalc                 C   s   | j sd| _ d S d S )NrE   r   rg   r?   r?   rY   rx     s   
zPlainResource.freezerM   c                 C   s<   | dsJ |drJ t|dksJ || j | _d S NrE   r   )r   endswithr   r   rs   r?   r?   rY   rt     s   zPlainResource.add_prefixc                 C   s   | j |kri S d S r_   r   rz   r?   r?   rY   r     s   
zPlainResource._matchc                 C   
   | j |kS r_   r   rz   r?   r?   rY   r{     re   zPlainResource.raw_matchc                 C   
   d| j iS )NrI   r   rg   r?   r?   rY   rv     re   zPlainResource.get_infoc                 C   s   t j| jddS )NTrI   encoded)r   buildr   rg   r?   r?   rY   rm        zPlainResource.url_forc                 C   s0   | j d urd| j  d nd}d| d| j dS )N'' r   z<PlainResource  r   )r\   r   rb   r?   r?   rY   r     s   zPlainResource.__repr__r|   )rT   rU   rV   rW   r   rd   r}   rj   rx   rt   r
   r   r   r{   rH   rv   r   rm   r   r   r?   r?   r   rY   r4     s    $
r4   c                       s   e Zd ZedZedZdZdddede	e ddf fd	d
Z
edefddZdeddfddZdede	eeef  fddZdedefddZdefddZdedefddZdefddZ  ZS )r5   z#\{(?P<var>[_a-zA-Z][_a-zA-Z0-9]*)\}z.\{(?P<var>[_a-zA-Z][_a-zA-Z0-9]*):(?P<re>.+)\}z[^{}/]+Nr[   rI   r\   r]   c          	   
      s^  t  j|d || _d}d}t|D ]d}| j|}|r5|d|d| j	7 }|d|d d 7 }q| j
|}|rU|djdi | 7 }|d|d d 7 }qd|v s]d|v rhtd| d	| d
t|}||7 }|t|7 }qzt|}W n tjy } ztd| d| d d }~ww |jtsJ |dsJ || _|| _d S )Nr[   r   z
(?P<{}>{})var{}z(?P<{var}>{re})zInvalid path 'z'['z']zBad pattern 'z': rE   r?   )r   rd   
_orig_pathrD   splitDYN	fullmatchr   groupGOODDYN_WITH_RE	groupdictr   _requote_pathreescapecompileerrorrK   r   rF   _pattern
_formatter)	rc   rI   r\   rK   rJ   partr   compiledexcr   r?   rY   rd     s<   
zDynamicResource.__init__c                 C   rf   r_   )r  rg   r?   r?   rY   rj     rh   zDynamicResource.canonicalrM   c                 C   sV   | dsJ |drJ t|dksJ tt|| jj | _|| j | _d S r   )	r   r   r   r   r  r  r  rK   r  rs   r?   r?   rY   rt     s
   zDynamicResource.add_prefixc                 C   s.   | j |}|d u rd S dd |  D S )Nc                 S      i | ]	\}}|t |qS r?   )_unquote_path_safe).0keyvaluer?   r?   rY   
<dictcomp>  s    z*DynamicResource._match.<locals>.<dictcomp>)r  r   r   items)rc   rI   r   r?   r?   rY   r     s   
zDynamicResource._matchc                 C   r   r_   )r   rz   r?   r?   rY   r{     re   zDynamicResource.raw_matchc                 C      | j | jdS )N)rJ   rK   )r  r  rg   r?   r?   rY   rv        zDynamicResource.get_infopartsc                 K   s(   | j dd | D }tj|ddS )Nc                 S   r	  r?   )_quote_path)r  kvr?   r?   rY   r    s    z+DynamicResource.url_for.<locals>.<dictcomp>Tr   )r  
format_mapr  r   r   )rc   r  urlr?   r?   rY   rm     s   zDynamicResource.url_forc                 C   s,   | j d urd| j  d nd}dj|| jdS )Nr   r   r   z$<DynamicResource {name} {formatter}>)r\   rJ   )r\   r   r  rb   r?   r?   rY   r     s   zDynamicResource.__repr__)rT   rU   rV   r   r  r   r   r   rW   r   rd   r}   rj   rt   r
   r   r   r{   rH   rv   r   rm   r   r   r?   r?   r   rY   r5     s    

$"r5   c                       sj   e Zd Zdddedee ddf fddZedefdd	Zdeddfd
dZdede	fddZ
  ZS )PrefixResourceNr[   rM   r\   r]   c                   sX   |r| dsJ ||dv s|drJ |t j|d t|| _| jd | _d S )NrE   )r   rE   r[   )r   r   r   rd   r   _prefix_prefix2)rc   rM   r\   r   r?   rY   rd   	  s
   
zPrefixResource.__init__c                 C   rf   r_   )r  rg   r?   r?   rY   rj     rh   zPrefixResource.canonicalc                 C   sH   | dsJ |drJ t|dksJ || j | _| jd | _d S r   )r   r   r   r  r  rs   r?   r?   rY   rt     s
   zPrefixResource.add_prefixc                 C   ri   r   r?   rs   r?   r?   rY   r{     ry   zPrefixResource.raw_match)rT   rU   rV   rW   r   rd   r}   rj   rt   r   r{   r   r?   r?   r   rY   r    s    $r  c                       s*  e Zd ZdZddddddddededee d	ee d
ede	de	de	ddf fddZ
dddedee	 defddZededefddZdefddZdeddfddZdedefddZdefd d!Zdee fd"d#Zdedefd$d%Zd&edefd'd(Zd)edefd*d+Zdefd,d-Z   Z!S ).r8   r  N   Fr\   r   
chunk_size
show_indexfollow_symlinksappend_versionrM   rL   r\   r   r  r  r  r   r]   c          
   
      s   t  j||d zt| jdd}W n ty) }	 z	td| d|	d }	~	ww | s6td| d|| _|| _	|| _
|| _|| _|| _td| j| |dtd	| j| |dd
| _d S )Nr[   T)strictr   z' does not existz' is not a directoryGETr   HEAD)r"  r#  )r   rd   r   
expanduserrq   FileNotFoundErrorr   is_dir
_directory_show_index_chunk_size_follow_symlinksr   _append_versionr7   _handler   )
rc   rM   rL   r\   r   r  r  r  r   r  r   r?   rY   rd   $  s,   

zStaticResource.__init__)r   filenamec          
   	   C   s  |d u r| j }t|d}tj| jdd}tdk r#||dd }n|| }|r| j	|}z"| j
rFttj|}|| j | }n
| }|| j W n ttfy^   | Y S w | r|d}| }W d    n1 sww   Y  | |}	|| j|	i}|S |S )NrE   Tr   r      %%25rb)r+  rW   lstripr   r   r  rB   replacer'  joinpathr*  r   osrI   normpathrelative_torq   r   r%  is_fileopenread_get_file_hash
with_queryVERSION_KEY)
rc   r-  r   r  unresolved_pathnormalized_pathfilepathf
file_byteshr?   r?   rY   rm   G  s8   


zStaticResource.url_for
byte_arrayc                 C   s*   t  }||  t| }|dS )Nascii)hashlibsha256updatebase64urlsafe_b64encodedigestdecode)rE  mb64r?   r?   rY   r<  p  s   

zStaticResource._get_file_hashc                 C   s   | j | j| jdS )N)rL   rM   rN   )r'  r  r   rg   r?   r?   rY   rv   w  s   zStaticResource.get_infor   c                 C   s.   d| j v r	tdtd|| | jd| j d< d S )NOPTIONSzOPTIONS route was set alreadyr   )r   r   r7   r   )rc   r   r?   r?   rY   set_options_route~  s
   

z StaticResource.set_options_routern   c                    s|   |j j}|j}t| j}|| js|| jkrd t fS ||vr%d |fS dt|t	| jd d  i}t
|| j| |fS )Nr-  r   )r   r   r   r   r   r   r  r  r
  r   r1   )rc   rn   rI   r   r   r   r?   r?   rY   rq     s   

zStaticResource.resolvec                 C   r   r_   r   rg   r?   r?   rY   r     re   zStaticResource.__len__c                 C   s   t | j S r_   )r   r   valuesrg   r?   r?   rY   r     r  zStaticResource.__iter__c                    sJ   |j d }t|}|jrt | j|}t }|d | j	|I d H S )Nr-  )

match_infor   anchorr(   r'  r5  r   get_running_looprun_in_executor_resolve_path_to_response)rc   rn   r   r-  r?  loopr?   r?   rY   r,    s   

zStaticResource._handler?  c              
   C   s   z"| j rttj|}|| j | }n
| }|| j W n tgt	R y6 } zt
 |d}~ww z| rL| jrIt| |ddW S t W n ty] } zt |d}~ww t|| jdS )zFTake the unresolved path and query the file system to form a response.Nz	text/html)r   content_type)r  )r*  r   r6  rI   r7  r8  r'  rq   r   CIRCULAR_SYMLINK_ERRORr*   r&  r(  r-   _directory_as_htmlr(   PermissionErrorr+   r)  )rc   r?  r@  	file_pathr  r?   r?   rY   rW    s4   
z(StaticResource._resolve_path_to_responsedir_pathc                 C   s   |  sJ || j }dt| }d| d}g }| }t|D ]0}|| j }t| j d| }	|  rD|j	 d}
n|j	}
|
d|	 dt|
 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>rE   z<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&  r8  r'  as_posixhtml_escapeiterdirsortedr  r  r\   r   r   join)rc   r^  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?   rY   r[    s(   z!StaticResource._directory_as_htmlc                 C   s0   | j d urd| j  d nd}dj|| j| jdS )Nr   r   z/<StaticResource {name} {path} -> {directory!r}>)r\   rI   rL   )r\   r   r  r'  rb   r?   r?   rY   r     s   
zStaticResource.__repr__)"rT   rU   rV   r>  rW   r%   r   r   r   r   rd   r   rm   staticmethodbytesr<  rH   rv   r$   rQ  r,   r   rq   r   r   r6   r   r.   r,  r   rW  r[  r   r   r?   r?   r   rY   r8   !  s\    	
'
)# r8   c                       s   e Zd Zdeddddf fddZdeddf fdd	Zdeddfd
dZdededefddZde	fddZ
dedefddZdefddZdee fddZdefddZ  ZS )PrefixedSubAppResourcerM   rO   r:   r]   Nc                    s    t  | || _| | d S r_   )r   rd   _app_add_prefix_to_resources)rc   rM   rO   r   r?   rY   rd     s   zPrefixedSubAppResource.__init__c                    s   t  | | | d S r_   )r   rt   rv  rs   r   r?   rY   rt     s   z!PrefixedSubAppResource.add_prefixc                 C   s8   | j j}| D ]}|| || || qd S r_   )ru  router	resourcesunindex_resourcert   index_resource)rc   rM   rw  r   r?   r?   rY   rv    s   

z/PrefixedSubAppResource._add_prefix_to_resourcesr   rl   c                 O      t d)Nz3.url_for() is not supported by sub-application rootr   r   r?   r?   rY   rm        zPrefixedSubAppResource.url_forc                 C   r  )N)rO   rM   )ru  r  rg   r?   r?   rY   rv     r  zPrefixedSubAppResource.get_inforn   c                    sL   | j j|I d H }|| j  t|jtr|jj}||fS t }||fS r_   )	ru  rw  rq   r   r   rS   r)   r   r   rc   rn   rS  methodsr?   r?   rY   rq   
  s   zPrefixedSubAppResource.resolvec                 C      t | jj S r_   )r   ru  rw  rN   rg   r?   r?   rY   r     r   zPrefixedSubAppResource.__len__c                 C   r  r_   )r   ru  rw  rN   rg   r?   r?   rY   r     r   zPrefixedSubAppResource.__iter__c                 C   s   dj | j| jdS )Nz,<PrefixedSubAppResource {prefix} -> {app!r}>)rM   rO   )r   r  ru  rg   r?   r?   rY   r     s   zPrefixedSubAppResource.__repr__)rT   rU   rV   rW   rd   rt   rv  r   rm   rH   rv   r,   r   rq   r   r   r   r6   r   r   r   r?   r?   r   rY   rt    s    		rt  c                   @   sP   e Zd ZejdedefddZejdefddZ	e
ejdefddZd	S )
rQ   rn   r]   c                    ro   )z1Return bool if the request satisfies the criteriaNr?   rp   r?   r?   rY   r      rr   zAbstractRuleMatching.matchc                 C   ri   ru   r?   rg   r?   r?   rY   rv   $  rk   zAbstractRuleMatching.get_infoc                 C   ri   )zReturn a strNr?   rg   r?   r?   rY   rj   (  rk   zAbstractRuleMatching.canonicalN)rT   rU   rV   r~   r   r,   r   r   rH   rv   r}   rW   rj   r?   r?   r?   rY   rQ     s    rQ   c                       s   e Zd ZedZdeddf fddZedefddZ	dedefd	d
Z
dedefddZdedefddZdefddZ  ZS )Domainz(?!-)[a-z\d-]{1,63}(?<!-)rP   r]   Nc                    s   t    | || _d S r_   )r   rd   
validation_domain)rc   rP   r   r?   rY   rd   1  s   
zDomain.__init__c                 C   rf   r_   r  rg   r?   r?   rY   rj   5  rh   zDomain.canonicalc                    s   t |ts	td|d }|stdd|v rtdtd| }|jd us+J t fdd|j	dD s>td	|j
d
krF|jS |j d|j
 S )NzDomain must be strr@   zDomain cannot be emptyz://zScheme not supportedzhttp://c                 3   s    | ]	} j |V  qd S r_   )re_partr   )r  xrg   r?   rY   	<genexpr>C  s    z$Domain.validation.<locals>.<genexpr>zDomain not validP   :)r   rW   	TypeErrorrstripr   r   r   raw_hostallr   port)rc   rP   r  r?   rg   rY   r  9  s   

zDomain.validationrn   c                    s"   |j tj}|sdS | |S r   )r   r   r   HOSTmatch_domain)rc   rn   hostr?   r?   rY   r   I  s
   
zDomain.matchr  c                 C   s   |  | jkS r_   )r   r  rc   r  r?   r?   rY   r  O  r  zDomain.match_domainc                 C   r   )NrP   r  rg   r?   r?   rY   rv   R  re   zDomain.get_info)rT   rU   rV   r   r  r  rW   rd   r}   rj   r  r,   r   r   r  rH   rv   r   r?   r?   r   rY   r  .  s    
r  c                       sT   e Zd ZedZdeddf fddZedefddZ	d	ede
fd
dZ  ZS )
MaskDomainz(?!-)[a-z\d\*-]{1,63}(?<!-)rP   r]   Nc                    s2   t  | | jdddd}t|| _d S )Nr@   z\.*z.*)r   rd   r  r4  r   r  _mask)rc   rP   maskr   r?   rY   rd   Y  s   zMaskDomain.__init__c                 C   r   r_   )r  rK   rg   r?   r?   rY   rj   ^  r   zMaskDomain.canonicalr  c                 C   s   | j |d uS r_   )r  r   r  r?   r?   rY   r  b  r   zMaskDomain.match_domain)rT   rU   rV   r   r  r  rW   rd   r}   rj   r   r  r   r?   r?   r   rY   r  V  s    
r  c                   @   sb   e Zd ZdeddddfddZedefdd	Zdefd
dZ	de
defddZdefddZdS )MatchedSubAppResourcerR   rO   r:   r]   Nc                 C   s    t |  d| _|| _|| _d S )Nr   )r2   rd   r  ru  _rule)rc   rR   rO   r?   r?   rY   rd   g  s   

zMatchedSubAppResource.__init__c                 C   r   r_   )r  rj   rg   r?   r?   rY   rj   m  r   zMatchedSubAppResource.canonicalc                 C   r  )N)rO   rR   )ru  r  rg   r?   r?   rY   rv   q  r  zMatchedSubAppResource.get_inforn   c                    sh   | j |I d H sd t fS | jj|I d H }|| j t|jt	r-|jj
}||fS t }||fS r_   )r  r   r   ru  rw  rq   r   r   rS   r)   r   r~  r?   r?   rY   rq   t  s   
zMatchedSubAppResource.resolvec                 C   s   dj | jdS )Nz"<MatchedSubAppResource -> {app!r}>)rO   )r   ru  rg   r?   r?   rY   r     r  zMatchedSubAppResource.__repr__)rT   rU   rV   rQ   rd   r}   rW   rj   rH   rv   r,   r   rq   r   r?   r?   r?   rY   r  f  s    r  c                       s   e Zd ZdZdddedeeee f de	de
e ddf
 fd	d
ZdefddZede
e fddZdededefddZdefddZ  ZS )r7   zA route with resourceNr   r   r   r   r   r]   c                   s   t  j||||d d S )Nr   )r   rd   )rc   r   r   r   r   r   r?   rY   rd     s   
zResourceRoute.__init__c                 C   s   dj | j| j| jdS )Nz3<ResourceRoute [{method}] {resource} -> {handler!r})r   r   r   )r   r   r   r   rg   r?   r?   rY   r     s   zResourceRoute.__repr__c                 C   s   | j d u rd S | j jS r_   )r   r\   rg   r?   r?   rY   r\     s   
zResourceRoute.namer   rl   c                 O   s    | j dusJ | j j|i |S r   )r   rm   r   r?   r?   rY   rm     s   zResourceRoute.url_forc                 C   s   | j d usJ | j  S r_   )r   rv   rg   r?   r?   rY   rv     r   zResourceRoute.get_info)rT   rU   rV   __doc__rW   r   r$   r   r!   r2   r   r   rd   r   r}   r\   r   rm   rH   rv   r   r?   r?   r   rY   r7     s&    r7   c                       s   e Zd Zdeddf fddZdededefdd	Zede	e fd
dZ
defddZdedefddZedefddZedefddZdefddZ  ZS )r   rS   r]   Nc                    s   t  tj| j || _d S r_   )r   rd   r   r   r,  _http_exceptionr   r   r?   rY   rd     s   
zSystemRoute.__init__r   rl   c                 O   r{  )Nz).url_for() is not allowed for SystemRouter|  r   r?   r?   rY   rm     r}  zSystemRoute.url_forc                 C   rw   r_   r?   rg   r?   r?   rY   r\     r   zSystemRoute.namec                 C   r   )NrS   r  rg   r?   r?   rY   rv     re   zSystemRoute.get_inforn   c                    s   | j r_   r  rp   r?   r?   rY   r,    s   zSystemRoute._handlec                 C   r   r_   )r  r   rg   r?   r?   rY   r     r   zSystemRoute.statusc                 C   r   r_   )r  r   rg   r?   r?   rY   r     r   zSystemRoute.reasonc                 C   s   dj | dS )Nz*<SystemRoute {self.status}: {self.reason}>rg   )r   rg   r?   r?   rY   r        zSystemRoute.__repr__)rT   rU   rV   r&   rd   rW   r   rm   r}   r   r\   rH   rv   r,   r.   r,  r   r   r   r   r   r?   r?   r   rY   r     s    r   c                   @   s@   e Zd ZdefddZdeedef fddZdefddZ	dS )	r9   r]   c                    sZ   | j jtjvr|   t| | j j d }|d u r|   | I d H }t|ts+J |S r_   )	rn   r   r   METH_ALL_raise_allowed_methodsgetattrr   r   r.   )rc   r   retr?   r?   rY   _iter  s   z
View._iterNc                 C   s   |    S r_   )r  	__await__rg   r?   r?   rY   r    r  zView.__await__c                    s"    fddt jD }t jj|)Nc                    s   h | ]}t  | r|qS r?   )hasattrr   )r  rN  rg   r?   rY   	<setcomp>  s    z.View._raise_allowed_methods.<locals>.<setcomp>)r   r  r)   rn   r   )rc   r   r?   rg   rY   r    s   zView._raise_allowed_methods)
rT   rU   rV   r.   r  r   r   r  r   r  r?   r?   r?   rY   r9     s    r9   c                   @   sT   e Zd Zdee ddfddZdefddZdee fdd	Z	d
e
defddZdS )ResourcesViewrx  r]   Nc                 C   r^   r_   
_resources)rc   rx  r?   r?   rY   rd     re   zResourcesView.__init__c                 C   r   r_   )r   r  rg   r?   r?   rY   r     re   zResourcesView.__len__c                 c       | j E d H  d S r_   r  rg   r?   r?   rY   r     r   zResourcesView.__iter__r   c                 C   
   || j v S r_   r  rc   r   r?   r?   rY   __contains__  re   zResourcesView.__contains__)rT   rU   rV   r   r2   rd   r   r   r   r   objectr   r  r?   r?   r?   rY   r    s
    r  c                   @   sP   e Zd Zdee fddZdefddZdee	 fddZ
d	edefd
dZdS )
RoutesViewrx  c                 C   s*   g | _ |D ]}|D ]}| j | q	qd S r_   )r   r   )rc   rx  r   r   r?   r?   rY   rd     s   zRoutesView.__init__r]   c                 C   r   r_   r   rg   r?   r?   rY   r     re   zRoutesView.__len__c                 c   r  r_   r   rg   r?   r?   rY   r     r   zRoutesView.__iter__r   c                 C   r  r_   r  r   r?   r?   rY   r    re   zRoutesView.__contains__N)rT   rU   rV   r   r2   rd   r   r   r   r6   r   r  r   r  r?   r?   r?   rY   r    s
    r  c                       s  e Zd ZedZdN fddZdedefddZ	de
e fd	d
ZdefddZdedefddZdedefddZdefddZdefddZdeeef fddZdeddfddZdedefddZdeddfddZdeddfdd Zdd!d"edee defd#d$Z ddd%d&ed"ed'e!e"e#e$ f dee d(ee% de&fd)d*Z'ddd+d,d,d,d-d.ed"e(dee d(ee% d/ed0ed1ed2edefd3d4Z)d"ed'e"d5e*de&fd6d7Z+d"ed'e"d5e*de&fd8d9Z,dd:d;d"ed'e"dee d<ed5e*de&fd=d>Z-d"ed'e"d5e*de&fd?d@Z.d"ed'e"d5e*de&fdAdBZ/d"ed'e"d5e*de&fdCdDZ0d"ed'e"d5e*de&fdEdFZ1d"ed'e#e$ d5e*de&fdGdHZ2dN fdIdJZ3dKe4e5 de6e& fdLdMZ7  Z8S )Or0   z[.:-]r]   Nc                    s&   t    g | _i | _i | _g | _d S r_   )r   rd   r  _named_resources_resource_index_matched_sub_app_resourcesrg   r   r?   rY   rd     s
   

zUrlDispatcher.__init__rn   c           	         s   | j }t }|jj}|r<||dD ]}||I d H \}}|d ur'|  S ||O }q|dkr1n|dd p9d}|s| jD ]}||I d H \}}|d urS|  S ||O }q?|rbtt	|j
|S tt S )Nr?   rE   r   )r  r   r   r   r   rq   
rpartitionr  r   r)   r   r*   )	rc   rn   resource_indexr   url_part	candidater   allowedr   r?   r?   rY   rq     s,   



zUrlDispatcher.resolvec                 C   r   r_   )r   r  rg   r?   r?   rY   r   ,  re   zUrlDispatcher.__iter__c                 C   r   r_   )r   r  rg   r?   r?   rY   r   /  re   zUrlDispatcher.__len__r   c                 C   r  r_   r  r  r?   r?   rY   r  2  re   zUrlDispatcher.__contains__r\   c                 C   s
   | j | S r_   r  rb   r?   r?   rY   __getitem__5  re   zUrlDispatcher.__getitem__c                 C   r   r_   )r  r  rg   r?   r?   rY   rx  8  re   zUrlDispatcher.resourcesc                 C   r   r_   )r  r  rg   r?   r?   rY   rN   ;  re   zUrlDispatcher.routesc                 C   r   r_   )r   r  rg   r?   r?   rY   named_resources>  re   zUrlDispatcher.named_resourcesc                 C   s   t |tsJ d|| jrtd|j}|d urR| j|}|D ]}t|r1t	d|d|
 s<t	d|q"|| jv rMt	d|| j| || j|< | j| t |tre| j| d S | | d S )Nz4Instance of AbstractResource class is required, got z.Cannot register a resource into frozen router.zIncorrect 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  r   r  r  rz  )rc   r   r\   r  r  r?   r?   rY   register_resourceA  s>   




zUrlDispatcher.register_resourcec                 C   s4   d|j  }v r|dd dd }|dpdS )z9Return a key to index the resource in the resource index.r   r   rE   )rj   	partitionr  r  )rc   r   	index_keyr?   r?   rY   _get_resource_index_keyh  s   z%UrlDispatcher._get_resource_index_keyc                 C   s"   |  |}| j|g | dS )z%Add a resource to the resource index.N)r  r  
setdefaultr   rc   r   resource_keyr?   r?   rY   rz  s  s   
zUrlDispatcher.index_resourcec                 C   s   |  |}| j| | dS )z*Remove a resource from the resource index.N)r  r  remover  r?   r?   rY   ry  {  s   
zUrlDispatcher.unindex_resourcer[   rI   c                C   s   |r| dstd| jr"| jd }|j|kr"||r"tt|S d|v s<d|v s<t|s<t	||d}| 
| |S t||d}| 
| |S )NrE   z)path should be started with / or be emptyr   r   r[   )r   r   r  r\   r{   r   r3   rD   searchr4   r  r5   )rc   rI   r\   r   r?   r?   rY   add_resource  s   



zUrlDispatcher.add_resource)r\   r   r   r   r   c                C   s   | j ||d}|j|||dS )Nr[   r   )r  r   )rc   r   rI   r   r\   r   r   r?   r?   rY   r     s   	zUrlDispatcher.add_router  Fr  rM   r  r  r  r   c          
   
   C   sJ   | dsJ |dr|dd }t||||||||d}	| |	 |	S )z^Add static files view.

        prefix - url prefix
        path - folder with files

        rE   Nr  r  )r   r   r8   r  )
rc   rM   rI   r\   r   r  r  r  r   r   r?   r?   rY   
add_static  s   


zUrlDispatcher.add_staticrl   c                 K      | j tj||fi |S )z(Shortcut for add_route with method HEAD.)r   r   	METH_HEADrc   rI   r   rl   r?   r?   rY   add_head     zUrlDispatcher.add_headc                 K   r  )z+Shortcut for add_route with method OPTIONS.)r   r   METH_OPTIONSr  r?   r?   rY   add_options  r  zUrlDispatcher.add_optionsT)r\   
allow_headr  c                K   s>   | j ||d}|r|jtj|fi | |jtj|fi |S )zShortcut 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   r   r  METH_GET)rc   rI   r   r\   r  rl   r   r?   r?   rY   add_get  s   zUrlDispatcher.add_getc                 K   r  )z(Shortcut for add_route with method POST.)r   r   	METH_POSTr  r?   r?   rY   add_post  r  zUrlDispatcher.add_postc                 K   r  )z'Shortcut for add_route with method PUT.)r   r   METH_PUTr  r?   r?   rY   add_put  r  zUrlDispatcher.add_putc                 K   r  )z)Shortcut for add_route with method PATCH.)r   r   
METH_PATCHr  r?   r?   rY   	add_patch  r  zUrlDispatcher.add_patchc                 K   r  )z*Shortcut for add_route with method DELETE.)r   r   METH_DELETEr  r?   r?   rY   
add_delete  r  zUrlDispatcher.add_deletec                 K   r  )z?Shortcut for add_route with ANY methods for a class-based view.)r   r   r   r  r?   r?   rY   add_view  s   zUrlDispatcher.add_viewc                    s"   t    | jD ]}|  qd S r_   )r   rx   r  r  r   r?   rY   rx     s   


zUrlDispatcher.freezerN   c                 C   s"   g }|D ]
}| ||  q|S )zAppend routes to route table.

        Parameter should be a sequence of RouteDef objects.

        Returns a list of registered AbstractRoute instances.
        )extendregister)rc   rN   registered_routes	route_defr?   r?   rY   
add_routes  s   zUrlDispatcher.add_routesr|   )9rT   rU   rV   r   r  r  rd   r,   r1   rq   r   rW   r   r   r   r  r   r  r2   r  r  rx  r  rN   r   r  r  r  rz  ry  r   r3   r  r   r$   r   r!   r   r6   r   r%   r  r   r  r  r  r  r  r  r  r  rx   r   r/   r   r  r   r?   r?   r   rY   r0     s    
)' 
	

"	

"r0   r  c                 C   s$   t dk r
| dd} tj| ddjS )Nr.  r0  r1  Fr   )rB   r4  r   r   raw_pathr  r?   r?   rY   r    s   r  c                 C   s    d| vr| S |  dd ddS )Nr0  z%2FrE   r1  )r4  r  r?   r?   rY   r
    s   r
  c                 C   s    t | }d| v r|dd}|S )Nr0  r1  )r  r4  )r  r   r?   r?   rY   r     s   r   )|r~   r   rJ  	functoolsrG  rq  r   r  r6  r   sysr   r   pathlibr   typesr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   yarlr   r   yarl_versionr   r   r   r    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   rZ  r   mapr   r   rB   rX   r  rC   rD   r  rF   r   r   partialra  rH   r2   ABCr6   r1   r   r   r3   r4   r5   r  r8   rt  rQ   r  r  r  r7   r   r9   r  r  r0   r  r
  r   r?   r?   r?   rY   <module>   s   
 `0/Q><(L Q.($  