o
    m=8ju                     @   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Zd dlmZmZmZmZmZmZmZmZ d dlm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# d dl$m%Z%m&Z' d	d
l(m)Z) d	dl m*Z*m+Z+m,Z, d	dl-m.Z.m/Z/ d	dl0m1Z1 d	dl2m3Z3m4Z4 d	dl5m6Z6m7Z7m8Z8m9Z9m:Z: d	dl;m<Z< d	dl=m>Z> d	dl?m@Z@mAZA d	dlBmCZC dZDerd	dlEmFZF eGeHeHf ZIneGZIejJdk reKfndZLeMeNeOe'Pddd ZQeeMeOdf  eRd< e
SdZTeeeH  eRd< e
SdZUeeeH  eRd< e
Vd ZWeeH eRd!< e	X d"kZYeeZ eRd#< ee>geeAdB  f Z[eMe!d$ e\eH f Z]ej^ejVd%d&Z_G d'd( d(e"d)d*Z`G d+d, d,eed- ZaG d.d- d-e jbZcG d/d$ d$eIe*ZdG d0d1 d1edZed2e>d3dfd4d5ZfG d6d7 d7eaZgG d8d9 d9egZhG d:d; d;egZiG d<d= d=eaZjG d>d? d?ejZkG d@dA dAejZlG dBdC dCe jbZmG dDdE dEemZnG dFdG dGenZoG dHdI dIelZpG dJdK dKecZqG dLdM dMecZrG dNdO dOe,ZsG dPdQ dQeeea eea ZtG dRdS dSeeec eec ZuG dTdU dUe+eeHeaf ZvdVeHd3eHfdWdXZwdVeHd3eHfdYdZZxdVeHd3eHfd[d\ZydS )]    N)	AwaitableCallable	Container	GeneratorIterableIteratorMappingSized)wraps)Path)Pattern)MappingProxyType)TYPE_CHECKINGAnyFinalNoReturnOptional	TypedDictcast)URL__version__   )hdrs)AbstractMatchInfoAbstractRouterAbstractView)DEBUGDEFAULT_CHUNK_SIZE)HttpVersion11)HandlerPathLike)HTTPExceptionHTTPExpectationFailedHTTPForbiddenHTTPMethodNotAllowedHTTPNotFound)FileResponse)Request)ResponseStreamResponse)AbstractRouteDef)
UrlDispatcherUrlMappingMatchInfoAbstractResourceResourcePlainResourceDynamicResourceAbstractRouteResourceRouteStaticResourceView)Application)       .   .YARL_VERSIONz$^[0-9A-Za-z!#\$%&'\*\+\-\.\^_`\|~]+$HTTP_METHOD_REz*(\{[_a-zA-Z][^{}]*(?:\{[^{}]*\}[^{}]*)*\})ROUTE_RE/PATH_SEPWindows
IS_WINDOWSr,   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prefixr1   routesr5   appdomainAbstractRuleMatchingrulehttp_exceptionN)	__name__
__module____qualname__str__annotations__r   r   r   r!   r8   r8   r8   `/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/aiohttp/web_urldispatcher.pyrC   Z   s   
 rC   F)totalc                   @   s   e Zd ZdddedB ddfddZededB 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 )r-   NnamerW   returnc                C   
   || _ d S N_nameselfrW   r8   r8   rT   __init__n      
zAbstractResource.__init__c                 C      | j S rZ   r[   r^   r8   r8   rT   rW   q      zAbstractResource.namec                 C      dS )zWExposes the resource's canonical path.

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

        Nr8   rb   r8   r8   rT   	canonicalu       zAbstractResource.canonicalkwargsc                 K   rd   )z2Construct url for resource with additional params.Nr8   )r^   rg   r8   r8   rT   url_for~   rf   zAbstractResource.url_forrequestc                       dS )zWResolve resource.

        Return (UrlMappingMatchInfo, allowed_methods) pair.
        Nr8   r^   ri   r8   r8   rT   resolve       zAbstractResource.resolverH   c                 C   rd   )zWAdd a prefix to processed URLs.

        Required for subapplications support.
        Nr8   r^   rH   r8   r8   rT   
add_prefix   rf   zAbstractResource.add_prefixc                 C   rd   z;Return a dict with additional info useful for introspectionNr8   rb   r8   r8   rT   get_info   rf   zAbstractResource.get_infoc                 C      d S rZ   r8   rb   r8   r8   rT   freeze      zAbstractResource.freezerD   c                 C   rd   )z Perform a raw match against pathNr8   r^   rD   r8   r8   rT   	raw_match   rf   zAbstractResource.raw_matchrX   N)rO   rP   rQ   rR   r_   propertyrW   abcabstractmethodre   r   rh   r'   _Resolverl   ro   rC   rq   rs   boolrv   r8   r8   r8   rT   r-   m   s$    
r-   r1   c                   @   s   e Zd Zddddedeee B dedB dedB 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dB fddZe
dedB 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dB fddZdS )r1   Nexpect_handlerresourcemethodhandlerr~   r   rX   c                   s  |d u rt }t|stjdk rt|sJ d|| }t|s,t	| dt
|s4J |t|sCtjdk rDt|rDn4t|rTtrMJ tdt n$t|tr_t|tr_ntdt t|dtdtf fd	d
}| |}|| _|| _|| _|| _d S )N)r6      zCoroutine is expected, got z is not allowed HTTP methodFz6Bare generators are deprecated, use @coroutine wrapperz-Bare functions are deprecated, use async onesri   rX   c                    s0    | }t |r|I d H }t|tsJ |S rZ   )asyncioiscoroutine
isinstancer)   )ri   resultold_handlerr8   rT   handler_wrapper   s   

z/AbstractRoute.__init__.<locals>.handler_wrapper)_default_expect_handlerinspectiscoroutinefunctionsysversion_infor   upperr<   match
ValueErrorcallableisgeneratorfunctionr   warningswarnDeprecationWarningr   type
issubclassr   r
   r'   r)   _method_handler_expect_handler	_resource)r^   r   r   r~   r   r   r8   r   rT   r_      sB   	




zAbstractRoute.__init__c                 C   ra   rZ   )r   rb   r8   r8   rT   r      rc   zAbstractRoute.methodc                 C   ra   rZ   )r   rb   r8   r8   rT   r      rc   zAbstractRoute.handlerc                 C   rd   )z8Optional route's name, always equals to resource's name.Nr8   rb   r8   r8   rT   rW      rf   zAbstractRoute.namec                 C   ra   rZ   )r   rb   r8   r8   rT   r      rc   zAbstractRoute.resourcec                 C   rd   rp   r8   rb   r8   r8   rT   rq      rf   zAbstractRoute.get_infoargsrg   c                 O   rd   z/Construct url for route with additional params.Nr8   r^   r   rg   r8   r8   rT   rh      rf   zAbstractRoute.url_forri   c                    s   |  |I d H S rZ   )r   rk   r8   r8   rT   handle_expect_header      z"AbstractRoute.handle_expect_header)rO   rP   rQ   rR   r   r   r   _ExpectHandlerr-   r_   rx   r   r   ry   rz   rW   r   rC   rq   r   rh   r'   r)   r   r8   r8   r8   rT   r1      s8    

7c                       s   e Zd ZdZdeeef dedd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dB 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 )#r,   )_route_apps_current_app_frozen
match_dictrouterX   Nc                    s(   t  | || _g | _d | _d| _d S NF)superr_   r   r   r   r   )r^   r   r   	__class__r8   rT   r_      s
   
zUrlMappingMatchInfo.__init__c                 C      | j jS rZ   )r   r   rb   r8   r8   rT   r         zUrlMappingMatchInfo.handlerc                 C   ra   rZ   )r   rb   r8   r8   rT   r      rc   zUrlMappingMatchInfo.routec                 C   r   rZ   )r   r   rb   r8   r8   rT   r~     r   z"UrlMappingMatchInfo.expect_handlerc                 C   rr   rZ   r8   rb   r8   r8   rT   rN        z"UrlMappingMatchInfo.http_exceptionc                 C   s
   | j  S rZ   )r   rq   rb   r8   r8   rT   rq     r`   zUrlMappingMatchInfo.get_info)r5   .c                 C   
   t | jS rZ   )tupler   rb   r8   r8   rT   apps  s   
