o
    4˜Žju«  ã                   @   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rÚd	dlEmFZF eGeHeHf ZIneGZIejJdk räeKf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   úV/var/www/kodo/Anonymous/send/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 )z™Default 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¡s J ‚| d¡s§J ‚|| _|| _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 validéP   ú:)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 emptyéÿÿÿÿrû   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 )zœShortcut 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 )z¢Append 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,("  