o
    ~îj“! ã                   @   sh  d dl 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 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 d d
lmZmZ d dlmZ d dlmZ d dlmZmZmZm Z  d dl!m"Z" d dl#m$Z$m%Z% d dl&m'Z'm(Z(m)Z)m*Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;Z;d dl<Z<d dl=Z=d dl>Z>d dl?Z@d dlAZAd dlBmCZC d dlDZDd dlEZEd dlFZFd dlGZGd dlHZHd dlIZId dlJZJd dlKZKd dlLZLd dlMZNdd„ ZOG dd„ deƒZPG dd„ dePƒZQG dd„ de(ƒZRG dd„ de(ƒZSG dd„ deLjTƒZUG dd„ deLjTƒZVG d d!„ d!ePƒZWG d"d#„ d#ePƒZXG d$d%„ d%e(ƒZYG d&d'„ d'ePƒZZG d(d)„ d)e(ƒZ[G d*d+„ d+ePƒZ\G d,d-„ d-e(ƒZ]G d.d/„ d/ePƒZ^G d0d1„ d1e(ƒZ_G d2d3„ d3e(ƒZ`G d4d5„ d5e(ƒZaG d6d7„ d7e(ƒZbG d8d9„ d9e(ƒZcG d:d;„ d;e(ƒZdG d<d=„ d=e(ƒZ*G d>d?„ d?e(ƒZeG d@dA„ dAe(ƒZfG dBdC„ dCe(ƒZgG dDdE„ dEe(ƒZhG dFdG„ dGe(ƒZiG dHdI„ dIePƒZjG dJdK„ dKePƒZkG dLdM„ dMePƒZlG dNdO„ dOePƒZmeL neFjodPkdQ¡G dRdS„ dSePƒƒZpG dTdU„ dUe)ƒZqeL neFjodPkdQ¡G dVdW„ dWePƒƒZrG dXdY„ dYePƒZsG dZd[„ d[ePƒZtG d\d]„ d]ePƒZuG d^d_„ d_ePƒZvG d`da„ daePƒZwG dbdc„ dcePƒZxG ddde„ deePƒZyG dfdg„ dgePƒZzG dhdi„ dieQƒZ{G djdk„ dkeQƒZ|G dldm„ dmeQƒZ}G dndo„ doeQƒZ~G dpdq„ dqeQƒZG drds„ dseQƒZ€G dtdu„ duePƒZ�G dvdw„ dweQƒZ‚G dxdy„ dyePƒZƒG dzd{„ d{eQƒZ„G d|d}„ d}e…ƒZ†G d~d„ deQƒZ‡G d€d�„ d�eQƒZˆG d‚dƒ„ dƒeQƒZ‰G d„d…„ d…eQƒZŠG d†d‡„ d‡eQƒZ‹G dˆd‰„ d‰ePƒZŒG dŠd‹„ d‹eQƒZ�G dŒd�„ d�eQƒZŽG dŽd�„ d�eQƒZ�G d�d‘„ d‘eQƒZ�G d’d“„ d“eQƒZ‘G d”d•„ d•ePƒZ’G d–d—„ d—ePƒZ“G d˜d™„ d™ePƒZ”G dšd›„ d›ePƒZ•G dœd�„ d�ePƒZ–e7G dždŸ„ dŸe(ƒƒZ—G d d¡„ d¡ƒZ˜G d¢d£„ d£e˜ePƒZ™G d¤d¥„ d¥e˜ePƒZšG d¦d§„ d§eQƒZ›G d¨d©„ d©eQƒZœG dªd«„ d«eLjTƒZ�G d¬d­„ d­eQƒZžG d®d¯„ d¯eQƒZŸG d°d±„ d±eQƒZ G d²d³„ d³eQƒZ¡G d´dµ„ dµePƒZ¢G d¶d·„ d·ePƒZ£G d¸d¹„ d¹eQƒZ¤G dºd»„ d»eLjTƒZ¥G d¼d½„ d½eƒZ¦G d¾d¿„ d¿eLjTƒZ§G dÀdÁ„ dÁePƒZ¨G dÂdÃ„ dÃePƒZ©dS )Äé    N)ÚFuture)Úgen)Újson_decodeÚutf8Ú
to_unicodeÚrecursive_unicodeÚ
native_strÚto_basestring)ÚHTTPClientError)Úformat_timestamp)ÚIOStream)Úlocale)ÚEvent)Úapp_logÚgen_log©ÚSimpleAsyncHTTPClient©Ú
DictLoader)ÚAsyncHTTPTestCaseÚAsyncTestCaseÚ	ExpectLogÚgen_test)Úignore_deprecation)Ú
ObjectDictÚunicode_type)ÚApplicationÚRequestHandlerÚStaticFileHandlerÚRedirectHandlerÚ	HTTPErrorÚMissingArgumentErrorÚErrorHandlerÚauthenticatedÚurlÚ_create_signature_v1Úcreate_signed_valueÚdecode_signed_valueÚget_signature_key_versionÚUIModuleÚFinishÚstream_request_bodyÚremoveslashÚaddslashÚGZipContentEncoding)ÚBytesIOc                  G   s   t jjt j t¡g| ¢R Ž S ©N)ÚosÚpathÚjoinÚdirnameÚ__file__)Úa© r7   ú_/raid/bulk_storage/M2HATS/real-image-venv/lib/python3.10/site-packages/tornado/test/web_test.pyÚrelpathA   ó   r9   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚWebTestCasezÂBase class for web tests that also supports WSGI mode.

    Override get_handlers and get_app_kwargs instead of get_app.
    This class is deprecated since WSGI mode is no longer supported.
    c                 C   s    t |  ¡ fi |  ¡ ¤Ž| _| jS r0   )r   Úget_handlersÚget_app_kwargsÚapp©Úselfr7   r7   r8   Úget_appL   s   zWebTestCase.get_appc                 C   ó   t ƒ ‚r0   ©ÚNotImplementedErrorr?   r7   r7   r8   r<   P   ó   zWebTestCase.get_handlersc                 C   s   i S r0   r7   r?   r7   r7   r8   r=   S   ó   zWebTestCase.get_app_kwargsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rA   r<   r=   r7   r7   r7   r8   r;   E   s
    r;   c                   @   s   e Zd ZdZdZdd„ ZdS )ÚSimpleHandlerTestCasez�Simplified base class for tests that work with a single handler class.

    To use, define a nested class named ``Handler``.
    Nc                 C   s   d| j fgS )Nú/©ÚHandlerr?   r7   r7   r8   r<   _   ó   z"SimpleHandlerTestCase.get_handlers)rG   rH   rI   rJ   rN   r<   r7   r7   r7   r8   rK   W   s    rK   c                   @   ó   e Zd Zdd„ ZdS )ÚHelloHandlerc                 C   ó   |   d¡ d S ©NÚhello©Úwriter?   r7   r7   r8   Úgetd   ó   zHelloHandler.getN©rG   rH   rI   rW   r7   r7   r7   r8   rQ   c   ó    rQ   c                   @   s(   e Zd Zd	dd„Zdd„ Zd
dd„ZdS )ÚCookieTestRequestHandlerÚ
0123456789Nc                 C   s<   i | _ |d u rtt|d�d�| _d S tt||d�d�| _d S )N)Úcookie_secret)Úsettings©r]   Úkey_version)Ú_cookiesr   ÚdictÚapplication)r@   r]   r`   r7   r7   r8   Ú__init__j   s   ÿ
ÿz!CookieTestRequestHandler.__init__c                 C   s   | j  |¡S r0   )ra   rW   )r@   Únamer7   r7   r8   Ú
get_cookiev   rO   z#CookieTestRequestHandler.get_cookiec                 C   s   || j |< d S r0   )ra   )r@   re   ÚvalueÚexpires_daysr7   r7   r8   Ú
set_cookiey   rX   z#CookieTestRequestHandler.set_cookie)r\   Nr0   )rG   rH   rI   rd   rf   ri   r7   r7   r7   r8   r[   h   s    
r[   c                   @   ó$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚSecureCookieV1Testc                 C   ó0   t ƒ }|jdddd� |  |jddd�d¡ d S )NÚfooó   baré   ©Úversion©Úmin_version©r[   Úset_signed_cookieÚassertEqualÚget_signed_cookie©r@   Úhandlerr7   r7   r8   Útest_round_trip   ó   z"SecureCookieV1Test.test_round_tripc                 C   s  t ƒ }|jdt d¡dd� |jd }t d|¡}|  |¡ |d us$J ‚| d¡}| d¡}|  	t
|jjd dd|ƒ|¡ |  	t
|jjd dd	d
| ƒ|¡ tdt|ƒ› dt|ƒ› �ƒ|jd< ttdƒ� |  |jddd�¡ W d   ƒ d S 1 szw   Y  d S )Nrm   s   d76df8e7aefcro   rp   s   12345678\|([0-9]+)\|([0-9a-f]+)é   r]   Ú12345678Ú1234s   5678z	1234|5678ú|zCookie timestamp in futurerr   )r[   ru   ÚbinasciiÚa2b_hexra   ÚreÚmatchÚassertIsNotNoneÚgrouprv   r%   rc   r^   r   r	   r   r   ÚassertIsNonerw   )r@   ry   Úcookierƒ   Ú	timestampÚsigr7   r7   r8   Ú&test_cookie_tampering_future_timestamp„   s@   




üù
üù

ÿ"ÿz9SecureCookieV1Test.test_cookie_tampering_future_timestampc                 C   rl   )Nrm   ó   éro   rp   rr   rt   rx   r7   r7   r8   Útest_arbitrary_bytes«   s   z'SecureCookieV1Test.test_arbitrary_bytesN)rG   rH   rI   rz   rŠ   rŒ   r7   r7   r7   r8   rk   ~   s    'rk   c                   @   s>   e Zd ZdddœZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚSecureCookieV2TestÚajklasdf0ojaisdfÚaslkjasaolwkjsdf)r   ro   c                 C   rl   )Nrm   rn   r|   rp   rr   rt   rx   r7   r7   r8   rz   ·   r{   z"SecureCookieV2Test.test_round_tripc                 C   ó0   t | jdd�}| dd¡ |  | d¡d¡ d S )Nr   r_   rm   rn   ©r[   ÚKEY_VERSIONSru   rv   rw   rx   r7   r7   r8   Útest_key_version_roundtrip¼   ó
   ÿz-SecureCookieV2Test.test_key_version_roundtripc                 C   r�   )Nro   r_   rm   rn   r‘   rx   r7   r7   r8   Ú,test_key_version_roundtrip_differing_versionÃ   r”   z?SecureCookieV2Test.test_key_version_roundtrip_differing_versionc                 C   sF   t | jdd�}| dd¡ t | jdd�}|j|_|  | d¡d¡ d S ©Nr   r_   rm   rn   ro   )r[   r’   ru   ra   rv   rw   )r@   ry   Únew_handlerr7   r7   r8   Ú"test_key_version_increment_versionÊ   s   ÿÿz5SecureCookieV2Test.test_key_version_increment_versionc                 C   sX   t | jdd�}| dd¡ | j ¡ }| d¡ t |dd�}|j|_|  | d¡d ¡ d S r–   )r[   r’   ru   ÚcopyÚpopra   rv   rw   )r@   ry   Únew_key_versionsr—   r7   r7   r8   Ú#test_key_version_invalidate_versionÕ   s   ÿ

ÿz6SecureCookieV2Test.test_key_version_invalidate_versionN)	rG   rH   rI   r’   rz   r“   r•   r˜   rœ   r7   r7   r7   r8   r�   ´   s    
r�   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ ZdS )
ÚFinalReturnTestNc                    s<   | ‰ G ‡ fdd„dt ƒ}G ‡ fdd„dt ƒ}d|fd|fgS )Nc                       s0   e Zd Zej‡ fdd„ƒZej‡ fdd„ƒZdS )z3FinalReturnTest.get_handlers.<locals>.FinishHandlerc                 3   s   � |   ¡ ˆ _ˆ jV  d S r0   )ÚfinishÚfinal_returnr?   ©Útestr7   r8   rW   ê   s   €
z7FinalReturnTest.get_handlers.<locals>.FinishHandler.getc                 3   s.   � |   d¡ |  ¡ V  |  d¡ˆ _ˆ jV  d S )Nzhello,Úworld)rV   Úflushrž   rŸ   r?   r    r7   r8   Úpostï   s
   €

z8FinalReturnTest.get_handlers.<locals>.FinishHandler.postN)rG   rH   rI   r   Ú	coroutinerW   r¤   r7   r    r7   r8   ÚFinishHandleré   s
    r¦   c                       s&   e Zd Zdd„ Zej‡ fdd„ƒZdS )z3FinalReturnTest.get_handlers.<locals>.RenderHandlerc                 S   s   t ddiƒS )Núfoo.htmlÚhir   ©r@   r2   r7   r7   r8   Úcreate_template_loader÷   rO   zJFinalReturnTest.get_handlers.<locals>.RenderHandler.create_template_loaderc                    s   |   d¡ˆ _d S ©Nr§   )ÚrenderrŸ   r?   r    r7   r8   rW   ú   s   z7FinalReturnTest.get_handlers.<locals>.RenderHandler.getN)rG   rH   rI   rª   r   r¥   rW   r7   r    r7   r8   ÚRenderHandlerö   s    r­   ú/finishú/render©r   )r@   r¦   r­   r7   r    r8   r<   æ   s   zFinalReturnTest.get_handlersc                 C   ó
   t dd�S )Nr�   )Útemplate_path©rb   r?   r7   r7   r8   r=      ó   
zFinalReturnTest.get_app_kwargsc                 C   s‚   |   |  d¡¡}|  |jd¡ |  | jt¡ |  | j ¡ ¡ | j |  d¡ddd�}|  |jd¡ |  | jt¡ |  | j ¡ ¡ d S )Nr®   éÈ   ÚPOSTó    ©ÚmethodÚbody)	ÚfetchÚget_urlrv   ÚcodeÚassertIsInstancerŸ   r   Ú
assertTrueÚdone©r@   Úresponser7   r7   r8   Ú test_finish_method_return_future  s   z0FinalReturnTest.test_finish_method_return_futurec                 C   s0   |   |  d¡¡}|  |jd¡ |  | jt¡ d S )Nr¯   rµ   )r»   r¼   rv   r½   r¾   rŸ   r   rÁ   r7   r7   r8   Ú test_render_method_return_future  s   z0FinalReturnTest.test_render_method_return_future)rG   rH   rI   rŸ   r<   r=   rÃ   rÄ   r7   r7   r7   r8   r�   ã   s    r�   c                   @   ód   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )Ú
CookieTestc                 C   sà   G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G d	d
„ d
t ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}	G dd„ dt ƒ}
d|fd|fd|fd|fd|fd|fd|fd|fd|	fd|
fg
S )Nc                   @   rP   )z1CookieTest.get_handlers.<locals>.SetCookieHandlerc                 S   ó(   |   dd¡ |   dd¡ |   dd¡ d S )NÚstrÚasdfÚunicodeÚqwerÚbytess   zxcv©ri   r?   r7   r7   r8   rW     s   z5CookieTest.get_handlers.<locals>.SetCookieHandler.getNrY   r7   r7   r7   r8   ÚSetCookieHandler  rZ   rÎ   c                   @   rP   )z1CookieTest.get_handlers.<locals>.GetCookieHandlerc                 S   s&   |   dd¡}|d usJ ‚|  |¡ d S )Nrm   Údefault)rf   rV   )r@   r‡   r7   r7   r8   rW     s   z5CookieTest.get_handlers.<locals>.GetCookieHandler.getNrY   r7   r7   r7   r8   ÚGetCookieHandler  rZ   rÐ   c                   @   rP   )z7CookieTest.get_handlers.<locals>.SetCookieDomainHandlerc                 S   ó   | j ddddd� d S )NÚunicode_argsÚblahzfoo.comú/foo)Údomainr2   rÍ   r?   r7   r7   r8   rW   %  s   z;CookieTest.get_handlers.<locals>.SetCookieDomainHandler.getNrY   r7   r7   r7   r8   ÚSetCookieDomainHandler$  rZ   rÖ   c                   @   rP   )z<CookieTest.get_handlers.<locals>.SetCookieSpecialCharHandlerc                 S   rÇ   )NÚequalsúa=bÚ	semicolonúa;bÚquoteúa"brÍ   r?   r7   r7   r8   rW   ,  s   z@CookieTest.get_handlers.<locals>.SetCookieSpecialCharHandler.getNrY   r7   r7   r7   r8   ÚSetCookieSpecialCharHandler*  ó    rÝ   c                   @   rP   )z>CookieTest.get_handlers.<locals>.SetCookieForbiddenCharHandlerc                 S   sV  t tttdƒƒƒtdƒdg D �]}z|  d| d¡ |  d| ¡ W n# tjjyF } zdt	|ƒvr<|  d||f ¡ W Y d }~nd }~ww z| jddd	| d
 d� |  d| ¡ W n# tjjy } zdt	|ƒvru|  d||f ¡ W Y d }~nd }~ww z| jddd	| d
 d� |  d| ¡ W n# tjjy¸ } zdt	|ƒvr®|  d||f ¡ W Y d }~nd }~ww z| jddd| d� |  d| ¡ W n# tjjyï } zdt	|ƒvrå|  d||f ¡ W Y d }~nd }~ww z| jddd| d� |  d| ¡ W q tjj�y( } zdt	|ƒv�r|  d||f ¡ W Y d }~qd }~ww d S )Né    é   ú;rm   Úbarz2Didn't get expected exception for char %r in name
zInvalid cookie attribute namez-unexpected exception for char %r in name: %s
Úexamplez.com©rÕ   z4Didn't get expected exception for char %r in domain
zInvalid cookie attribute domainz/unexpected exception for char %r in domain: %s
)ÚDoMaInz4Didn't get expected exception for char %r in DoMaIn
zInvalid cookie attribute DoMaInz/unexpected exception for char %r in DoMaIn: %s
rL   ©r2   z2Didn't get expected exception for char %r in path
zInvalid cookie attribute pathz-unexpected exception for char %r in path: %s
r6   )Úsamesitez6Didn't get expected exception for char %r in samesite
z!Invalid cookie attribute samesitez1unexpected exception for char %r in samesite: %s
)
ÚlistÚmapÚchrÚrangeri   rV   ÚhttpÚcookiesÚCookieErrorrÈ   )r@   ÚcharÚer7   r7   r8   rW   2  sœ   $ÿÿÿ€þÿÿÿÿ€þÿÿÿÿ€þÿÿÿ€þÿÿÿÿ€þÈzBCookieTest.get_handlers.<locals>.SetCookieForbiddenCharHandler.getNrY   r7   r7   r7   r8   ÚSetCookieForbiddenCharHandler1  rZ   rñ   c                   @   rP   )z:CookieTest.get_handlers.<locals>.SetCookieOverwriteHandlerc                 S   s0   | j dddd� | j dddd� |   dd¡ d S )Nr6   Úbzexample.comrä   ÚcÚdrð   rÍ   r?   r7   r7   r8   rW   u  s   z>CookieTest.get_handlers.<locals>.SetCookieOverwriteHandler.getNrY   r7   r7   r7   r8   ÚSetCookieOverwriteHandlert  rZ   rõ   c                   @   rP   )z7CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandlerc                 S   ó   | j dddd� d S )Nrm   râ   é
   )Úmax_agerÍ   r?   r7   r7   r8   rW   }  ó   z;CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandler.getNrY   r7   r7   r7   r8   ÚSetCookieMaxAgeHandler|  rZ   rú   c                   @   rP   )z<CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandlerc                 S   rö   )Nrm   râ   r÷   )rh   rÍ   r?   r7   r7   r8   rW   �  rù   z@CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandler.getNrY   r7   r7   r7   r8   ÚSetCookieExpiresDaysHandler€  rZ   rû   c                   @   rP   )z4CookieTest.get_handlers.<locals>.SetCookieFalsyFlagsc                 S   sD   | j dddd� | j dddd� | j dddd� | j d	ddd� d S )
Nr6   Ú1T)Úsecurerò   Fró   )Úhttponlyrô   rÍ   r?   r7   r7   r8   rW   …  s   z8CookieTest.get_handlers.<locals>.SetCookieFalsyFlags.getNrY   r7   r7   r7   r8   ÚSetCookieFalsyFlags„  rZ   rÿ   c                   @   rP   )z8CookieTest.get_handlers.<locals>.SetCookieDeprecatedArgsc                 S   rÑ   )Nr6   rò   TrÔ   )ÚHttpOnlyÚpATHrÍ   r?   r7   r7   r8   rW   Œ  s   z<CookieTest.get_handlers.<locals>.SetCookieDeprecatedArgs.getNrY   r7   r7   r7   r8   ÚSetCookieDeprecatedArgs‹  rZ   r  ú/setú/getú/set_domainú/special_charú/forbidden_charú/set_overwriteú/set_max_ageú/set_expires_daysú/set_falsy_flagsú/set_deprecatedr°   )r@   rÎ   rÐ   rÖ   rÝ   rñ   rõ   rú   rû   rÿ   r  r7   r7   r8   r<     s*   CözCookieTest.get_handlersc                 C   s*   |   d¡}|  t|j d¡ƒg d¢¡ d S )Nr  ú
Set-Cookie)zbytes=zxcv; Path=/zstr=asdf; Path=/zunicode=qwer; Path=/)r»   rv   ÚsortedÚheadersÚget_listrÁ   r7   r7   r8   Útest_set_cookie�  s
   
þzCookieTest.test_set_cookiec                 C   sd   | j dddid�}|  |jd¡ | j dddid�}|  |jd¡ | j dddid�}|  |jd¡ d S )	Nr  ÚCookieúfoo=bar©r  rn   z	foo="bar"z/=exception;ó   default©r»   rv   rº   rÁ   r7   r7   r8   Útest_get_cookie¤  s   zCookieTest.test_get_cookiec                 C   s$   |   d¡}|  |j d¡dg¡ d S )Nr  r  z,unicode_args=blah; Domain=foo.com; Path=/foo©r»   rv   r  r  rÁ   r7   r7   r8   Útest_set_cookie_domain®  s
   

þz!CookieTest.test_set_cookie_domainc                 C   sª   |   d¡}t|j d¡ƒ}|  t|ƒd¡ |  |d d¡ |  |d d¡ |  |d d	|d ¡ g d
¢}|D ]\}}t d|¡ | j dd|id�}|  |j	t
|ƒ¡ q6d S )Nr  r  é   r   zequals="a=b"; Path=/ro   zquote="a\"b"; Path=/r|   )zsemicolon="a;b"; Path=/zsemicolon="a\073b"; Path=/))zfoo=a=brØ   )z	foo="a=b"rØ   )z	foo="a;b"z"a)z
foo=a\073bza\073b)zfoo="a\073b"rÚ   )z
foo="a\"b"rÜ   z	trying %rr  r  r  )r»   r  r  r  rv   ÚlenÚassertInÚloggingÚdebugrº   r   )r@   rÂ   r  ÚdataÚheaderÚexpectedr7   r7   r8   Útest_cookie_special_charµ  s    
ýýz#CookieTest.test_cookie_special_charc                 C   s4   |   d¡}|  |jd¡ d| _|  t|jƒd¡ d S )Nr  rµ   i'  Ú )r»   rv   r½   ÚmaxDiffÚassertMultiLineEqualr   rº   rÁ   r7   r7   r8   Útest_set_cookie_forbidden_charÏ  s   
z)CookieTest.test_set_cookie_forbidden_charc                 C   s.   |   d¡}|j d¡}|  t|ƒddg¡ d S )Nr  r  za=e; Path=/zc=d; Domain=example.com; Path=/©r»   r  r  rv   r  ©r@   rÂ   r  r7   r7   r8   Útest_set_cookie_overwriteÕ  s
   
ÿz$CookieTest.test_set_cookie_overwritec                 C   s,   |   d¡}|j d¡}|  t|ƒdg¡ d S )Nr	  r  zfoo=bar; Max-Age=10; Path=/r'  r(  r7   r7   r8   Útest_set_cookie_max_ageÜ  s   
z"CookieTest.test_set_cookie_max_agec                 C   sš   |   d¡}|j d¡}|  |¡ |d usJ ‚t d|¡}|  |¡ |d us'J ‚tj tjj	¡tj
dd� }tj | ¡ d ¡}|  t||  ¡ ƒd¡ d S )Nr
  r  z(foo=bar; expires=(?P<expires>.+); Path=/r÷   ©ÚdaysÚexpires)r»   r  rW   r„   r‚   rƒ   ÚdatetimeÚnowÚtimezoneÚutcÚ	timedeltaÚemailÚutilsÚparsedate_to_datetimeÚ	groupdictÚ
assertLessÚabsÚtotal_seconds©r@   rÂ   r   rƒ   r-  Úheader_expiresr7   r7   r8   Útest_set_cookie_expires_daysá  s   


ÿz'CookieTest.test_set_cookie_expires_daysc                 C   s^   |   d¡}t|j d¡ƒ}|  |d d¡ |  |d d¡ |  |d d¡ |  |d	 d
¡ d S )Nr  r  r   za=1; Path=/; Securero   zb=1; Path=/r|   zc=1; HttpOnly; Path=/r  zd=1; Path=/)r»   r  r  r  rv   r(  r7   r7   r8   Útest_set_cookie_false_flagsð  s   
z&CookieTest.test_set_cookie_false_flagsc                 C   sL   t ƒ � |  d¡}W d   ƒ n1 sw   Y  |j d¡}|  |d¡ d S )Nr  r  za=b; HttpOnly; Path=/foo)r   r»   r  rW   rv   )r@   rÂ   r   r7   r7   r8   Útest_set_cookie_deprecatedø  s
   ÿz%CookieTest.test_set_cookie_deprecatedN)rG   rH   rI   r<   r  r  r  r"  r&  r)  r*  r<  r=  r>  r7   r7   r7   r8   rÆ     s     	
rÆ   c                   @   s(   e Zd Zdd„ Zdd„ Zedd„ ƒZdS )ÚAuthRedirectRequestHandlerc                 C   ó
   || _ d S r0   ©Ú	login_url)r@   rB  r7   r7   r8   Ú
initialize   r´   z%AuthRedirectRequestHandler.initializec                 C   ó   | j S r0   rA  r?   r7   r7   r8   Úget_login_url  rE   z(AuthRedirectRequestHandler.get_login_urlc                 C   rR   )Néô  )Ú
send_errorr?   r7   r7   r8   rW     ó   zAuthRedirectRequestHandler.getN)rG   rH   rI   rC  rE  r#   rW   r7   r7   r7   r8   r?  ÿ  s
    r?  c                   @   rj   )ÚAuthRedirectTestc                 C   s    dt tdd�fdt tdd�fgS )Nú	/relativez/loginrA  ú	/absolutezhttp://example.com/login)r?  rb   r?   r7   r7   r8   r<     s   ýþzAuthRedirectTest.get_handlersc                 C   s8   | j |  d¡dd�}|  |jd¡ |  |jd d¡ d S )NrJ  F©Úfollow_redirectsé.  ÚLocationz/login?next=%2Frelative)r»   r¼   rv   r½   r  rÁ   r7   r7   r8   Útest_relative_auth_redirect  s   z,AuthRedirectTest.test_relative_auth_redirectc                 C   sF   | j |  d¡dd�}|  |jd¡ |  t d|jd ¡|jd ¡ d S )NrK  FrL  rN  zIhttp://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2FabsoluterO  )r»   r¼   rv   r½   r¿   r‚   rƒ   r  rÁ   r7   r7   r8   Útest_absolute_auth_redirect  s   þûz,AuthRedirectTest.test_absolute_auth_redirectN)rG   rH   rI   r<   rP  rQ  r7   r7   r7   r8   rI    s    
rI  c                   @   s*   e Zd Zdd„ Zejdd„ ƒZdd„ ZdS )ÚConnectionCloseHandlerc                 C   r@  r0   r    ©r@   r¡   r7   r7   r8   rC  )  r´   z!ConnectionCloseHandler.initializec                 c   s   � | j  ¡  | j j ¡ V  d S r0   )r¡   Úon_handler_waitingÚcleanup_eventÚwaitr?   r7   r7   r8   rW   ,  s   €
zConnectionCloseHandler.getc                 C   s   | j  ¡  d S r0   )r¡   Úon_connection_closer?   r7   r7   r8   rW  1  rX   z*ConnectionCloseHandler.on_connection_closeN)rG   rH   rI   rC  r   r¥   rW   rW  r7   r7   r7   r8   rR  (  s
    
rR  c                   @   ó,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚConnectionCloseTestc                 C   s   t ƒ | _dtt| d�fgS )NrL   r    )r   rU  rR  rb   r?   r7   r7   r8   r<   6  s   z ConnectionCloseTest.get_handlersc                 C   s`   t   t jt jd¡}| d|  ¡ f¡ t|ƒ| _| j d¡ |  ¡  | j	 
¡  | j dd„ ¡ d S )Nr   ú	127.0.0.1s   GET / HTTP/1.0

