a
    `g1                     @   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ZgeAdd0d1d2ZhG d3d4 d4ecZiG d5d6 d6eiZjG d7d8 d8eiZkG d9d: d:ecZlG d;d< d<elZmG d=d> d>elZnG d?d@ d@e jdZoG dAdB dBeoZpG dCdD dDepZqG dEdF dFenZrG dGdH dHeeZsG dIdJ dJeeZtG dKdL dLe0ZuG dMdN dNe"eec eec ZvG dOdP dPe"eee eee ZwG dQdR dRe/eeJecf ZxeJeJdSdTdUZyeJeJdSdVdWZzeJeJdSdXdYZ{dS )Z    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?   g/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/aiohttp/web_urldispatcher.pyrH   h   s   
rH   F)totalc                   @   s   e Zd Zddee ddddZeee dddZeej	edd	d
Z
ej	eedddZej	eedddZej	eddddZej	edddZddddZej	eedddZdS )r2   Nnamer\   returnc                C   s
   || _ d S N_nameselfr\   r?   r?   rY   __init__|   s    zAbstractResource.__init__r^   c                 C   s   | j S r_   r`   rc   r?   r?   rY   r\      s    zAbstractResource.namec                 C   s   dS )zWExposes the resource's canonical path.

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

        Nr?   rf   r?   r?   rY   	canonical   s    zAbstractResource.canonical)kwargsr^   c                 K   s   dS )z2Construct url for resource with additional params.Nr?   )rc   rh   r?   r?   rY   url_for   s    zAbstractResource.url_forrequestr^   c                    s   dS )zWResolve resource.

        Return (UrlMappingMatchInfo, allowed_methods) pair.
        Nr?   rc   rk   r?   r?   rY   resolve   s    zAbstractResource.resolverM   r^   c                 C   s   dS )zWAdd a prefix to processed URLs.

        Required for subapplications support.
        Nr?   rc   rM   r?   r?   rY   