zUrlMappingMatchInfo.appsrJ   r5   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r^   rJ   r8   r8   rT   add_app  s
   
zUrlMappingMatchInfo.add_appc                 C   s   | j }|d us	J |S rZ   )r   r   r8   r8   rT   current_app  s   zUrlMappingMatchInfo.current_appc                 C   s.   t r|| jvrtd| jd||| _d S )Nz#Expected one of the following apps z, got )r   r   r   r   r   r8   r8   rT   r      s   

c                 C   s
   d| _ d S )NT)r   rb   r8   r8   rT   rs   )  r`   zUrlMappingMatchInfo.freezec                    s   dt    d| j dS )Nz<MatchInfo : >)r   __repr__r   rb   r   r8   rT   r   ,     zUrlMappingMatchInfo.__repr__)rJ   r5   rX   N)rX   r5   rw   )rO   rP   rQ   	__slots__dictrR   r1   r_   rx   r   r   r   r   r~   r!   rN   rC   rq   r   r   r   r   setterrs   r   __classcell__r8   r8   r   rT   r,      s*    "

c                       sJ   e Zd 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 )MatchInfoError
_exceptionrN   rX   Nc                    s   || _ t i t| j  d S rZ   )r   r   r_   SystemRouter^   rN   r   r8   rT   r_   4  s   zMatchInfoError.__init__c                 C   ra   rZ   r   rb   r8   r8   rT   rN   8  rc   zMatchInfoError.http_exceptionc                 C   s   d| j j d| j j dS )Nz<MatchInfoError r   r   )r   statusreasonrb   r8   r8   rT   r   <  r   zMatchInfoError.__repr__)rO   rP   rQ   r   r!   r_   rx   rN   rR   r   r   r8   r8   r   rT   r   0  s    r   ri   rX   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"   )ri   expectr8   r8   rT   r   @  s   
r   c                	       s   e Zd ZdddedB ddf fddZddded	ee eB d
edB 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f dB fddZdefddZded fddZ  ZS )r.   NrV   rW   rX   c                   s&   t  j|d i | _d | _t | _d S )NrV   )r   r_   _routes
_any_routeset_allowed_methodsr]   r   r8   rT   r_   Q  s   zResource.__init__r~   r   r   r~   r2   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   r2   register_route)r^   r   r   r~   r   	route_objr8   r8   rT   	add_routeW  s   
zResource.add_router   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   r2   r   r   METH_ANYr   r   addr   r^   r   r8   r8   rT   r   i  s   zResource.register_routeri   c                    sR   |  |jj }d u rd t fS | j|j| j }r$t||| j	fS d | j	fS rZ   )
_matchrel_url	path_safer   r   r   r   r   r,   r   )r^   ri   r   r   r8   r8   rT   rl   r  s   

zResource.resolverD   c                 C   rr   rZ   r8   ru   r8   r8   rT   r   y  r   zResource._matchc                 C   r   rZ   lenr   rb   r8   r8   rT   __len__}  r`   zResource.__len__c                 C      t | j S rZ   iterr   valuesrb   r8   r8   rT   __iter__     zResource.__iter__)r   r2   rX   N)rO   rP   rQ   rR   r_   r   r   r   r   r   r   r'   r{   rl   ry   rz   r   r   intr   r   r   r   r8   r8   r   rT   r.   P  s$     


	 r.   c                       s   e Zd ZdddededB 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f dB 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 )r/   NrV   rD   rW   rX   c                   s*   t  j|d |r|dsJ || _d S )NrV   r>   )r   r_   
