o
    	³hyÞ ã                   @   sì  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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 d dl:Z:d dl;Z;d dl<Z<d dl=Z=d dl>Z?d dl@Z@d dlAmBZB d dlCZCd dlDZDd dlEZEd dlFZFd dlGZGd dlHZHd dlIZId dlJZKdd„ ZLG dd„ deƒZMG dd„ deMƒZNG dd„ de'ƒZOG dd„ de'ƒZPG dd„ deIjQƒZRG dd„ deIjQƒZSG d d!„ d!eMƒZTG d"d#„ d#eMƒZUG d$d%„ d%e'ƒZVG d&d'„ d'eMƒZWG d(d)„ d)e'ƒZXG d*d+„ d+eMƒZYG d,d-„ d-e'ƒZZG d.d/„ d/eMƒZ[G d0d1„ d1e'ƒZ\G d2d3„ d3e'ƒZ]G d4d5„ d5e'ƒZ^G d6d7„ d7e'ƒZ_G d8d9„ d9e'ƒZ`G d:d;„ d;e'ƒZaG d<d=„ d=e'ƒZ)G d>d?„ d?e'ƒZbG d@dA„ dAe'ƒZcG dBdC„ dCe'ƒZdG dDdE„ dEe'ƒZeG dFdG„ dGe'ƒZfG dHdI„ dIeMƒZgG dJdK„ dKeMƒZhG dLdM„ dMeMƒZiG dNdO„ dOeMƒZjG dPdQ„ dQeMƒZkG dRdS„ dSeMƒZlG dTdU„ dUeMƒZmG dVdW„ dWeMƒZnG dXdY„ dYeMƒZoG dZd[„ d[eMƒZpG d\d]„ d]eMƒZqG d^d_„ d_eNƒZrG d`da„ daeNƒZsG dbdc„ dceNƒZtG ddde„ deeNƒZuG dfdg„ dgeNƒZvG dhdi„ dieNƒZwG djdk„ dkeMƒZxG dldm„ dmeNƒZyG dndo„ doeMƒZzG dpdq„ dqeNƒZ{G drds„ dse|ƒZ}G dtdu„ dueNƒZ~G dvdw„ dweNƒZG dxdy„ dyeNƒZ€G dzd{„ d{eNƒZG d|d}„ d}eNƒZ‚G d~d„ deMƒZƒG d€d„ deNƒZ„G d‚dƒ„ dƒeNƒZ…G d„d…„ d…eNƒZ†G d†d‡„ d‡eNƒZ‡G dˆd‰„ d‰eNƒZˆG dŠd‹„ d‹eMƒZ‰G dŒd„ deMƒZŠG dŽd„ deMƒZ‹G dd‘„ d‘eMƒZŒG d’d“„ d“eMƒZe6G d”d•„ d•e'ƒƒZŽG d–d—„ d—ƒZG d˜d™„ d™eeMƒZG dšd›„ d›eeMƒZ‘G dœd„ deNƒZ’G dždŸ„ dŸeNƒZ“G d d¡„ d¡eIjQƒZ”G d¢d£„ d£eNƒZ•G d¤d¥„ d¥eNƒZ–G d¦d§„ d§eNƒZ—G d¨d©„ d©eNƒZ˜G dªd«„ d«eMƒZ™G d¬d­„ d­eMƒZšG d®d¯„ d¯eNƒZ›G d°d±„ d±eIjQƒZœG d²d³„ d³eƒZG d´dµ„ dµeIjQƒZžG d¶d·„ d·eMƒZŸG d¸d¹„ d¹eMƒZ dS )ºé    )Ú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ÚGZipContentEncodingN)ÚBytesIOc                  G   s   t jjt j t¡g| ¢R Ž S ©N)ÚosÚpathÚjoinÚdirnameÚ__file__)Úa© r7   úR/var/www/html/mmpi2/mmpi_env/lib/python3.10/site-packages/tornado/test/web_test.pyÚrelpath=   ó   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_appH   s   zWebTestCase.get_appc                 C   ó   t ƒ ‚r0   ©ÚNotImplementedErrorr?   r7   r7   r8   r<   L   ó   zWebTestCase.get_handlersc                 C   s   i S r0   r7   r?   r7   r7   r8   r=   O   ó   zWebTestCase.get_app_kwargsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rA   r<   r=   r7   r7   r7   r8   r;   A   s
    r;   c                   @   s   e Zd ZdZdZdd„ ZdS )ÚSimpleHandlerTestCasezSimplified 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   S   s    rK   c                   @   ó   e Zd Zdd„ ZdS )ÚHelloHandlerc                 C   ó   |   d¡ d S ©NÚhello©Úwriter?   r7   r7   r8   Úget`   ó   zHelloHandler.getN©rG   rH   rI   rW   r7   r7   r7   r8   rQ   _   ó    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__f   s   ÿ
ÿz!CookieTestRequestHandler.__init__c                 C   s   | j  |¡S r0   )ra   rW   )r@   Únamer7   r7   r8   Ú
get_cookier   rO   z#CookieTestRequestHandler.get_cookiec                 C   s   || j |< d S r0   )ra   )r@   re   ÚvalueÚexpires_daysr7   r7   r8   Ú
set_cookieu   rX   z#CookieTestRequestHandler.set_cookie)r\   Nr0   )rG   rH   rI   rd   rf   ri   r7   r7   r7   r8   r[   d   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   z   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                   @   s\   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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 ƒ}	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&  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.com)rÔ   ÚcÚdÚerÌ   r?   r7   r7   r8   rW   -  s   z>CookieTest.get_handlers.<locals>.SetCookieOverwriteHandler.getNrY   r7   r7   r7   r8   ÚSetCookieOverwriteHandler,  rZ   rá   c                   @   rP   )z7CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandlerc                 S   ó   | j dddd d S )Nrm   Úbaré
   )Úmax_agerÌ   r?   r7   r7   r8   rW   5  ó   z;CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandler.getNrY   r7   r7   r7   r8   ÚSetCookieMaxAgeHandler4  rZ   rç   c                   @   rP   )z<CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandlerc                 S   râ   )Nrm   rã   rä   )rh   rÌ   r?   r7   r7   r8   rW   9  ræ   z@CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandler.getNrY   r7   r7   r7   r8   ÚSetCookieExpiresDaysHandler8  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   D  s   z<CookieTest.get_handlers.<locals>.SetCookieDeprecatedArgs.getNrY   r7   r7   r7   r8   ÚSetCookieDeprecatedArgsC  rZ   rï   ú/setú/getú/set_domainú/special_charú/set_overwriteú/set_max_ageú/set_expires_daysú/set_falsy_flagsú/set_deprecatedr°   )
r@   rÍ   rÏ   rÕ   rÜ   rá   rç   rè   rì   rï   r7   r7   r8   r<     s&   ÷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_cookieT  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_domaine  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_charl  s    
ýýz#CookieTest.test_cookie_special_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&  r7   r7   r7   r8   rÅ     s    C
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@   r*  r7   r7   r8   Ú
initialize±  r´   z%AuthRedirectRequestHandler.initializec                 C   ó   | j S r0   r)  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   r+  r-  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/loginr)  ú	/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 )Nr2  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 )Nr3  Fr4  r6  zIhttp://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2Fabsoluter7  )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<   r8  r9  r7   r7   r7   r8   r1  ½  s    
r1  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   r+  Ú  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   r?  â  rX   z*ConnectionCloseHandler.on_connection_closeN)rG   rH   rI   r+  r   r¥   rW   r?  r7   r7   r7   r8   r:  Ù  s
    
r:  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   r=  r:  rb   r?   r7   r7   r8   r<   ç  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>ó  s   
 z;ConnectionCloseTest.test_connection_close.<locals>.<lambda>)ÚsocketÚAF_INETÚSOCK_STREAMÚconnectÚget_http_portr   ÚstreamrV   r>  r=  Ú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
  rK  Úcloser?   r7   r7   r8   r<  õ  ó   
z&ConnectionCloseTest.on_handler_waitingc                 C   s   t  d¡ |  ¡  d S )Nzconnection closed)r	  r
  Ústopr?   r7   r7   r8   r?  ù  ó   
z'ConnectionCloseTest.on_connection_closeN)rG   rH   rI   r<   rP  r<  r?  r7   r7   r7   r8   rA  æ  s
    
rA  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@   rW  ÚkeyÚbvalueÚsvalueÚargr7   r7   r8   rW   ÿ  s.   ÿÿÿÿ
ýÿzEchoHandler.getNrY   r7   r7   r7   r8   rU  þ  rZ   rU  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/([^/]*)/([^/]*))rU  r?   r7   r7   r8   r<     ó   z RequestEncodingTest.get_handlersc                 C   s   t |  |¡jƒS r0   )r   r»   rº   r©   r7   r7   r8   Ú
fetch_json  rc  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ú?rV  z/group/%3F?%3F=%3F©rv   rd  rb   r?   r7   r7   r8   Útest_group_question_mark   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õ   Ã©ra  rV  ©rv   rd  r?   r7   r7   r8   Útest_group_encoding+  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ã   rV  z/slashes/a%2Fb/c%2Fdza/bzc/drf  r?   r7   r7   r8   Útest_slashes6  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_errorB  ó   "ÿzRequestEncodingTest.test_errorN)	rG   rH   rI   r<   rd  rg  rj  rk  rm  r7   r7   r7   r8   rb    s    rb  c                   @   r@  )
Ú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   ÚlistÚcookiesÚkeysrÇ   Úvaluesrg   r\  rw   rË   rf   rt  ru  rv  Ú_request_summaryr?   r7   r7   r8   ÚprepareJ  s   ÿzTypeCheckHandler.preparec                 C   ó   |   d|t¡ |  | j¡ d S ©NÚpath_component©rz  r   rV   ry  ©r@   r†  r7   r7   r8   rW   e  s   zTypeCheckHandler.getc                 C   r„  r…  r‡  rˆ  r7   r7   r8   r¤   k  s   zTypeCheckHandler.postc                 C   s.   t |ƒ}||krd|› d|› | j|< d S d S )Nz	expected z, got )r[  ry  )r@   re   ÚobjÚexpected_typeÚactual_typer7   r7   r8   rz  o  s   ÿzTypeCheckHandler.check_typeN)rG   rH   rI   rƒ  rW   r¤   rz  r7   r7   r7   r8   ro  I  s
    ro  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   )r[  rË   r\  rY  rZ  Údecoder   )r@   rg   re   r7   r7   r8   Údecode_argumentv  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)r[  rË   r   r€   Úb2a_hexr   r\  )rO  r7   r7   r8   Údescribe€  s
   z&DecodeArgHandler.get.<locals>.describerm   ©r2   Úquery)rV   r}  )r@   ra  r‘  r7   r7   r8   rW     s   "zDecodeArgHandler.getr0   )rG   rH   rI   r  rW   r7   r7   r7   r8   rŒ  u  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¤  rp  )rp  z(didn't get permanent or status arguments)r}  ÚredirectÚboolr|  r\  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¢  r\  Ú
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   )Úchr)Ú.0r©  r7   r7   r8   Ú
<listcomp>È  ó    z(SetHeaderHandler.get.<locals>.<listcomp>r   é    é   ú	r­  rm   rã   r®  r¯  Ú r°  )	ÚrangeÚappendr´  Úremover¢  r\  r±  rÇ   rž   )r@   Úillegal_charsÚcharrà   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   r]  Úget_query_argumentsÚget_body_argumentsr?   r7   r7   r8   rƒ  å  s   ýÿzGetArgumentsHandler.prepareNrÆ  r7   r7   r7   r8   rÇ  ä  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=   ó  s   øÿýzWSGISafeWebTest.get_app_kwargsc                    ó   t ƒ  ¡  tj ¡  d S r0   ©ÚsuperÚtearDownr   Ú_template_loadersÚclearr?   ©Ú	__class__r7   r8   rÔ    rR  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/(.*)rw  )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$   ro  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@   rX  ÚkwargsrÂ   r7   r7   r8   rd  1  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@   rs  rÂ   r  r7   r7   r8   Ú
test_types6  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É   rh  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_argumentG  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%FFi  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_plusd  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/%E9rh  z/decode_arg/%C3%A9rñ  z/decode_arg/1%20%2B%201)rv   r>   rv  r?   r7   r7   r8   Útest_reverse_urls  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/ri  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=1Fr4  é-  z/redirect?permanent=0r6  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Ý  Fr4  rþ  r7  rÞ  rß  r6  ©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à  Fr4  rþ  r7  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_argumentsé  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_gzipü  s   
zWSGISafeWebTest.test_no_gzip)rG   rH   rI   rÏ  r=   rÔ  r<   rd  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´   zNonWSGIWebTests.get_handlersc                 C   rõ  )Nr  r°  r  rÁ   r7   r7   r8   Útest_empty_flush  r  z NonWSGIWebTests.test_empty_flushN)rG   rH   rI   r<   r  r7   r7   r7   r8   r    ó    r  c                   @   r@  )
Ú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 ©Nrp  ro   r   )r}  r    r|  r?   r7   r7   r8   rW     s   z:ErrorResponseTest.get_handlers.<locals>.DefaultHandler.getNrY   r7   r7   r7   r8   ÚDefaultHandler  rZ   r"  c                   @   r  )z9ErrorResponseTest.get_handlers.<locals>.WriteErrorHandlerc                 S   s0   |   dd ¡r|  t|   d¡ƒ¡ d S dd  d S r!  )r}  r/  r|  r?   r7   r7   r8   rW     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_error  s   zEErrorResponseTest.get_handlers.<locals>.WriteErrorHandler.write_errorN©rG   rH   rI   rW   r(  r7   r7   r7   r8   ÚWriteErrorHandler  s    r*  c                   @   r  )z?ErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandlerc                 S   ó   dd  d S ©Nro   r   r7   r?   r7   r7   r8   rW   "  rO   zCErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.getc                 [   ó   t dƒ‚)Nzexception in write_error©r\  r&  r7   r7   r8   r(  %  ó   zKErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.write_errorNr)  r7   r7   r7   r8   ÚFailedWriteErrorHandler!  r  r0  ú/defaultú/write_errorú/failed_write_error)r   r$   )r@   r"  r*  r0  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 exceptionr1  r.  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 )Nr4  r2  r.  s   Exception: ZeroDivisionErrorz/write_error?status=503r5  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 )Nr4  r3  r.  r·   r7  rÁ   r7   r7   r8   Útest_failed_write_errorF  s
   
"ýz)ErrorResponseTest.test_failed_write_errorN)rG   rH   rI   r<   r6  r8  r9  r7   r7   r7   r8   r     s
    "
r   c                   @   sX  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,e- .ej/dIkdJ¡dKdL„ ƒZ0dMS )NÚ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é   )r<  )r|  r}  rV   Ú
static_url)r@   r2   Úwith_vr7   r7   r8   rW   X  s   z9StaticFileTest.get_handlers.<locals>.StaticUrlHandler.getNrY   r7   r7   r7   r8   ÚStaticUrlHandlerW  rZ   r?  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    rA  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 )Nr@  )r@  Fz://r   éÿÿÿÿ)
r¦  r}  r@  r=  rV   rÇ   rY  Úprotocolr  Úfind)
r@   r2   Ú
do_includeÚregular_urlÚoverride_urlrC  Úprotocol_lengthÚcheck_regularÚcheck_overrideÚresultr7   r7   r8   rW   `  s   
zAStaticFileTest.get_handlers.<locals>.OverrideStaticUrlHandler.getNrY   r7   r7   r7   r8   ÚOverrideStaticUrlHandler_  rZ   rL  ú/static_url/(.*)z/abs_static_url/(.*)z/override_static_url/(.*)z/root_static/(.*)rL   )r2   )r   r   rb   )r@   r?  rA  rL  r7   r7   r8   r<   V  s   üzStaticFileTest.get_handlersc                 C   s   t tdƒdS )Nr;  )Ú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.txtr#  r$  )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=12345rQ  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.gzr#  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¼   rW  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¯  rR  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@   r@  r2   rÂ   r7   r7   r8   r]  ³  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»   rL  Ú	itertoolsÚchainrû   Ú
startswithÚaddrv   rW   )r@   rX  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 )NrR  úIf-Modified-SinceúLast-Modifiedr   é0  úContent-Length)ri  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 )NrR  úIf-None-MatchÚEtagr   rl  ©ri  rû   rv   r½   rn  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 )NrR  z
"MISMATCH"rk  )rr  rj  r   rµ   rt  rn  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 )NrR  rj  z!nv@l!dr   rµ   ©ri  rv   r½   rÁ   r7   r7   r8   Ú)test_static_304_if_modified_since_invalidè  s
   þz8StaticFileTest.test_static_304_if_modified_since_invalidc                 C   rw  )NrR  rj  zFri, 01 Jan 1960 00:00:00 GMTr   rµ   rx  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 )Nr[  rR  rj  ro   r   rµ   rl  )r1   Ústatr9   ri  r   Úst_mtimerv   r½   )r@   r{  rÂ   r7   r7   r8   Ú'test_static_if_modified_since_time_zoneù  s   þþz6StaticFileTest.test_static_if_modified_since_time_zonec                 C   s0   |   d¡}|  t|j d¡ƒd| j d ¡ d S )NrR  rs  ó   ")ri  rv   r   rû   rW   rW  rÁ   r7   r7   r8   Útest_static_etag  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 )NrR  ÚRangez	bytes=0-9r   éÎ   s
   User-agentrs  r~  rm  Ú10úContent-Rangezbytes 0-9/26)ri  rv   r½   rº   r   rû   rW   rW  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 )NrR  r€  zbytes=0-r   rµ   ú