add_prefix   s    zAbstractResource.add_prefixc                 C   s   dS z;Return a dict with additional info useful for introspectionNr?   rf   r?   r?   rY   get_info   s    zAbstractResource.get_infoc                 C   s   d S r_   r?   rf   r?   r?   rY   freeze   s    zAbstractResource.freezerI   r^   c                 C   s   dS )z Perform a raw match against pathNr?   rc   rI   r?   r?   rY   	raw_match   s    zAbstractResource.raw_match)rT   rU   rV   r   rW   rd   propertyr\   abcabstractmethodrg   r   ri   r,   _Resolverm   rp   rH   rr   rs   boolrv   r?   r?   r?   rY   r2   {   s"   r2   r6   c                   @   s   e Zd Zdddeeeee f ee	 ee
 ddddZeedddZeedd	d
Zeejee dddZeee
 dddZejedddZejeeedddZeee d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|sDt| dt|sTJ |t|r`n^t	|rxt
dt nFt|trt|trn0t
dt t|ttd 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 onesrj   c                    s.    | }t |r|I d H }t|ts*J |S r_   )asyncioiscoroutine
isinstancer.   )rk   resultZ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__re   c                 C   s   | j S r_   )r   rf   r?   r?   rY   r      s    zAbstractRoute.methodc                 C   s   | j S r_   )r   rf   r?   r?   rY   r      s    zAbstractRoute.handlerc                 C   s   dS )z8Optional route's name, always equals to resource's name.Nr?   rf   r?   r?   rY   r\      s    zAbstractRoute.namec                 C   s   | j S r_   )r   rf   r?   r?   rY   r~      s    zAbstractRoute.resourcec                 C   s   dS rq   r?   rf   r?   r?   rY   rr      s    zAbstractRoute.get_infoargsrh   r^   c                 O   s   dS z/Construct url for route with additional params.Nr?   rc   r   rh   r?   r?   rY   ri      s    zAbstractRoute.url_forrj   c                    s   |  |I d H S r_   )r   rl   r?   r?   rY   handle_expect_header   s    z"AbstractRoute.handle_expect_header)rT   rU   rV   rW   r   r$   r   r!   r   _ExpectHandlerr2   rd   rw   r   r   rx   ry   r\   r~   rH   rr   r   ri   r,   r.   r   r?   r?   r?   rY   r6      s.   3c                       s   e Zd ZdZeeef edd fddZee	dddZ
eedd	d
ZeedddZeee dddZedddZeed dddZdddddZeddddZejdddddZddddZed fddZ  ZS )r1   )_route_apps_current_app_frozenN)
match_dictrouter^   c                    s(   t  | || _g | _d | _d| _d S NF)superrd   r   r   r   r   )rc   r   r   	__class__r?   rY   rd      s
    zUrlMappingMatchInfo.__init__re   c                 C   s   | j jS r_   )r   r   rf   r?   r?   rY   r     s    zUrlMappingMatchInfo.handlerc                 C   s   | j S r_   )r   rf   r?   r?   rY   r   
  s    zUrlMappingMatchInfo.routec                 C   s   | j jS r_   )r   r   rf   r?   r?   rY   r}     s    z"UrlMappingMatchInfo.expect_handlerc                 C   s   d S r_   r?   rf   r?   r?   rY   rS     s    z"UrlMappingMatchInfo.http_exceptionc                 C   s
   | j  S r_   )r   rr   rf   r?   r?   rY   rr     s    zUrlMappingMatchInfo.get_info)r:   .c                 C   s
   t | jS r_   )tupler   rf   r?   r?   rY   apps  s    zUrlMappingMatchInfo.appsr:   )rO   r^   c                 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   rf   r?   r?   rY   rs   5  s    zUrlMappingMatchInfo.freezec                    s   dt    d| j dS )Nz<MatchInfo z: >)r   __repr__r   rf   r   r?   rY   r   8  s    zUrlMappingMatchInfo.__repr__)rT   rU   rV   	__slots__r
   rW   r6   rd   rw   r$   r   r   r   r}   r   r&   rS   rH   rr   r   r   r   r   setterrs   r   __classcell__r?   r?   r   rY   r1      s(   
c                       sH   e Zd ZdZedd fddZeedddZedd	d
Z	  Z
S )MatchInfoError
_exceptionNrS   r^   c                    s   || _ t i t| j  d S r_   )r   r   rd   SystemRouterc   rS   r   r?   rY   rd   @  s    zMatchInfoError.__init__re   c                 C   s   | j S r_   r   rf   r?   r?   rY   rS   D  s    zMatchInfoError.http_exceptionc                 C   s   d | jj| jjS )Nz<MatchInfoError {}: {}>)r   r   statusreasonrf   r?   r?   rY   r   H  s    zMatchInfoError.__repr__)rT   rU   rV   r   r&   rd   rw   rS   rW   r   r   r?   r?   r   rY   r   <  s
   r   rj   c                    sT   | j tjd}| jtkrP| dkrB| jdI dH  d| j_	n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   ZEXPECTversionr#   lowerwriterwriteZoutput_sizer'   )rk   expectr?   r?   rY   r   N  s    

r   c                       s   e Zd Zddee dd fddZddeeee e	f ee
 ddd	d
ZdddddZeedddZejeeeeef  dddZedddZed dddZ  ZS )r3   Nr[   r]   c                   s&   t  j|d i | _d | _t | _d S )Nr[   )r   rd   _routes
_any_routeset_allowed_methodsrb   r   r?   rY   rd   _  s    zResource.__init__r}   r7   )r   r   r}   r^   c                C   sD   | j || j }r&td|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)rc   r   r   r}   r   Z	route_objr?   r?   rY   	add_routee  s    
zResource.add_router   r^   c                 C   sH   t |tsJ d||jtjkr*|| _| j|j || j|j< d S )Nz)Instance of Route class is required, got )	r   r7   r   r   METH_ANYr   r   addr   rc   r   r?   r?   rY   r   w  s    zResource.register_routerj   c                    sP   |  |jj }d u r d t fS | j|j| j }rFt||| j	fS d | j	fS r_   )
_matchrel_url	path_safer   r   r   r   r   r1   r   )rc   rk   r   r   r?   r?   rY   rm     s
    
zResource.resolvert   c                 C   s   d S r_   r?   ru   r?   r?   rY   r     s    zResource._matchre   c                 C   s
   t | jS r_   lenr   rf   r?   r?   rY   __len__  s    zResource.__len__c                 C   s   t | j S r_   iterr   valuesrf   r?   r?   rY   __iter__  s    zResource.__iter__)rT   rU   rV   r   rW   rd   r   r   r!   r$   r   r   r   r,   rz   rm   rx   ry   r
   r   intr   r   r   r   r?   r?   r   rY   r3   ^  s   	r3   c                       s   e Zd Zddeee dd fddZeedddZddd	d
ZeddddZ	eee
eef  dddZeedddZedddZedddZed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__re   c                 C   s   | j S r_   r   rf   r?   r?   rY   rg     s    zPlainResource.canonicalc                 C   s   | j sd| _ d S )NrE   r   rf   r?   r?   rY   rs     s    zPlainResource.freezern   c                 C   s<   | dsJ |drJ t|dks,J || j | _d S NrE   r   )r   endswithr   r   ro   r?   r?   rY   rp     s    zPlainResource.add_prefixrt   c                 C   s   | j |kri S d S r_   r   ru   r?   r?   rY   r     s    
zPlainResource._matchc                 C   s
   | j |kS r_   r   ru   r?   r?   rY   rv     s    zPlainResource.raw_matchc                 C   s
   d| j iS )NrI   r   rf   r?   r?   rY   rr     s    zPlainResource.get_infoc                 C   s   t j| jddS )NTrI   encoded)r   buildr   rf   r?   r?   rY   ri     s    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__)rT   rU   rV   rW   r   rd   rw   rg   rs   rp   r
   r   r{   rv   rH   rr   r   ri   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ee	e dd fddZ
eed	d
dZeddddZee	eeef  dddZeedddZed	ddZeedddZed	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[   r   c          	   
      sp  t  j|d || _d}d}t|D ]}| j|}|rj|d|d| j	7 }|d|d d 7 }q&| j
|}|r|djf i | 7 }|d|d d 7 }q&d|v sd|v rtd| d	| d
t|}||7 }|t|7 }q&zt|}W n> tjy< } z"td| d| d W Y d }~n
d }~0 0 |jtsPJ |ds`J || _|| _d S )Nr[   r   z
(?P<{}>{})var{}z(?P<{var}>{re})zInvalid path 'z'['z']zBad pattern 'z': rE   )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     s8    ,zDynamicResource.__init__re   c                 C   s   | j S r_   )r   rf   r?   r?   rY   rg     s    zDynamicResource.canonicalrn   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   ro   r?   r?   rY   rp     s
    zDynamicResource.add_prefixrt   c                 C   s.   | j |}|d u rd S dd |  D S )Nc                 S   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   s
   | j |kS r_   )r   ru   r?   r?   rY   rv     s    zDynamicResource.raw_matchc                 C   s   | j | jdS )N)rJ   rK   )r   r   rf   r?   r?   rY   rr     s    zDynamicResource.get_info)partsr^   c                 K   s(   | j dd | D }tj|ddS )Nc                 S   s   i | ]\}}|t |qS r?   )_quote_path)r   kvr?   r?   rY   r        z+DynamicResource.url_for.<locals>.<dictcomp>Tr   )r   