startswith_path)r^   rD   rW   r   r8   rT   r_     s   
zPlainResource.__init__c                 C   ra   rZ   r   rb   r8   r8   rT   re     rc   zPlainResource.canonicalc                 C   s   | j sd| _ d S d S )Nr>   r   rb   r8   r8   rT   rs     s   
zPlainResource.freezerH   c                 C   s<   | dsJ |drJ t|dksJ || j | _d S Nr>   r   )r   endswithr   r   rn   r8   r8   rT   ro     s   zPlainResource.add_prefixc                 C   s   | j |kri S d S rZ   r   ru   r8   r8   rT   r     s   
zPlainResource._matchc                 C   
   | j |kS rZ   r   ru   r8   r8   rT   rv     r`   zPlainResource.raw_matchc                 C   
   d| j iS )NrD   r   rb   r8   r8   rT   rq     r`   zPlainResource.get_infoc                 C   s   t j| jddS )NTrD   encoded)r   buildr   rb   r8   r8   rT   rh        zPlainResource.url_forc                 C   0   | j d urd| j  d nd}d| d| j dS )N'' r   z<PlainResource  r   )rW   r   r]   r8   r8   rT   r        zPlainResource.__repr__rw   )rO   rP   rQ   rR   r_   rx   re   rs   ro   r   r   r|   rv   rC   rq   r   rh   r   r   r8   r8   r   rT   r/     s    $
r/   c                       s   e Zd ZedZedZdZdddededB 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f dB 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 )r0   z#\{(?P<var>[_a-zA-Z][_a-zA-Z0-9]*)\}z.\{(?P<var>[_a-zA-Z][_a-zA-Z0-9]*):(?P<re>.+)\}z[^{}/]+NrV   rD   rW   rX   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 )NrV   r   z
(?P<{}>{})var{}z(?P<{var}>{re})zInvalid path 'z'['z']zBad pattern 'z': r>   r8   )r   r_   
_orig_pathr=   splitDYN	fullmatchformatgroupGOODDYN_WITH_RE	groupdictr   _requote_pathreescapecompileerrorrF   r   r?   _pattern
_formatter)	r^   rD   rW   rF   rE   partr   compiledexcr   r8   rT   r_     s<   
zDynamicResource.__init__c                 C   ra   rZ   )r  rb   r8   r8   rT   re     rc   zDynamicResource.canonicalrH   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  rF   r  rn   r8   r8   rT   ro     s
   zDynamicResource.add_prefixc                 C   s.   | j |}|d u rd S dd |  D S )Nc                 S      i | ]	\}}|t |qS r8   )_unquote_path_safe).0keyvaluer8   r8   rT   