robots.txtúutf-8©r  rm  Ú26rƒ  ©ri  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_file  s   ÿÿz/StaticFileTest.test_static_with_range_full_filec                 C   r…  )NrR  r€  zbytes=0-10000000r   rµ   r†  r‡  rˆ  rm  r‰  rƒ  rŠ  rŽ  r7   r7   r8   Ú$test_static_with_range_full_past_end*  ó   ÿÿ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 )NrR  r€  zbytes=1-10000000r   r  r†  r‡  rˆ  ro   rm  Ú25rƒ  zbytes 1-25/26)ri  rv   r½   r1   r2   r3   r‹  rŒ  rº   r   r  rû   rW   rŽ  r7   r7   r8   Ú'test_static_with_range_partial_past_end5  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 )
NrR  r€  z	bytes=22-r   ó   : /
rm  r¡  rƒ  úbytes 22-25/26©ri  rv   rº   rû   rW   rÁ   r7   r7   r8   Útest_static_with_range_end_edge@  ó   ÿz.StaticFileTest.test_static_with_range_end_edgec                 C   r–  )
NrR  r€  zbytes=-4r   r—  rm  r¡  rƒ  r˜  r™  rÁ   r7   r7   r8   Útest_static_with_range_neg_endH  r›  z-StaticFileTest.test_static_with_range_neg_endc                 C   r…  )NrR  r€  zbytes=-1000000r   rµ   r†  r‡  rˆ  rm  r‰  rƒ  rŠ  rŽ  r7   r7   r8   Ú%test_static_with_range_neg_past_startP  r“  z4StaticFileTest.test_static_with_range_neg_past_startc                 C   rw  )NrR  r€  rÈ   r   rµ   rx  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 )NrR  r€  zbytes=-0r   rƒ  ú
bytes */26é   )ri  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 )NrR  r€  zbytes=26r   r   rƒ  rŸ  ©ri  rv   r½   rû   rW   rÁ   r7   r7   r8   Ú-test_static_unsatisfiable_range_invalid_startf  ó
   ÿz<StaticFileTest.test_static_unsatisfiable_range_invalid_startc                 C   r¢  )NrR  r€  z