c                   S   s
   t  d¡S ©Nr   )r   Úsleepr7   r7   r7   r8   Ú<lambda>B  s   
 z;ConnectionCloseTest.test_connection_close.<locals>.<lambda>)ÚsocketÚAF_INETÚSOCK_STREAMÚconnectÚget_http_portr   ÚstreamrV   rV  rU  ÚsetÚio_loopÚrun_sync)r@   Úsr7   r7   r8   Útest_connection_close:  s   

z)ConnectionCloseTest.test_connection_closec                 C   s   t  d¡ | j ¡  d S )Nzhandler waiting)r  r  rc  Úcloser?   r7   r7   r8   rT  D  ó   
z&ConnectionCloseTest.on_handler_waitingc                 C   s   t  d¡ |  ¡  d S )Nzconnection closed)r  r  Ústopr?   r7   r7   r8   rW  H  ó   
z'ConnectionCloseTest.on_connection_closeN)rG   rH   rI   r<   rh  rT  rW  r7   r7   r7   r8   rY  5  s
    
rY  c                   @   rP   )ÚEchoHandlerc                 G   sÎ   | j jD ]=}t|ƒturtdt|ƒ ƒ‚| j j| D ]}t|ƒtur*tdt|ƒ ƒ‚q|  |¡D ]}t|ƒtur@tdt|ƒ ƒ‚q0q|D ]}t|ƒturTtdt|ƒ ƒ‚qD|  t	| j j
|t| j jƒd�¡ d S )Nzincorrect type for key: %rzincorrect type for value: %rzincorrect type for path arg: %r©r2   Ú	path_argsÚargs)ÚrequestÚ	argumentsÚtyperÈ   Ú	ExceptionrÌ   Úget_argumentsr   rV   rb   r2   r   )r@   ro  ÚkeyÚbvalueÚsvalueÚargr7   r7   r8   rW   N  s.   ÿÿÿÿ
ýÿzEchoHandler.getNrY   r7   r7   r7   r8   rm  M  rZ   rm  c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚRequestEncodingTestc                 C   s   dt fdt fgS )Nz/group/(.*)z/slashes/([^/]*)/([^/]*))rm  r?   r7   r7   r8   r<   i  ó   z RequestEncodingTest.get_handlersc                 C   s   t |  |¡jƒS r0   )r   r»   rº   r©   r7   r7   r8   Ú
fetch_jsonl  r{  zRequestEncodingTest.fetch_jsonc                 C   sF   |   |  d¡tddgi d�¡ |   |  d¡tddgddgid�¡ d S )Nz
/group/%3Fú?rn  z/group/%3F?%3F=%3F©rv   r|  rb   r?   r7   r7   r8   Útest_group_question_marko  s   þþz,RequestEncodingTest.test_group_question_markc                 C   s&   |   |  d¡ddgddgidœ¡ d S )Nz/group/%C3%A9?arg=%C3%A9z/group/%C3%A9õ   Ã©ry  rn  ©rv   r|  r?   r7   r7   r8   Útest_group_encodingz  s   ýþz'RequestEncodingTest.test_group_encodingc                 C   sD   |   |  d¡tdddgi d�¡ |   |  d¡tdddgi d�¡ d S )Nz/slashes/foo/barrm   râ   rn  z/slashes/a%2Fb/c%2Fdza/bzc/dr~  r?   r7   r7   r8   Útest_slashes…  s   þþz RequestEncodingTest.test_slashesc                 C   ó:   t tdƒ� |  d¡ W d   ƒ d S 1 sw   Y  d S )Nz.*Invalid unicodez/group/?arg=%25%e9)r   r   r»   r?   r7   r7   r8   Ú
test_error‘  ó   "ÿzRequestEncodingTest.test_errorN)	rG   rH   rI   r<   r|  r  r‚  rƒ  r…  r7   r7   r7   r8   rz  h  s    rz  c                   @   rX  )
ÚTypeCheckHandlerc                 C   s  i | _ |  d|  ¡ t¡ |  d|  d¡t¡ |  dt| j ¡ ƒd t	¡ |  dt| j 
¡ ƒd jt	¡ t| j ¡ ƒdgkrFtd| j ¡  ƒ‚|  d	|  d¡t¡ |  d
|  d¡t	¡ |  d| jt¡ |  d|  ¡ t	¡ |  d|  dd¡t	¡ |  d|  ¡ t	¡ d S )NÚstatusÚargumentrm   Ú
cookie_keyr   Úcookie_valuerÉ   z%unexpected values for cookie keys: %rrw   rf   Ú
xsrf_tokenÚxsrf_form_htmlÚreverse_urlÚ	typecheckÚrequest_summary)ÚerrorsÚ
check_typeÚ
get_statusÚintÚget_argumentr   rè   rí   ÚkeysrÈ   Úvaluesrg   rt  rw   rÌ   rf   rŒ  r�  rŽ  Ú_request_summaryr?   r7   r7   r8   Úprepare™  s   ÿzTypeCheckHandler.preparec                 C   ó   |   d|t¡ |  | j¡ d S ©NÚpath_component©r’  r   rV   r‘  ©r@   rœ  r7   r7   r8   rW   ´  s   zTypeCheckHandler.getc                 C   rš  r›  r�  rž  r7   r7   r8   r¤   º  s   zTypeCheckHandler.postc                 C   s.   t |ƒ}||krd|› d|› �| j|< d S d S )Nz	expected z, got )rs  r‘  )r@   re   ÚobjÚexpected_typeÚactual_typer7   r7   r8   r’  ¾  s   ÿzTypeCheckHandler.check_typeN)rG   rH   rI   r™  rW   r¤   r’  r7   r7   r7   r8   r‡  ˜  s
    r‡  c                   @   s   e Zd Zddd„Zdd„ ZdS )ÚDecodeArgHandlerNc                 C   sF   t |ƒturtdt |ƒ ƒ‚d| jjv r!| t| jjd d ƒ¡S |S )Nzunexpected type for value: %rÚencodingr   )rs  rÌ   rt  rq  rr  Údecoder   )r@   rg   re   r7   r7   r8   Údecode_argumentÅ  s
   z DecodeArgHandler.decode_argumentc                 C   s*   dd„ }|   ||ƒ||  d¡ƒdœ¡ d S )Nc                 S   s:   t | ƒtu rdtt | ¡ƒgS t | ƒtu rd| gS tdƒ‚)NrÌ   rÊ   zunknown type)rs  rÌ   r   r€   Úb2a_hexr   rt  )rg  r7   r7   r8   ÚdescribeÏ  s
   z&DecodeArgHandler.get.<locals>.describerm   ©r2   Úquery)rV   r•  )r@   ry  r§  r7   r7   r8   rW   Î  s   "zDecodeArgHandler.getr0   )rG   rH   rI   r¥  rW   r7   r7   r7   r8   r¢  Ä  s    
	r¢  c                   @   rP   )ÚLinkifyHandlerc                 C   s   | j ddd� d S )Núlinkify.htmlzhttp://example.com)Úmessage©r¬   r?   r7   r7   r8   rW   Ú  ó   zLinkifyHandler.getNrY   r7   r7   r7   r8   rª  Ù  rZ   rª  c                   @   rP   )ÚUIModuleResourceHandlerc                 C   s   | j dddgd� d S )Nú	page.htmlro   r|   )Úentriesr­  r?   r7   r7   r8   rW   ß  ó   zUIModuleResourceHandler.getNrY   r7   r7   r7   r8   r¯  Þ  rZ   r¯  c                   @   rP   )ÚOptionalPathHandlerc                 C   s   |   d|i¡ d S )Nr2   rU   r©   r7   r7   r8   rW   ä  r®  zOptionalPathHandler.getNrY   r7   r7   r7   r8   r³  ã  rZ   r³  c                   @   rP   )ÚMultiHeaderHandlerc                 C   s4   |   dd¡ |   dd¡ |  dd¡ |  dd¡ d S )	Núx-overwriterü   zX-Overwriter|   úx-multir  zX-MultiÚ4)Ú
set_headerÚ
add_headerr?   r7   r7   r8   rW   é  s   zMultiHeaderHandler.getNrY   r7   r7   r7   r8   r´  è  rZ   r´  c                   @   rP   )r   c                 C   sd   |   dd ¡d ur| jdtt|   d¡ƒƒd� d S |   dd ¡d ur.| jdt|   d¡ƒd� d S tdƒ‚)NÚ	permanentrL   )rº  rˆ  )rˆ  z(didn't get permanent or status arguments)r•  ÚredirectÚboolr”  rt  r?   r7   r7   r8   rW   ñ  s
    zRedirectHandler.getNrY   r7   r7   r7   r8   r   ð  rZ   r   c                   @   ó   e Zd Zejdd„ ƒZdS )ÚEmptyFlushCallbackHandlerc                 c   sB   � |   ¡ V  |   ¡ V  |  d¡ |   ¡ V  |   ¡ V  |  d¡ d S )NÚoÚk)r£   rV   rž   r?   r7   r7   r8   rW   û  s   €




zEmptyFlushCallbackHandler.getN)rG   rH   rI   r   r¥   rW   r7   r7   r7   r8   r¾  ú  ó    r¾  c                   @   rP   )ÚHeaderInjectionHandlerc              
   C   sV   z
|   dd¡ tdƒ‚ ty* } zdt|ƒv r|  d¡ n‚ W Y d }~d S d }~ww )NúX-Foozfoo
X-Bar: bazúDidn't get expected exceptionúUnsafe header valueó   ok)r¸  rt  Ú
ValueErrorrÈ   rž   ©r@   rð   r7   r7   r8   rW   	  s   þ€þzHeaderInjectionHandler.getNrY   r7   r7   r7   r8   rÂ    rZ   rÂ  c                   @   rP   )ÚSetHeaderHandlerc                 C   sž   dd„ t ddƒD ƒ}| tdƒ¡ | d¡ |D ])}z|  dd| d	 ¡ td
ƒ‚ tyA } zdt|ƒvr7‚ W Y d }~qd }~ww |  dd¡ |  d¡ d S )Nc                 S   s   g | ]}t |ƒ‘qS r7   )rê   )Ú.0r¿  r7   r7   r8   Ú
<listcomp>  ó    z(SetHeaderHandler.get.<locals>.<listcomp>r   rß   rà   ú	rÃ  rm   râ   rÄ  rÅ  r#  rÆ  )	rë   Úappendrê   Úremover¸  rt  rÇ  rÈ   rž   )r@   Úillegal_charsrï   rð   r7   r7   r8   rW     s   
ÿ€ÿzSetHeaderHandler.getNrY   r7   r7   r7   r8   rÉ    rZ   rÉ  c                   @   rP   )ÚGetArgumentHandlerc                 C   sJ   |   dd ¡dkr| j}n|   dd ¡dkr| j}n| j }|  |ddƒ¡ d S )NÚsourcer©  rº   rm   rÏ   )r•  Úget_query_argumentÚget_body_argumentrž   ©r@   r¹   r7   r7   r8   r™  )  s   zGetArgumentHandler.prepareN©rG   rH   rI   r™  r7   r7   r7   r8   rÑ  (  rZ   rÑ  c                   @   rP   )ÚGetArgumentsHandlerc                 C   s*   |   t|  d¡|  d¡|  d¡d�¡ d S )Nrm   ©rÏ   r©  rº   )rž   rb   ru  Úget_query_argumentsÚget_body_argumentsr?   r7   r7   r8   r™  4  s   ýÿzGetArgumentsHandler.prepareNrÖ  r7   r7   r7   r8   r×  3  rZ   r×  c                       sÈ   e Zd ZdZdd„ Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Z‡  ZS ).ÚWSGISafeWebTestzWebTest.COOKIE_SECRETc                 C   s    t ddddœƒ}t|d| jd�S )Nz{% module linkify(message) %}zv<html><head></head><body>
{% for e in entries %}
{% module Template("entry.html", entry=e) %}
{% end %}
</body></html>aY  {{ set_resources(embedded_css=".entry { margin-bottom: 1em; }",
                 embedded_javascript="js_embed()",
                 css_files=["/base.css", "/foo.css"],
                 javascript_files="/common.js",
                 html_head="<meta>",
                 html_body='<script src="/analytics.js"/>') }}
<div class="entry">...</div>)r«  r°  z
entry.htmlÚxhtml_escape)Útemplate_loaderÚ
autoescaper]   )r   rb   ÚCOOKIE_SECRET)r@   Úloaderr7   r7   r8   r=   B  s   øÿýzWSGISafeWebTest.get_app_kwargsc                    ó   t ƒ  ¡  tj ¡  d S r0   ©ÚsuperÚtearDownr   Ú_template_loadersÚclearr?   ©Ú	__class__r7   r8   rä  \  rj  zWSGISafeWebTest.tearDownc                 C   sœ   t dtdd�t dtdd�t dtƒt dtƒt dtƒt d	tƒt d
tƒt dtƒt dtddiƒt dtdddœƒt dtddiƒt dt	ƒt dt
ƒt dtƒt dtƒg}|S )Nz/typecheck/(.*)r�  )re   z/decode_arg/(.*)Ú
decode_argz/decode_arg_kw/(?P<arg>.*)ú/linkifyú/uimodule_resourcesz/optional_path/(.+)?ú/multi_headerz	/redirectú/web_redirect_permanentr$   ú/web_redirect_newpathú/web_redirectF)r$   rº  ú//web_redirect_double_slashú/header_injectionú/get_argumentz/get_argumentsú/set_header)r$   r‡  r¢  rª  r¯  r³  r´  r   ÚWebRedirectHandlerrÂ  rÑ  r×  rÉ  )r@   Úurlsr7   r7   r8   r<   `  s:   ýýýåzWSGISafeWebTest.get_handlersc                 O   s"   | j |i |¤Ž}| ¡  t|jƒS r0   )r»   Úrethrowr   rº   )r@   rp  ÚkwargsrÂ   r7   r7   r8   r|  €  s   
zWSGISafeWebTest.fetch_jsonc                 C   s\   t t| jddƒƒ}| jddd| id�}t|jƒ}|  |i ¡ | jdddd| idd	�}d S )
NrÉ   rË   z/typecheck/asdf?foo=barr  zasdf=r  r¶   r  ©r¹   r  rº   )r   r&   rß  r»   r   rº   rv   )r@   r‹  rÂ   r  r7   r7   r8   Ú
test_types…  s   ÿÿ