format_mapr  r   r   )rc   r  urlr?   r?   rY   ri     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   rw   rg   rp   r
   r   r{   rv   rH   rr   r   ri   r   r   r?   r?   r   rY   r5     s   

 "r5   c                       sb   e Zd Zddeee dd fddZeedddZedd	d
dZee	d	ddZ
  ZS )PrefixResourceNr[   )rM   r\   r^   c                   sX   |r| dsJ ||dv s0|dr0J |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__re   c                 C   s   | j S r_   )r  rf   r?   r?   rY   rg     s    zPrefixResource.canonicalrn   c                 C   sH   | dsJ |drJ t|dks,J || j | _| jd | _d S r   )r   r   r   r  r  ro   r?   r?   rY   rp     s
    zPrefixResource.add_prefixc                 C   s   dS r   r?   ro   r?   r?   rY   rv     s    zPrefixResource.raw_match)rT   rU   rV   rW   r   rd   rw   rg   rp   r{   rv   r   r?   r?   r   rY   r
    s
    r
  c                       s
  e Zd ZdZdddddddeeee ee ee	e	e	dd	 fddZ
dd	eee	 ed
ddZeeedddZedddZeddddZeedddZedddZee dddZeedddZeedd d!Zeed"d#d$Zedd%d&Z   Z!S )'r8   r  N   Fr\   r}   
chunk_size
show_indexfollow_symlinksappend_version)	rM   rL   r\   r}   r  r  r  r  r^   c          
   
      s   t  j||d zt| jdd}W n6 ty^ }	 ztd| d|	W Y d }	~	n