bytes=10-3r   r   rƒ  rŸ  r£  rÁ   r7   r7   r8   Ú3test_static_unsatisfiable_range_end_less_than_startm  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 )
NrR  r_  ©r¹   rµ   r·   rm  r‰  rs  r~  ©r»   rv   r½   rº   rû   r   rW  rÁ   r7   r7   r8   Útest_static_headt  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 )NrR  r_  r€  ú	bytes=1-4)r¹   rû   r  r·   rm  r¡  rs  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 )
NrR  rª  r~  )r€  rr  r   rl  r·   rm  rs  )ri  rW  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é”  rx  rÁ   r7   r7   r8   Útest_static_404˜  r  zStaticFileTest.test_static_404c                 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.txté“  )Úhttp_clientrQ  r   r   r   ri  rv   r½   rÁ   r7   r7   r8   Útest_path_traversal_protectionœ  s   
ÿz-StaticFileTest.test_path_traversal_protectionÚposixznon-posix OSc                 C   sF   t j t j t j t¡¡d¡}|  dtj 	|¡ ¡}|  
|jd¡ d S )Nr[  z/root_staticrµ   )r1   r2   r3   r4   Úabspathr5   ri  r  r  rÚ   rv   r½   )r@   r2   rÂ   r7   r7   r8   Útest_root_static_path©  s
   ÿz$StaticFileTest.test_root_static_pathN)1rG   rH   rI   rW  r1   r2   r3   r4   r5   r‹  r<   r=   rS  rU  rV  rX  rY  rZ  r\  r^  r]  ri  rq  ru  rv  ry  rz  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   r:  M  sR    ÿ%		

r:  c                   @   r@  )
ÚStaticDefaultFilenameTestc                 C   ó   t tdƒt dddS ©Nr;  ú
index.html©Údefault_filename)rN  Ústatic_handler_argsrO  r?   r7   r7   r8   r=   ·  ó   þz(StaticDefaultFilenameTest.get_app_kwargsc                 C   ó   g S r0   r7   r?   r7   r7   r8   r<   ½  rF   z&StaticDefaultFilenameTest.get_handlersc                 C   s.   | j ddd}|  |jd¡ |  d|j¡ d S )Nú/static/dir/Fr4  rµ   s   this is the index
©r»   rv   r½   rº   rÁ   r7   r7   r8   Útest_static_default_filenameÀ  s   z6StaticDefaultFilenameTest.test_static_default_filenamec                 C   s6   | j ddd}|  |jd¡ |  |jd  d¡¡ d S )Nú/static/dirFr4  rþ  r7  rÀ  )r»   rv   r½   r¿   rû   ÚendswithrÁ   r7   r7   r8   Útest_static_default_redirectÅ  s   z6StaticDefaultFilenameTest.test_static_default_redirectN)rG   rH   rI   r=   r<   rÂ  rÅ  r7   r7   r7   r8   r·  ¶  s
    r·  c                   @   r@  )
ÚStaticDefaultFilenameRootTestc                 C   s    t tj tdƒ¡t ddddS )Nr;  rº  r»  rL   )rN  r½  Ústatic_url_prefix)rb   r1   r2   r³  r9   r?   r7   r7   r8   r=   Ì  s
   ýz,StaticDefaultFilenameRootTest.get_app_kwargsc                 C   r¿  r0   r7   r?   r7   r7   r8   r<   Ó  rF   z*StaticDefaultFilenameRootTest.get_handlersc                 C   ó   t ƒ S 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Ã  Fr4  r¯  )r1   r2   r4   r5   Ú