<dictcomp>  s    z*DynamicResource._match.<locals>.<dictcomp>)r  r   r  items)r^   rD   r   r8   r8   rT   r     s   
zDynamicResource._matchc                 C   r   rZ   )r   ru   r8   r8   rT   rv     r`   zDynamicResource.raw_matchc                 C      | j | jdS )N)rE   rF   )r  r  rb   r8   r8   rT   rq     r   zDynamicResource.get_infopartsc                 K   s(   | j dd | D }tj|ddS )Nc                 S   r  r8   )_quote_path)r  kvr8   r8   rT   r    s    z+DynamicResource.url_for.<locals>.<dictcomp>Tr   )r  
format_mapr  r   r   )r^   r  urlr8   r8   rT   rh     s   zDynamicResource.url_forc                 C   r   )Nr   r   r   z<DynamicResource r   r   )rW   r  r]   r8   r8   rT   r     r   zDynamicResource.__repr__)rO   rP   rQ   r  r	  r   r  r  rR   r_   rx   re   ro   r   r   r|   rv   rC   rq   r   rh   r   r   r8   r8   r   rT   r0     s    

$"r0   c                       sj   e Zd ZdddededB 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 )PrefixResourceNrV   rH   rW   rX   c                   sX   |r| dsJ ||dv s|drJ |t j|d t|| _| jd | _d S )Nr>   )r   r>   rV   )r   r   r   r_   r  _prefix_prefix2)r^   rH   rW   r   r8   rT   r_     s
   
zPrefixResource.__init__c                 C   ra   rZ   )r  rb   r8   r8   rT   re      rc   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   rn   r8   r8   rT   ro     s
   zPrefixResource.add_prefixc                 C   rd   r   r8   rn   r8   r8   rT   rv     rt   zPrefixResource.raw_match)rO   rP   rQ   rR   r_   rx   re   ro   r|   rv   r   r8   r8   r   rT   r    s    $r  c                       s*  e Zd ZdZddedddddedededB dedB d	ed
e	de	de	ddf fddZ
dddede	dB 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 )-r3   r  NFrW   r~   
chunk_size
show_indexfollow_symlinksappend_versionrH   rG   rW   r~   r"  r#  r$  r%  rX   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
| _t| j| _d S )NrV   T)strictr   z' does not existz' is not a directoryGETr   HEAD)r'  r(  )r   r_   r   
expanduserrl   FileNotFoundErrorr   is_dir
_directory_show_index_chunk_size_follow_symlinksr   _append_versionr2   _handler   r   r   )
r^   rH   rG   rW   r~   r"  r#  r$  r%  r
  r   r8   rT   r_     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 )Nr>   Tr   r      %%25rb)r0  rR   lstripr   r   r  r;   replacer,  joinpathr/  r   osrD   normpathrelative_torl   r   r*  is_fileopenread_get_file_hash
with_queryVERSION_KEY)
r^   r2  r%  r  unresolved_pathnormalized_pathfilepathf
file_byteshr8   r8   rT   rh   8  s8   


zStaticResource.url_for
byte_arrayc                 C   s*   t  }||  t| }|dS )Nascii)hashlibsha256updatebase64urlsafe_b64encodedigestdecode)rJ  mb64r8   r8   rT   rA  a  s   

zStaticResource._get_file_hashc                 C   s   | j | j| jdS )N)rG   rH   rI   )r,  r  r   rb   r8   r8   rT   rq   h  s   zStaticResource.get_infor   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   r2   r   r   r   )r^   r   r8   r8   rT   set_options_routeo  s   

z StaticResource.set_options_routeri   c                    s   |j j}|j}tj|}tr|dd}|| j	s&|| j
kr&d t fS | j}||vr1d |fS dt|t| j
d d  i}t|| j| |fS )N\r>   r2  r   )r   r   r   r;  rD   r<  rA   r9  r   r   r  r   r   r  r   r,   r   )r^   ri   rD   r   	norm_pathallowed_methodsr   r8   r8   rT   rl   w  s   
zStaticResource.resolvec                 C   r   rZ   r   rb   r8   r8   rT   r     r`   zStaticResource.__len__c                 C   r   rZ   r   rb   r8   r8   rT   r     r   zStaticResource.__iter__c                    sH   |j d }t| rt | j|}t }|d | j	|I d H S )Nr2  )

match_infor   is_absoluter%   r,  r:  r   get_running_looprun_in_executor_resolve_path_to_response)r^   ri   r2  rD  loopr8   r8   rT   r1    s   