üzWSGISafeWebTest.test_typesc                 C   s‚   g d¢}|D ]}|   |¡}| ¡  t|jƒ}|  |ddgddgdœ¡ q|   d¡}| ¡  t|jƒ}|  |ddgddgdœ¡ d S )N)z,/decode_arg/%C3%A9?foo=%C3%A9&encoding=utf-8z'/decode_arg/%E9?foo=%E9&encoding=latin1z*/decode_arg_kw/%E9?foo=%E9&encoding=latin1rÊ   r€  r¨  z/decode_arg/%C3%A9?foo=%C3%A9rÌ   Úc3a9©r»   rö  r   rº   rv   ©r@   rõ  Úreq_urlrÂ   r  r7   r7   r8   Útest_decode_argument–  s   

þ

z$WSGISafeWebTest.test_decode_argumentc                 C   s`   t tdƒ�! |  d¡}|  |jd¡ |  d¡}|  |jd¡ W d   ƒ d S 1 s)w   Y  d S )Nz.*Invalid unicode.*z/typecheck/invalid%FFé�  z/typecheck/invalid?foo=%FF©r   r   r»   rv   r½   rÁ   r7   r7   r8   Ú$test_decode_argument_invalid_unicode«  s   

"üz4WSGISafeWebTest.test_decode_argument_invalid_unicodec                 C   sL   ddg}|D ]}|   |¡}| ¡  t|jƒ}|  |ddgddgdœ¡ qd S )Nz6/decode_arg/1%20%2B%201?foo=1%20%2B%201&encoding=utf-8z0/decode_arg/1%20+%201?foo=1+%2B+1&encoding=utf-8rÊ   ú1 + 1r¨  rû  rü  r7   r7   r8   Útest_decode_argument_plus³  s   þ

þüz)WSGISafeWebTest.test_decode_argument_plusc                 C   sr   |   | j dd¡d¡ |   | j dd¡d¡ |   | j dd¡d¡ |   | j dd¡d	¡ |   | j dd
¡d¡ d S )Nré  rm   z/decode_arg/fooé*   z/decode_arg/42r‹   z/decode_arg/%E9r€  z/decode_arg/%C3%A9r  z/decode_arg/1%20%2B%201)rv   r>   rŽ  r?   r7   r7   r8   Útest_reverse_urlÂ  s   ÿÿz WSGISafeWebTest.test_reverse_urlc                 C   ó   |   d¡}|  |jd¡ d S )Nrê  s3   <a href="http://example.com">http://example.com</a>r  rÁ   r7   r7   r8   Útest_uimodule_unescapedÍ  s   
ÿz'WSGISafeWebTest.test_uimodule_unescapedc                 C   r  )Nrë  s¿  <html><head><link href="/base.css" type="text/css" rel="stylesheet"/><link href="/foo.css" type="text/css" rel="stylesheet"/>
<style type="text/css">
.entry { margin-bottom: 1em; }
</style>
<meta>
</head><body>


<div class="entry">...</div>


<div class="entry">...</div>

<script src="/common.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
js_embed()
//]]>
</script>
<script src="/analytics.js"/>
</body></html>r  rÁ   r7   r7   r8   Útest_uimodule_resourcesÓ  ó
   
þz'WSGISafeWebTest.test_uimodule_resourcesc                 C   s0   |   |  d¡ddi¡ |   |  d¡dd i¡ d S )Nz/optional_path/foor2   rm   z/optional_path/r�  r?   r7   r7   r8   Útest_optional_pathï  ó   z"WSGISafeWebTest.test_optional_pathc                 C   s8   |   d¡}|  |jd d¡ |  |j d¡ddg¡ d S )Nrì  rµ  Ú2r¶  Ú3r·  r  rÁ   r7   r7   r8   Útest_multi_headeró  s   
z!WSGISafeWebTest.test_multi_headerc                 C   sX   | j ddd�}|  |jd¡ | j ddd�}|  |jd¡ | j ddd�}|  |jd¡ d S )	Nz/redirect?permanent=1FrL  é-  z/redirect?permanent=0rN  z/redirect?status=307i3  ©r»   rv   r½   rÁ   r7   r7   r8   Útest_redirectø  s   zWSGISafeWebTest.test_redirectc                 C   s`   | j ddd�}|  |jd¡ |  |jd d¡ | j ddd�}|  |jd¡ |  |jd d¡ d S )	Nrí  FrL  r  rO  rî  rï  rN  ©r»   rv   r½   r  rÁ   r7   r7   r8   Útest_web_redirect   s   z!WSGISafeWebTest.test_web_redirectc                 C   ó2   | j ddd�}|  |jd¡ |  |jd d¡ d S )Nrð  FrL  r  rO  rî  r  rÁ   r7   r7   r8   Útest_web_redirect_double_slash  ó   z.WSGISafeWebTest.test_web_redirect_double_slashc                 C   r  )Nrñ  rÆ  r  rÁ   r7   r7   r8   Útest_header_injection  ó   
z%WSGISafeWebTest.test_header_injectionc                 C   r  )Nró  rÆ  r  rÁ   r7   r7   r8   Útest_set_header  r  zWSGISafeWebTest.test_set_headerc                 C   s°   |   d¡}|  |jd¡ |   d¡}|  |jd¡ |   d¡}|  |jd¡ tj tdd�¡}| j dd	|d
�}|  |jd¡ | j dd	|d
�}|  t|jƒtddgdgdgd�¡ d S )Nz/get_argument?foo=barrn   z/get_argument?foo=r·   rò  r  rT   ©rm   r¶   r¸   ó   helloz/get_arguments?foo=barrâ   rØ  )r»   rv   rº   ÚurllibÚparseÚ	urlencoderb   r   )r@   rÂ   rº   r7   r7   r8   Útest_get_argument  s   


þz!WSGISafeWebTest.test_get_argumentc                 C   sp   t j tdd�¡}| jdd|d�}|  |jd¡ | jdd|d�}|  |jd¡ | jd	d|d�}|  |jd
¡ d S )NrT   r  z"/get_argument?source=query&foo=barr¶   r¸   rn   z/get_argument?source=query&foo=r·   z/get_argument?source=queryr  ©r  r  r  rb   r»   rv   rº   ©r@   rº   rÂ   r7   r7   r8   Útest_get_query_arguments)  s   ÿÿz(WSGISafeWebTest.test_get_query_argumentsc                 C   s�   t j tdd�¡}| jdd|d�}|  |jd¡ t j tdd�¡}| jdd|d�}|  |jd¡ t j tƒ ¡}| jdd|d�}|  |jd	¡ d S )
Nrâ   r  z#/get_argument?source=body&foo=hellor¶   r¸   rn   r#  r·   r  r   r!  r7   r7   r8   Útest_get_body_arguments8  s   ÿÿÿz'WSGISafeWebTest.test_get_body_argumentsc                 C   s:   |   d¡}|  d|j dd¡¡ |  d|j dd¡¡ d S )Nrò  úAccept-EncodingÚVaryr#  ÚgzipúContent-Encoding)r»   ÚassertNotInr  rW   rÁ   r7   r7   r8   Útest_no_gzipK  s   
zWSGISafeWebTest.test_no_gzip)rG   rH   rI   rß  r=   rä  r<   r|  rù  rþ  r  r  r  r  r  r
  r  r  r  r  r  r  r  r"  r#  r)  Ú__classcell__r7   r7   rç  r8   rÛ  ?  s0     rÛ  c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚNonWSGIWebTestsc                 C   ó
   dt fgS )Nú/empty_flush)r¾  r?   r7   r7   r8   r<   R  r´   zNonWSGIWebTests.get_handlersc                 C   r  )Nr.  rÆ  r  rÁ   r7   r7   r8   Útest_empty_flushU  r  z NonWSGIWebTests.test_empty_flushN)rG   rH   rI   r<   r/  r7   r7   r7   r8   r,  Q  ó    r,  c                   @   rX  )
ÚErrorResponseTestc                 C   sL   G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}td|ƒtd|ƒtd	|ƒgS )
Nc                   @   rP   )z6ErrorResponseTest.get_handlers.<locals>.DefaultHandlerc                 S   s*   |   dd ¡rtt|   d¡ƒƒ‚dd  d S ©Nrˆ  ro   r   )r•  r    r”  r?   r7   r7   r8   rW   ]  s   z:ErrorResponseTest.get_handlers.<locals>.DefaultHandler.getNrY   r7   r7   r7   r8   ÚDefaultHandler\  rZ   r3  c                   @   r+  )z9ErrorResponseTest.get_handlers.<locals>.WriteErrorHandlerc                 S   s0   |   dd ¡r|  t|   d¡ƒ¡ d S dd  d S r2  )r•  rG  r”  r?   r7   r7   r8   rW   c  s   z=ErrorResponseTest.get_handlers.<locals>.WriteErrorHandler.getc                 [   sB   |   dd¡ d|v r|  d|d d j ¡ d S |  d| ¡ d S )NúContent-Typeú
text/plainÚexc_infozException: %sr   z
Status: %d)r¸  rV   rG   ©r@   Ústatus_coder÷  r7   r7   r8   Úwrite_errori  s   zEErrorResponseTest.get_handlers.<locals>.WriteErrorHandler.write_errorN©rG   rH   rI   rW   r9  r7   r7   r7   r8   ÚWriteErrorHandlerb  s    r;  c                   @   r+  )z?ErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandlerc                 S   ó   dd  d S ©Nro   r   r7   r?   r7   r7   r8   rW   q  rO   zCErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.getc                 [   ó   t dƒ‚)Nzexception in write_error©rt  r7  r7   r7   r8   r9  t  ó   zKErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.write_errorNr:  r7   r7   r7   r8   ÚFailedWriteErrorHandlerp  r0  rA  ú/defaultú/write_errorú/failed_write_error)r   r$   )r@   r3  r;  rA  r7   r7   r8   r<   [  s   ýzErrorResponseTest.get_handlersc                 C   s¢   t tdƒ�B |  d¡}|  |jd¡ |  d|j¡ |  d¡}|  |jd¡ |  d|j¡ |  d¡}|  |jd	¡ |  d
|j¡ W d   ƒ d S 1 sJw   Y  d S )NúUncaught exceptionrB  rF  s   500: Internal Server Errorz/default?status=503é÷  s   503: Service Unavailablez/default?status=435i³  s   435: Unknown)r   r   r»   rv   r½   r  rº   rÁ   r7   r7   r8   Útest_default}  s   


"õzErrorResponseTest.test_defaultc                 C   s|   t tdƒ�/ |  d¡}|  |jd¡ |  d|j¡ |  d¡}|  |jd¡ |  d|j¡ W d   ƒ d S 1 s7w   Y  d S )NrE  rC  rF  s   Exception: ZeroDivisionErrorz/write_error?status=503rF  s   Status: 503©r   r   r»   rv   r½   rº   rÁ   r7   r7   r8   Útest_write_error‹  s   

"ùz"ErrorResponseTest.test_write_errorc                 C   sV   t tdƒ� |  d¡}|  |jd¡ |  d|j¡ W d   ƒ d S 1 s$w   Y  d S )NrE  rD  rF  r·   rH  rÁ   r7   r7   r8   Útest_failed_write_error•  s
   
"ýz)ErrorResponseTest.test_failed_write_errorN)rG   rH   rI   r<   rG  rI  rJ  r7   r7   r7   r8   r1  Z  s
    "
r1  c                   @   s`  e Zd ZdZej ej e¡d¡Z	dd„ Z
dd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Z d1d2„ Z!d3d4„ Z"d5d6„ Z#d7d8„ Z$d9d:„ Z%d;d<„ Z&d=d>„ Z'd?d@„ Z(dAdB„ Z)dCdD„ Z*dEdF„ Z+dGdH„ Z,dIdJ„ Z-e. /ej0dKkdL¡dMdN„ ƒZ1dOS )PÚStaticFileTests€   63a36e950e134b5217e33c763e88840c10a07d80e6057d92b9ac97508de7fb1fa6f0e9b7531e169657165ea764e8963399cb6d921ffe6078425aaafe54c04563Ústaticc                 C   sT   G dd„ dt ƒ}G dd„ d|ƒ}G dd„ dt ƒ}d|fd|fd	|fd
ttdd�fgS )Nc                   @   rP   )z5StaticFileTest.get_handlers.<locals>.StaticUrlHandlerc                 S   s(   t |  dd¡ƒ}|  | j||d�¡ d S )NÚinclude_versionrü   )rM  )r”  r•  rV   Ú
static_url)r@   r2   Úwith_vr7   r7   r8   rW   §  s   z9StaticFileTest.get_handlers.<locals>.StaticUrlHandler.getNrY   r7   r7   r7   r8   ÚStaticUrlHandler¦  rZ   rP  c                   @   s   e Zd ZdZdS )z=StaticFileTest.get_handlers.<locals>.AbsoluteStaticUrlHandlerTN)rG   rH   rI   Úinclude_hostr7   r7   r7   r8   ÚAbsoluteStaticUrlHandler«  s    rR  c                   @   rP   )z=StaticFileTest.get_handlers.<locals>.OverrideStaticUrlHandlerc           
      S   s¬   t |  d¡ƒ}| | _|  |¡}| j||d�}||kr"|  tdƒ¡S | jjd }t|ƒ}| 	|d|¡}| 	|d|¡}|rE|dkoC|dk}	n|dkoL|dk}	|  t|	ƒ¡ d S )NrQ  )rQ  Fz://r   éÿÿÿÿ)
r¼  r•  rQ  rN  rV   rÈ   rq  Úprotocolr  Úfind)
r@   r2   Ú
do_includeÚregular_urlÚoverride_urlrT  Úprotocol_lengthÚcheck_regularÚcheck_overrideÚresultr7   r7   r8   rW   ¯  s   
zAStaticFileTest.get_handlers.<locals>.OverrideStaticUrlHandler.getNrY   r7   r7   r7   r8   ÚOverrideStaticUrlHandler®  rZ   r]  ú/static_url/(.*)z/abs_static_url/(.*)z/override_static_url/(.*)z/root_static/(.*)rL   ræ   )r   r   rb   )r@   rP  rR  r]  r7   r7   r8   r<   ¥  s   üzStaticFileTest.get_handlersc                 C   s   t tdƒd�S )NrL  )Ústatic_path©rb   r9   r?   r7   r7   r8   r=   Ê  rX   zStaticFileTest.get_app_kwargsc                 C   sH   |   d¡}|  d|j¡ |   d¡}|  d|j¡ |  |j d¡d¡ d S )Nú/robots.txtó   Disallow: /ú/static/robots.txtr4  r5  )r»   r  rº   rv   r  rW   rÁ   r7   r7   r8   Útest_static_filesÍ  s
   

z StaticFileTest.test_static_filesc                 C   s8   |   d¡}|  d|j¡ |  d|j¡ |  d|j¡ d S )Nz/robots.txt?v=12345rb  zCache-ControlÚExpires)r»   r  rº   r  rÁ   r7   r7   r8   Útest_static_files_cacheableÕ  s   
z*StaticFileTest.test_static_files_cacheablec                 C   sb   |   d¡}|  |j d¡d¡ |   d¡}|  |j d¡d¡ |   d¡}|  |j d¡ddh¡ d S )	Nz/static/sample.xml.gzr4  zapplication/gzipz/static/sample.xml.bz2zapplication/octet-streamz/static/sample.xmlztext/xmlzapplication/xml)r»   rv   r  rW   r  rÁ   r7   r7   r8   Útest_static_compressed_filesÞ  s   

ÿ
ÿz+StaticFileTest.test_static_compressed_filesc                 C   s"   |   d¡}|  |jd| j ¡ d S )Nz/static_url/robots.txts   /static/robots.txt?v=)r»   rv   rº   Úrobots_txt_hashrÁ   r7   r7   r8   Útest_static_urlë  s   
zStaticFileTest.test_static_urlc                 C   s0   |   d¡}|  |jt|  d¡ƒd | j ¡ d S )Nz/abs_static_url/robots.txtrL   s   static/robots.txt?v=)r»   rv   rº   r   r¼   rh  rÁ   r7   r7   r8   Útest_absolute_static_urlï  s
   
þz'StaticFileTest.test_absolute_static_urlc                 C   r  )Nz(/static_url/robots.txt?include_version=0s   /static/robots.txtr  rÁ   r7   r7   r8   Útest_relative_version_exclusionö  r  z.StaticFileTest.test_relative_version_exclusionc                 C   s*   |   d¡}|  |jt|  d¡d ƒ¡ d S )Nz,/abs_static_url/robots.txt?include_version=0rL   ústatic/robots.txt)r»   rv   rº   r   r¼   rÁ   r7   r7   r8   Útest_absolute_version_exclusionú  s   
 z.StaticFileTest.test_absolute_version_exclusionc                 C   s   |   d¡ |   d¡ d S )NFT)Ú_trigger_include_host_checkr?   r7   r7   r8   Útest_include_host_overrideþ  rj  z)StaticFileTest.test_include_host_overridec                 C   s0   d}|   |t|ƒ ¡}|  |jttdƒƒ¡ d S )Nz//override_static_url/robots.txt?include_host=%sT)r»   r”  rv   rº   r   rÈ   )r@   rQ  r2   rÂ   r7   r7   r8   rn    s   z*StaticFileTest._trigger_include_host_checkc                 O   sž   | j |ddi|¤Ž}| j |ddi|¤Ž}tƒ }t |j|j¡D ]}| d¡r+| |¡ q|D ]}|  |j |¡|j |¡d||j |¡|j |¡f ¡ q.|S )zŸPerforms a GET and HEAD request and returns the GET response.

        Fails if any ``Content-*`` headers returned by the two requests
        differ.
        r¹   ÚHEADÚGETzContent-z)%s differs between GET (%s) and HEAD (%s))	r»   rd  Ú	itertoolsÚchainr  Ú
startswithÚaddrv   rW   )r@   rp  r÷  Úhead_responseÚget_responseÚcontent_headersÚhr7   r7   r8   Úget_and_head  s    

€

ÿýzStaticFileTest.get_and_headc                 C   sB   |   d¡}| j dd|jd id�}|  |jd¡ |  d|j¡ d S )Nrc  úIf-Modified-SinceúLast-Modifiedr  é0  úContent-Length)rz  r  rv   r½   r(  ©r@   Ú	response1Ú	response2r7   r7   r8   Ú!test_static_304_if_modified_since  s   
þz0StaticFileTest.test_static_304_if_modified_sincec                 C   s4   |   d¡}| j dd|jd id�}|  |jd¡ d S )Nrc  úIf-None-MatchÚEtagr  r}  ©rz  r  rv   r½   r  r7   r7   r8   Útest_static_304_if_none_match%  s
   
ÿz,StaticFileTest.test_static_304_if_none_matchc                 C   s6   |   d¡}| j dd|jd dœd�}|  |jd¡ d S )Nrc  z
"MISMATCH"r|  )rƒ  r{  r  rµ   r…  r  r7   r7   r8   Ú!test_static_304_etag_modified_bug,  s   
þþz0StaticFileTest.test_static_304_etag_modified_bugc                 C   ó$   | j dddid�}|  |jd¡ d S )Nrc  r{  z!nv@l!dr  rµ   ©rz  rv   r½   rÁ   r7   r7   r8   Ú)test_static_304_if_modified_since_invalid7  s
   þz8StaticFileTest.test_static_304_if_modified_since_invalidc                 C   rˆ  )Nrc  r{  zFri, 01 Jan 1960 00:00:00 GMTr  rµ   r‰  rÁ   r7   r7   r8   Ú'test_static_if_modified_since_pre_epoch>  s
   þz6StaticFileTest.test_static_if_modified_since_pre_epochc                 C   sf   t  tdƒ¡}| jddt|jd ƒid�}|  |jd¡ | jddt|jd ƒid�}|  |jd¡ d S )Nrl  rc  r{  ro   r  rµ   r}  )r1   Ústatr9   rz  r   Úst_mtimerv   r½   )r@   rŒ  rÂ   r7   r7   r8   Ú'test_static_if_modified_since_time_zoneH  s   þþz6StaticFileTest.test_static_if_modified_since_time_zonec                 C   s0   |   d¡}|  t|j d¡ƒd| j d ¡ d S )Nrc  r„  ó   ")rz  rv   r   r  rW   rh  rÁ   r7   r7   r8   Útest_static_etagZ  s   
ÿzStaticFileTest.test_static_etagc                 C   s|   | j dddid�}|  |jd¡ |  |jd¡ |  t|j d¡ƒd| j d ¡ |  |j d	¡d
¡ |  |j d¡d¡ d S )Nrc  ÚRangez	bytes=0-9r  éÎ   s
   User-agentr„  r�  r~  Ú10úContent-Rangezbytes 0-9/26)rz  rv   r½   rº   r   r  rW   rh  rÁ   r7   r7   r8   Útest_static_with_range`  s   ÿÿz%StaticFileTest.test_static_with_rangec                 C   óœ   | j dddid�}|  |jd¡ tj | jd¡}t|dd��}|  |jt	| 