splitdrivere   rv   r   r   r»   r½   )r@   Útest_dirÚdriveÚtailrÂ   r7   r7   r8   Útest_no_open_redirectÛ  s   

þÿz3StaticDefaultFilenameRootTest.test_no_open_redirectN)rG   rH   rI   r=   r<   rÉ  rÎ  r7   r7   r7   r8   rÆ  Ë  s
    rÆ  c                   @   rj   )ÚStaticFileWithPathTestc                 C   r¸  r¹  rO  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<   rÐ  r7   r7   r7   r8   rÏ  ð  s    rÏ  c                   @   r@  )
Ú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)Úclsr^   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 )NrÒ  r   )rÔ  )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   Úget_absolute_path  s   zPCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_absolute_pathc                 S   s   |S r0   r7   )r@   ÚrootÚabsolute_pathr7   r7   r8   Úvalidate_absolute_path  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  ƒ‚)Nrä  r  rå  )râ  r\  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   rß  r7   r7   r8   rÓ  )  ó   zJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_version©NN)rG   rH   rI   ÚclassmethodrÛ  rÞ  rà  rã  rè  ré  rë  rÓ  r7   r7   r7   r8   ÚMyStaticFileHandler  s    

rñ  c                   @   rP   )z;CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandlerc                 S   s   |   |  |¡¡ d S r0   )rV   r=  r©   r7   r7   r8   rW   .  ræ   z?CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandler.getNrY   r7   r7   r7   r8   r?  -  rZ   r?  rM  )r   r   Ústatic_handler_class)r@   rñ  r?  r7   r7   r8   r<      s   ,
z!CustomStaticFileTest.get_handlersc                 C   s   t d| jdS )NÚdummy)rN  rò  )rb   rò  r?   r7   r7   r8   r=   5  rX   z#CustomStaticFileTest.get_app_kwargsc                 C   rõ  )Nz/static/foo.42.txtrn   r  rÁ   r7   r7   r8   rÐ  8  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   rX  <  s   
"þz$CustomStaticFileTest.test_static_urlN)rG   rH   rI   r<   r=   rÐ  rX  r7   r7   r7   r8   rÑ  ÿ  s
    5rÑ  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@   r÷  r7   r7   r8   r+  D  r´   z#HostMatchingTest.Handler.initializec                 C   ó   |   | j¡ d S r0   )rV   r÷  r?   r7   r7   r8   rW   G  rc  zHostMatchingTest.Handler.getN)rG   rH   rI   r+  rW   r7   r7   r7   r8   rN   C  r  rN   c                 C   s   dt jddifgS )NrÓ   r÷  Úwildcard)rö  rN   r?   r7   r7   r8   r<   J  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Ó   r÷  ú[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_handlersrö  rN   r»   rv   rº   r½   rÁ   r7   r7   r8   Útest_host_matchingM  s4   ÿÿÿÿ


z#HostMatchingTest.test_host_matchingN)rG   rH   rI   r   rN   r<   r  r7   r7   r7   r8   rö  B  s    rö  c                   @   rj   )ÚDefaultHostMatchingTestc                 C   r¿  r0   r7   r?   r7   r7   r8   r<   m  rF   z$DefaultHostMatchingTest.get_handlersc                 C   s   ddiS )NÚdefault_hostrú  r7   r?   r7   r7   r8   r=   p  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 )Nrú  rÓ   r÷  rû  rü  rý  rþ  zwww.test.comrÿ  r   r  r  r­  z	X-Real-IprB  r   r  )	r>   r  rö  rN   r»   rv   rº   r½   r  rÁ   r7   r7   r8   Útest_default_host_matchings  s(   ÿÿÿ



z2DefaultHostMatchingTest.test_default_host_matchingN)rG   rH   rI   r<   r=   r	  r7   r7   r7   r8   r  l  s    r  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   rU    rZ   rU  z/str/(?P<path>.*)z/unicode/(?P<path>.*)r°   )r@   rU  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<   r  r7   r7   r7   r8   r
  Ž  s    
r
  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   r  r  rã   ©r»   r  rû   rv   rÁ   r7   r7   r8   Útest_clear_header©  s   
z!ClearHeaderTest.test_clear_headerN)rG   rH   rI   r   rN   r  r7   r7   r7   r8   r  ¡  ó    r  c                   @   r  )ÚHeader204Testc                   @   rP   )zHeader204Test.Handlerc                 C   s   |   d¡ |  ¡  d S )NéÌ   )Ú
set_statusrž   r?   r7   r7   r8   rW   ±  rT  zHeader204Test.Handler.getNrY   r7   r7   r7   r8   rN   °  rZ   rN   c                 C   s8   |   d¡}|  |jd¡ |  d|j¡ |  d|j¡ d S )NrL   r  rm  úTransfer-Encoding)r»   rv   r½   r  rû   rÁ   r7   r7   r8   Útest_204_headersµ  ó   
zHeader204Test.test_204_headersN)rG   rH   rI   r   rN   r  r7   r7   r7   r8   r  ¯  ó    r  c                   @   r  )ÚHeader304Testc                   @   rP   )zHeader304Test.Handlerc                 C   s   |   dd¡ |  d¡ d S )NúContent-LanguageÚen_USrT   )r¢  rV   r?   r7   r7   r8   rW   ¾  s   zHeader304Test.Handler.getNrY   r7   r7   r7   r8   rN   ½  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   rm  Ú5r  r  rr  rs  r   rl  r  )r»   rv   rû   r½   r  rn  r7   r7   r8   Útest_304_headersÂ  s   
ÿzHeader304Test.test_304_headersN)rG   rH   rI   r   rN   r!  r7   r7   r7   r8   r  ¼  r  r  c                   @   rõ  )ÚStatusReasonTestc                   @   rP   )zStatusReasonTest.Handlerc                 C   s<   | j j dg ¡}| jt|  d¡ƒ|rt|d ƒnd d d S )NÚreasonr½   r   ©r#  )rY  rZ  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É  Ú  ó   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=304rl  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_statusÞ  s   



zStatusReasonTest.test_statusN)rG   rH   rI   r   rN   rÉ  r*  r7   r7   r7   r8   r"  Ñ  s    r"  c                   @   r  )Ú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»   r  r  r  rû   r  r  r  r  r  r  )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                   @   s<   e Zd ZG dd„ deƒZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú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   s8   |   d¡}|  |jd¡ |  |jd¡ |  d|j¡ d S )NrL   r'  r&  s   682: Foo)r»   rv   r½   r#  r  rº   rÁ   r7   r7   r8   Útest_raise_with_reason  r  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: Unknownr3  r?   r7   r7   r8   Ú test_httperror_str_from_httputil  s   z4RaiseWithReasonTest.test_httperror_str_from_httputilN)	rG   rH   rI   r   rN   rÉ  r2  r4  r5  r7   r7   r7   r8   r0  û  s    r0  c                   @   r@  )
ÚErrorHandlerXSRFTestc                 C   s   dt tddfgS )Nú/erroré¡  ©r'  )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 )Nr7  r¶   r»  r¸   r8  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   r6    s
    r6  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ú!)r]  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 )NTr;  )r  rN  )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_compressed1  s   ÿüzGzipTestCase.assert_compressedc                 C   ó*   |   d¡}|  |¡ |  |jd d¡ d S )NrL   r  r  ©r»   rE  rv   rû   rÁ   r7   r7   r8   Ú	test_gzip;  s   