zStaticResource._handlerD  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   r;  rD   r<  r=  r,  rl   r   CIRCULAR_SYMLINK_ERRORr%   r+  r-  r(   _directory_as_htmlr#   PermissionErrorr&   r.  )r^   rD  rE  	file_pathr
  r8   r8   rT   r^    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>r>   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  rW   appendr  join)r^   re  relative_path_to_dirindex_ofh1
index_list	dir_index_filerel_pathquoted_file_url	file_nameulbodyhead_strhtmlr8   r8   rT   rb    s(   z!StaticResource._directory_as_htmlc                 C   s8   | j d urd| j  d nd}d| d| j d| jdS )Nr   r   z<StaticResource r    -> r   )rW   r  r,  r]   r8   r8   rT   r     s   zStaticResource.__repr__)"rO   rP   rQ   rC  r   rR   r    r   r   r|   r_   r   rh   staticmethodbytesrA  rC   rq   r   rV  r'   r{   rl   r   r   r1   r   r)   r1  r   r^  rb  r   r   r8   r8   r   rT   r3     s\    	
(
)# r3   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 )PrefixedSubAppResourcerH   rJ   r5   rX   Nc                    s    t  | || _| | d S rZ   )r   r_   _app_add_prefix_to_resources)r^   rH   rJ   r   r8   rT   r_     s   zPrefixedSubAppResource.__init__c                    s   t  | | | d S rZ   )r   ro   r  rn   r   r8   rT   ro     s   z!PrefixedSubAppResource.add_prefixc                 C   s8   | j j}| D ]}|| || || qd S rZ   )r~  router	resourcesunindex_resourcero   index_resource)r^   rH   r  r   r8   r8   rT   r    s   

z/PrefixedSubAppResource._add_prefix_to_resourcesr   rg   c                 O      t d)Nz3.url_for() is not supported by sub-application rootr   r   r8   r8   rT   rh        zPrefixedSubAppResource.url_forc                 C   r  )N)rJ   rH   )r~  r  rb   r8   r8   rT   rq     r   zPrefixedSubAppResource.get_infori   c                    sL   | j j|I d H }|| j  t|jtr|jj}||fS t }||fS rZ   )	r~  r  rl   r   r   rN   r$   rY  r   r^   ri   rZ  methodsr8   r8   rT   rl     s   zPrefixedSubAppResource.resolvec                 C      t | jj S rZ   )r   r~  r  rI   rb   r8   r8   rT   r     r   zPrefixedSubAppResource.__len__c                 C   r  rZ   )r   r~  r  rI   rb   r8   r8   rT   r     r   zPrefixedSubAppResource.__iter__c                 C   s   d| j  d| jdS )Nz<PrefixedSubAppResource rz  r   )r  r~  rb   r8   r8   rT   r        zPrefixedSubAppResource.__repr__)rO   rP   rQ   rR   r_   ro   r  r   rh   rC   rq   r'   r{   rl   r   r   r   r1   r   r   r   r8   r8   r   rT   r}    s    		r}  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 )
rL   ri   rX   c                    rj   )z1Return bool if the request satisfies the criteriaNr8   rk   r8   r8   rT   r     rm   zAbstractRuleMatching.matchc                 C   rd   rp   r8   rb   r8   r8   rT   rq     rf   zAbstractRuleMatching.get_infoc                 C   rd   )zReturn a strNr8   rb   r8   r8   rT   re     rf   zAbstractRuleMatching.canonicalN)rO   rP   rQ   ry   rz   r'   r|   r   rC   rq   rx   rR   re   r8   r8   r8   rT   rL     s    rL   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}(?<!-)rK   rX   Nc                    s   t    | || _d S rZ   )r   r_   
validation_domain)r^   rK   r   r8   rT   r_   !  s   
zDomain.__init__c                 C   ra   rZ   r  rb   r8   r8   rT   re   %  rc   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 strr9   zDomain cannot be emptyz://zScheme not supportedzhttp://c                 3   s    | ]	} j |V  qd S rZ   )re_partr   )r  xrb   r8   rT   	<genexpr>3  s    z$Domain.validation.<locals>.<genexpr>zDomain not validP   :)r   rR   	TypeErrorrstripr   r   r   raw_hostallr   port)r^   rK   r  r8   rb   rT   r  )  s   

zDomain.validationri   c                    s"   |j tj}|sdS | |S r   )r   r   r   HOSTmatch_domain)r^   ri   hostr8   r8   rT   r   9  s
   