d }	~	0 0 | sxtd| d|| _|| _	|| _
|| _|| _|| _td| j| |dtd	| j| |dd
| _t| j| _d S )Nr[   T)strictr   z' does not existz' is not a directoryGETr   HEAD)r  r  )r   rd   r   
expanduserrm   FileNotFoundErrorr   is_dir
_directory_show_index_chunk_size_follow_symlinksr   _append_versionr7   _handler   r   r   )
rc   rM   rL   r\   r}   r  r  r  r  r   r   r?   rY   rd   $  s*    (

zStaticResource.__init__)r  )filenamer  r^   c          
   	   C   s  |d u r| j }t|d}tj| jdd}tdk rF||dd }n|| }|r| j	|}zD| j
rttj|}|| j | }n| }|| j W n ttfy   | Y S 0 | r|d}| }W d    n1 s0    Y  | |}	|| j|	i}|S |S )NrE   Tr   r      %%25rb)r  rW   lstripr   r   r  rB   replacer  joinpathr  r   osrI   normpathrelative_torm   r   r  is_fileopenread_get_file_hashZ
with_queryVERSION_KEY)
rc   r  r  r	  unresolved_pathnormalized_pathfilepathfZ
file_byteshr?   r?   rY   ri   H  s2    


&
zStaticResource.url_for)
byte_arrayr^   c                 C   s*   t  }||  t| }|dS )Nascii)hashlibsha256updatebase64urlsafe_b64encodedigestdecode)r5  mZb64r?   r?   rY   r.  q  s    
zStaticResource._get_file_hashre   c                 C   s   | j | j| jdS )N)rL   rM   rN   )r  r  r   rf   r?   r?   rY   rr   x  s    zStaticResource.get_info)r   r^   c                 C   s:   d| j v rtdtd|| | jd| j d< | jd d S )NOPTIONSzOPTIONS route was set alreadyr   )r   r   r7   r   r   r   )rc   r   r?   r?   rY   set_options_route  s    

z StaticResource.set_options_routerj   c                    sv   |j j}|j}|| js.|| jkr.d t fS | j}||vrDd |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   r   )rc   rk   rI   r   allowed_methodsr   r?   r?   rY   rm     s    
zStaticResource.resolvec                 C   s
   t | jS r_   r   rf   r?   r?   rY   r     s    zStaticResource.__len__c                 C   s   t | j S r_   r   rf   r?   r?   rY   r     s    zStaticResource.__iter__c                    sH   |j d }t|}|jrt | j|}t }|d | j	|I d H S )Nr  )

match_infor   anchorr(   r  r'  r   get_running_looprun_in_executor_resolve_path_to_response)rc   rk   r   r  r0  loopr?   r?   rY   r    s    
zStaticResource._handle)r0  r^   c              
   C   s   zD| j r.ttj|}|| j | }n| }|| j W n4 tgt	R yx } zt
 |W Y d}~n