zGzipTestCase.test_gzipc                 C   rF  )NrP  r  r  rG  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  r  rÁ   r7   r7   r8   Útest_gzip_not_requestedG  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µ  rO  r7   r7   r8   r¶  P  r·  z:GzipTestCase.test_vary_already_present.<locals>.<listcomp>r  ú,úAccept-Languager  ©r»   rE  rv   rû   ÚsplitrÁ   r7   r7   r8   Útest_vary_already_presentL  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   rL  r7   rM  rO  r7   r7   r8   r¶  Y  r·  zCGzipTestCase.test_vary_already_present_multiple.<locals>.<listcomp>r  rP  )rQ  rþ   r  rR  rÁ   r7   r7   r8   Ú"test_vary_already_present_multipleT  s   

þz/GzipTestCase.test_vary_already_present_multipleN)rG   rH   rI   r   rN   r=   rE  rH  rI  rK  rT  rU  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©rX  rç  )rV   rb   rW  Ú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   c  s   z!PathArgsInPrepareTest.Handler.getN©rG   rH   rI   rƒ  rW   r7   r7   r7   r8   rN   _  r  rN   c                 C   s   d| j fd| j fgS )Nz	/pos/(.*)z/kw/(?P<path>.*)rM   r?   r7   r7   r8   r<   g  ræ   z"PathArgsInPrepareTest.get_handlersc                 C   s4   |   d¡}| ¡  t|jƒ}|  |dgi dœ¡ d S )Nz/pos/foorm   rX  rë  ©r@   rÂ   r  r7   r7   r8   Útest_posj  s   

zPathArgsInPrepareTest.test_posc                 C   s6   |   d¡}| ¡  t|jƒ}|  |g ddidœ¡ d S )Nz/kw/foor2   rm   rX  rë  r\  r7   r7   r8   Útest_kwp  s   

zPathArgsInPrepareTest.test_kwN)rG   rH   rI   r   rN   r<   r]  r^  r7   r7   r7   r8   rW  ^  s
    rW  c                   @   r  )ÚClearAllCookiesTestc                   @   rP   )zClearAllCookiesTest.Handlerc                 C   s   |   ¡  |  d¡ d S ©NÚok)Úclear_all_cookiesrV   r?   r7   r7   r8   rW   y  s   zClearAllCookiesTest.Handler.getNrY   r7   r7   r7   r8   rN   x  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¿   rc  )r@   rÂ   Úset_cookiesr7   r7   r8   Útest_clear_all_cookies}  s   z*ClearAllCookiesTest.test_clear_all_cookiesN)rG   rH   rI   r   rN   rd  r7   r7   r7   r8   r_  w  r  r_  c                   @   ó   e Zd ZdS )ÚPermissionErrorN©rG   rH   rI   r7   r7   r7   r8   rf  …  ó    rf  c                   @   rV  )
Ú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ÚexcÚhttpéš  zno longer hereÚzeroro   r   Ú
permissionznot allowed)r}  r    rf  )r@   rj  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 )Nr%  r¯  rf  )Ú
isinstancerf  r  rV   r   r(  )r@   r'  rç  Útyprg   Útbr7   r7   r8   r(  ”  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   )ro  rf  r   ÚwarningrX  r   Úlog_exception©r@   rp  rg   rq  r7   r7   r8   rs    s   
z*ExceptionHandlerTest.Handler.log_exceptionN)rG   rH   rI   rW   r(  rs  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=httprl  rï  rÁ   r7   r7   r8   Útest_http_error£  ó   
"þz$ExceptionHandlerTest.test_http_errorc                 C   ru  )Nr4  z
/?exc=zeror.  ©r   r   r»   rv   r½   rÁ   r7   r7   r8   Útest_unknown_errorª  s   
"þz'ExceptionHandlerTest.test_unknown_errorc                 C   ru  )Nz/custom logging for PermissionError: not allowedz/?exc=permissionr¯  rx  rÁ   r7   r7   r8   Útest_known_error°  rw  z%ExceptionHandlerTest.test_known_errorN)rG   rH   rI   r   rN   rv  ry  rz  r7   r7   r7   r8   ri  ‰  s
    ri  c                   @   r  )ÚBuggyLoggingTestc                   @   r  )zBuggyLoggingTest.Handlerc                 C   r+  r,  r7   r?   r7   r7   r8   rW   º  rO   zBuggyLoggingTest.Handler.getc                 C   r+  r,  r7   rt  r7   r7   r8   rs  ½  rO   z&BuggyLoggingTest.Handler.log_exceptionN)rG   rH   rI   rW   rs  r7   r7   r7   r8   rN   ¹  r  rN   c                 C   rl  )Nz.*rL   )r   r   r»   r?   r7   r7   r8   Útest_buggy_log_exceptionÀ  rn  z)BuggyLoggingTest.test_buggy_log_exceptionN)rG   rH   rI   r   rN   r|  r7   r7   r7   r8   r{  ¸  r  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   Í  rX   z UIMethodUIModuleTest.Handler.getc                 C   s
   |   d¡S )Nrg   )r}  r?   r7   r7   r8   rg   Ð  r´   z"UIMethodUIModuleTest.Handler.valueN)rG   rH   rI   rW   rg   r7   r7   r7   r8   rN   Ì  r  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 rÒ  )rg   )ry   Úxr7   r7   r8   Úmy_ui_methodÔ  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¬   Ø  s   þz<UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModule.renderN©rG   rH   rI   r¬   r7   r7   r7   r8   ÚMyModule×  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=   Ó  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                   @   r  )Ú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                   @   r  )ÚSetLazyPropertiesTestc                   @   r@  )
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   rì  )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Ô  6  rR  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;  r  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   D  ó   
z?GetCurrentUserTest.get_handlers.<locals>.WithoutUserHandler.getNrY   r7   r7   r7   r8   ÚWithoutUserHandlerC  rZ   r¥  c                   @   rP   )z8GetCurrentUserTest.get_handlers.<locals>.WithUserHandlerc                 S   r¡  )Nr›  r¢  r?   r7   r7   r8   rW   I  r¤  z<GetCurrentUserTest.get_handlers.<locals>.WithUserHandler.getNrY   r7   r7   r7   r8   ÚWithUserHandlerH  rZ   r¦  c                   @   rP   )zAGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandlerc                 S   r,  r0   )Úuir?   r7   r7   r8   Úget_template_namespaceN  s   zXGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandler.get_template_namespaceN)rG   rH   rI   r¨  r7   r7   r7   r8   ÚCurrentUserModuleHandlerM  rZ   r©  c                   @   rP   )zAGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandlerc                 S   r¡  )Nrœ  r¢  r?   r7   r7   r8   rW   U  r¤  zEGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandler.getNrY   r7   r7   r7   r8   ÚWithoutUserModuleHandlerT  rZ   rª  c                   @   rP   )z>GetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandlerc                 S   r¡  )Nr  r¢  r?   r7   r7   r8   rW   Z  r¤  zBGetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandler.getNrY   r7   r7   r7   r8   ÚWithUserModuleHandlerY  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_lazye  r•  z0GetCurrentUserTest.test_get_current_user_is_lazyc                 C   rõ  )Nr­  ó   Truer  rÁ   r7   r7   r8   Útest_get_current_user_worksk  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_lazyo  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_workss  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                   @   r  )ÚUnimplementedHTTPMethodsTestc                   @   re  )z$UnimplementedHTTPMethodsTest.HandlerNrg  r7   r7   r7   r8   rN   y  rh  rN   c                 C   sR   dD ]}| j d|d}|  |jd¡ qdD ]}| j d|dd}|  |jd¡ qd S )N)r_  r`  Ú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·  x  s    r·  c                   @   rõ  )Ú#UnimplementedNonStandardMethodsTestc                   @   rP   )z+UnimplementedNonStandardMethodsTest.Handlerc                 C   rR   ©NÚotherrU   r?   r7   r7   r8   rÀ  ‡  r0  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                   @   r  )Ú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   )rY  r¹   rV   r?   r7   r7   r8   r¹   ™  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   r_  r§  r·   )r`  r¸  r¹  r»  r¸   )r»   rv   rº   r   )r@   rÂ   r¹   r7   r7   r8   Útest_standard_methodsŸ  s   þz(AllHTTPMethodsTest.test_standard_methodsN)rG   rH   rI   r   rN   rË  r7   r7   r7   r8   rÇ  —  r  rÇ  c                   @   rõ  )Ú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Í  °  rX   zPatchMethodTest.Handler.patchc                 C   rR   r¿  rU   r?   r7   r7   r8   rÀ  ³  rX   zPatchMethodTest.Handler.otherN)rG   rH   rI   r   ÚSUPPORTED_METHODSrÍ  rÀ  r7   r7   r7   r8   rN   «  s    
rN   c                 C   r<  )NrL   rÁ  r·   r¸   s   patchr  rÁ   r7   r7   r8   Ú
test_patch¶  r>  zPatchMethodTest.test_patchc                 C   r<  )NrL   rÃ  TrÄ  s   otherr  rÁ   r7   r7   r8   Ú
test_otherº  r>  zPatchMethodTest.test_otherN)rG   rH   rI   r   rN   rÏ  rÐ  r7   r7   r7   r8   rÌ  ª  s    rÌ  c                   @   r  )ÚFinishInPrepareTestc                   @   r  )zFinishInPrepareTest.Handlerc                 C   rR   )NrÀ   rZ  r?   r7   r7   r8   rƒ  Á  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   À  r  rN   c                 C   rõ  )NrL   s   doner  rÁ   r7   r7   r8   Útest_finish_in_prepareÊ  r  z*FinishInPrepareTest.test_finish_in_prepareN)rG   rH   rI   r   rN   rÒ  r7   r7   r7   r8   rÑ  ¿  ó    
rÑ  c                   @   r  )ÚDefault404Testc                 C   r  ©NrÓ   r°   r?   r7   r7   r8   r<   Ð  s   
zDefault404Test.get_handlersc                 C   ó*   |   d¡}|  |jd¡ |  |jd¡ d S )NrL   r­  sE   <html><title>404: Not Found</title><body>404: Not Found</body></html>rÁ  rÁ   r7   r7   r8   Útest_404Ô  s   
þzDefault404Test.test_404N)rG   rH   rI   r<   r×  r7   r7   r7   r8   rÔ  Ï  s    rÔ  c                   @   rj   )ÚCustom404Testc                 C   r  rÕ  r°   r?   r7   r7   r8   r<   ß  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)r  rV   r?   r7   r7   r8   rW   ä  rR  z:Custom404Test.get_app_kwargs.<locals>.Custom404Handler.getNrY   r7   r7   r7   r8   ÚCustom404Handlerã  rZ   rÙ  )Údefault_handler_class)r   rb   )r@   rÙ  r7   r7   r8   r=   â  s   
zCustom404Test.get_app_kwargsc                 C   rÖ  )NrL   r­  s   custom 404 responserÁ  rÁ   r7   r7   r8   r×  ê  s   
zCustom404Test.test_404N)rG   rH   rI   r<   r=   r×  r7   r7   r7   r8   rØ  Þ  s    rØ  c                   @   rj   )ÚDefaultHandlerArgumentsTestc                 C   r  rÕ  r°   r?   r7   r7   r8   r<   ñ  r´   z(DefaultHandlerArgumentsTest.get_handlersc                 C   s   t tt dddS )Nr¯  r9  )rÚ  Ú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à  râ  r  ©r@   Úrespr7   r7   r8   Útest_handler_by_name	  s   