¡ ƒ¡ W d   ƒ n1 s4w   Y  |  |j d	¡d
¡ |  |j d¡¡ d S )Nrc  r‘  zbytes=0-r  rµ   ú
robots.txtúutf-8©r£  r~  Ú26r”  ©rz  rv   r½   r1   r2   r3   Ú
static_dirÚopenrº   r   Úreadr  rW   r†   ©r@   rÂ   Úrobots_file_pathÚfr7   r7   r8   Ú test_static_with_range_full_filel  s   ÿÿz/StaticFileTest.test_static_with_range_full_filec                 C   r–  )Nrc  r‘  zbytes=0-10000000r  rµ   r—  r˜  r™  r~  rš  r”  r›  rŸ  r7   r7   r8   Ú$test_static_with_range_full_past_endy  ó   ÿÿz3StaticFileTest.test_static_with_range_full_past_endc                 C   s¦   | j dddid�}|  |jd¡ tj | jd¡}t|dd��}|  |jt	| 
¡ d	d … ƒ¡ W d   ƒ n1 s8w   Y  |  |j d
¡d¡ |  |j d¡d¡ d S )Nrc  r‘  zbytes=1-10000000r  r’  r—  r˜  r™  ro   r~  Ú25r”  zbytes 1-25/26)rz  rv   r½   r1   r2   r3   rœ  r�  rº   r   rž  r  rW   rŸ  r7   r7   r8   Ú'test_static_with_range_partial_past_end„  s   ÿ ÿz6StaticFileTest.test_static_with_range_partial_past_endc                 C   óL   | j dddid�}|  |jd¡ |  |j d¡d¡ |  |j d¡d	¡ d S )
Nrc  r‘  z	bytes=22-r  ó   : /
r~  r·  r”  úbytes 22-25/26©rz  rv   rº   r  rW   rÁ   r7   r7   r8   Útest_static_with_range_end_edge�  ó   ÿz.StaticFileTest.test_static_with_range_end_edgec                 C   r§  )
Nrc  r‘  zbytes=-4r  r¨  r~  r·  r”  r©  rª  rÁ   r7   r7   r8   Útest_static_with_range_neg_end—  r¬  z-StaticFileTest.test_static_with_range_neg_endc                 C   r–  )Nrc  r‘  zbytes=-1000000r  rµ   r—  r˜  r™  r~  rš  r”  r›  rŸ  r7   r7   r8   Ú%test_static_with_range_neg_past_startŸ  r¤  z4StaticFileTest.test_static_with_range_neg_past_startc                 C   rˆ  )Nrc  r‘  rÉ   r  rµ   r‰  rÁ   r7   r7   r8   Útest_static_invalid_rangeª  s   z(StaticFileTest.test_static_invalid_rangec                 C   s8   | j dddid�}|  |j d¡d¡ |  |jd¡ d S )Nrc  r‘  zbytes=-0r  r”  ú
bytes */26é   )rz  rv   r  rW   r½   rÁ   r7   r7   r8   Ú+test_static_unsatisfiable_range_zero_suffix®  s
   ÿz:StaticFileTest.test_static_unsatisfiable_range_zero_suffixc                 C   ó8   | j dddid�}|  |jd¡ |  |j d¡d¡ d S )Nrc  r‘  zbytes=26r  r±  r”  r°  ©rz  rv   r½   r  rW   rÁ   r7   r7   r8   Ú-test_static_unsatisfiable_range_invalid_startµ  ó
   ÿz<StaticFileTest.test_static_unsatisfiable_range_invalid_startc                 C   r³  )Nrc  r‘  z
bytes=10-3r  r±  r”  r°  r´  rÁ   r7   r7   r8   Ú3test_static_unsatisfiable_range_end_less_than_start¼  r¶  zBStaticFileTest.test_static_unsatisfiable_range_end_less_than_startc                 C   s`   | j ddd�}|  |jd¡ |  |jd¡ |  |jd d¡ |  t|jd ƒd	| j d	 ¡ d S )
Nrc  rp  ©r¹   rµ   r·   r~  rš  r„  r�  ©r»   rv   r½   rº   r  r   rh  rÁ   r7   r7   r8   Útest_static_headÃ  s   ÿzStaticFileTest.test_static_headc                 C   sf   | j ddddid�}|  |jd¡ |  |jd¡ |  |jd d	¡ |  t|jd
 ƒd| j d ¡ d S )Nrc  rp  r‘  ú	bytes=1-4)r¹   r  r’  r·   r~  r·  r„  r�  r¹  rÁ   r7   r7   r8   Útest_static_head_rangeÍ  s   
ÿÿz%StaticFileTest.test_static_head_rangec                 C   sl   | j ddd| j d dœd�}|  |jd¡ |  |jd¡ |  d|j¡ |  t|jd	 ƒd| j d ¡ d S )
Nrc  r»  r�  )r‘  rƒ  r  r}  r·   r~  r„  )rz  rh  rv   r½   rº   r(  r  r   rÁ   r7   r7   r8   Útest_static_range_if_none_matchØ  s   þþÿz.StaticFileTest.test_static_range_if_none_matchc                 C   r  )Nz/static/blargé”  r‰  rÁ   r7   r7   r8   Útest_static_404ç  r  zStaticFileTest.test_static_404c                 C   óF   t tdƒ� |  d¡}W d   ƒ n1 sw   Y  |  |jd¡ d S )Nz.*is not a fileú/static/dir/é“  )r   r   rz  rv   r½   rÁ   r7   r7   r8   Ú.test_static_directory_without_default_filenameë  s   ÿz=StaticFileTest.test_static_directory_without_default_filenamec                 C   sX   | j  ¡  tƒ | _ ttdƒ� |  d¡}W d   ƒ n1 sw   Y  |  |jd¡ d S )Nz.*not in root static directoryz/static/../static_foo.txtrÂ  )Úhttp_clientri  r   r   r   rz  rv   r½   rÁ   r7   r7   r8   Útest_path_traversal_protectionó  s   
ÿz-StaticFileTest.test_path_traversal_protectionÚposixúnon-posix OSc                 C   sF   t j t j t j t¡¡d¡}|  dtj 	|¡ ¡}|  
|jd¡ d S )Nrl  z/root_staticrµ   )r1   r2   r3   r4   Úabspathr5   rz  r  r  rÛ   rv   r½   )r@   r2   rÂ   r7   r7   r8   Útest_root_static_path   s
   ÿz$StaticFileTest.test_root_static_pathN)2rG   rH   rI   rh  r1   r2   r3   r4   r5   rœ  r<   r=   rd  rf  rg  ri  rj  rk  rm  ro  rn  rz  r‚  r†  r‡  rŠ  r‹  rŽ  r�  r•  r¢  r£  r¦  r«  r­  r®  r¯  r²  rµ  r·  rº  r¼  r½  r¿  rÃ  rÅ  ÚunittestÚskipIfre   rÉ  r7   r7   r7   r8   rK  œ  sT    ÿ%		

rK  rÆ  rÇ  c                       s€   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚStaticFileSymlinkTestz…Symlinks must not be followed out of the static directory unless the
    application opts in with ``allowed_symlink_directory``.
    c                    sâ  t  ¡ | _|  tj| j¡ tj | jd¡| _	tj | jd¡| _
t | j	¡ t | j
¡ ttj | j	d¡ddd��}| d¡ W d   ƒ n1 sHw   Y  ttj | j
d¡ddd��}| d	¡ W d   ƒ n1 sjw   Y  ttj | j	d
¡ddd��}| d¡ W d   ƒ n1 sŒw   Y  t tj | j
d¡tj | j	d¡¡ t | j
tj | j	d¡¡ t tj | j
d¡¡ t tj | j
d¡tj | j	d¡¡ t tj | j
d¡tj | j	d¡¡ t tj | j	d¡tj | j	d¡¡ tj | jd¡| _t | j¡ ttj | jd¡ddd��}| d¡ W d   ƒ n	1 �sw   Y  t tj | jd¡tj | j	d¡¡ ttj | jd¡ddd��}| d¡ W d   ƒ n	1 �sSw   Y  t tj | jd¡tj | j	d¡¡ tƒ  ¡  d S )NrL  Úoutsideú
inside.txtÚwr˜  r™  Úinsideú
secret.txtÚsecretú
index.htmlz
root indexúlink.txtÚlinkdirÚrealdirÚlink_existsÚnopeÚlink_missingúinternal.txtÚoutside2z	other.txtÚotherú	link2.txtzelsewhere.txtÚ	elsewherezlink_elsewhere.txt)ÚtempfileÚmkdtempÚtmpdirÚ
addCleanupÚshutilÚrmtreer1   r2   r3   ÚrootrÍ  Úmkdirr�  rV   ÚsymlinkrÛ  rã  ÚsetUp)r@   r¡  rç  r7   r8   rè    sj   
ÿÿÿþþþþÿþÿýþzStaticFileSymlinkTest.setUpc              	   C   sX   dt t| jd�fdt t| j| jd�fdt t| j| j| j| jgd�fdt t| jdd�fgS )	Nz/default/(.*)ræ   z/permissive/(.*))r2   Úallowed_symlink_directoryz/permissive_list/(.*)z/default_filename/(.*)rÓ  )r2   Údefault_filename)r   rb   rå  rá  rÍ  rÛ  r?   r7   r7   r8   r<   K  s(   ýýþýýíz"StaticFileSymlinkTest.get_handlersc                 C   ó   t ƒ S r0   r³   r?   r7   r7   r8   r=   f  rE   z$StaticFileSymlinkTest.get_app_kwargsc                 C   ó*   |   d¡}|  |jd¡ |  |jd¡ d S )Nz/default/inside.txtrµ   ó   inside©r»   rv   r½   rº   rÁ   r7   r7   r8   Útest_regular_filei  ó   
z'StaticFileSymlinkTest.test_regular_filec                 C   rì  )Nz/default/internal.txtrµ   rí  rî  rÁ   r7   r7   r8   Útest_symlink_within_rootn  ó   
z.StaticFileSymlinkTest.test_symlink_within_rootc                 C   rÀ  )Nú!.*is not in root static directoryz/default/link.txtrÂ  r   rÁ   r7   r7   r8   Ú!test_symlinked_file_escaping_roott  ó   ÿz7StaticFileSymlinkTest.test_symlinked_file_escaping_rootc                 C   rÀ  )Nró  z/default/linkdir/secret.txtrÂ  r   rÁ   r7   r7   r8   Ú&test_symlinked_directory_escaping_rooty  rõ  z<StaticFileSymlinkTest.test_symlinked_directory_escaping_rootc                 C   rì  )Nú/default_filename/rµ   s
   root indexrî  rÁ   r7   r7   r8   Útest_served_directory_itself~  s   
z2StaticFileSymlinkTest.test_served_directory_itselfc                 C   s‚   t  t j | jd¡¡ t  t j | jd¡t j | jdd¡¡ ttdƒ� |  	d¡}W d   ƒ n1 s3w   Y  |  
|jd¡ d S )NÚdirrÑ  rÓ  ró  z/default_filename/dir/rÂ  )r1   ræ  r2   r3   rå  rç  rÍ  r   r   r»   rv   r½   rÁ   r7   r7   r8   Útest_symlinked_default_filename†  s   þÿz5StaticFileSymlinkTest.test_symlinked_default_filenamec              	   C   sf   g }dD ]$}t tdƒ� | | jd| dd�j¡ W d   ƒ n1 s#w   Y  q|  |ddg¡ d S )N)r×  rÙ  ró  r÷  FrL  rÂ  )r   r   rÎ  r»   r½   rv   )r@   Úcodesre   r7   r7   r8   Ú0test_no_existence_oracle_for_symlinked_directory’  s   ÿÿ€zFStaticFileSymlinkTest.test_no_existence_oracle_for_symlinked_directoryc                 C   sP   |   d¡}|  |jd¡ |  |jd¡ |   d¡}|  |jd¡ |  |jd¡ d S )Nz/permissive/link.txtrµ   ó   secretz/permissive/linkdir/secret.txtrî  rÁ   r7   r7   r8   Útest_allowed_symlink_directory¡  s   

z4StaticFileSymlinkTest.test_allowed_symlink_directoryc                 C   s<   dD ]\}}|   d| ¡}|  |jd¡ |  |j|¡ qd S )N))rÎ  rí  )rÔ  rý  )rÝ  ó   otherz/permissive_list/rµ   rî  )r@   r2   r!  rÂ   r7   r7   r8   Ú#test_allowed_symlink_directory_list¬  s
   ùz9StaticFileSymlinkTest.test_allowed_symlink_directory_listc                 C   rÀ  )Nró  z#/permissive_list/link_elsewhere.txtrÂ  r   rÁ   r7   r7   r8   Ú2test_allowed_symlink_directory_list_rejects_others¹  ó   ÿzHStaticFileSymlinkTest.test_allowed_symlink_directory_list_rejects_others)rG   rH   rI   rJ   rè  r<   r=   rï  rñ  rô  rö  rø  rú  rü  rþ  r   r  r*  r7   r7   rç  r8   rÌ    s    8rÌ  c                       s>   e Zd ZU dZeed< dd„ Zedd„ ƒZ‡ fdd„Z	‡  Z
S )	ÚMultiRootStaticFileHandleraŸ  A subclass that searches a list of directories.

    It replaces ``initialize`` without calling ``super().initialize()``, so
    ``allowed_symlink_directory`` is never set, and it puts something other
    than a string in ``self.root``, passing the directory that matched to
    ``validate_absolute_path``. The symlink check must run against that
    directory. Jupyter's ``FileFindHandler`` is built this way.
    rå  c                 C   s   t dd„ |D ƒƒ| _d | _d S )Nc                 s   s$   � | ]}t j |¡t jj V  qd S r0   )r1   r2   rÈ  Úsep)rÊ  Úpr7   r7   r8   Ú	<genexpr>Î  s   €" z8MultiRootStaticFileHandler.initialize.<locals>.<genexpr>)Útuplerå  rê  r©   r7   r7   r8   rC  Í  s   
z%MultiRootStaticFileHandler.initializec                 C   sN   |D ]}t j t j ||¡¡}t j |¡r|  S qt j t j |d |¡¡S r[  )r1   r2   rÈ  r3   Úexists)ÚclsÚrootsr2   rå  Ú	candidater7   r7   r8   Úget_absolute_pathÑ  s   ÿz,MultiRootStaticFileHandler.get_absolute_pathc                    s4   | j D ]}|tjj  |¡r|} nqtƒ  ||¡S r0   )rå  r1   r2   r  rt  rã  Úvalidate_absolute_path)r@   rå  Úabsolute_pathr  rç  r7   r8   r  Ù  s   
þz1MultiRootStaticFileHandler.validate_absolute_path)rG   rH   rI   rJ   r  Ú__annotations__rC  Úclassmethodr  r  r*  r7   r7   rç  r8   r  Á  s   
 	
r  c                       sP   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
‡  ZS )ÚStaticFileMultiRootTestz€Subclasses that search several directories and never set
    ``allowed_symlink_directory`` must keep working (issue #3724).
    c                    s’  t  ¡ | _|  tj| j¡ tj | jd¡| _	tj | jd¡| _
tj | jd¡| _| j	| j
| jfD ]}t |¡ q0ttj | j	d¡ddd��}| d¡ W d   ƒ n1 sUw   Y  ttj | j
d	¡ddd��}| d
¡ W d   ƒ n1 sww   Y  ttj | jd¡ddd��}| d¡ W d   ƒ n1 s™w   Y  t tj | j	d¡tj | j
d¡¡ t tj | jd¡tj | j	d¡¡ tƒ  ¡  d S )NÚstatic1Ústatic2rÍ  zone.txtrÏ  r˜  r™  Úoneztwo.txtÚtworÑ  rÒ  rÚ  rÔ  )rß  rà  rá  râ  rã  rä  r1   r2   r3   Úroot1Úroot2rÍ  ræ  r�  rV   rç  rã  rè  )r@   rô   r¡  rç  r7   r8   rè  ç  s2   
ÿÿÿþþzStaticFileMultiRootTest.setUpc                 C   s   dt t| j| jgd�fgS )Nz/multi/(.*)ræ   )r  rb   r  r  r?   r7   r7   r8   r<   ÿ  s
   ýÿz$StaticFileMultiRootTest.get_handlersc                 C   rë  r0   r³   r?   r7   r7   r8   r=     rE   z&StaticFileMultiRootTest.get_app_kwargsc                 C   rì  )Nz/multi/one.txtrµ   s   onerî  rÁ   r7   r7   r8   Útest_first_root  rð  z'StaticFileMultiRootTest.test_first_rootc                 C   rì  )Nz/multi/two.txtrµ   s   tworî  rÁ   r7   r7   r8   Útest_second_root  rð  z(StaticFileMultiRootTest.test_second_rootc                 C   rÀ  )Nró  z/multi/internal.txtrÂ  r   rÁ   r7   r7   r8   Ú#test_symlink_to_other_root_rejected  r  z;StaticFileMultiRootTest.test_symlink_to_other_root_rejectedc                 C   rÀ  )Nró  z/multi/link.txtrÂ  r   rÁ   r7   r7   r8   Ú$test_symlink_escaping_roots_rejected  rõ  z<StaticFileMultiRootTest.test_symlink_escaping_roots_rejected)rG   rH   rI   rJ   rè  r<   r=   r  r  r  r  r*  r7   r7   rç  r8   r  á  s    	r  c                       sJ   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Ze e	j
dkd	¡d
d„ ƒZ‡  ZS )ÚStaticFileSymlinkedRootTestzpThe root itself may be reached through a symlink; that must not make
    every request look like an escape.
    c                    s¤   t  ¡ | _|  tj| j¡ tj | jd¡}t 	|¡ t
tj |d¡ddd��}| d¡ W d   ƒ n1 s6w   Y  tj | jd¡| _t || j¡ tƒ  ¡  d S )NÚrealrÎ  rÏ  r˜  r™  rÐ  Úlink)rß  rà  rá  râ  rã  rä  r1   r2   r3   ræ  r�  rV   rå  rç  rã  rè  )r@   Ú	real_rootr¡  rç  r7   r8   rè  '  s   

ÿz!StaticFileSymlinkedRootTest.setUpc                 C   s   dt t| jd�fgS )Nz/static/(.*)ræ   )r   rb   rå  r?   r7   r7   r8   r<   3  rù   z(StaticFileSymlinkedRootTest.get_handlersc                 C   rë  r0   r³   r?   r7   r7   r8   r=   6  rE   z*StaticFileSymlinkedRootTest.get_app_kwargsrÆ  rÇ  c                 C   rì  )Nz/static/inside.txtrµ   rí  rî  rÁ   r7   r7   r8   Útest_symlinked_root9  rò  z/StaticFileSymlinkedRootTest.test_symlinked_root)rG   rH   rI   rJ   rè  r<   r=   rÊ  rË  r1   re   r   r*  r7   r7   rç  r8   r  "  s    r  c                   @   rX  )
ÚStaticDefaultFilenameTestc                 C   ó   t tdƒt dd�d�S ©NrL  rÓ  ©rê  )r_  Ústatic_handler_argsr`  r?   r7   r7   r8   r=   A  ó   þz(StaticDefaultFilenameTest.get_app_kwargsc                 C   ó   g S r0   r7   r?   r7   r7   r8   r<   G  rF   z&StaticDefaultFilenameTest.get_handlersc                 C   s.   | j ddd�}|  |jd¡ |  d|j¡ d S )NrÁ  FrL  rµ   s   this is the index
rî  rÁ   r7   r7   r8   Útest_static_default_filenameJ  s   z6StaticDefaultFilenameTest.test_static_default_filenamec                 C   s6   | j ddd�}|  |jd¡ |  |jd  d¡¡ d S )Nú/static/dirFrL  r  rO  rÁ  )r»   rv   r½   r¿   r  ÚendswithrÁ   r7   r7   r8   Útest_static_default_redirectO  s   z6StaticDefaultFilenameTest.test_static_default_redirectN)rG   rH   rI   r=   r<   r(  r+  r7   r7   r7   r8   r!  @  s
    r!  c                   @   rX  )
ÚStaticDefaultFilenameRootTestc                 C   s    t tj tdƒ¡t dd�dd�S )NrL  rÓ  r$  rL   )r_  r%  Ústatic_url_prefix)rb   r1   r2   rÈ  r9   r?   r7   r7   r8   r=   V  s
   ýz,StaticDefaultFilenameRootTest.get_app_kwargsc                 C   r'  r0   r7   r?   r7   r7   r8   r<   ]  rF   z*StaticDefaultFilenameRootTest.get_handlersc                 C   rë  r0   r   r?   r7   r7   r8   Úget_http_client`  s   z-StaticDefaultFilenameRootTest.get_http_clientc                 C   sŠ   t j t¡}t j |¡\}}t jdkr|  ||¡ n|}ttdƒ� | j	d|› d�dd�}W d   ƒ n1 s7w   Y  |  |j
d¡ d S )NrÆ  z/.*cannot redirect path with two initial slashesz//evil.com/../r)  FrL  rÂ  )r1   r2   r4   r5   Ú
splitdrivere   rv   r   r   r»   r½   )r@   Útest_dirÚdriveÚtailrÂ   r7   r7   r8   Útest_no_open_redirecte  s   