d}~0 0 z,| r| jrt| |ddW S t W n, ty } zt |W Y d}~n
d}~0 0 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   r(  rI   r)  r*  r  rm   r   CIRCULAR_SYMLINK_ERRORr*   r  r  r-   _directory_as_htmlr(   PermissionErrorr+   r  )rc   r0  r1  	file_pathr   r?   r?   rY   rF    s(    

z(StaticResource._resolve_path_to_response)dir_pathr^   c                 C   s   |  sJ || j }dt| }d| d}g }| }t|D ]`}|| j }t| j d| }	|  r|j	 d}
n|j	}
|
d|	 dt|
 d qJd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  r*  r  as_posixhtml_escapeiterdirsortedr  r  r\   appendr   join)rc   rM  Zrelative_path_to_dirZindex_ofZh1Z
index_listZ	dir_index_filerel_pathZquoted_file_url	file_nameZulbodyZhead_strhtmlr?   r?   rY   rJ    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   ri   staticmethodbytesr.  rH   rr   r$   r@  r,   rz   rm   r   r   r6   r   r.   r  r   rF  rJ  r   r   r?   r?   r   rY   r8   !  sF   ()# r8   c                       s   e Zd Zeddd fddZedd fddZeddd	d
ZeeedddZe	dddZ
eedddZedddZee dddZedddZ  ZS )PrefixedSubAppResourcer:   N)rM   rO   r^   c                    s    t  | || _| | d S r_   )r   rd   _app_add_prefix_to_resources)rc   rM   rO   r   r?   rY   rd     s    zPrefixedSubAppResource.__init__rn   c                    s   t  | | | d S r_   )r   rp   r^  ro   r   r?   rY   rp     s    z!PrefixedSubAppResource.add_prefixc                 C   s8   | j j}| D ]"}|| || || qd S r_   )r]  router	resourcesunindex_resourcerp   index_resource)rc   rM   r_  r~   r?   r?   rY   r^    s
    

z/PrefixedSubAppResource._add_prefix_to_resourcesr   c                 O   s   t dd S )Nz3.url_for() is not supported by sub-application rootr   r   r?   r?   rY   ri     s    zPrefixedSubAppResource.url_forre   c                 C   s   | j | jdS )N)rO   rM   )r]  r  rf   r?   r?   rY   rr   	  s    zPrefixedSubAppResource.get_inforj   c                    sD   | j j|I d H }|| j  t|jtr6|jj}nt }||fS r_   )	r]  r_  rm   r   r   rS   r)   rA  r   rc   rk   rB  methodsr?   r?   rY   rm     s    
zPrefixedSubAppResource.resolvec                 C   s   t | jj S r_   )r   r]  r_  rN   rf   r?   r?   rY   r     s    zPrefixedSubAppResource.__len__c                 C   s   t | jj S r_   )r   r]  r_  rN   rf   r?   r?   rY   r     s    zPrefixedSubAppResource.__iter__c                 C   s   dj | j| jdS )Nz,<PrefixedSubAppResource {prefix} -> {app!r}>)rM   rO   )r   r  r]  rf   r?   r?   rY   r     s    zPrefixedSubAppResource.__repr__)rT   rU   rV   rW   rd   rp   r^  r   ri   rH   rr   r,   rz   rm   r   r   r   r6   r   r   r   r?   r?   r   rY   r\    s   		r\  c                   @   sN   e Zd ZejeedddZejedddZ	e
ejedddZd	S )
rQ   rj   c                    s   dS )z1Return bool if the request satisfies the criteriaNr?   rl   r?   r?   rY   r   "  s    zAbstractRuleMatching.matchre   c                 C   s   dS rq   r?   rf   r?   r?   rY   rr   &  s    zAbstractRuleMatching.get_infoc                 C   s   dS )zReturn a strNr?   rf   r?   r?   rY   rg   *  s    zAbstractRuleMatching.canonicalN)rT   rU   rV   rx   ry   r,   r{   r   rH   rr   rw   rW   rg   r?   r?   r?   rY   rQ   !  s   rQ   c                       s~   e Zd ZedZedd fddZeedddZ	eedd	d
Z
eedddZeedddZedddZ  ZS )Domainz(?!-)[a-z\d-]{1,63}(?<!-)NrP   r^   c                    s   t    | || _d S r_   )r   rd   
validation_domain)rc   rP   r   r?   rY   rd   3  s    
zDomain.__init__re   c                 C   s   | j S r_   ri  rf   r?   r?   rY   rg   7  s    zDomain.canonicalc                    s   t |tstd|d }|s.tdnd|v r>tdtd| }|jd usXJ t fdd|j	dD s~td	|j
d
kr|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   xrf   r?   rY   	<genexpr>E  r  z$Domain.validation.<locals>.<genexpr>zDomain not validP   :)r   rW   	TypeErrorrstripr   r   r   Zraw_hostallr   port)rc   rP   r	  r?   rf   rY   rh  ;  s    


zDomain.validationrj   c                    s    |j tj}|sdS | |S r   )r   r   r   ZHOSTmatch_domain)rc   rk   hostr?   r?   rY   r   K  s    zDomain.matchru  r^   c                 C   s   |  | jkS r_   )r   ri  rc   ru  r?   r?   rY   rt  Q  s    zDomain.match_domainc                 C   s
   d| j iS )NrP   rj  rf   r?   r?   rY   rr   T  s    zDomain.get_info)rT   rU   rV   r   r   rk  rW   rd   rw   rg   rh  r,   r{   r   rt  rH   rr   r   r?   r?   r   rY   rf  0  s   
rf  c                       sP   e Zd ZedZedd fddZeedddZ	ee
d	d
dZ  ZS )
MaskDomainz(?!-)[a-z\d\*-]{1,63}(?<!-)Nrg  c                    s2   t  | | jdddd}t|| _d S )Nr@   z\.*z.*)r   rd   ri  r&  r   r   _mask)rc   rP   maskr   r?   rY   rd   [  s    zMaskDomain.__init__re   c                 C   s   | j jS r_   )rz  rK   rf   r?   r?   rY   rg   `  s    zMaskDomain.canonicalrv  c                 C   s   | j |d uS r_   )rz  r   rw  r?   r?   rY   rt  d  s    zMaskDomain.match_domain)rT   rU   rV   r   r   rk  rW   rd   rw   rg   r{   rt  r   r?   r?   r   rY   rx  X  s
   
rx  c                   @   s\   e Zd ZedddddZeedddZedd	d
Z	e
edddZedddZdS )MatchedSubAppResourcer:   N)rR   rO   r^   c                 C   s    t |  d| _|| _|| _d S )Nr   )r2   rd   r  r]  _rule)rc   rR   rO   r?   r?   rY   rd   i  s    
zMatchedSubAppResource.__init__re   c                 C   s   | j jS r_   )r}  rg   rf   r?   r?   rY   rg   o  s    zMatchedSubAppResource.canonicalc                 C   s   | j | jdS )N)rO   rR   )r]  r}  rf   r?   r?   rY   rr   s  s    zMatchedSubAppResource.get_inforj   c                    s`   | j |I d H sd t fS | jj|I d H }|| j t|jt	rR|jj
}nt }||fS r_   )r}  r   r   r]  r_  rm   r   r   rS   r)   rA  rd  r?   r?   rY   rm   v  s    

zMatchedSubAppResource.resolvec                 C   s   d| j dS )Nz<MatchedSubAppResource -> r   )r]  rf   r?   r?   rY   r     s    zMatchedSubAppResource.__repr__)rT   rU   rV   rQ   rd   rw   rW   rg   rH   rr   r,   rz   rm   r   r?   r?   r?   rY   r|  h  s   r|  c                       s   e Zd ZdZddeeeee f e	e
e dd fddZeddd	Zee
e dd
dZeeedddZed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__re   c                 C   s   dj | j| j| jdS )Nz3<ResourceRoute [{method}] {resource} -> {handler!r})r   r~   r   )r   r   r   r   rf   r?   r?   rY   r     s    zResourceRoute.__repr__c                 C   s   | j d u rd S | j jS r_   )r   r\   rf   r?   r?   rY   r\     s    
zResourceRoute.namer   c                 O   s    | j dusJ | j j|i |S r   )r   ri   r   r?   r?   rY   ri     s    zResourceRoute.url_forc                 C   s   | j d usJ | j  S r_   )r   rr   rf   r?   r?   rY   rr     s    zResourceRoute.get_info)rT   rU   rV   __doc__rW   r   r$   r   r!   r2   r   r   rd   r   rw   r\   r   ri   rH   rr   r   r?   r?   r   rY   r7     s   r7   c                       s   e Zd Zedd fddZeeedddZee	e dd	d
Z
edddZeedddZeedddZeedddZedddZ  ZS )r   Nr   c                    s   t  tj| j || _d S r_   )r   rd   r   r   r  _http_exceptionr   r   r?   rY   rd     s    zSystemRoute.__init__r   c                 O   s   t dd S )Nz).url_for() is not allowed for SystemRouterc  r   r?   r?   rY   ri     s    zSystemRoute.url_forre   c                 C   s   d S r_   r?   rf   r?   r?   rY   r\     s    zSystemRoute.namec                 C   s
   d| j iS )NrS   r  rf   r?   r?   rY   rr     s    zSystemRoute.get_inforj   c                    s
   | j d S r_   r  rl   r?   r?   rY   r    s    zSystemRoute._handlec                 C   s   | j jS r_   )r  r   rf   r?   r?   rY   r     s    zSystemRoute.statusc                 C   s   | j jS r_   )r  r   rf   r?   r?   rY   r     s    zSystemRoute.reasonc                 C   s   dj | dS )Nz*<SystemRoute {self.status}: {self.reason}>rf   )r   rf   r?   r?   rY   r     s    zSystemRoute.__repr__)rT   rU   rV   r&   rd   rW   r   ri   rw   r   r\   rH   rr   r,   r.   r  r   r   r   r   r   r?   r?   r   rY   r     s   r   c                   @   s@   e Zd ZedddZeedef dddZedddZ	dS )	r9   re   c                    sX   | j jtjvr|   t| | j j d }|d u r:|   | I d H }t|tsTJ |S r_   )	rk   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__rf   r?   r?   rY   r    s    zView.__await__c                    s&    fddt jD }t jj|d S )Nc                    s   h | ]}t  | r|qS r?   )hasattrr   )r   r>  rf   r?   rY   	<setcomp>  r  z.View._raise_allowed_methods.<locals>.<setcomp>)r   r  r)   rk   r   )rc   rA  r?   rf   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                   @   sP   e Zd Zee ddddZedddZee ddd	Z	e
ed
ddZdS )ResourcesViewN)r`  r^   c                 C   s
   || _ d S r_   