z&HandlerByNameTest.test_handler_by_nameN)rG   rH   rI   r<   rå  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                   @   r@  )
zCStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandlerc                 S   r(  r0   r    r;  r7   r7   r8   r+  	  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  rè  ©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¡   Úfinishedrè  rV   r?   r7   r7   r8   rW   	  s   zGStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.getN)rG   rH   rI   r+  rƒ  rê  rW   r7   r7   r7   r8   ÚStreamingBodyHandler	  s
    rì  c                   @   rP   )zAStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandlerc                 S   r-  )Né‘  r1  r?   r7   r7   r8   rƒ  $	  s   zIStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandler.prepareNrÆ  r7   r7   r7   r8   ÚEarlyReturnHandler"	  s    rî  c                       s$   e Zd Zdd„ Z‡ fdd„Z‡  ZS )zDStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandlerc                 S   r(  r0   r    r;  r7   r7   r8   r+  +	  r´   zOStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.initializec                    s   t ƒ  ¡  | jj d ¡ d S r0   )rÓ  r?  r¡   Úclose_futurerè  r?   r×  r7   r8   r?  .	  r  zXStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.on_connection_close)rG   rH   rI   r+  r?  r  r7   r7   r×  r8   ÚCloseDetectionHandler)	  s    rð  z/stream_bodyr    z/early_returnz/close_detection)r+   r   rb   )r@   rì  rî  rð  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   rB  s   GET s    HTTP/1.1
Host: 127.0.0.1
s   Connection: close
s   Transfer-Encoding: chunked

)rF  rG  rH  rI  rJ  r   rV   )r@   r$   Úconnection_closerO  rK  r7   r7   r8   rI  8	  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©rñ  ó	   4
asdf
s   asdfs	   4
qwer
s   qwers   0

s   {})r   rç  r  rë  rI  rV   rv   Úread_until_closer¿   rÄ  rQ  ©r@   rK  r  r7   r7   r8   Útest_streaming_bodyC	  s$   €



z,StreamingRequestBodyTest.test_streaming_bodyc                 c   s.    | j ddd}| ¡ V }|  | d¡¡ d S )Nó   /early_returnFrò  ó   HTTP/1.1 401)rI  rô  r¿   rc  rõ  r7   r7   r8   Útest_early_returnZ	  s   €
z*StreamingRequestBodyTest.test_early_returnc                 c   s8    | j ddd}| d¡ | ¡ V }|  | d¡¡ d S )Nr÷  Frò  ró  rø  )rI  rV   rô  r¿   rc  rõ  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_detectionFrò  )r   rï  rI  rQ  )r@   rK  r7   r7   r8   Útest_close_during_uploadg	  s
   €z1StreamingRequestBodyTest.test_close_during_uploadN)
rG   rH   rI   r<   rI  r   rö  rù  rú  rû  r7   r7   r7   r8   ræ  	  s    &


ræ  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¹   Úmethodsr;  r7   r7   r8   r+  u	  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_methodz	  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   r+  Ú
contextlibÚcontextmanagerrÿ  r   r¥   rƒ  r¤   r7   r7   r7   r8   rü  s	  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É  ™	  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ƒ  rê  rê  rê  r¤   r  )r»   ræ  rv   r   rº   rb   rÁ   r7   r7   r8   Útest_flow_control_fixed_bodyž	  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_producer±	  s   €ÿzYBaseStreamingRequestFlowControlTest.test_flow_control_chunked_body.<locals>.body_producerrL   r¶   )r  r¹   r	  r  )r   r¥   r»   ræ  rv   r   rº   rb   )r@   r  rÂ   r7   r  r8   Útest_flow_control_chunked_body®	  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 )NÚw)ÚmodeÚfileobjs   abcdefghijklmnopqrstuvwxyzrL   r¶   r  r  )rº   r¹   rû   r	  r  )r/   r  ÚGzipFilerV   rQ  Ú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   r  rÉ  r€  ÚAnyr
  r  r  r7   r7   r7   r8   r  “	  s    r  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 )Nrê  )rÿ  r   r   ré  r7   r7   r8   rê  å	  s   €
"ÿzhDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandler.data_receivedN)rG   rH   rI   r   r¥   rê  r7   r7   r7   r8   ÚDecoratedFlowControlHandlerä	  r«  r  rL   r    ©rü  rb   )r@   r  r7   r7   r8   r<   ã	  s   z5DecoratedStreamingRequestFlowControlTest.get_handlersN©rG   rH   rI   r<   r7   r7   r7   r8   r  à	  ó    r  c                   @   rP   )Ú%NativeStreamingRequestFlowControlTestc                 C   r  )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 )Nrê  r   )rÿ  ÚasynciorD  )r@   r  r!  r7   r7   r8   rê  ò	  s
   €"ýzbNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandler.data_receivedN)rG   rH   rI   rê  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 )Nrm  rí  ra  ©r¢  rž   r\  Ú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%  )Nrm  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/  r0  r-  Tr1  z,Tried to write more data than Content-Lengthr3  r?   r7   r7   r8   Útest_content_length_too_low%
  r6  z6IncorrectContentLengthTest.test_content_length_too_lowN)rG   rH   rI   r<   r5  r7  r7   r7   r7   r8   r#  û	  s    r#  c                   @   r  )Ú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)rY  rq   rc  Ú
connectionrK  rQ  rV   r?   r7   r7   r8   rW   8
  s   zClientCloseTest.Handler.getNrY   r7   r7   r7   r8   rN   7
  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   Tr1  s   requires HTTP/1.xr9  iW  )	r4  r
   rµ  ÚSkipTestr»   rº   ÚskipTestrv   r½   rÁ   r7   r7   r8   Útest_client_closeE
  s   

"üz!ClientCloseTest.test_client_closeN)rG   rH   rI   r   rN   r=  r7   r7   r7   r8   r8  6
  r–  r8  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   ÚpastQ
  rO   zSignedValueTest.pastc                 C   rì  )Ni m|Mr7   r?   r7   r7   r8   rB  T
  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 )Nr^  rg   ro   )rq   Úclocks<   dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4fr|   se   2|1:0|10:1300000000|3:key|8:dmFsdWU=|3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152©rD  )rs   rD  ó   value)r&   r>  ÚSECRETrB  rv   r'   )r@   Ú	signed_v1Ú	signed_v2Úsigned_defaultÚ
decoded_v1Ú
decoded_v2r7   r7   r8   Útest_known_valuesW
  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   rE  Úkey2)r&   r>  rG  rB  r'   r†   )r@   Úsigned1Úsigned2Údecoded1Údecoded2r7   r7   r8   Útest_name_swapw
  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 )NrN  rg   rE  rF  )r&   r>  rG  rC  r'   rv   rB  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 ©NrF  r^  rE  ©r'   r>  rG  rB  )Úprefix©r@   r‰   r7   r8   Úvalidate™
  ó   ÿ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 rZ  r[  )r‰   ©r\  r@   r7   r8   r^  ©
  r_  z:SignedValueTest.test_signature_tampering.<locals>.validaterY  Ú 00000000000000000000000000000000Ú@4d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152Ú@3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e153Ú?3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e15ÚA3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e1538ra  rc  r7   re  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‹   r^  rE  )r&   r>  rG  rB  r'   rv   ©r@   rg   rU  Ú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‹   r^  r   ©rD  r`   rE  ©r&   r>  ÚSECRET_DICTrB  r'   rv   rl  r7   r7   r8   Ú*test_key_versioning_read_write_default_keyÐ
  ó   ÿÿz:SignedValueTest.test_key_versioning_read_write_default_keyc                 C   ro  )Nr‹   r^  ro   rq  rE  rr  rl  r7   r7   r8   Ú.test_key_versioning_read_write_non_default_keyÚ
  ru  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 rp  )r&   r>  rs  rB  r™   rš   r'   r†   )r@   rg   rU  Únewkeysrm  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‹   r^  ro   rq  )r&   r>  rs  rB  r(   rv   )r@   rg   rU  r`   r7   r7   r8   Útest_key_version_retrievalî
  s   ÿz*SignedValueTest.test_key_version_retrievalN)rG   rH   rI   rG  rs  rC  rB  rM  rT  rX  rd  rk  rn  rt  rv  rx  ry  r7   r7   r7   r8   r>  M
  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   rt  )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Ó  ÚsetUpÚ	get_tokenrt  r?   r×  r7   r8   r    rR  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=©rt  ©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   rt  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   rt  rv   r½   rÁ   r7   r7   r8   Ú$test_xsrf_fail_cookie_invalid_format2  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_tokenC  ó   