þÿz3StaticDefaultFilenameRootTest.test_no_open_redirectN)rG   rH   rI   r=   r<   r.  r3  r7   r7   r7   r8   r,  U  s
    r,  c                   @   rj   )ÚStaticFileWithPathTestc                 C   r"  r#  r`  r?   r7   r7   r8   r=   {  r&  z%StaticFileWithPathTest.get_app_kwargsc                 C   s   dt dtdƒifgS )Nz	/foo/(.*)r2   z
templates/)r   r9   r?   r7   r7   r8   r<   �  rù   z#StaticFileWithPathTest.get_handlersc                 C   r  )Nz/foo/utf8.htmls   HÃ©llo
r  rÁ   r7   r7   r8   Ú
test_serve„  r  z!StaticFileWithPathTest.test_serveN)rG   rH   rI   r=   r<   r5  r7   r7   r7   r8   r4  z  s    r4  c                   @   rX  )
ÚCustomStaticFileTestc                 C   s0   G dd„ dt ƒ}G dd„ dtƒ}|| _d|fgS )Nc                   @   s^   e Zd Zedd„ ƒZdd„ Zedd„ ƒZdd„ Zedd
d„ƒZdd„ Z	dd„ Z
edd„ ƒZd	S )z>CustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandlerc                 S   s@   |   ||¡}| d¡}|d |… }||d d … }d |||¡S )NÚ.ro   z/static/{}.{}.{})Úget_versionÚrindexÚformat)r	  r^   r2   Úversion_hashÚextension_indexÚbefore_versionÚafter_versionr7   r7   r8   Úmake_static_urlŒ  s   
ýzNCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.make_static_urlc                 S   s4   |  d¡}|  dd|¡}|d |… › ||d … › �S )Nr7  r   )r9  )r@   Úurl_pathr<  Úversion_indexr7   r7   r8   Úparse_url_path˜  s   
zMCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.parse_url_pathc                 S   s   d| S )NzCustomStaticFileTest:r7   ©r	  r^   r2   r7   r7   r8   r  �  s   zPCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_absolute_pathc                 S   s   |S r0   r7   )r@   rå  r  r7   r7   r8   r  ¡  rF   zUCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.validate_absolute_pathNc                 S   s,   |d u r|d u s
J ‚|dkrdS t d| ƒ‚)NúCustomStaticFileTest:foo.txtrn   úunexpected path %rr?  )r@   r2   ÚstartÚendr7   r7   r8   Úget_content¤  s   zJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_contentc                 S   s   | j dkrdS td| j  ƒ‚)NrD  r  rE  )r  rt  r?   r7   r7   r8   Úget_content_size«  s   
zOCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_content_sizec                 S   ó   d S r0   r7   r?   r7   r7   r8   Úget_modified_time°  rF   zPCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_modified_timec                 S   ó   dS )NÚ42r7   rC  r7   r7   r8   r8  ³  ó   zJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_version©NN)rG   rH   rI   r  r?  rB  r  r  rH  rI  rK  r8  r7   r7   r7   r8   ÚMyStaticFileHandler‹  s    

rP  c                   @   rP   )z;CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandlerc                 S   s   |   |  |¡¡ d S r0   )rV   rN  r©   r7   r7   r8   rW   ¸  rù   z?CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandler.getNrY   r7   r7   r7   r8   rP  ·  rZ   rP  r^  )r   r   Ústatic_handler_class)r@   rP  rP  r7   r7   r8   r<   Š  s   ,
z!CustomStaticFileTest.get_handlersc                 C   s   t d| jd�S )NÚdummy)r_  rQ  )rb   rQ  r?   r7   r7   r8   r=   ¿  rX   z#CustomStaticFileTest.get_app_kwargsc                 C   r  )Nz/static/foo.42.txtrn   r  rÁ   r7   r7   r8   r5  Â  r  zCustomStaticFileTest.test_servec                 C   sL   t tddd�� |  d¡}|  |jd¡ W d   ƒ d S 1 sw   Y  d S )NzCould not open static fileF)Úrequiredz/static_url/foo.txts   /static/foo.42.txt)r   r   r»   rv   rº   rÁ   r7   r7   r8   ri  Æ  s   
"þz$CustomStaticFileTest.test_static_urlN)rG   rH   rI   r<   r=   r5  ri  r7   r7   r7   r8   r6  ‰  s
    5r6  c                   @   ó,   e Zd ZG dd„ deƒZdd„ Zdd„ ZdS )ÚHostMatchingTestc                   @   r+  )zHostMatchingTest.Handlerc                 C   r@  r0   )Úreply)r@   rV  r7   r7   r8   rC  Î  r´   z#HostMatchingTest.Handler.initializec                 C   ó   |   | j¡ d S r0   )rV   rV  r?   r7   r7   r8   rW   Ñ  r{  zHostMatchingTest.Handler.getN)rG   rH   rI   rC  rW   r7   r7   r7   r8   rN   Í  r0  rN   c                 C   s   dt jddifgS )NrÔ   rV  Úwildcard)rU  rN   r?   r7   r7   r8   r<   Ô  r®  zHostMatchingTest.get_handlersc                 C   s<  | j  ddtjddifg¡ | j  ddtjddifg¡ | j  ddtjdd	ifg¡ | j  d
dtjddifg¡ |  d¡}|  |jd¡ |  d¡}|  |jd¡ |  d¡}|  |jd¡ | jdddid�}|  |jd¡ | jdddid�}|  |jd¡ | jdddid�}|  |jd¡ | jdddid�}|  |jd¡ d S )Núwww.example.comrÔ   rV  ú[0]úwww\.example\.comú/barú[1]ú/bazú[2]zwww.e.*e.comz[3]s   wildcardr¾  ÚHostr  ó   [0]ó   [1]ó   [2]zwww.exe.coms   [3])r>   Úadd_handlersrU  rN   r»   rv   rº   r½   rÁ   r7   r7   r8   Útest_host_matching×  s4   ÿÿÿÿ


z#HostMatchingTest.test_host_matchingN)rG   rH   rI   r   rN   r<   re  r7   r7   r7   r8   rU  Ì  s    rU  c                   @   rj   )ÚDefaultHostMatchingTestc                 C   r'  r0   r7   r?   r7   r7   r8   r<   ÷  rF   z$DefaultHostMatchingTest.get_handlersc                 C   s   ddiS )NÚdefault_hostrY  r7   r?   r7   r7   r8   r=   ú  r@  z&DefaultHostMatchingTest.get_app_kwargsc                 C   sà   | j  ddtjddifg¡ | j  ddtjddifg¡ | j  dd	tjdd
ifg¡ |  d¡}|  |jd¡ |  d¡}|  |jd¡ |  d	¡}|  |jd¡ | jdddid�}|  |jd¡ d| j _|  d	¡}|  |jd¡ d S )NrY  rÔ   rV  rZ  r[  r\  r]  zwww.test.comr^  r_  ra  rb  r¾  z	X-Real-IprZ  r  rc  )	r>   rd  rU  rN   r»   rv   rº   r½   rg  rÁ   r7   r7   r8   Útest_default_host_matchingý  s(   ÿÿÿ



z2DefaultHostMatchingTest.test_default_host_matchingN)rG   rH   rI   r<   r=   rh  r7   r7   r7   r8   rf  ö  s    rf  c                   @   r+  )ÚNamedURLSpecGroupsTestc                 C   s    G dd„ dt ƒ}d|fd|fgS )Nc                   @   rP   )z8NamedURLSpecGroupsTest.get_handlers.<locals>.EchoHandlerc                 S   ó   |   |¡ d S r0   rU   r©   r7   r7   r8   rW     rX   z<NamedURLSpecGroupsTest.get_handlers.<locals>.EchoHandler.getNrY   r7   r7   r7   r8   rm    rZ   rm  z/str/(?P<path>.*)z/unicode/(?P<path>.*)r°   )r@   rm  r7   r7   r8   r<     s   þz#NamedURLSpecGroupsTest.get_handlersc                 C   s4   |   d¡}|  |jd¡ |   d¡}|  |jd¡ d S )Nz/str/foos   fooz/unicode/barrn   r  rÁ   r7   r7   r8   Útest_named_urlspec_groups#  s   

z0NamedURLSpecGroupsTest.test_named_urlspec_groupsN)rG   rH   rI   r<   rk  r7   r7   r7   r8   ri    s    
ri  c                   @   ó$   e Zd ZG dd„ deƒZdd„ ZdS )ÚClearHeaderTestc                   @   rP   )zClearHeaderTest.Handlerc                 C   s0   |   dd¡ |   dd¡ |  d¡ |  d¡ d S )NÚh1rm   Úh2râ   Únonexistent)r¸  Úclear_headerr?   r7   r7   r8   rW   -  s   
zClearHeaderTest.Handler.getNrY   r7   r7   r7   r8   rN   ,  rZ   rN   c                 C   s.   |   d¡}|  d|j¡ |  |jd d¡ d S )NrL   rn  ro  râ   ©r»   r(  r  rv   rÁ   r7   r7   r8   Útest_clear_header3  s   
z!ClearHeaderTest.test_clear_headerN)rG   rH   rI   r   rN   rs  r7   r7   r7   r8   rm  +  ó    rm  c                   @   rl  )ÚHeader204Testc                   @   rP   )zHeader204Test.Handlerc                 C   s   |   d¡ |  ¡  d S )NéÌ   )Ú
set_statusrž   r?   r7   r7   r8   rW   ;  rl  zHeader204Test.Handler.getNrY   r7   r7   r7   r8   rN   :  rZ   rN   c                 C   s8   |   d¡}|  |jd¡ |  d|j¡ |  d|j¡ d S )NrL   rv  r~  úTransfer-Encoding)r»   rv   r½   r(  r  rÁ   r7   r7   r8   Útest_204_headers?  ó   
zHeader204Test.test_204_headersN)rG   rH   rI   r   rN   ry  r7   r7   r7   r8   ru  9  ó    ru  c                   @   rl  )ÚHeader304Testc                   @   rP   )zHeader304Test.Handlerc                 C   s   |   dd¡ |  d¡ d S )NúContent-LanguageÚen_USrT   )r¸  rV   r?   r7   r7   r8   rW   H  s   zHeader304Test.Handler.getNrY   r7   r7   r7   r8   rN   G  rZ   rN   c                 C   s‚   |   d¡}|  |jd d¡ |  |jd d¡ | j dd|jd id�}|  |jd	¡ |  d|j¡ |  d|j¡ |  d
|j¡ d S )NrL   r~  Ú5r}  r~  rƒ  r„  r  r}  rx  )r»   rv   r  r½   r(  r  r7   r7   r8   Útest_304_headersL  s   
ÿzHeader304Test.test_304_headersN)rG   rH   rI   r   rN   r€  r7   r7   r7   r8   r|  F  r{  r|  c                   @   ó<   e Zd ZG dd„ deƒZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚStatusReasonTestc                   @   rP   )zStatusReasonTest.Handlerc                 C   s:   | j j dg ¡}tt|  d¡ƒ|rt|d ƒd�‚d d�‚)NÚreasonr½   r   ©rƒ  )rq  rr  rW   r    r”  r•  r   )r@   rƒ  r7   r7   r8   rW   ]  s   þþzStatusReasonTest.Handler.getNrY   r7   r7   r7   r8   rN   \  rZ   rN   c                 C   rë  r0   r   r?   r7   r7   r8   r.  d  ó   z StatusReasonTest.get_http_clientc                 C   sœ   |   d¡}|  |jd¡ |  |jd¡ |   d¡}|  |jd¡ |  |jd¡ |   d¡}|  |jd¡ |  |jd¡ |   d	¡}|  |jd¡ |  |jd
¡ d S )Nz
/?code=304r}  zNot Modifiedz/?code=304&reason=FooÚFooz/?code=682&reason=Baréª  ÚBarz
/?code=682ÚUnknown)r»   rv   r½   rƒ  rÁ   r7   r7   r8   Útest_statush  s   



zStatusReasonTest.test_statusc                 C   ó8   |   d¡}|  |jd¡ |  |jd¡ |  d|j¡ d S )Nz./?code=200&reason=OK%0D%0AX-Injection:injectedrµ   r‰  zX-Injection)r»   rv   r½   rƒ  r(  r  rÁ   r7   r7   r8   r  v  rz  z&StatusReasonTest.test_header_injectionc                 C   sF   |   d¡}|  |jd¡ |  |jd¡ |  d|j¡ |  d|j¡ d S )Nz+/?code=400&reason=<script>alert(1)</script>rÿ  r‰  s   scripts   Unknown)r»   rv   r½   rƒ  r(  rº   r  rÁ   r7   r7   r8   Útest_reason_xss|  s
   
z StatusReasonTest.test_reason_xssN)	rG   rH   rI   r   rN   r.  rŠ  r  rŒ  r7   r7   r7   r8   r‚  [  s    r‚  c                   @   rl  )ÚDateHeaderTestc                   @   rP   )zDateHeaderTest.Handlerc                 C   rR   rS   rU   r?   r7   r7   r8   rW   †  rX   zDateHeaderTest.Handler.getNrY   r7   r7   r7   r8   rN   …  rZ   rN   c                 C   sD   |   d¡}tj |jd ¡}|  |tj tjj	¡ tj
dd�¡ d S )NrL   ÚDater|   )Úseconds)r»   r3  r4  r5  r  r7  r.  r/  r0  r1  r2  )r@   rÂ   Úheader_dater7   r7   r8   Útest_date_header‰  s   

þzDateHeaderTest.test_date_headerN)rG   rH   rI   r   rN   r‘  r7   r7   r7   r8   r�  „  s    r�  c                   @   r�  )ÚRaiseWithReasonTestc                   @   rP   )zRaiseWithReasonTest.Handlerc                 C   s   t ddd�‚)Nr‡  r†  r„  ©r    r?   r7   r7   r8   rW   ”  rO   zRaiseWithReasonTest.Handler.getNrY   r7   r7   r7   r8   rN   “  rZ   rN   c                 C   rë  r0   r   r?   r7   r7   r8   r.  —  r…  z#RaiseWithReasonTest.get_http_clientc                 C   r‹  )NrL   r‡  r†  s   682: Foo)r»   rv   r½   rƒ  r  rº   rÁ   r7   r7   r8   Útest_raise_with_reason›  rz  z*RaiseWithReasonTest.test_raise_with_reasonc                 C   s   |   ttddd�ƒd¡ d S )Nr‡  r†  r„  zHTTP 682: Foo©rv   rÈ   r    r?   r7   r7   r8   Útest_httperror_str¡  r:   z&RaiseWithReasonTest.test_httperror_strc                 C   s   |   ttdƒƒd¡ d S )Nr‡  zHTTP 682: Unknownr•  r?   r7   r7   r8   Ú test_httperror_str_from_httputil¤  s   z4RaiseWithReasonTest.test_httperror_str_from_httputilN)	rG   rH   rI   r   rN   r.  r”  r–  r—  r7   r7   r7   r8   r’  ’  s    r’  c                   @   rX  )
ÚErrorHandlerXSRFTestc                 C   s   dt tdd�fgS )Nú/erroré¡  ©r8  )r"   rb   r?   r7   r7   r8   r<   ©  s   z!ErrorHandlerXSRFTest.get_handlersc                 C   r±   ©NT)Úxsrf_cookiesr³   r?   r7   r7   r8   r=   ¯  r´   z#ErrorHandlerXSRFTest.get_app_kwargsc                 C   ó"   | j dddd�}|  |jd¡ d S )Nr™  r¶   r#  r¸   rš  r  rÁ   r7   r7   r8   Útest_error_xsrf²  ó   z$ErrorHandlerXSRFTest.test_error_xsrfc                 C   rž  )Nz/404r¶   r#  r¸   r¾  r  rÁ   r7   r7   r8   Útest_404_xsrf¶  r   z"ErrorHandlerXSRFTest.test_404_xsrfN)rG   rH   rI   r<   r=   rŸ  r¡  r7   r7   r7   r8   r˜  ¨  s
    r˜  c                   @   sT   e Zd ZG dd„ deƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚGzipTestCasec                   @   rP   )zGzipTestCase.Handlerc                 C   s4   |   d¡D ]}|  d|¡ q|  ddtj  ¡ d S )NÚvaryr%  zhello worldú!)ru  r¹  rV   r.   Ú
MIN_LENGTH)r@   Úvr7   r7   r8   rW   ½  s   zGzipTestCase.Handler.getNrY   r7   r7   r7   r8   rN   ¼  rZ   rN   c                 C   s   t dtj tj t¡d¡d�S )NTrL  )r&  r_  )rb   r1   r2   r3   r4   r5   r?   r7   r7   r8   r=   Ã  s   ÿzGzipTestCase.get_app_kwargsc                 C   s"   |   |j d|j d¡¡d¡ d S )Nr'  zX-Consumed-Content-Encodingr&  )rv   r  rW   rÁ   r7   r7   r8   Úassert_compressedÈ  s   ÿüzGzipTestCase.assert_compressedc                 C   ó*   |   d¡}|  |¡ |  |jd d¡ d S )NrL   r%  r$  ©r»   r§  rv   r  rÁ   r7   r7   r8   Ú	test_gzipÒ  s   

zGzipTestCase.test_gzipc                 C   r¨  )Nra  r%  r$  r©  rÁ   r7   r7   r8   Útest_gzip_static×  s   

zGzipTestCase.test_gzip_staticc                 C   s2   | j ddd�}|  d|j¡ |  |jd d¡ d S )NrL   F)Úuse_gzipr'  r%  r$  rr  rÁ   r7   r7   r8   Útest_gzip_not_requestedÞ  r  z$GzipTestCase.test_gzip_not_requestedc                 C   s>   |   d¡}|  |¡ |  dd„ |jd  d¡D ƒddg¡ d S )Nz/?vary=Accept-Languagec                 S   ó   g | ]}|  ¡ ‘qS r7   ©Ústrip©rÊ  rg  r7   r7   r8   rË  ç  rÌ  z:GzipTestCase.test_vary_already_present.<locals>.<listcomp>r%  ú,úAccept-Languager$  ©r»   r§  rv   r  ÚsplitrÁ   r7   r7   r8   Útest_vary_already_presentã  s   

þz&GzipTestCase.test_vary_already_presentc                 C   s>   |   d¡}|  |¡ |  dd„ |jd  d¡D ƒg d¢¡ d S )Nz"/?vary=Accept-Language&vary=Cookiec                 S   r®  r7   r¯  r±  r7   r7   r8   rË  ð  rÌ  zCGzipTestCase.test_vary_already_present_multiple.<locals>.<listcomp>r%  r²  )r³  r  r$  r´  rÁ   r7   r7   r8   Ú"test_vary_already_present_multipleë  s   

þz/GzipTestCase.test_vary_already_present_multipleN)rG   rH   rI   r   rN   r=   r§  rª  r«  r­  r¶  r·  r7   r7   r7   r8   r¢  »  s    
r¢  c                   @   ó4   e Zd ZG dd„ deƒZdd„ Zdd„ Zdd„ Zd	S )
ÚPathArgsInPrepareTestc                   @   r+  )zPathArgsInPrepareTest.Handlerc                 C   s   |   t| j| jd�¡ d S )N©rp  r÷  )rV   rb   ro  Úpath_kwargsr?   r7   r7   r8   r™  ÷  s   z%PathArgsInPrepareTest.Handler.preparec                 C   s   |dksJ ‚|   ¡  d S )Nrm   ©rž   r©   r7   r7   r8   rW   ú  s   z!PathArgsInPrepareTest.Handler.getN©rG   rH   rI   r™  rW   r7   r7   r7   r8   rN   ö  r0  rN   c                 C   s   d| j fd| j fgS )Nz	/pos/(.*)z/kw/(?P<path>.*)rM   r?   r7   r7   r8   r<   þ  rù   z"PathArgsInPrepareTest.get_handlersc                 C   s4   |   d¡}| ¡  t|jƒ}|  |dgi dœ¡ d S )Nz/pos/foorm   rº  rû  ©r@   rÂ   r  r7   r7   r8   Útest_pos	  s   

zPathArgsInPrepareTest.test_posc                 C   s6   |   d¡}| ¡  t|jƒ}|  |g ddidœ¡ d S )Nz/kw/foor2   rm   rº  rû  r¾  r7   r7   r8   Útest_kw	  s   

zPathArgsInPrepareTest.test_kwN)rG   rH   rI   r   rN   r<   r¿  rÀ  r7   r7   r7   r8   r¹  õ  s
    r¹  c                   @   rl  )ÚClearAllCookiesTestc                   @   rP   )zClearAllCookiesTest.Handlerc                 C   s   |   ¡  |  d¡ d S ©NÚok)Úclear_all_cookiesrV   r?   r7   r7   r8   rW   	  s   zClearAllCookiesTest.Handler.getNrY   r7   r7   r7   r8   rN   	  rZ   rN   c                 C   sN   | j dddid�}t|j d¡ƒ}|  |d  d¡¡ |  |d  d	¡¡ d S )