_resources)rc   r`  r?   r?   rY   rd     s    zResourcesView.__init__re   c                 C   s
   t | jS r_   )r   r  rf   r?   r?   rY   r     s    zResourcesView.__len__c                 c   s   | j E d H  d S r_   r  rf   r?   r?   rY   r     s    zResourcesView.__iter__r~   r^   c                 C   s
   || j v S r_   r  rc   r~   r?   r?   rY   __contains__  s    zResourcesView.__contains__)rT   rU   rV   r   r2   rd   r   r   r   r   objectr{   r  r?   r?   r?   rY   r    s   r  c                   @   sN   e Zd Zee dddZedddZee	 dddZ
eed	d
dZdS )
RoutesView)r`  c                 C   s*   g | _ |D ]}|D ]}| j | qq
d S r_   )r   rS  )rc   r`  r~   r   r?   r?   rY   rd     s    zRoutesView.__init__re   c                 C   s
   t | jS r_   r   rf   r?   r?   rY   r     s    zRoutesView.__len__c                 c   s   | j E d H  d S r_   r   rf   r?   r?   rY   r     s    zRoutesView.__iter__r   c                 C   s
   || j v S r_   r  r   r?   r?   rY   r    s    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                       sR  e Zd ZedZdd fddZeedddZ	e
e dd	d
ZedddZeedddZeedddZedddZedddZeeef dddZeddddZeedddZeddddZedddd Zdd!eee ed"d#d$Z ddd%eee!e"e#e$ f ee ee% e&d&d'd(Z'ddd)d*d*d*d+ee(ee ee% eeeeed,	d-d.Z)ee"e*e&d/d0d1Z+ee"e*e&d/d2d3Z,dd4d5ee"ee ee*e&d6d7d8Z-ee"e*e&d/d9d:Z.ee"e*e&d/d;d<Z/ee"e*e&d/d=d>Z0ee"e*e&d/d?d@Z1ee#e$ e*e&d/dAdBZ2dd fdCdDZ3e4e5 e6e& dEdFdGZ7  Z8S )Hr0   z[.:-]Nre   c                    s&   t    g | _i | _i | _g | _d S r_   )r   rd   r  _named_resources_resource_index_matched_sub_app_resourcesrf   r   r?   rY   rd     s
    
zUrlDispatcher.__init__rj   c           	         s   | j }t }|jj}|rt||dD ]0}||I d H \}}|d urL|  S ||O }q$|dkr`qt|dd ppd}q| jD ]0}||I d H \}}|d ur|  S ||O }qz|rtt	|j
|S tt S )Nr?   rE   r   )r  r   r   r   r   rm   
rpartitionr  r   r)   r   r*   )	rc   rk   Zresource_indexrA  Zurl_part	candidater   allowedr~   r?   r?   rY   rm     s(    



zUrlDispatcher.resolvec                 C   s
   t | jS r_   )r   r  rf   r?   r?   rY   r   .  s    zUrlDispatcher.__iter__c                 C   s
   t | jS r_   )r   r  rf   r?   r?   rY   r   1  s    zUrlDispatcher.__len__r  c                 C   s
   || j v S r_   r  r  r?   r?   rY   r  4  s    zUrlDispatcher.__contains__r]   c                 C   s
   | j | S r_   r  rb   r?   r?   rY   __getitem__7  s    zUrlDispatcher.__getitem__c                 C   s
   t | jS r_   )r  r  rf   r?   r?   rY   r`  :  s    zUrlDispatcher.resourcesc                 C   s
   t | jS r_   )r  r  rf   r?   r?   rY   rN   =  s    zUrlDispatcher.routesc                 C   s
   t | jS r_   )r   r  rf   r?   r?   rY   named_resources@  s    zUrlDispatcher.named_resourcesc                 C   s   t |tsJ d|| jr&td|j}|d ur| j|}|D ]4}t|rbt	d|d|
 sDt	d|qD|| jv rt	d|| j| || j|< | j| t |tr| j| n
| | 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  rS  r|  r  rb  )rc   r~   r\   r  r   r?   r?   rY   register_resourceC  s@    





zUrlDispatcher.register_resourcec                 C   s4   d|j  }v r&|dd dd }|dp2dS )z9Return a key to index the resource in the resource index.r   r   rE   )rg   	partitionr  rq  )rc   r~   Z	index_keyr?   r?   rY   _get_resource_index_keyj  s    z%UrlDispatcher._get_resource_index_keyc                 C   s"   |  |}| j|g | dS )z%Add a resource to the resource index.N)r  r  
setdefaultrS  rc   r~   Zresource_keyr?   r?   rY   rb  u  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   ra  }  s    
zUrlDispatcher.unindex_resourcer[   r   c                C   s   |r| dstd| jrD| jd }|j|krD||rDtt|S d|v sxd|v sxt|sxt	||d}| 
| |S t||d}| 
| |S )NrE   z)path should be started with / or be emptyr   r   r[   )r   r   r  r\   rv   r   r3   rD   searchr4   r  r5   )rc   rI   r\   r~   r?   r?   rY   add_resource  s    



zUrlDispatcher.add_resource)r\   r}   )r   rI   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   rI   r\   r}   r  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_static)rI   r   rh   r^   c                 K   s   | j tj||fi |S )z(Shortcut for add_route with method HEAD.)r   r   	METH_HEADrc   rI   r   rh   r?   r?   rY   add_head  s    zUrlDispatcher.add_headc                 K   s   | j tj||fi |S )z+Shortcut for add_route with method OPTIONS.)r   r   ZMETH_OPTIONSr  r?   r?   rY   add_options  s    zUrlDispatcher.add_optionsT)r\   
allow_head)rI   r   r\   r  rh   r^   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  ZMETH_GET)rc   rI   r   r\   r  rh   r~   r?   r?   rY   add_get  s    zUrlDispatcher.add_getc                 K   s   | j tj||fi |S )z(Shortcut for add_route with method POST.)r   r   Z	METH_POSTr  r?   r?   rY   add_post  s    zUrlDispatcher.add_postc                 K   s   | j tj||fi |S )z'Shortcut for add_route with method PUT.)r   r   ZMETH_PUTr  r?   r?   rY   add_put  s    zUrlDispatcher.add_putc                 K   s   | j tj||fi |S )z)Shortcut for add_route with method PATCH.)r   r   Z
METH_PATCHr  r?   r?   rY   	add_patch  s    zUrlDispatcher.add_patchc                 K   s   | j tj||fi |S )z*Shortcut for add_route with method DELETE.)r   r   ZMETH_DELETEr  r?   r?   rY   
add_delete  s    zUrlDispatcher.add_deletec                 K   s   | j tj||fi |S )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   rs   r  r  r   r?   rY   rs     s    

zUrlDispatcher.freeze)rN   r^   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   Zregistered_routesZ	route_defr?   r?   rY   
add_routes  s    zUrlDispatcher.add_routes)9rT   rU   rV   r   r   r  rd   r,   r1   rm   r   rW   r   r   r   r  r{   r  r2   r  r  r`  r  rN   r   r  r  r  rb  ra  r   r3   r  r   r$   r   r!   r   r6   r   r%   r  r   r  r  r  r  r  r  r  r  rs   r   r/   r   r  r   r?   r?   r   rY   r0     s~   
)'"	
r0   )r   r^   c                 C   s$   t dk r| dd} tj| ddjS )Nr   r"  r#  Fr   )rB   r&  r   r   raw_pathr   r?   r?   rY   r    s    r  c                 C   s    d| vr| S |  dd ddS )Nr"  z%2FrE   r#  )r&  r  r?   r?   rY   r   	  s    r   c                 C   s    t | }d| v r|dd}|S )Nr"  r#  )r  r&  )r   r   r?   r?   rY   r     s    r   )|rx   r   r:  	functoolsr7  rY  r   r  r(  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   Zyarlr   r   Zyarl_versionr   r   r   r    r!   helpersr"   httpr#   Ztypedefsr$   r%   Zweb_exceptionsr&   r'   r(   r)   r*   Zweb_fileresponser+   Zweb_requestr,   Zweb_responser-   r.   Zweb_routedefr/   __all__Zweb_appr:   rW   ZBaseDictdictversion_infoplatformr   OSErrorr   rI  r   mapr   r   rB   rX   r   rC   rD   r   rF   r   rz   partialrP  rH   r2   ABCr6   r1   r   r   r3   r4   r5   r
  r8   r\  rQ   rf  rx  r|  r7   r   r9   r  r  r0   r  r   r   r?   r?   r?   rY   <module>   s   
`

0/QA6(L S.($  