ü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_tokenL  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   rt  r‚  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_post_bodyU  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   rt  r‚  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_headerg  s   ÿþü	z!XSRFTest.test_xsrf_success_headerc                 C   s:   d}t ƒ }t|ƒD ]	}| |  ¡ ¡ q	|  t|ƒ|¡ d S )Nrä   )rL  r¼  rd  r€  rv   r  )r@   Ú
NUM_TOKENSÚtokensr  r7   r7   r8   Útest_distinct_tokenss  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€  rt  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µ   é   )rt  r¼  r€  rd  r»   r  r  r  rb   r‚  rv   r½   r  )r@   r‡  Útokens_seenr  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_tokenr  Úv2_tokenr­  r®  rÂ   r7   r7   r8   Útest_versioning¨  s    
üùzXSRFTest.test_versioningrï  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   rz  ÷
  s(    

	

				rz  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   rø  r0   ©rV   rt  r?   r7   r7   r8   rW   Å  rc  zXSRFCookieNameTest.Handler.getc                 C   rR   r`  rU   r?   r7   r7   r8   r¤   È  rX   zXSRFCookieNameTest.Handler.postNr|  r7   r7   r7   r8   rN   Ä  r  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=   Ë  s
   ýz!XSRFCookieNameTest.get_app_kwargsc                    r}  r0   r~  r?   r×  r7   r8   r  Ò  rR  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€  Ö  s   
zXSRFCookieNameTest.get_tokenc                 C   r„  )Nrþ   z__Host-xsrf=r…  r†  r7   r7   r8   r‚  ß  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¸  Ã  s    

		r¸  c                   @   rõ  )ÚXSRFCookieKwargsTestc                   @   rP   )zXSRFCookieKwargsTest.Handlerc                 C   rø  r0   r¹  r?   r7   r7   r8   rW   ÿ  rc  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  r  r  r  r  r  r  r  r½  Úreplacer¿   r   r!  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                   @   r  )ÚFinishExceptionTestc                   @   rP   )zFinishExceptionTest.Handlerc                 C   s:   |   d¡ |  dd¡ |  dd¡rtdƒ‚|  d¡ tƒ ‚)Nrí  úWWW-AuthenticateúBasic realm="something"Úfinish_valuer»  zauthentication required)r  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=1rí  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Á    rÓ  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   rê  r0   r7   r?   r7   r7   r8   rW   1  rî  z:DecoratorTest.get_handlers.<locals>.RemoveSlashHandler.getN)rG   rH   rI   r,   rW   r7   r7   r7   r8   ÚRemoveSlashHandler0  ó    rÉ  c                   @   rÈ  )z3DecoratorTest.get_handlers.<locals>.AddSlashHandlerc                 S   rê  r0   r7   r?   r7   r7   r8   rW   6  rî  z7DecoratorTest.get_handlers.<locals>.AddSlashHandler.getN)rG   rH   rI   r-   rW   r7   r7   r7   r8   ÚAddSlashHandler5  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Ì  Fr4  rþ  r7  z/removeslashz/removeslash/?foo=barz/removeslash?foo=barr  rÁ   r7   r7   r8   Útest_removeslash<  ó   zDecoratorTest.test_removeslashc                 C   rÎ  )	NrÍ  Fr4  rþ  r7  z
/addslash/z/addslash?foo=barz/addslash/?foo=barr  rÁ   r7   r7   r8   Útest_addslashE  rÐ  zDecoratorTest.test_addslashN)rG   rH   rI   r<   rÏ  rÑ  r7   r7   r7   r8   rÇ  .  s    	rÇ  c                   @   sd   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 )Ú	CacheTestc                 C   s   G dd„ dt ƒ}d|fgS )Nc                   @   r  )z+CacheTest.get_handlers.<locals>.EtagHandlerc                 S   r  r0   rU   )r@   Úcomputed_etagr7   r7   r8   rW   R  rX   z/CacheTest.get_handlers.<locals>.EtagHandler.getc                 S   s
   | j d S rC  )Ú_write_bufferr?   r7   r7   r8   Úcompute_etagU  r´   z8CacheTest.get_handlers.<locals>.EtagHandler.compute_etagN)rG   rH   rI   rW   rÕ  r7   r7   r7   r8   ÚEtagHandlerQ  r  rÖ  z
/etag/(.*)r°   )r@   rÖ  r7   r7   r8   r<   P  s   
zCacheTest.get_handlersc                 C   ó   d}d}|   ||d¡ d S )Nú"xyzzy"Ú*rl  ©Ú
_test_etag©r@   rÓ  Úetagsr7   r7   r8   Útest_wildcard_etagZ  ó   zCacheTest.test_wildcard_etagc                 C   s   d}d}|   ||d¡ d S )NrØ  rl  rÚ  rÜ  r7   r7   r8   Útest_strong_etag_match_  rß  z CacheTest.test_strong_etag_matchc                 C   r×  )Nú"xyzzy1"ú"xyzzy1", "xyzzy2"rl  rÚ  rÜ  r7   r7   r8   Útest_multiple_strong_etag_matchd  rß  z)CacheTest.test_multiple_strong_etag_matchc                 C   r×  )NrØ  rá  rµ   rÚ  rÜ  r7   r7   r8   Útest_strong_etag_not_matchi  rß  z$CacheTest.test_strong_etag_not_matchc                 C   r×  )NrØ  râ  rµ   rÚ  rÜ  r7   r7   r8   Ú#test_multiple_strong_etag_not_matchn  rß  z-CacheTest.test_multiple_strong_etag_not_matchc                 C   r×  )Nrá  ú
W/"xyzzy1"rl  rÚ  rÜ  r7   r7   r8   Útest_weak_etag_matchs  rß  zCacheTest.test_weak_etag_matchc                 C   r×  )Nú"xyzzy2"úW/"xyzzy1", W/"xyzzy2"rl  rÚ  rÜ  r7   r7   r8   Útest_multiple_weak_etag_matchx  rß  z'CacheTest.test_multiple_weak_etag_matchc                 C   r×  )Nrè  ræ  rµ   rÚ  rÜ  r7   r7   r8   Útest_weak_etag_not_match}  rß  z"CacheTest.test_weak_etag_not_matchc                 C   r×  )Nz"xyzzy3"ré  rµ   rÚ  rÜ  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/rr  r   rÿ  )r@   rÓ  rÝ  r'  rÂ   r7   r7   r8   rÛ  ‡  s   ÿzCacheTest._test_etagN)rG   rH   rI   r<   rÞ  rà  rã  rä  rå  rç  rê  rë  rì  rÛ  r7   r7   r7   r8   rÒ  O  s    
rÒ  c                   @   r  )ÚRequestSummaryTestc                   @   rP   )zRequestSummaryTest.Handlerc                 C   s   d | j _|  |  ¡ ¡ d S r0   )rY  Ú	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  rã  r7   r7   r8   Útest_missing_remote_ip—  r  z)RequestSummaryTest.test_missing_remote_ipN)rG   rH   rI   r   rN   rï  r7   r7   r7   r8   rí  Ž  r  rí  c                   @   rP   )ÚHTTPErrorTestc                 C   sF   t ddd}t |¡}|  ||¡ |  |j|j¡ |  |j|j¡ d S )Nr¯  zGo awayr$  )r    r™   ÚassertIsNotrv   r'  r#  )r@   rà   Úe2r7   r7   r8   Ú	test_copy  s
   
zHTTPErrorTest.test_copyN)rG   rH   rI   ró  r7   r7   r7   r8   rð  œ  rZ   rð  c                   @   rP   )ÚApplicationTestc                 C   s"   t g ƒ}|jddd}| ¡  d S )Nr   rB  )Úaddress)r   ÚlistenrS  )r@   r>   Úserverr7   r7   r8   Útest_listen¦  s   zApplicationTest.test_listenN)rG   rH   rI   rø  r7   r7   r7   r8   rô  ¥  rZ   rô  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_reverse­  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$   rû  rþ  r±  )r@   Úpathsr2   Úurl_specrK  r7   r7   r8   Útest_non_reversible±  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°  rú  r?   r7   r7   r8   Útest_reverse_argumentsÃ  s   ÿþz)URLSpecReverseTest.test_reverse_argumentsN)rG   rH   rI   rü  rÿ  r   r7   r7   r7   r8   rù  ¬  s    rù  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<   Î  s   ýz RedirectHandlerTest.get_handlersc                 C   r  )Nr  Fr4  rþ  r7  r  r  rÁ   r7   r7   r8   Útest_basic_redirectÕ  r  z'RedirectHandlerTest.test_basic_redirectc                 C   r  )Nz/src?foo=barFr4  rþ  r7  z/dst?foo=barr  rÁ   r7   r7   r8   Útest_redirect_with_argumentÚ  r  z/RedirectHandlerTest.test_redirect_with_argumentc                 C   r  )Nz/src2?foo2=bar2Fr4  rþ  r7  z/dst2?foo=bar&foo2=bar2r  rÁ   r7   r7   r8   Ú%test_redirect_with_appending_argumentß  r  z9RedirectHandlerTest.test_redirect_with_appending_argumentc                 C   r  )Nz/a/b/cFr4  rþ  r7  z/b/a/cr  rÁ   r7   r7   r8   Útest_redirect_patternä  r  z)RedirectHandlerTest.test_redirect_patternN)rG   rH   rI   r<   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 )Ú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   r  rL   )r   Úload_gettext_translationsr1   r2   r3   r4   r5   r   )r@   r  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   rQ  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   rQ  z	fr-FR;q=0r   r  úen-USr  rÁ   r7   r7   r8   Útest_accept_language_ignore  ó   z.AcceptLanguageTest.test_accept_language_ignorec                 C   r  )NrL   rQ  z
fr-FR;q=-1r   r  r  r  rÁ   r7   r7   r8   Útest_accept_language_invalid	  r  z/AcceptLanguageTest.test_accept_language_invalidN)rG   rH   rI   rJ   r<   r  r  r  r7   r7   r7   r8   r  ê  s    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€   r  r™   r  Úemail.utilsr  r  Úior/   ra  r	  r1   r‚   rF  r€  rµ  Úurllib.parser  r9   r;   rK   rQ   r[   ÚTestCaserk   r   r   rÅ   r'  r1  r:  rA  rU  rb  ro  rŒ  r”  r™  r  rž  r¨  r¬  r³  rÁ  rÇ  rË  r  r   r:  r·  rÆ  rÏ  rÑ  rö  r  r
  r  r  r  r"  r+  r0  r6  r@  rW  r_  r\  rf  ri  r{  r}  rˆ  rŽ  r—  r·  r¾  rÇ  rÌ  rÑ  rÔ  rØ  rÛ  rÞ  ræ  rü  r  r  r   r#  r8  r>  rz  r¸  r¼  rÁ  rÇ  rÒ  rí  rð  rô  rù  r  r  r7   r7   r7   r8   Ú<module>   sü     T6/1 !0,
  	B  k%C*":/.\b
Mÿ
ÿ; + M:!?	!