NrL   r  zfoo=bar; baz=xyzzyr  r  r   zbaz="";ro   zfoo="";)r»   r  r  r  r¿   rt  )r@   rÂ   Úset_cookiesr7   r7   r8   Útest_clear_all_cookies	  s   z*ClearAllCookiesTest.test_clear_all_cookiesN)rG   rH   rI   r   rN   rÆ  r7   r7   r7   r8   rÁ  	  r{  rÁ  c                   @   ó   e Zd ZdS )ÚPermissionErrorN©rG   rH   rI   r7   r7   r7   r8   rÈ  	  ó    rÈ  c                   @   r¸  )
ÚExceptionHandlerTestc                   @   rj   )zExceptionHandlerTest.Handlerc                 C   sD   |   d¡}|dkrtddƒ‚|dkrdd  d S |dkr td	ƒ‚d S )
NÚexcrì   éš  zno longer hereÚzeroro   r   Ú
permissionznot allowed)r•  r    rÈ  )r@   rÌ  r7   r7   r8   rW   "	  s   

ÿz ExceptionHandlerTest.Handler.getc                 K   sP   d|v r|d \}}}t |tƒr|  d¡ |  d¡ d S tj| |fi |¤Ž d S )Nr6  rÂ  rÈ  )Ú
isinstancerÈ  rw  rV   r   r9  )r@   r8  r÷  Útyprg   Útbr7   r7   r8   r9  +	  s   


z(ExceptionHandlerTest.Handler.write_errorc                 C   s4   t |tƒrt d|jd ¡ d S t | |||¡ d S )Nz&custom logging for PermissionError: %sr   )rÐ  rÈ  r   Úwarningrp  r   Úlog_exception©r@   rÑ  rg   rÒ  r7   r7   r8   rÔ  4	  s   
z*ExceptionHandlerTest.Handler.log_exceptionN)rG   rH   rI   rW   r9  rÔ  r7   r7   r7   r8   rN   !	  s    		rN   c                 C   óH   t tdƒ� |  d¡}|  |jd¡ W d   ƒ d S 1 sw   Y  d S )Nz.*no longer herez
/?exc=httprÍ  r   rÁ   r7   r7   r8   Útest_http_error:	  ó   
"þz$ExceptionHandlerTest.test_http_errorc                 C   rÖ  )NrE  z
/?exc=zerorF  ©r   r   r»   rv   r½   rÁ   r7   r7   r8   Útest_unknown_errorA	  s   
"þz'ExceptionHandlerTest.test_unknown_errorc                 C   rÖ  )Nz/custom logging for PermissionError: not allowedz/?exc=permissionrÂ  rÙ  rÁ   r7   r7   r8   Útest_known_errorG	  rØ  z%ExceptionHandlerTest.test_known_errorN)rG   rH   rI   r   rN   r×  rÚ  rÛ  r7   r7   r7   r8   rË   	  s
    rË  c                   @   rl  )ÚBuggyLoggingTestc                   @   r+  )zBuggyLoggingTest.Handlerc                 C   r<  r=  r7   r?   r7   r7   r8   rW   Q	  rO   zBuggyLoggingTest.Handler.getc                 C   r<  r=  r7   rÕ  r7   r7   r8   rÔ  T	  rO   z&BuggyLoggingTest.Handler.log_exceptionN)rG   rH   rI   rW   rÔ  r7   r7   r7   r8   rN   P	  r0  rN   c                 C   r„  )Nz.*rL   )r   r   r»   r?   r7   r7   r8   Útest_buggy_log_exceptionW	  r†  z)BuggyLoggingTest.test_buggy_log_exceptionN)rG   rH   rI   r   rN   rÝ  r7   r7   r7   r8   rÜ  O	  rt  rÜ  c                       s@   e Zd ZdZG dd„ deƒZdd„ Z‡ fdd„Zdd	„ Z‡  Z	S )
ÚUIMethodUIModuleTestz`Test that UI methods and modules are created correctly and
    associated with the handler.
    c                   @   r+  )zUIMethodUIModuleTest.Handlerc                 C   rR   r«   r­  r?   r7   r7   r8   rW   d	  rX   z UIMethodUIModuleTest.Handler.getc                 C   s
   |   d¡S )Nrg   )r•  r?   r7   r7   r8   rg   g	  r´   z"UIMethodUIModuleTest.Handler.valueN)rG   rH   rI   rW   rg   r7   r7   r7   r8   rN   c	  r0  rN   c                 C   s:   dd„ }G dd„ dt ƒ}tddiƒ}t|d|id|id�S )	Nc                 S   s   d|› d|   ¡ › d�S )NzIn my_ui_method(z) with handler value r7  )rg   )ry   Úxr7   r7   r8   Úmy_ui_methodk	  r²  z9UIMethodUIModuleTest.get_app_kwargs.<locals>.my_ui_methodc                   @   rP   )z5UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModulec                 S   s   d  |t tj| j¡ ¡ ¡S )Nz&In MyModule({}) with handler value {}.)r:  ÚtypingÚcastrÞ  rN   ry   rg   )r@   rß  r7   r7   r8   r¬   o	  s   þz<UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModule.renderN©rG   rH   rI   r¬   r7   r7   r7   r8   ÚMyModulen	  rZ   rä  r§   z1{{ my_ui_method(42) }} {% module MyModule(123) %}rà  )rÝ  Ú
ui_methodsÚ
ui_modules©r)   r   rb   )r@   rà  rä  rà  r7   r7   r8   r=   j	  s   ÿýz#UIMethodUIModuleTest.get_app_kwargsc                    rá  r0   râ  r?   rç  r7   r8   rä  ~	  s   
zUIMethodUIModuleTest.tearDownc                 C   r  )Nz/?value=asdfsV   In my_ui_method(42) with handler value asdf. In MyModule(123) with handler value asdf.r  rÁ   r7   r7   r8   Útest_ui_methodƒ	  r	  z#UIMethodUIModuleTest.test_ui_method)
rG   rH   rI   rJ   r   rN   r=   rä  rè  r*  r7   r7   rç  r8   rÞ  ^	  s    rÞ  c                   @   rl  )ÚGetArgumentErrorTestc                   @   rP   )zGetArgumentErrorTest.Handlerc              
   C   sV   z|   d¡ |  i ¡ W d S  ty* } z|  |j|jdœ¡ W Y d }~d S d }~ww )Nrm   ©Úarg_nameÚlog_message)r•  rV   r!   rë  rì  rÈ  r7   r7   r8   rW   Ž	  s   
"€ÿz GetArgumentErrorTest.Handler.getNrY   r7   r7   r7   r8   rN   �	  rZ   rN   c                 C   s&   |   d¡}|  t|jƒdddœ¡ d S )NrL   rm   zMissing argument foorê  )r»   rv   r   rº   rÁ   r7   r7   r8   Útest_catch_error•	  s
   
þz%GetArgumentErrorTest.test_catch_errorN)rG   rH   rI   r   rN   rí  r7   r7   r7   r8   ré  Œ	  ó    ré  c                   @   rl  )ÚSetLazyPropertiesTestc                   @   rX  )
zSetLazyPropertiesTest.Handlerc                 C   s   d| _ t d¡| _d S )NÚBenr~  )Úcurrent_userr   rW   r?   r7   r7   r8   r™  Ÿ	  s   z%SetLazyPropertiesTest.Handler.preparec                 C   rB   r0   rC   r?   r7   r7   r8   Úget_user_locale£	  rE   z-SetLazyPropertiesTest.Handler.get_user_localec                 C   rB   r0   rC   r?   r7   r7   r8   Úget_current_user¦	  rE   z.SetLazyPropertiesTest.Handler.get_current_userc                 C   s"   |   d| j› d| jj› d�¡ d S )NzHello z (ú))rV   rñ  r   r½   r?   r7   r7   r8   rW   ©	  s   "z!SetLazyPropertiesTest.Handler.getN)rG   rH   rI   r™  rò  ró  rW   r7   r7   r7   r8   rN   ž	  s
    rN   c                 C   r  )NrL   s   Hello Ben (en_US)r  rÁ   r7   r7   r8   Útest_set_properties¬	  ó   
z)SetLazyPropertiesTest.test_set_propertiesN)rG   rH   rI   r   rN   rõ  r7   r7   r7   r8   rï  �	  ó    rï  c                       sV   e Zd Zdd„ Z‡ fdd„Zdd„ Ze d¡dd	„ ƒZd
d„ Z	dd„ Z
dd„ Z‡  ZS )ÚGetCurrentUserTestc                 C   sD   G dd„ dt ƒ}G dd„ dt ƒ}tddddd	œƒ}t|||d
œd�S )Nc                   @   rP   )z<GetCurrentUserTest.get_app_kwargs.<locals>.WithoutUserModulec                 S   rL  )Nr#  r7   r?   r7   r7   r8   r¬   ¶	  rF   zCGetCurrentUserTest.get_app_kwargs.<locals>.WithoutUserModule.renderNrã  r7   r7   r7   r8   ÚWithoutUserModuleµ	  rZ   rù  c                   @   rP   )z9GetCurrentUserTest.get_app_kwargs.<locals>.WithUserModulec                 S   s
   t | jƒS r0   )rÈ   rñ  r?   r7   r7   r8   r¬   º	  r´   z@GetCurrentUserTest.get_app_kwargs.<locals>.WithUserModule.renderNrã  r7   r7   r7   r8   ÚWithUserModule¹	  rZ   rú  r#  z{{ current_user }}z {% module WithoutUserModule() %}z{% module WithUserModule() %})úwithout_user.htmlúwith_user.htmlúwithout_user_module.htmlúwith_user_module.html)rú  rù  )rÝ  ræ  rç  )r@   rù  rú  rà  r7   r7   r8   r=   ´	  s   üÿþþz!GetCurrentUserTest.get_app_kwargsc                    rá  r0   râ  r?   rç  r7   r8   rä  Í	  rj  zGetCurrentUserTest.tearDownc                 C   s|   G dd„ dt ƒ}G dd„ d|ƒ}G dd„ d|ƒ}G dd„ d|ƒ}G d	d
„ d
|ƒ}G dd„ d|ƒ}d|fd|fd|fd|fgS )Nc                   @   r+  )z;GetCurrentUserTest.get_handlers.<locals>.CurrentUserHandlerc                 S   s
   d| _ d S )NF©Úhas_loaded_current_userr?   r7   r7   r8   r™  Ó	  r´   zCGetCurrentUserTest.get_handlers.<locals>.CurrentUserHandler.preparec                 S   s
   d| _ dS )NTr#  rÿ  r?   r7   r7   r8   ró  Ö	  s   zLGetCurrentUserTest.get_handlers.<locals>.CurrentUserHandler.get_current_userN)rG   rH   rI   r™  ró  r7   r7   r7   r8   ÚCurrentUserHandlerÒ	  r0  r  c                   @   rP   )z;GetCurrentUserTest.get_handlers.<locals>.WithoutUserHandlerc                 S   ó   |   d¡ |  t| jƒ¡ d S )Nrû  ©Úrender_stringrž   rÈ   r   r?   r7   r7   r8   rW   Û	  ó   
z?GetCurrentUserTest.get_handlers.<locals>.WithoutUserHandler.getNrY   r7   r7   r7   r8   ÚWithoutUserHandlerÚ	  rZ   r  c                   @   rP   )z8GetCurrentUserTest.get_handlers.<locals>.WithUserHandlerc                 S   r  )Nrü  r  r?   r7   r7   r8   rW   à	  r  z<GetCurrentUserTest.get_handlers.<locals>.WithUserHandler.getNrY   r7   r7   r7   r8   ÚWithUserHandlerß	  rZ   r  c                   @   rP   )zAGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandlerc                 S   rD  r0   )Úuir?   r7   r7   r8   Úget_template_namespaceå	  s   zXGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandler.get_template_namespaceN)rG   rH   rI   r	  r7   r7   r7   r8   ÚCurrentUserModuleHandlerä	  rZ   r
  c                   @   rP   )zAGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandlerc                 S   r  )Nrý  r  r?   r7   r7   r8   rW   ì	  r  zEGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandler.getNrY   r7   r7   r7   r8   ÚWithoutUserModuleHandlerë	  rZ   r  c                   @   rP   )z>GetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandlerc                 S   r  )Nrþ  r  r?   r7   r7   r8   rW   ñ	  r  zBGetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandler.getNrY   r7   r7   r7   r8   ÚWithUserModuleHandlerð	  rZ   r  ú/without_userú
/with_userú/without_user_moduleú/with_user_moduler°   )r@   r  r  r  r
  r  r  r7   r7   r8   r<   Ñ	  s   üzGetCurrentUserTest.get_handlersz	needs fixc                 C   r  )Nr  ó   Falser  rÁ   r7   r7   r8   Útest_get_current_user_is_lazyü	  rö  z0GetCurrentUserTest.test_get_current_user_is_lazyc                 C   r  )Nr  ó   Truer  rÁ   r7   r7   r8   Útest_get_current_user_works
  r  z.GetCurrentUserTest.test_get_current_user_worksc                 C   r  )Nr  r  r  rÁ   r7   r7   r8   Ú,test_get_current_user_from_ui_module_is_lazy
  r  z?GetCurrentUserTest.test_get_current_user_from_ui_module_is_lazyc                 C   r  )Nr  r  r  rÁ   r7   r7   r8   Ú*test_get_current_user_from_ui_module_works

  r  z=GetCurrentUserTest.test_get_current_user_from_ui_module_works)rG   rH   rI   r=   rä  r<   rÊ  Úskipr  r  r  r  r*  r7   r7   rç  r8   rø  ³	  s    +
rø  c                   @   rl  )ÚUnimplementedHTTPMethodsTestc                   @   rÇ  )z$UnimplementedHTTPMethodsTest.HandlerNrÉ  r7   r7   r7   r8   rN   
  rÊ  rN   c                 C   sR   dD ]}| j d|d�}|  |jd¡ qdD ]}| j d|dd�}|  |jd¡ qd S )N)rp  rq  ÚDELETEÚOPTIONSrL   r¸  é•  ©r¶   ÚPUTr·   r¸   r  )r@   r¹   rÂ   r7   r7   r8   Ú#test_unimplemented_standard_methods
  s   þz@UnimplementedHTTPMethodsTest.test_unimplemented_standard_methodsN)rG   rH   rI   r   rN   r  r7   r7   r7   r8   r  
  s    r  c                   @   rT  )Ú#UnimplementedNonStandardMethodsTestc                   @   rP   )z+UnimplementedNonStandardMethodsTest.Handlerc                 C   rR   ©NrÜ  rU   r?   r7   r7   r8   rÜ  
  rH  z1UnimplementedNonStandardMethodsTest.Handler.otherN)rG   rH   rI   rÜ  r7   r7   r7   r8   rN   
  rZ   rN   c                 C   rž  )NrL   ÚPATCHr·   r¸   r  r  rÁ   r7   r7   r8   Útest_unimplemented_patch#
  s   z<UnimplementedNonStandardMethodsTest.test_unimplemented_patchc                 C   rž  )NrL   ÚOTHERT©r¹   Úallow_nonstandard_methodsr  r  rÁ   r7   r7   r8   Útest_unimplemented_other)
  r   z<UnimplementedNonStandardMethodsTest.test_unimplemented_otherN)rG   rH   rI   r   rN   r"  r&  r7   r7   r7   r8   r  
  s    r  c                   @   rl  )ÚAllHTTPMethodsTestc                   @   s(   e Zd Zdd„ Ze Z Z Z ZZdS )zAllHTTPMethodsTest.Handlerc                 C   s"   | j jd usJ ‚|  | j j¡ d S r0   )rq  r¹   rV   r?   r7   r7   r8   r¹   0
  r   z!AllHTTPMethodsTest.Handler.methodN)	rG   rH   rI   r¹   rW   ÚdeleteÚoptionsr¤   Úputr7   r7   r7   r8   rN   /
  s    rN   c                 C   sv   | j ddd�}|  |jd¡ dD ]}| j d|d�}|  |jt|ƒ¡ qdD ]}| j d|dd�}|  |jt|ƒ¡ q%d S )NrL   rp  r¸  r·   )rq  r  r  r  r¸   )r»   rv   rº   r   )r@   rÂ   r¹   r7   r7   r8   Útest_standard_methods6
  s   þz(AllHTTPMethodsTest.test_standard_methodsN)rG   rH   rI   r   rN   r+  r7   r7   r7   r8   r'  .
  rt  r'  c                   @   rT  )ÚPatchMethodTestc                   @   s&   e Zd Zejd Zdd„ Zdd„ ZdS )zPatchMethodTest.Handler)r#  c                 C   rR   )NÚpatchrU   r?   r7   r7   r8   r-  G
  rX   zPatchMethodTest.Handler.patchc                 C   rR   r   rU   r?   r7   r7   r8   rÜ  J
  rX   zPatchMethodTest.Handler.otherN)rG   rH   rI   r   ÚSUPPORTED_METHODSr-  rÜ  r7   r7   r7   r8   rN   B
  s    
rN   c                 C   rž  )NrL   r!  r·   r¸   s   patchr  rÁ   r7   r7   r8   Ú
test_patchM
  r   zPatchMethodTest.test_patchc                 C   rž  )NrL   r#  Tr$  rÿ  r  rÁ   r7   r7   r8   Ú
test_otherQ
  r   zPatchMethodTest.test_otherN)rG   rH   rI   r   rN   r/  r0  r7   r7   r7   r8   r,  A
  s    r,  c                   @   rl  )ÚFinishInPrepareTestc                   @   r+  )zFinishInPrepareTest.Handlerc                 C   rR   )NrÀ   r¼  r?   r7   r7   r8   r™  X
  rX   z#FinishInPrepareTest.Handler.preparec                 C   r>  )Nzshould not reach this methodr?  r?   r7   r7   r8   rW   [
  s   zFinishInPrepareTest.Handler.getNr½  r7   r7   r7   r8   rN   W
  r0  rN   c                 C   r  )NrL   s   doner  rÁ   r7   r7   r8   Útest_finish_in_preparea
  r  z*FinishInPrepareTest.test_finish_in_prepareN)rG   rH   rI   r   rN   r2  r7   r7   r7   r8   r1  V
  ó    
r1  c                   @   r+  )ÚDefault404Testc                 C   r-  ©NrÔ   r°   r?   r7   r7   r8   r<   g
  s   
zDefault404Test.get_handlersc                 C   rì  )NrL   r¾  sE   <html><title>404: Not Found</title><body>404: Not Found</body></html>rî  rÁ   r7   r7   r8   Útest_404k
  s   
þzDefault404Test.test_404N)rG   rH   rI   r<   r6  r7   r7   r7   r8   r4  f
  s    r4  c                   @   rj   )ÚCustom404Testc                 C   r-  r5  r°   r?   r7   r7   r8   r<   v
  r´   zCustom404Test.get_handlersc                 C   s   G dd„ dt ƒ}t|d�S )Nc                   @   rP   )z6Custom404Test.get_app_kwargs.<locals>.Custom404Handlerc                 S   s   |   d¡ |  d¡ d S )Nr¾  zcustom 404 response)rw  rV   r?   r7   r7   r8   rW   {
  rj  z:Custom404Test.get_app_kwargs.<locals>.Custom404Handler.getNrY   r7   r7   r7   r8   ÚCustom404Handlerz
  rZ   r8  )Údefault_handler_class)r   rb   )r@   r8  r7   r7   r8   r=   y
  s   
zCustom404Test.get_app_kwargsc                 C   rì  )NrL   r¾  s   custom 404 responserî  rÁ   r7   r7   r8   r6  �
  rð  zCustom404Test.test_404N)rG   rH   rI   r<   r=   r6  r7   r7   r7   r8   r7  u
  s    r7  c                   @   rj   )ÚDefaultHandlerArgumentsTestc                 C   r-  r5  r°   r?   r7   r7   r8   r<   ˆ
  r´   z(DefaultHandlerArgumentsTest.get_handlersc                 C   s   t tt dd�d�S )NrÂ  r›  )r9  Údefault_handler_args)rb   r"   r?   r7   r7   r8   r=   ‹
  s   þz*DefaultHandlerArgumentsTest.get_app_kwargsc                 C   r  )NrL   rÂ  r  rÁ   r7   r7   r8   Útest_403‘
  r  z$DefaultHandlerArgumentsTest.test_403N)rG   rH   rI   r<   r=   r<  r7   r7   r7   r8   r:  ‡
  s    r:  c                   @   r+  )ÚHandlerByNameTestc                 C   s   dt fdtddƒgS )Nú/hello1)ú/hello2ú"tornado.test.web_test.HelloHandlerú/hello3r@  )rQ   r$   r?   r7   r7   r8   r<   —
  s   ýzHandlerByNameTest.get_handlersc                 C   sL   |   d¡}|  |jd¡ |   d¡}|  |jd¡ |   d¡}|  |jd¡ d S )Nr>  r  r?  rA  r  ©r@   Úrespr7   r7   r8   Útest_handler_by_nameŸ
  s   


z&HandlerByNameTest.test_handler_by_nameN)rG   rH   rI   r<   rD  r7   r7   r7   r8   r=  –
  s    r=  c                   @   sL   e Zd Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	dS )ÚStreamingRequestBodyTestc                 C   sb   t G dd„ dtƒƒ}t G dd„ dtƒƒ}t G dd„ dtƒƒ}d|t| d�fd	|fd
|t| d�fgS )Nc                   @   rX  )
zCStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandlerc                 S   r@  r0   r    rS  r7   r7   r8   rC  ¬
  r´   zNStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.initializec                 S   s   | j j d ¡ d S r0   )r¡   ÚpreparedÚ
set_resultr?   r7   r7   r8   r™  ¯
  r®  zKStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.preparec                 S   s   | j j |¡ d S r0   )r¡   r  rG  ©r@   r  r7   r7   r8   Údata_received²
  r®  zQStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.data_receivedc                 S   s   | j j d ¡ |  i ¡ d S r0   )r¡   ÚfinishedrG  rV   r?   r7   r7   r8   rW   µ
  s   zGStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.getN)rG   rH   rI   rC  r™  rI  rW   r7   r7   r7   r8   ÚStreamingBodyHandlerª
  s
    rK  c                   @   rP   )zAStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandlerc                 S   r>  )Né‘  r“  r?   r7   r7   r8   r™  »
  s   zIStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandler.prepareNrÖ  r7   r7   r7   r8   ÚEarlyReturnHandler¹
  rÞ   rM  c                       s$   e Zd Zdd„ Z‡ fdd„Z‡  ZS )zDStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandlerc                 S   r@  r0   r    rS  r7   r7   r8   rC  Â
  r´   zOStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.initializec                    s   t ƒ  ¡  | jj d ¡ d S r0   )rã  rW  r¡   Úclose_futurerG  r?   rç  r7   r8   rW  Å
  r  zXStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.on_connection_close)rG   rH   rI   rC  rW  r*  r7   r7   rç  r8   ÚCloseDetectionHandlerÀ
  s    rO  z/stream_bodyr    z/early_returnz/close_detection)r+   r   rb   )r@   rK  rM  rO  r7   r7   r8   r<   ©
  s   	ýz%StreamingRequestBodyTest.get_handlersc                 C   sZ   t   t jt jd¡}| d|  ¡ f¡ t|ƒ}| d| d ¡ |r&| d¡ | d¡ |S )Nr   rZ  s   GET s    HTTP/1.1
Host: 127.0.0.1
s   Connection: close
s   Transfer-Encoding: chunked

)r^  r_  r`  ra  rb  r   rV   )r@   r$   Úconnection_closerg  rc  r7   r7   r8   ra  Ï
  s   