zDomain.matchr  c                 C   s   |  | jkS rZ   )r   r  r^   r  r8   r8   rT   r  ?  r   zDomain.match_domainc                 C   r   )NrK   r  rb   r8   r8   rT   rq   B  r`   zDomain.get_info)rO   rP   rQ   r  r	  r  rR   r_   rx   re   r  r'   r|   r   r  rC   rq   r   r8   r8   r   rT   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}(?<!-)rK   rX   Nc                    s2   t  | | jdddd}t|| _d S )Nr9   z\.*z.*)r   r_   r  r9  r  r	  _mask)r^   rK   maskr   r8   rT   r_   I  s   zMaskDomain.__init__c                 C   r   rZ   )r  rF   rb   r8   r8   rT   re   N  r   zMaskDomain.canonicalr  c                 C   s   | j |d uS rZ   )r  r   r  r8   r8   rT   r  R  r   zMaskDomain.match_domain)rO   rP   rQ   r  r	  r  rR   r_   rx   re   r|   r  r   r8   r8   r   rT   r  F  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 )MatchedSubAppResourcerM   rJ   r5   rX   Nc                 C   s    t |  d| _|| _|| _d S )Nr   )r-   r_   r  r~  _rule)r^   rM   rJ   r8   r8   rT   r_   W  s   

zMatchedSubAppResource.__init__c                 C   r   rZ   )r  re   rb   r8   r8   rT   re   ]  r   zMatchedSubAppResource.canonicalc                 C   r  )N)rJ   rM   )r~  r  rb   r8   r8   rT   rq   a  r   zMatchedSubAppResource.get_infori   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 rZ   )r  r   r   r~  r  rl   r   r   rN   r$   rY  r  r8   r8   rT   rl   d  s   
zMatchedSubAppResource.resolvec                 C   s   d| j dS )Nz<MatchedSubAppResource -> r   )r~  rb   r8   r8   rT   r   o  r   zMatchedSubAppResource.__repr__)rO   rP   rQ   rL   r_   rx   rR   re   rC   rq   r'   r{   rl   r   r8   r8   r8   rT   r  V  s    r  c                       s   e Zd ZdZdddedeee B dede	dB ddf
 fd	d
Z
defddZededB fddZdededefddZdefddZ  ZS )r2   zA route with resourceNr   r   r   r   r~   rX   c                   s   t  j||||d d S )Nr}   )r   r_   )r^   r   r   r   r~   r   r8   rT   r_   v  s   
zResourceRoute.__init__c                 C   s   d| j  d| j d| jS )Nz<ResourceRoute [z] rz  )r   r   r   rb   r8   r8   rT   r     s   zResourceRoute.__repr__c                 C   s   | j d u rd S | j jS rZ   )r   rW   rb   r8   r8   rT   rW     s   
zResourceRoute.namer   rg   c                 O   s    | j dusJ | j j|i |S r   )r   rh   r   r8   r8   rT   rh     s   zResourceRoute.url_forc                 C   s   | j d usJ | j  S rZ   )r   rq   rb   r8   r8   rT   rq     s   
zResourceRoute.get_info)rO   rP   rQ   __doc__rR   r   r   r   r-   r   r_   r   rx   rW   r   rh   rC   rq   r   r8   r8   r   rT   r2   s  s&    
r2   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dB 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   rN   rX   Nc                    s   t  tj| j || _d S rZ   )r   r_   r   r   r1  _http_exceptionr   r   r8   rT   r_     s   
zSystemRoute.__init__r   rg   c                 O   r  )Nz).url_for() is not allowed for SystemRouter  r   r8   r8   rT   rh     r  zSystemRoute.url_forc                 C   rr   rZ   r8   rb   r8   r8   rT   rW     r   zSystemRoute.namec                 C   r   )NrN   r  rb   r8   r8   rT   rq     r`   zSystemRoute.get_infori   c                    s   | j rZ   r  rk   r8   r8   rT   r1    s   zSystemRoute._handlec                 C   r   rZ   )r  r   rb   r8   r8   rT   r     r   zSystemRoute.statusc                 C   r   rZ   )r  r   rb   r8   r8   rT   r     r   zSystemRoute.reasonc                 C   s   d| j  d| j dS )Nz<SystemRoute r   r   )r   r   rb   r8   r8   rT   r     r  zSystemRoute.__repr__)rO   rP   rQ   r!   r_   rR   r   rh   rx   rW   rC   rq   r'   r)   r1  r   r   r   r   r   r8   r8   r   rT   r     s    r   c                   @   s@   e Zd ZdefddZdeddef fddZdefddZdS )	r4   rX   c                    sZ   | j jtjvr|   t| | j j d }|d u r|   | I d H }t|ts+J |S rZ   )	ri   r   r   METH_ALL_raise_allowed_methodsgetattrr   r   r)   )r^   r   retr8   r8   rT   _iter  s   z
View._iterNc                 C   s   |    S rZ   )r  	__await__rb   r8   r8   rT   r    s   zView.__await__c                    s"    fddt jD }t jj|)Nc                    s   h | ]}t  | r|qS r8   )hasattrr   )r  rS  rb   r8   rT   	<setcomp>  s    z.View._raise_allowed_methods.<locals>.<setcomp>)r   r  r$   ri   r   )r^   rY  r8   rb   rT   r    s   zView._raise_allowed_methods)	rO   rP   rQ   r)   r  r   r  r   r  r8   r8   r8   rT   r4     s    r4   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 )ResourcesViewr  rX   Nc                 C   rY   rZ   
_resources)r^   r  r8   r8   rT   r_     r`   zResourcesView.__init__c                 C   r   rZ   )r   r  rb   r8   r8   rT   r     r`   zResourcesView.__len__c                 c       | j E d H  d S rZ   r  rb   r8   r8   rT   r     r   zResourcesView.__iter__r   c                 C   
   || j v S rZ   r  r^   r   r8   r8   rT   __contains__  r`   zResourcesView.__contains__)rO   rP   rQ   listr-   r_   r   r   r   r   objectr|   r  r8   r8   r8   rT   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 )
RoutesViewr  c                 C   s*   g | _ |D ]}|D ]}| j | q	qd S rZ   )r   rk  )r^   r  r   r   r8   r8   rT   r_     s   zRoutesView.__init__rX   c                 C   r   rZ   r   rb   r8   r8   rT   r     r`   zRoutesView.__len__c                 c   r  rZ   r   rb   r8   r8   rT   r     r   zRoutesView.__iter__r   c                 C   r  rZ   r  r   r8   r8   rT   r    r`   zRoutesView.__contains__N)rO   rP   rQ   r  r-   r_   r   r   r   r1   r   r  r|   r  r8   r8   r8   rT   r    s
    r  c                       s  e Zd ZedZdM 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dB defd#d$Zddd%d&ed"ed'e e!e" B dedB d(e#dB de$fd)d*Z%dde&d+d+d+d,d-ed"e'dedB d(e#dB d.ed/ed0ed1edefd2d3Z(d"ed'e d4e)de$fd5d6Z*d"ed'e d4e)de$fd7d8Z+dd9d:d"ed'e dedB d;ed4e)de$fd<d=Z,d"ed'e d4e)de$fd>d?Z-d"ed'e d4e)de$fd@dAZ.d"ed'e d4e)de$fdBdCZ/d"ed'e d4e)de$fdDdEZ0d"ed'e!e" d4e)de$fdFdGZ1dM fdHdIZ2dJe3e4 de5e$ fdKdLZ6  Z7S )Nr+   z[.:-]rX   Nc                    s&   t    g | _i | _i | _g | _d S rZ   )r   r_   r  _named_resources_resource_index_matched_sub_app_resourcesrb   r   r8   rT   r_     s
   

zUrlDispatcher.__init__ri   c           	         s   | j }t }| jD ]}||I d H \}}|d ur|  S ||O }q
|jj}|rX||dD ]}||I d H \}}|d urC|  S ||O }q/|dkrMn|dd pUd}|s)|rbtt	|j
|S tt S )Nr8   r>   r   )r  r   r  rl   r   r   r   
rpartitionr   r$   r   r%   )	r^   ri   resource_indexrY  r   r   allowedurl_part	candidater8   r8   rT   rl     s,   




zUrlDispatcher.resolvec                 C   r   rZ   )r   r  rb   r8   r8   rT   r     r`   zUrlDispatcher.__iter__c                 C   r   rZ   )r   r  rb   r8   r8   rT   r     r`   zUrlDispatcher.__len__r   c                 C   r  rZ   r  r  r8   r8   rT   r     r`   zUrlDispatcher.__contains__rW   c                 C   s
   | j | S rZ   r  r]   r8   r8   rT   __getitem__#  r`   zUrlDispatcher.__getitem__c                 C   r   rZ   )r  r  rb   r8   r8   rT   r  &  r`   zUrlDispatcher.resourcesc                 C   r   rZ   )r  r  rb   r8   r8   rT   rI   )  r`   zUrlDispatcher.routesc                 C   r   rZ   )r   r  rb   r8   r8   rT   named_resources,  r`   zUrlDispatcher.named_resourcesc                 C   s   t |tsJ d|| jrtd|j}|d urU| j|}|D ]}t|r1t	d|d|
 s=t	d|dq"|| jv rPt	d|d| j| || j|< | j| t |trh| 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 namezV, the name should be a sequence of python identifiers separated by dash, dot or columnz
Duplicate z, already handled by )r   r-   frozenr   rW   NAME_SPLIT_REr   keyword	iskeywordr   isidentifierr  r  rk  r  r  r  )r^   r   rW   r  r  r8   r8   rT   register_resource/  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   r>   )re   	partitionr  r  )r^   r   	index_keyr8   r8   rT   _get_resource_index_keyV  s   z%UrlDispatcher._get_resource_index_keyc                 C   s"   |  |}| j|g | dS )z%Add a resource to the resource index.N)r  r  
setdefaultrk  r^   r   resource_keyr8   r8   rT   r  a  s   
zUrlDispatcher.index_resourcec                 C   s   |  |}| j| | dS )z*Remove a resource from the resource index.N)r  r  remover  r8   r8   rT   r  i  s   
zUrlDispatcher.unindex_resourcerV   rD   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 )Nr>   z)path should be started with / or be emptyr   r   rV   )r   r   r  rW   rv   r   r.   r=   searchr/   r  r0   )r^   rD   rW   r   r8   r8   rT   add_resourcen  s   



zUrlDispatcher.add_resource)rW   r~   r   r   r~   c                C   s   | j ||d}|j|||dS )NrV   r   )r  r   )r^   r   rD   r   rW   r~   r   r8   r8   rT   r   ~  s   	zUrlDispatcher.add_routeFr!  rH   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

        r>   Nr  r!  )r   r   r3   r  )