z StreamingRequestBodyTest.connectc                 c   s¬   � t ƒ | _t ƒ | _t ƒ | _| jddd�}| jV  | d¡ | jV }|  |d¡ t ƒ | _| d¡ | jV }|  |d¡ | d¡ | jV  | ¡ V }|  | 	d	¡¡ | 
¡  d S )
Ns   /stream_bodyT©rP  ó	   4
asdf
s   asdfs	   4
qwer
s   qwers   0

s   {})r   rF  r  rJ  ra  rV   rv   Úread_until_closer¿   r*  ri  ©r@   rc  r  r7   r7   r8   Útest_streaming_bodyÚ
  s$   €



z,StreamingRequestBodyTest.test_streaming_bodyc                 c   s.   � | j ddd�}| ¡ V }|  | d¡¡ d S )Nó   /early_returnFrQ  ó   HTTP/1.1 401)ra  rS  r¿   rt  rT  r7   r7   r8   Útest_early_returnñ
  s   €
z*StreamingRequestBodyTest.test_early_returnc                 c   s8   � | j ddd�}| d¡ | ¡ V }|  | d¡¡ d S )NrV  FrQ  rR  rW  )ra  rV   rS  r¿   rt  rT  r7   r7   r8   Útest_early_return_with_data÷
  s
   €

z4StreamingRequestBodyTest.test_early_return_with_datac                 c   s,   � t ƒ | _| jddd�}| ¡  | jV  d S )Ns   /close_detectionFrQ  )r   rN  ra  ri  )r@   rc  r7   r7   r8   Útest_close_during_uploadþ
  s
   €z1StreamingRequestBodyTest.test_close_during_uploadN)
rG   rH   rI   r<   ra  r   rU  rX  rY  rZ  r7   r7   r7   r8   rE  ¨
  s    &


rE  c                   @   s>   e Zd Zdd„ Zejdd„ ƒZejdd„ ƒZ	ejdd„ ƒZ
d	S )
ÚBaseFlowControlHandlerc                 C   s   || _ d | _g | _d S r0   )r¡   r¹   ÚmethodsrS  r7   r7   r8   rC    s   
z!BaseFlowControlHandler.initializec                 c   sT   � | j d ur| j d|› d| j › �¡ || _ | j |¡ z	d V  W d | _ d S d | _ w )Nzentered method z
 while in )r¹   r¡   Úfailr\  rÎ  rÕ  r7   r7   r8   Ú	in_method  s   €
z BaseFlowControlHandler.in_methodc                 c   s   � | j  d¡ tjV  d S )Nr™  )r\  rÎ  r   Úmomentr?   r7   r7   r8   r™    s   €zBaseFlowControlHandler.preparec                 c   sJ   � |   d¡� tjV  W d   ƒ n1 sw   Y  |  t| jd�¡ d S )Nr¤   ©r\  )r^  r   r_  rV   rb   r\  r?   r7   r7   r8   r¤   #  s
   €
ÿzBaseFlowControlHandler.postN)rG   rH   rI   rC  Ú
contextlibÚcontextmanagerr^  r   r¥   r™  r¤   r7   r7   r7   r8   r[  
  s    


r[  c                   @   sL   e Zd Zdd„ Zdd„ Zdejfdd„Zdejfdd	„Zdejfd
d„Z	dS )Ú#BaseStreamingRequestFlowControlTestc                 C   s   t ddd�S )Nr÷   T)Ú
chunk_sizeÚdecompress_requestr³   r?   r7   r7   r8   Úget_httpserver_options+  s   z:BaseStreamingRequestFlowControlTest.get_httpserver_optionsc                 C   rë  r0   r   r?   r7   r7   r8   r.  0  r…  z3BaseStreamingRequestFlowControlTest.get_http_clientr@   c                 C   s8   | j dddd�}| ¡  |  t|jƒtg d¢d�¡ d S )NrL   Úabcdefghijklmnopqrstuvwxyzr¶   )rº   r¹   ©r™  rI  rI  rI  r¤   r`  )r»   rö  rv   r   rº   rb   rÁ   r7   r7   r8   Útest_flow_control_fixed_body5  s   ÿþz@BaseStreamingRequestFlowControlTest.test_flow_control_fixed_bodyc                    sR   g d¢‰ t j‡ fdd„ƒ}| jd|dd�}| ¡  |  t|jƒtg d¢d�¡ d S )	N)s   abcds   efghs   ijklc                 3   s   � ˆ D ]}| |ƒV  qd S r0   r7   )rV   Úi©Úchunksr7   r8   Úbody_producerH  s   €ÿzYBaseStreamingRequestFlowControlTest.test_flow_control_chunked_body.<locals>.body_producerrL   r¶   )rm  r¹   rh  r`  )r   r¥   r»   rö  rv   r   rº   rb   )r@   rm  rÂ   r7   rk  r8   Útest_flow_control_chunked_bodyE  s   ÿþzBBaseStreamingRequestFlowControlTest.test_flow_control_chunked_bodyc                 C   sl   t ƒ }tjd|d�}| d¡ | ¡  | ¡ }| jd|dddid�}| ¡  |  t	|j
ƒtg d	¢d
�¡ d S )NrÏ  )ÚmodeÚfileobjs   abcdefghijklmnopqrstuvwxyzrL   r¶   r'  r&  )rº   r¹   r  rh  r`  )r/   r&  ÚGzipFilerV   ri  Úgetvaluer»   rö  rv   r   rº   rb   )r@   ÚbytesioÚ	gzip_fileÚcompressed_bodyrÂ   r7   r7   r8   Ú!test_flow_control_compressed_body\  s$   
üÿþzEBaseStreamingRequestFlowControlTest.test_flow_control_compressed_bodyN)
rG   rH   rI   rf  r.  rá  ÚAnyri  rn  rv  r7   r7   r7   r8   rc  *  s    rc  c                   @   rP   )Ú(DecoratedStreamingRequestFlowControlTestc                 C   ó"   G dd„ dt ƒ}d|t| d�fgS )Nc                   @   r½  )zZDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandlerc                 s   s:   � |   d¡� tjV  W d   ƒ d S 1 sw   Y  d S )NrI  )r^  r   r_  rH  r7   r7   r8   rI  |  s   €
"ÿzhDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandler.data_receivedN)rG   rH   rI   r   r¥   rI  r7   r7   r7   r8   ÚDecoratedFlowControlHandler{  rÁ  rz  rL   r    ©r[  rb   )r@   rz  r7   r7   r8   r<   z  s   z5DecoratedStreamingRequestFlowControlTest.get_handlersN©rG   rH   rI   r<   r7   r7   r7   r8   rx  w  ó    rx  c                   @   rP   )Ú%NativeStreamingRequestFlowControlTestc                 C   ry  )Nc                   @   rP   )zTNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandlerc                 Ó   sJ   �|   d¡� dd l}| d¡I d H  W d   ƒ d S 1 sw   Y  d S )NrI  r   )r^  Úasyncior\  )r@   r  r  r7   r7   r8   rI  ‰  s
   €"ýzbNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandler.data_receivedN)rG   rH   rI   rI  r7   r7   r7   r8   ÚNativeFlowControlHandlerˆ  rZ   r€  rL   r    r{  )r@   r€  r7   r7   r8   r<   ‡  s   z2NativeStreamingRequestFlowControlTest.get_handlersNr|  r7   r7   r7   r8   r~  „  r}  r~  c                   @   rj   )ÚIncorrectContentLengthTestc                    sB   | ‰ d | _ G ‡ fdd„dtƒ}G ‡ fdd„dtƒ}d|fd|fgS )Nc                       ó   e Zd Z‡ fdd„ZdS )z8IncorrectContentLengthTest.get_handlers.<locals>.TooHighc              
      ó>   |   dd¡ z|  d¡ W d S  ty } z|ˆ _‚ d }~ww )Nr~  rM  rÃ  ©r¸  rž   rt  Úserver_errorrÈ  r    r7   r8   rW   ™  ó   €þz<IncorrectContentLengthTest.get_handlers.<locals>.TooHigh.getNrY   r7   r    r7   r8   ÚTooHigh˜  ó    r‡  c                       r‚  )z7IncorrectContentLengthTest.get_handlers.<locals>.TooLowc              
      rƒ  )Nr~  r  rT   r„  rÈ  r    r7   r8   rW   ¢  r†  z;IncorrectContentLengthTest.get_handlers.<locals>.TooLow.getNrY   r7   r    r7   r8   ÚTooLow¡  rˆ  r‰  ú/highú/low)r…  r   )r@   r‡  r‰  r7   r    r8   r<   “  s
   		z'IncorrectContentLengthTest.get_handlersc              
   C   ó¢   t tdƒ�9 t tdƒ�$ |  t¡� | jddd� W d   ƒ n1 s#w   Y  W d   ƒ n1 s2w   Y  W d   ƒ n1 sAw   Y  |  t| jƒd¡ d S )Nú*(Uncaught exception|Exception in callback)úS(Cannot send error response after headers written|Failed to flush partial response)rŠ  T©Úraise_errorz0Tried to write 40 bytes less than Content-Length©	r   r   r   ÚassertRaisesr
   r»   rv   rÈ   r…  r?   r7   r7   r8   Útest_content_length_too_high¬  ó   þÿ€û€ÿ
ÿz7IncorrectContentLengthTest.test_content_length_too_highc              
   C   rŒ  )Nr�  rŽ  r‹  Tr�  z,Tried to write more data than Content-Lengthr‘  r?   r7   r7   r8   Útest_content_length_too_low¼  r”  z6IncorrectContentLengthTest.test_content_length_too_lowN)rG   rH   rI   r<   r“  r•  r7   r7   r7   r8   r�  ’  s    r�  c                   @   rl  )ÚClientCloseTestc                   @   rP   )zClientCloseTest.Handlerc                 C   s8   | j j d¡r| j jj ¡  |  d¡ d S |  d¡ d S )NzHTTP/1rT   úrequires HTTP/1.x)rq  rq   rt  Ú
connectionrc  ri  rV   r?   r7   r7   r8   rW   Ï  s   zClientCloseTest.Handler.getNrY   r7   r7   r7   r8   rN   Î  rZ   rN   c                 C   sf   |   ttjf¡�! | jddd�}|jdkr|  d¡ |  |jd¡ W d   ƒ d S 1 s,w   Y  d S )NrL   Tr�  s   requires HTTP/1.xr—  iW  )	r’  r
   rÊ  ÚSkipTestr»   rº   ÚskipTestrv   r½   rÁ   r7   r7   r8   Útest_client_closeÜ  s   

"üz!ClientCloseTest.test_client_closeN)rG   rH   rI   r   rN   r›  r7   r7   r7   r8   r–  Í  r÷  r–  c                   @   s|   e Zd ZdZddddœZdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSignedValueTestzIt's a secret to everybodyÚ	asdfbasdfÚ12312312Ú2342342)r   ro   r|   c                 C   s   |   ¡ d S )Ni 0* )Úpresentr?   r7   r7   r8   Úpastè  rO   zSignedValueTest.pastc                 C   rL  )Ni m|Mr7   r?   r7   r7   r8   r   ë  rF   zSignedValueTest.presentc                 C   s¬   t tjddd| jd�}|  |d¡ t tjddd| jd�}|  |d¡ t tjdd| jd�}|  ||¡ ttjd|d| jd	�}|  |d
¡ ttjd|d| jd	�}|  |d
¡ d S )Nrv  rg   ro   )rq   Úclocks<   dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4fr|   se   2|1:0|10:1300000000|3:key|8:dmFsdWU=|3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152©r¢  )rs   r¢  ó   value)r&   rœ  ÚSECRETr   rv   r'   )r@   Ú	signed_v1Ú	signed_v2Úsigned_defaultÚ
decoded_v1Ú
decoded_v2r7   r7   r8   Útest_known_valuesî  s2   ÿÿÿþÿÿÿz!SignedValueTest.test_known_valuesc                 C   sh   t tjdd| jd�}t tjdd| jd�}ttjd|| jd�}|  |¡ ttjd|| jd�}|  |¡ d S )NÚkey1rg   r£  Úkey2)r&   rœ  r¥  r   r'   r†   )r@   Úsigned1Úsigned2Údecoded1Údecoded2r7   r7   r8   Útest_name_swap  s   ÿÿÿ
ÿzSignedValueTest.test_name_swapc                 C   sV   t tjdd| jd�}ttjd|| jd�}|  |d¡ ttjd|| jd�}|  |¡ d S )Nr¬  rg   r£  r¤  )r&   rœ  r¥  r¡  r'   rv   r   r†   )r@   ÚsignedÚdecoded_pastÚdecoded_presentr7   r7   r8   Útest_expired  s   ÿÿÿzSignedValueTest.test_expiredc                    sN   d‰‡ ‡fdd„}ˆ   |dƒ¡ ˆ  |dƒ¡ ˆ  |dƒ¡ ˆ  |dƒ¡ d S )NÚ@3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152c                    s   dt tjd| ˆ ˆ jd�kS ©Nr¤  rv  r£  ©r'   rœ  r¥  r   )Úprefix©r@   r‰   r7   r8   Úvalidate0  ó   ÿz8SignedValueTest.test_payload_tampering.<locals>.validateú%2|1:0|10:1300000000|3:key|8:dmFsdWU=|z%2|1:1|10:1300000000|3:key|8:dmFsdWU=|z$2|1:0|10:130000000|3:key|8:dmFsdWU=|z&2|1:0|10:1300000000|3:keey|8:dmFsdWU=|©r¿   ÚassertFalse©r@   r¼  r7   r»  r8   Útest_payload_tampering,  s   z&SignedValueTest.test_payload_tamperingc                    sj   d‰ ‡ ‡fdd„}ˆ  |dƒ¡ ˆ |dƒ¡ ˆ |dƒ¡ ˆ |dƒ¡ ˆ |dƒ¡ ˆ |d	ƒ¡ d S )
Nr¾  c                    s   dt tjdˆ |  ˆjd�kS r¸  r¹  )r‰   ©rº  r@   r7   r8   r¼  @  r½  z:SignedValueTest.test_signature_tampering.<locals>.validater·  Ú 00000000000000000000000000000000Ú@4d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152Ú@3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e153Ú?3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e15ÚA3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e1538r¿  rÁ  r7   rÃ  r8   Útest_signature_tampering=  s(   ÿÿÿÿÿÿz(SignedValueTest.test_signature_tamperingc                 C   s<   d}t tjd|| jd�}ttjd|| jd�}|  ||¡ d S )Nr‹   rv  r£  )r&   rœ  r¥  r   r'   rv   ©r@   rg   r³  Údecodedr7   r7   r8   Útest_non_ascii]  s   ÿÿzSignedValueTest.test_non_asciic                 C   ó>   d}t tjd|| jdd�}ttjd|| jd�}|  ||¡ d S ©Nr‹   rv  r   ©r¢  r`   r£  ©r&   rœ  ÚSECRET_DICTr   r'   rv   rÊ  r7   r7   r8   Ú*test_key_versioning_read_write_default_keyg  ó   ÿÿz:SignedValueTest.test_key_versioning_read_write_default_keyc                 C   rÍ  )Nr‹   rv  ro   rÏ  r£  rÐ  rÊ  r7   r7   r8   Ú.test_key_versioning_read_write_non_default_keyq  rÓ  z>SignedValueTest.test_key_versioning_read_write_non_default_keyc                 C   sN   d}t tjd|| jdd�}tj ¡ }| d¡ t|d|| jd�}|  |¡ d S rÎ  )r&   rœ  rÑ  r   r™   rš   r'   r†   )r@   rg   r³  ÚnewkeysrË  r7   r7   r8   Útest_key_versioning_invalid_key{  s   ÿ

z/SignedValueTest.test_key_versioning_invalid_keyc                 C   s2   d}t tjd|| jdd�}t|ƒ}|  d|¡ d S )Nr‹   rv  ro   rÏ  )r&   rœ  rÑ  r   r(   rv   )r@   rg   r³  r`   r7   r7   r8   Útest_key_version_retrieval…  s   ÿz*SignedValueTest.test_key_version_retrievalN)rG   rH   rI   r¥  rÑ  r¡  r   r«  r²  r¶  rÂ  rÉ  rÌ  rÒ  rÔ  rÖ  r×  r7   r7   r7   r8   rœ  ä  s      



rœ  c                       s¸   e Zd ZG dd„ deƒZdd„ Z‡ fdd„Zd(dd	„Zd)d
d„Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Z‡  ZS )*ÚXSRFTestc                   @   r+  )zXSRFTest.Handlerc                 C   s*   t |  dd¡ƒ}|| jd< |  | j¡ d S )Nrq   r  Úxsrf_cookie_version)r”  r•  r^   rV   rŒ  )r@   rq   r7   r7   r8   rW   �  s   
zXSRFTest.Handler.getc                 C   rR   rÂ  rU   r?   r7   r7   r8   r¤   —  rX   zXSRFTest.Handler.postN©rG   rH   rI   rW   r¤   r7   r7   r7   r8   rN   �  s    rN   c                 C   r±   rœ  r³   r?   r7   r7   r8   r=   š  r´   zXSRFTest.get_app_kwargsc                    ó   t ƒ  ¡  |  ¡ | _d S r0   ©rã  rè  Ú	get_tokenrŒ  r?   rç  r7   r8   rè  �  rj  zXSRFTest.setUpNc                 C   sH   |d ur
|   |¡}nd }| j|d u rdnd| |d�}| ¡  t|jƒS )NrL   z/?version=%dr  ©Úcookie_headersr»   rö  r   rº   )r@   Ú	old_tokenrq   r  rÂ   r7   r7   r8   rÝ  ¡  s   ÿ
zXSRFTest.get_tokenc                 C   ó   |d u r| j }dd| iS )Nr  z_xsrf=©rŒ  ©r@   Útokenr7   r7   r8   rß  ¬  ó   zXSRFTest.cookie_headersc                 C   óL   t tdƒ� | jdddd�}W d   ƒ n1 sw   Y  |  |jd¡ d S ©Nú.*'_xsrf' argument missingrL   r¶   r·   r¸   rÂ  r   rÁ   r7   r7   r8   Útest_xsrf_fail_no_token±  ó   ÿz XSRFTest.test_xsrf_fail_no_tokenc              	   C   ó\   t tdƒ� | jddtj t| jd�¡d�}W d   ƒ n1 s w   Y  |  |j	d¡ d S ©Nú!.*XSRF cookie does not match POSTrL   r¶   ©Ú_xsrfr¸   rÂ  ©
r   r   r»   r  r  r  rb   rŒ  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_fail_body_no_cookie¶  ó   ýÿz&XSRFTest.test_xsrf_fail_body_no_cookiec              
   C   s`   t tdƒ� | jdd|  ¡ tj tdd�¡d�}W d   ƒ n1 s"w   Y  |  |j	d¡ d S )Nz%.*'_xsrf' argument has invalid formatrL   r¶   ú3|rî  rø  rÂ  )
r   r   r»   rß  r  r  r  rb   rv   r½   rÁ   r7   r7   r8   Ú&test_xsrf_fail_argument_invalid_format¿  s   üÿz/XSRFTest.test_xsrf_fail_argument_invalid_formatc              
   C   sf   t tdƒ� | jdd| jdd�tj t| jd�¡d�}W d   ƒ n1 s%w   Y  |  	|j