r^   rH   rD   rW   r~   r"  r#  r$  r%  r   r8   r8   rT   
add_static  s   


zUrlDispatcher.add_staticrg   c                 K      | j tj||fi |S )z(Shortcut for add_route with method HEAD.)r   r   	METH_HEADr^   rD   r   rg   r8   r8   rT   add_head     zUrlDispatcher.add_headc                 K   r  )z+Shortcut for add_route with method OPTIONS.)r   r   METH_OPTIONSr  r8   r8   rT   add_options  r  zUrlDispatcher.add_optionsT)rW   
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.
        rV   )r  r   r   r  METH_GET)r^   rD   r   rW   r  rg   r   r8   r8   rT   add_get  s   zUrlDispatcher.add_getc                 K   r  )z(Shortcut for add_route with method POST.)r   r   	METH_POSTr  r8   r8   rT   add_post  r  zUrlDispatcher.add_postc                 K   r  )z'Shortcut for add_route with method PUT.)r   r   METH_PUTr  r8   r8   rT   add_put  r  zUrlDispatcher.add_putc                 K   r  )z)Shortcut for add_route with method PATCH.)r   r   
METH_PATCHr  r8   r8   rT   	add_patch  r  zUrlDispatcher.add_patchc                 K   r  )z*Shortcut for add_route with method DELETE.)r   r   METH_DELETEr  r8   r8   rT   
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  r8   r8   rT   add_view  s   zUrlDispatcher.add_viewc                    s"   t    | jD ]}|  qd S rZ   )r   rs   r  r  r   r8   rT   rs     s   


zUrlDispatcher.freezerI   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)r^   rI   registered_routes	route_defr8   r8   rT   
add_routes  s   zUrlDispatcher.add_routesrw   )8rO   rP   rQ   r  r	  r  r_   r'   r,   rl   r   rR   r   r   r   r  r|   r  r-   r  r  r  r  rI   r   r  r  r  r  r  r.   r  r   r   r   r   r1   r   r   r    r  r   r  r  r  r  r  r  r  r  rs   r   r*   r  r  r   r8   r8   r   rT   r+     s    
)' 

	

"	

"r+   r  c                 C   s$   t dk r
| dd} tj| ddjS )Nr3  r5  r6  Fr   )r;   r9  r   r   raw_pathr  r8   r8   rT   r    s   r  c                 C   s    d| vr| S |  dd ddS )Nr5  z%2Fr>   r6  )r9  r  r8   r8   rT   r    s   r  c                 C   s    t | }d| v r|dd}|S )Nr5  r6  )r  r9  )r  r   r8   r8   rT   r    s   r  )zry   r   rO  	functoolsrL  ry  r   r  r;  platformr  r   r   collections.abcr   r   r   r   r   r   r   r	   r
   pathlibr   r   typesr   typingr   r   r   r   r   r   r   yarlr   r   yarl_versionr   r   r   r   r   helpersr   r   httpr   typedefsr   r    web_exceptionsr!   r"   r#   r$   r%   web_fileresponser&   web_requestr'   web_responser(   r)   web_routedefr*   __all__web_appr5   r   rR   BaseDictr   r   ra  r   mapr   r   r;   rS   r	  r<   r=   r  r?   systemrA   r|   r   r   r{   partialrh  rC   r-   ABCr1   r,   r   r   r.   r/   r0   r  r3   r}  rL   r  r  r  r2   r   r4   r  r  r+   r  r  r  r8   r8   r8   rT   <module>   s   
 (
$0/U?6(J S,("  