d¡ d S )	Nrí  rL   r¶   ró  ©rä  rî  rø  rÂ  )r   r   r»   rß  r  r  r  rb   rŒ  rv   r½   rÁ   r7   r7   r8   Ú$test_xsrf_fail_cookie_invalid_formatÉ  s   
üÿz-XSRFTest.test_xsrf_fail_cookie_invalid_formatc                 C   sR   t tdƒ� | jddd|  ¡ d�}W d   ƒ n1 sw   Y  |  |jd¡ d S )Nrè  rL   r¶   r·   ©r¹   rº   r  rÂ  )r   r   r»   rß  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_fail_cookie_no_bodyÓ  s   ÿÿz&XSRFTest.test_xsrf_fail_cookie_no_bodyc                 C   ó:   | j ddtj tdd�¡| jdd�d�}|  |jd¡ d S )NrL   r¶   Údeadbeefrî  rõ  r÷  rµ   ©r»   r  r  r  rb   rß  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_short_tokenÚ  ó   
üz&XSRFTest.test_xsrf_success_short_tokenc                 C   rù  )NrL   r¶   Úxoxorî  rõ  r÷  rµ   rû  rÁ   r7   r7   r8   Útest_xsrf_success_non_hex_tokenã  rý  z(XSRFTest.test_xsrf_success_non_hex_tokenc                 C   ó8   | j ddtj t| jd�¡|  ¡ d�}|  |jd¡ d S ©NrL   r¶   rî  r÷  rµ   ©	r»   r  r  r  rb   rŒ  rß  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_post_bodyì  s   üz$XSRFTest.test_xsrf_success_post_bodyc                 C   s<   | j dtj t| jd�¡ dd|  ¡ d�}|  |jd¡ d S )Nz/?rî  r¶   r·   r÷  rµ   r  rÁ   r7   r7   r8   Útest_xsrf_success_query_stringõ  s   üz'XSRFTest.test_xsrf_success_query_stringc              	   C   s:   | j dddtd| jifi |  ¡ ¤Žd�}|  |jd¡ d S )NrL   r¶   r·   zX-Xsrftokenr÷  rµ   )r»   rb   rŒ  rß  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_headerþ  s   ÿþü	z!XSRFTest.test_xsrf_success_headerc                 C   s:   d}t ƒ }t|ƒD ]	}| |  ¡ ¡ q	|  t|ƒ|¡ d S )Nr÷   )rd  rë   ru  rÝ  rv   r  )r@   Ú
NUM_TOKENSÚtokensrj  r7   r7   r8   Útest_distinct_tokens
  s
   zXSRFTest.test_distinct_tokensc              
   C   sÌ   |   ¡ }| j|fD ]}| jddtj t|d�¡|  |¡d�}|  |j	d¡ q	| j|f|| jffD ]3\}}t
tdƒ� | jddtj t|d�¡|  |¡d�}W d   ƒ n1 sWw   Y  |  |j	d¡ q0d S )NrL   r¶   rî  r÷  rµ   rí  rÂ  )rÝ  rŒ  r»   r  r  r  rb   rß  rv   r½   r   r   )r@   Útoken2rä  rÂ   Úcookie_tokenÚ
body_tokenr7   r7   r8   Útest_cross_user  s,   üþüÿõzXSRFTest.test_cross_userc              	   C   sx   | j }|h}tdƒD ]'}|  |¡}| |¡ | jddtj t| j d�¡|  	|¡d�}|  
|jd¡ q
|  
t|ƒd¡ d S )Né   rL   r¶   rî  r÷  rµ   é   )rŒ  rë   rÝ  ru  r»   r  r  r  rb   rß  rv   r½   r  )r@   rä  Útokens_seenrj  rÂ   r7   r7   r8   Útest_refresh_token+  s   

üzXSRFTest.test_refresh_tokenc              	   C   sÆ   |   | jdd�| jdd�¡ | jdd�}tdƒD ]}|  | j|dd�|¡ q|  |¡}|   ||¡ |   ||  |¡¡ ||f||ffD ]\}}| jddtj t|d�¡|  	|¡d�}|  |j
d¡ qBd S )	Nro   rp   r  rL   r¶   rî  r÷  rµ   )ÚassertNotEqualrÝ  rë   rv   r»   r  r  r  rb   rß  r½   )r@   Úv1_tokenrj  Úv2_tokenr
  r  rÂ   r7   r7   r8   Útest_versioning?  s    
üùzXSRFTest.test_versioningrO  r0   )rG   rH   rI   r   rN   r=   rè  rÝ  rß  ré  rñ  rô  rö  rø  rü  rÿ  r  r  r  r  r  r  r  r*  r7   r7   rç  r8   rØ  Ž  s(    

	

				rØ  c                       s`   e Zd ZG dd„ deƒZdd„ Z‡ fdd„Zddd	„Zdd
d„Zdd„ Z	dd„ Z
dd„ Z‡  ZS )ÚXSRFCookieNameTestc                   @   r+  )zXSRFCookieNameTest.Handlerc                 C   rW  r0   ©rV   rŒ  r?   r7   r7   r8   rW   \  r{  zXSRFCookieNameTest.Handler.getc                 C   rR   rÂ  rU   r?   r7   r7   r8   r¤   _  rX   zXSRFCookieNameTest.Handler.postNrÚ  r7   r7   r7   r8   rN   [  r0  rN   c                 C   s   t ddddid�S )NTz__Host-xsrfrý   )r�  Úxsrf_cookie_nameÚxsrf_cookie_kwargsr³   r?   r7   r7   r8   r=   b  s
   ýz!XSRFCookieNameTest.get_app_kwargsc                    rÛ  r0   rÜ  r?   rç  r7   r8   rè  i  rj  zXSRFCookieNameTest.setUpNc                 C   s8   |d ur
|   |¡}nd }| jd|d�}| ¡  t|jƒS )NrL   r  rÞ  )r@   rà  r  rÂ   r7   r7   r8   rÝ  m  s   
zXSRFCookieNameTest.get_tokenc                 C   rá  )Nr  z__Host-xsrf=râ  rã  r7   r7   r8   rß  v  rå  z!XSRFCookieNameTest.cookie_headersc                 C   ræ  rç  r   rÁ   r7   r7   r8   ré  {  rê  z*XSRFCookieNameTest.test_xsrf_fail_no_tokenc              	   C   rë  rì  rð  rÁ   r7   r7   r8   rñ  €  rò  z0XSRFCookieNameTest.test_xsrf_fail_body_no_cookiec                 C   r   r  r  rÁ   r7   r7   r8   r  ‰  s   ûz.XSRFCookieNameTest.test_xsrf_success_post_bodyr0   )rG   rH   rI   r   rN   r=   rè  rÝ  rß  ré  rñ  r  r*  r7   r7   rç  r8   r  Z  s    

		r  c                   @   rT  )ÚXSRFCookieKwargsTestc                   @   rP   )zXSRFCookieKwargsTest.Handlerc                 C   rW  r0   r  r?   r7   r7   r8   rW   –  r{  z XSRFCookieKwargsTest.Handler.getNrY   r7   r7   r7   r8   rN   •  rZ   rN   c                 C   s   t dt ddd�d�S )NTr|   )rþ   rh   )r�  r  r³   r?   r7   r7   r8   r=   ™  s   ÿz#XSRFCookieKwargsTest.get_app_kwargsc                 C   sÎ   |   d¡}|  d|jd  ¡ ¡ |  d|jd  ¡ ¡ |j d¡}|d us'J ‚t d|¡}|d us3J ‚tj tj	j
¡tjdd� }tj | ¡ d ¡}|jd u rX|jtj	j
d	�}|  t||  ¡ ƒd
k ¡ d S )NrL   z	httponly;r  zexpires=z.*; expires=(?P<expires>.+);.*r|   r+  r-  )Útzinfor÷   )r»   r  r  ÚlowerrW   r‚   rƒ   r.  r/  r0  r1  r2  r3  r4  r5  r6  r  Úreplacer¿   r8  r9  r:  r7   r7   r8   Útest_xsrf_httponlyž  s   
ÿ
z'XSRFCookieKwargsTest.test_xsrf_httponlyN)rG   rH   rI   r   rN   r=   r  r7   r7   r7   r8   r  ”  s    r  c                   @   rl  )ÚFinishExceptionTestc                   @   rP   )zFinishExceptionTest.Handlerc                 C   s:   |   d¡ |  dd¡ |  dd¡rtdƒ‚|  d¡ tƒ ‚)NrL  úWWW-AuthenticateúBasic realm="something"Úfinish_valuer#  zauthentication required)rw  r¸  r•  r*   rV   r?   r7   r7   r8   rW   ²  s   

zFinishExceptionTest.Handler.getNrY   r7   r7   r7   r8   rN   ±  rZ   rN   c                 C   sH   dD ]}|   |¡}|  |jd¡ |  d|j d¡¡ |  d|j¡ qd S )N)rL   z/?finish_value=1rL  r   r  s   authentication required)r»   rv   r½   r  rW   rº   )r@   ÚurÂ   r7   r7   r8   Útest_finish_exception»  s   
ÿúz)FinishExceptionTest.test_finish_exceptionN)rG   rH   rI   r   rN   r#  r7   r7   r7   r8   r  °  r3  r  c                   @   rj   )ÚDecoratorTestc                 C   s0   G dd„ dt ƒ}G dd„ dt ƒ}d|fd|fgS )Nc                   @   ó   e Zd Zedd„ ƒZdS )z6DecoratorTest.get_handlers.<locals>.RemoveSlashHandlerc                 S   rJ  r0   r7   r?   r7   r7   r8   rW   È  rN  z:DecoratorTest.get_handlers.<locals>.RemoveSlashHandler.getN)rG   rH   rI   r,   rW   r7   r7   r7   r8   ÚRemoveSlashHandlerÇ  ó    r&  c                   @   r%  )z3DecoratorTest.get_handlers.<locals>.AddSlashHandlerc                 S   rJ  r0   r7   r?   r7   r7   r8   rW   Í  rN  z7DecoratorTest.get_handlers.<locals>.AddSlashHandler.getN)rG   rH   rI   r-   rW   r7   r7   r7   r8   ÚAddSlashHandlerÌ  r'  r(  ú/removeslash/ú	/addslashr°   )r@   r&  r(  r7   r7   r8   r<   Æ  s   zDecoratorTest.get_handlersc                 C   ó`   | j ddd�}|  |jd¡ |  |jd d¡ | j ddd�}|  |jd¡ |  |jd d¡ d S )	Nr)  FrL  r  rO  z/removeslashz/removeslash/?foo=barz/removeslash?foo=barr  rÁ   r7   r7   r8   Útest_removeslashÓ  ó   zDecoratorTest.test_removeslashc                 C   r+  )	Nr*  FrL  r  rO  z
/addslash/z/addslash?foo=barz/addslash/?foo=barr  rÁ   r7   r7   r8   Útest_addslashÜ  r-  zDecoratorTest.test_addslashN)rG   rH   rI   r<   r,  r.  r7   r7   r7   r8   r$  Å  s    	r$  c                   @   rÅ   )Ú	CacheTestc                 C   s   G dd„ dt ƒ}d|fgS )Nc                   @   r+  )z+CacheTest.get_handlers.<locals>.EtagHandlerc                 S   rj  r0   rU   )r@   Úcomputed_etagr7   r7   r8   rW   é  rX   z/CacheTest.get_handlers.<locals>.EtagHandler.getc                 S   s
   | j d S r[  )Ú_write_bufferr?   r7   r7   r8   Úcompute_etagì  r´   z8CacheTest.get_handlers.<locals>.EtagHandler.compute_etagN)rG   rH   rI   rW   r2  r7   r7   r7   r8   ÚEtagHandlerè  r0  r3  z
/etag/(.*)r°   )r@   r3  r7   r7   r8   r<   ç  s   
zCacheTest.get_handlersc                 C   ó   d}d}|   ||d¡ d S )Nú"xyzzy"Ú*r}  ©Ú
_test_etag©r@   r0  Úetagsr7   r7   r8   Útest_wildcard_etagñ  ó   zCacheTest.test_wildcard_etagc                 C   s   d}d}|   ||d¡ d S )Nr5  r}  r7  r9  r7   r7   r8   Útest_strong_etag_matchö  r<  z CacheTest.test_strong_etag_matchc                 C   r4  )Nú"xyzzy1"ú"xyzzy1", "xyzzy2"r}  r7  r9  r7   r7   r8   Útest_multiple_strong_etag_matchû  r<  z)CacheTest.test_multiple_strong_etag_matchc                 C   r4  )Nr5  r>  rµ   r7  r9  r7   r7   r8   Útest_strong_etag_not_match   r<  z$CacheTest.test_strong_etag_not_matchc                 C   r4  )Nr5  r?  rµ   r7  r9  r7   r7   r8   Ú#test_multiple_strong_etag_not_match  r<  z-CacheTest.test_multiple_strong_etag_not_matchc                 C   r4  )Nr>  ú
W/"xyzzy1"r}  r7  r9  r7   r7   r8   Útest_weak_etag_match
  r<  zCacheTest.test_weak_etag_matchc                 C   r4  )Nú"xyzzy2"úW/"xyzzy1", W/"xyzzy2"r}  r7  r9  r7   r7   r8   Útest_multiple_weak_etag_match  r<  z'CacheTest.test_multiple_weak_etag_matchc                 C   r4  )NrE  rC  rµ   r7  r9  r7   r7   r8   Útest_weak_etag_not_match  r<  z"CacheTest.test_weak_etag_not_matchc                 C   r4  )Nz"xyzzy3"rF  rµ   r7  r9  r7   r7   r8   Ú!test_multiple_weak_etag_not_match  r<  z+CacheTest.test_multiple_weak_etag_not_matchc                 C   s(   | j d| d|id�}|  |j|¡ d S )Nz/etag/rƒ  r  r  )r@   r0  r:  r8  rÂ   r7   r7   r8   r8    s   ÿzCacheTest._test_etagN)rG   rH   rI   r<   r;  r=  r@  rA  rB  rD  rG  rH  rI  r8  r7   r7   r7   r8   r/  æ  s    
r/  c                   @   rl  )ÚRequestSummaryTestc                   @   rP   )zRequestSummaryTest.Handlerc                 C   s   d | j _|  |  ¡ ¡ d S r0   )rq  Ú	remote_iprž   r˜  r?   r7   r7   r8   rW   '  s   zRequestSummaryTest.Handler.getNrY   r7   r7   r7   r8   rN   &  rZ   rN   c                 C   r  )NrL   s   GET / (None)r  rB  r7   r7   r8   Útest_missing_remote_ip.  r  z)RequestSummaryTest.test_missing_remote_ipN)rG   rH   rI   r   rN   rL  r7   r7   r7   r8   rJ  %  rî  rJ  c                   @   rP   )ÚHTTPErrorTestc                 C   sF   t ddd�}t |¡}|  ||¡ |  |j|j¡ |  |j|j¡ d S )NrÂ  zGo awayr„  )r    r™   ÚassertIsNotrv   r8  rƒ  )r@   rð   Úe2r7   r7   r8   Ú	test_copy4  s
   
zHTTPErrorTest.test_copyN)rG   rH   rI   rP  r7   r7   r7   r8   rM  3  rZ   rM  c                   @   rP   )ÚApplicationTestc                 C   s"   t g ƒ}|jddd�}| ¡  d S )Nr   rZ  )Úaddress)r   Úlistenrk  )r@   r>   Úserverr7   r7   r8   Útest_listen=  s   zApplicationTest.test_listenN)rG   rH   rI   rU  r7   r7   r7   r8   rQ  <  rZ   rQ  c                   @   rj   )ÚURLSpecReverseTestc                 C   s0   |   dtdd ƒ ¡ ¡ |   dtdd ƒ ¡ ¡ d S )Nz/favicon.icoz/favicon\.icoz^/favicon\.ico$©rv   r$   Úreverser?   r7   r7   r8   Útest_reverseD  r  zURLSpecReverseTest.test_reversec              	   C   sN   dg}|D ]}t |d ƒ}z| ¡ }|  d||f ¡ W q ty$   Y qw d S )Nz^/api/v\d+/foo/(\w+)$z<did not get expected exception when reversing %s. result: %s)r$   rX  r]  rÇ  )r@   Úpathsr2   Úurl_specr\  r7   r7   r8   Útest_non_reversibleH  s   
ÿÿÿ÷z&URLSpecReverseTest.test_non_reversiblec                 C   s4   |   dtdd ƒ d¡¡ |   dtdd ƒ d¡¡ d S )Nz/api/v1/foo/barz^/api/v1/foo/(\w+)$râ   z/api.v1/foo/5/icon.pngz/api\.v1/foo/([0-9]+)/icon\.pngr  rW  r?   r7   r7   r8   Útest_reverse_argumentsZ  s   ÿþz)URLSpecReverseTest.test_reverse_argumentsN)rG   rH   rI   rY  r\  r]  r7   r7   r7   r8   rV  C  s    rV  c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚRedirectHandlerTestc                 C   s(   dt ddifdt ddifdt ddifgS )Nú/srcr$   ú/dstz/src2z/dst2?foo=barz/(.*?)/(.*?)/(.*)z/{1}/{0}/{2})rô  r?   r7   r7   r8   r<   e  s   ýz RedirectHandlerTest.get_handlersc                 C   r  )Nr_  FrL  r  rO  r`  r  rÁ   r7   r7   r8   Útest_basic_redirectl  r  z'RedirectHandlerTest.test_basic_redirectc                 C   r  )Nz/src?foo=barFrL  r  rO  z/dst?foo=barr  rÁ   r7   r7   r8   Útest_redirect_with_argumentq  r  z/RedirectHandlerTest.test_redirect_with_argumentc                 C   r  )Nz/src2?foo2=bar2FrL  r  rO  z/dst2?foo=bar&foo2=bar2r  rÁ   r7   r7   r8   Ú%test_redirect_with_appending_argumentv  r  z9RedirectHandlerTest.test_redirect_with_appending_argumentc                 C   r  )Nz/a/b/cFrL  r  rO  z/b/a/cr  rÁ   r7   r7   r8   Útest_redirect_pattern{  r  z)RedirectHandlerTest.test_redirect_patternN)rG   rH   rI   r<   ra  rb  rc  rd  r7   r7   r7   r8   r^  d  s    r^  c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚAcceptLanguageTestz)Test evaluation of Accept-Language headerc                 C   s8   t  tj tj t¡d¡d¡ G dd„ dtƒ}d|fgS )NÚgettext_translationsÚtornado_testc                   @   rP   )z>AcceptLanguageTest.get_handlers.<locals>.AcceptLanguageHandlerc                 S   s(   |   d|  ¡ j dd¡¡ |  d¡ d S )Nr}  Ú_ú-r·   )r¸  Úget_browser_localer½   r  rž   r?   r7   r7   r8   rW   ‹  s   ÿzBAcceptLanguageTest.get_handlers.<locals>.AcceptLanguageHandler.getNrY   r7   r7   r7   r8   ÚAcceptLanguageHandlerŠ  rZ   rk  rL   )r   Úload_gettext_translationsr1   r2   r3   r4   r5   r   )r@   rk  r7   r7   r8   r<   „  s   þÿzAcceptLanguageTest.get_handlersc                 C   sL   | j dddid�}|  |jd d¡ | j dddid�}|  |jd d¡ d S )NrL   r³  zfr-FR;q=0.9r  r}  zfr-FRzfr-FR; q=0.9©r»   rv   r  rÁ   r7   r7   r8   Útest_accept_language•  s   z'AcceptLanguageTest.test_accept_languagec                 C   ó(   | j dddid�}|  |jd d¡ d S )NrL   r³  z	fr-FR;q=0r  r}  úen-USrm  rÁ   r7   r7   r8   Útest_accept_language_ignoreœ  ó   z.AcceptLanguageTest.test_accept_language_ignorec                 C   ro  )NrL   r³  z
fr-FR;q=-1r  r}  rp  rm  rÁ   r7   r7   r8   Útest_accept_language_invalid   rr  z/AcceptLanguageTest.test_accept_language_invalidN)rG   rH   rI   rJ   r<   rn  rq  rs  r7   r7   r7   r8   re  �  s    re  )ªrì   Útornado.concurrentr   Útornador   Útornado.escaper   r   r   r   r   r	   Útornado.httpclientr
   Útornado.httputilr   Útornado.iostreamr   r   Útornado.locksr   Útornado.logr   r   Útornado.simple_httpclientr   Útornado.templater   Útornado.testingr   r   r   r   Útornado.test.utilr   Útornado.utilr   r   Útornado.webr   r   r   r   rô  r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r€   ra  r™   r.  Úemail.utilsr3  r&  Úior/   rr  r  r1   r‚   rã  r^  rß  rá  rÊ  Úurllib.parser  r9   r;   rK   rQ   r[   ÚTestCaserk   r�   r�   rÆ   r?  rI  rR  rY  rm  rz  r‡  r¢  rª  r¯  r³  r´  r¾  rÂ  rÉ  rÑ  r×  rÛ  r,  r1  rK  rË  re   rÌ  r  r  r  r!  r,  r4  r6  rU  rf  ri  rm  ru  r|  r‚  r�  r’  r˜  r¢  r¹  rÁ  rt  rÈ  rË  rÜ  rÞ  ré  rï  rø  r  r  r'  r,  r1  r4  r7  r:  r=  rE  r[  rc  rx  r~  r�  r–  rœ  rØ  r  r  r  r$  r/  rJ  rM  rQ  rV  r^  re  r7   r7   r7   r8   Ú<module>   s    T6/1 l0,
  	B  s 4 @%C*"):/.\b
Mÿ
ÿ; + M:!?	!