
    g.                    (	   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 ZL G d de      ZM G d deM      ZN G d de'      ZO G d de'      ZP G d deIj                        ZR G d deIj                        ZS G d d eM      ZT G d! d"eM      ZU G d# d$e'      ZV G d% d&eM      ZW G d' d(e'      ZX G d) d*eM      ZY G d+ d,e'      ZZ G d- d.eM      Z[ G d/ d0e'      Z\ G d1 d2e'      Z] G d3 d4e'      Z^ G d5 d6e'      Z_ G d7 d8e'      Z` G d9 d:e'      Za G d; d<e'      Z) G d= d>e'      Zb G d? d@e'      Zc G dA dBe'      Zd G dC dDe'      Ze G dE dFeM      Zf G dG dHeM      Zg G dI dJeM      Zh G dK dLeM      Zi G dM dNeM      Zj G dO dPeM      Zk G dQ dReM      Zl G dS dTeM      Zm G dU dVeM      Zn G dW dXeM      Zo G dY dZeM      Zp G d[ d\eN      Zq G d] d^eN      Zr G d_ d`eN      Zs G da dbeN      Zt G dc ddeN      Zu G de dfeN      Zv G dg dheM      Zw G di djeN      Zx G dk dleM      Zy G dm dneN      Zz G do dpe{      Z| G dq dreN      Z} G ds dteN      Z~ G du dveN      Z G dw dxeN      Z G dy dzeN      Z G d{ d|eM      Z G d} d~eN      Z G d deN      Z G d deN      Z G d deN      Z G d deN      Z G d deM      Z G d deM      Z G d deM      Z G d deM      Z G d deM      Ze6 G d de'             Z G d de      Z G d deeM      Z G d deeM      Z G d deN      Z G d deN      Z G d deIj                        Z G d deN      Z G d deN      Z G d deN      Z G d deN      Z G d deM      Z G d deM      Z G d deN      Z G d deIj                        Z G d de      Z G d deIj                        Z G d deM      Z G d deM      Zy)    )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                      t        j                  j                  t         j                  j                  t              g|  S N)ospathjoindirname__file__)as    J/var/www/openai/venv/lib/python3.12/site-packages/tornado/test/web_test.pyrelpathr:   =   s'    77<<16A66    c                   "    e Zd ZdZd Zd Zd Zy)WebTestCasezBase 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                 t    t        | j                         fi | j                         | _        | j                  S r2   )r   get_handlersget_app_kwargsappselfs    r9   get_appzWebTestCase.get_appH   s.    t002Ld6I6I6KLxxr;   c                     t               r2   NotImplementedErrorrB   s    r9   r?   zWebTestCase.get_handlersL   s    !##r;   c                     i S r2    rB   s    r9   r@   zWebTestCase.get_app_kwargsO       	r;   N)__name__
__module____qualname____doc__rD   r?   r@   rI   r;   r9   r=   r=   A   s    $r;   r=   c                       e Zd ZdZdZd Zy)SimpleHandlerTestCasezSimplified base class for tests that work with a single handler class.

    To use, define a nested class named ``Handler``.
    Nc                      d| j                   fgS )N/HandlerrB   s    r9   r?   z"SimpleHandlerTestCase.get_handlers[   s    dll#$$r;   )rK   rL   rM   rN   rT   r?   rI   r;   r9   rP   rP   S   s    
 G%r;   rP   c                       e Zd Zd Zy)HelloHandlerc                 &    | j                  d       y NhellowriterB   s    r9   getzHelloHandler.get`   s    

7r;   NrK   rL   rM   r\   rI   r;   r9   rV   rV   _   s    r;   rV   c                   "    e Zd ZddZd ZddZy)CookieTestRequestHandlerNc                     i | _         |t        t        |            | _        y t        t        ||            | _        y )N)cookie_secret)settingsra   key_version)_cookiesr   dictapplication)rC   ra   rd   s      r9   __init__z!CookieTestRequestHandler.__init__f   s=    )M: D  *M{S Dr;   c                 8    | j                   j                  |      S r2   )re   r\   )rC   names     r9   
get_cookiez#CookieTestRequestHandler.get_cookier   s    }}  &&r;   c                 "    || j                   |<   y r2   )re   )rC   rj   valueexpires_dayss       r9   
set_cookiez#CookieTestRequestHandler.set_cookieu   s    #dr;   )
0123456789Nr2   )rK   rL   rM   rh   rk   ro   rI   r;   r9   r_   r_   d   s    
'$r;   r_   c                       e Zd Zd Zd Zd Zy)SecureCookieV1Testc                     t               }|j                  ddd       | j                  |j                  dd      d       y )Nfoo   bar   versionmin_versionr_   set_signed_cookieassertEqualget_signed_cookierC   handlers     r9   test_round_tripz"SecureCookieV1Test.test_round_trip{   ?    *,!!%!;225a2H&Qr;   c           	         t               }|j                  dt        j                  d      d       |j                  d   }t        j                  d|      }|J |j                  d      }|j                  d      }| j                  t        |j                  j                  d   dd|      |       | j                  t        |j                  j                  d   dd	d
|z         |       t        dt        |      dt        |            |j                  d<   t        t        d      5  | j!                  |j#                  dd      d u        d d d        y # 1 sw Y   y xY w)Nrt   s   d76df8e7aefcrv   rw   s   12345678\|([0-9]+)\|([0-9a-f]+)   ra   123456781234s   5678z	1234|5678|zCookie timestamp in futurery   )r_   r|   binasciia2b_hexre   rematchgroupr}   r&   rg   rb   r   r
   r   r   
assertTruer~   )rC   r   cookier   	timestampsigs         r9   &test_cookie_tampering_future_timestampz9SecureCookieV1Test.test_cookie_tampering_future_timestamp   sL   *,!!%)9)9/)JTU!V!!%(<fE   KKN	kk!n ##,,_=	 	
 	 ##,,_=)#	 	
 #' -i 8-:LM#
 w <=OOG55e5KtST >==s   *%EE!c                     t               }|j                  ddd       | j                  |j                  dd      d       y )Nrt      rv   rw   ry   r{   r   s     r9   test_arbitrary_bytesz'SecureCookieV1Test.test_arbitrary_bytes   sA     +,!!%!!<225a2H'Rr;   N)rK   rL   rM   r   r   r   rI   r;   r9   rr   rr   z   s    R
$ULSr;   rr   c                   4    e Zd ZdddZd Zd Zd Zd Zd Zy	)
SecureCookieV2Testajklasdf0ojaisdfaslkjasaolwkjsdf)r   rv   c                     t               }|j                  ddd       | j                  |j                  dd      d       y )Nrt   ru   r   rw   ry   r{   r   s     r9   r   z"SecureCookieV2Test.test_round_trip   r   r;   c                     t        | j                  d      }|j                  dd       | j                  |j	                  d      d       y )Nr   rc   rt   ru   r_   KEY_VERSIONSr|   r}   r~   r   s     r9   test_key_version_roundtripz-SecureCookieV2Test.test_key_version_roundtrip   D    *++
 	!!%022596Br;   c                     t        | j                  d      }|j                  dd       | j                  |j	                  d      d       y )Nrv   rc   rt   ru   r   r   s     r9   ,test_key_version_roundtrip_differing_versionz?SecureCookieV2Test.test_key_version_roundtrip_differing_version   r   r;   c                     t        | j                  d      }|j                  dd       t        | j                  d      }|j                  |_        | j	                  |j                  d      d       y Nr   rc   rt   ru   rv   )r_   r   r|   re   r}   r~   )rC   r   new_handlers      r9   "test_key_version_increment_versionz5SecureCookieV2Test.test_key_version_increment_version   si    *++
 	!!%0.++
  '//66u=vFr;   c                 *   t        | j                  d      }|j                  dd       | j                  j                         }|j	                  d       t        |d      }|j
                  |_        | j                  |j                  d      d        y r   )r_   r   r|   copypopre   r}   r~   )rC   r   new_key_versionsr   s       r9   #test_key_version_invalidate_versionz6SecureCookieV2Test.test_key_version_invalidate_version   s    *++
 	!!%0,,113Q.*
  '//66u=tDr;   N)	rK   rL   rM   r   r   r   r   r   r   rI   r;   r9   r   r      s+    ).@ALR
CC	GEr;   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)FinalReturnTestNc                 \    |  G fddt               } G fddt               }d|fd|fgS )Nc                   ^    e Zd Zej                   fd       Zej                   fd       Zy)3FinalReturnTest.get_handlers.<locals>.FinishHandlerc              3   T   K   | j                         _        j                   y wr2   )finishfinal_returnrC   tests    r9   r\   z7FinalReturnTest.get_handlers.<locals>.FinishHandler.get   s!     $(KKM!'''s   %(c              3      K   | j                  d       | j                          | j                  d      _        j                   y w)Nzhello,world)r[   flushr   r   r   s    r9   postz8FinalReturnTest.get_handlers.<locals>.FinishHandler.post   s<     

8$jjl"$(KK$8!'''s   A	AN)rK   rL   rM   r   	coroutiner\   r   r   s   r9   FinishHandlerr      s1    ]]( ( ]]( (r;   r   c                   <    e Zd Zd Zej
                   fd       Zy)3FinalReturnTest.get_handlers.<locals>.RenderHandlerc                     t        ddi      S )Nfoo.htmlhir   rC   r4   s     r9   create_template_loaderzJFinalReturnTest.get_handlers.<locals>.RenderHandler.create_template_loader   s    !:t"455r;   c                 2    | j                  d      _        y Nr   )renderr   r   s    r9   r\   z7FinalReturnTest.get_handlers.<locals>.RenderHandler.get   s    $(KK
$;!r;   N)rK   rL   rM   r   r   r   r\   r   s   r9   RenderHandlerr      s     6 ]]< <r;   r   /finish/renderr   )rC   r   r   r   s      @r9   r?   zFinalReturnTest.get_handlers   s7    	(N 	(	<N 	< M*Y,FGGr;   c                     t        d      S )Nr   )template_pathrf   rB   s    r9   r@   zFinalReturnTest.get_app_kwargs   s    "344r;   c                    | j                  | j                  d            }| j                  |j                  d       | j	                  | j
                  t               | j                  | j
                  j                                | j                  | j                  d      dd      }| j                  |j                  d       | j	                  | j
                  t               | j                  | j
                  j                                y )Nr      POSTr;   methodbody)	fetchget_urlr}   codeassertIsInstancer   r   r   donerC   responses     r9    test_finish_method_return_futurez0FinalReturnTest.test_finish_method_return_future   s    ::dll956,d//8))..01::dll95f3:O,d//8))..01r;   c                     | j                  | j                  d            }| j                  |j                  d       | j	                  | j
                  t               y )Nr   r   )r   r   r}   r   r   r   r   r   s     r9    test_render_method_return_futurez0FinalReturnTest.test_render_method_return_future	  sC    ::dll956,d//8r;   )rK   rL   rM   r   r?   r@   r   r   rI   r;   r9   r   r      s    LH45	29r;   r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)
CookieTestc           
      J    G d dt               } G d dt               } G d dt               } G d dt               } G d	 d
t               } G d dt               } G d dt               } G d dt               } G d dt               }	d|fd|fd|fd|fd|fd|fd|fd|fd|	fg	S )Nc                       e Zd Zd Zy)1CookieTest.get_handlers.<locals>.SetCookieHandlerc                 p    | j                  dd       | j                  dd       | j                  dd       y )Nstrasdfunicodeqwerbytess   zxcvro   rB   s    r9   r\   z5CookieTest.get_handlers.<locals>.SetCookieHandler.get  s.     v.	621r;   Nr]   rI   r;   r9   SetCookieHandlerr     s    2r;   r   c                       e Zd Zd Zy)1CookieTest.get_handlers.<locals>.GetCookieHandlerc                 R    | j                  dd      }|J | j                  |       y )Nrt   default)rk   r[   )rC   r   s     r9   r\   z5CookieTest.get_handlers.<locals>.GetCookieHandler.get  s*    	:)))

6"r;   Nr]   rI   r;   r9   GetCookieHandlerr     s    #r;   r   c                       e Zd Zd Zy)7CookieTest.get_handlers.<locals>.SetCookieDomainHandlerc                 .    | j                  dddd       y )Nunicode_argsblahzfoo.com/foo)domainr4   r   rB   s    r9   r\   z;CookieTest.get_handlers.<locals>.SetCookieDomainHandler.get   s     yvVr;   Nr]   rI   r;   r9   SetCookieDomainHandlerr     s    Wr;   r   c                       e Zd Zd Zy)<CookieTest.get_handlers.<locals>.SetCookieSpecialCharHandlerc                 p    | j                  dd       | j                  dd       | j                  dd       y )Nequalsa=b	semicolona;bquotea"br   rB   s    r9   r\   z@CookieTest.get_handlers.<locals>.SetCookieSpecialCharHandler.get&  s,    %0U3/r;   Nr]   rI   r;   r9   SetCookieSpecialCharHandlerr   %  s    0r;   r   c                       e Zd Zd Zy):CookieTest.get_handlers.<locals>.SetCookieOverwriteHandlerc                 x    | j                  ddd       | j                  ddd       | j                  dd       y )Nr8   bzexample.com)r   cder   rB   s    r9   r\   z>CookieTest.get_handlers.<locals>.SetCookieOverwriteHandler.get,  s6    S?S? S)r;   Nr]   rI   r;   r9   SetCookieOverwriteHandlerr  +  s    *r;   r  c                       e Zd Zd Zy)7CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandlerc                 ,    | j                  ddd       y )Nrt   bar
   )max_ager   rB   s    r9   r\   z;CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandler.get4  s    ub9r;   Nr]   rI   r;   r9   SetCookieMaxAgeHandlerr	  3  s    :r;   r  c                       e Zd Zd Zy)<CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandlerc                 ,    | j                  ddd       y )Nrt   r  r  )rn   r   rB   s    r9   r\   z@CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandler.get8  s    u2>r;   Nr]   rI   r;   r9   SetCookieExpiresDaysHandlerr  7  s    ?r;   r  c                       e Zd Zd Zy)4CookieTest.get_handlers.<locals>.SetCookieFalsyFlagsc                     | j                  ddd       | j                  ddd       | j                  ddd       | j                  d	dd       y )
Nr8   1T)securer  Fr  )httponlyr  r   rB   s    r9   r\   z8CookieTest.get_handlers.<locals>.SetCookieFalsyFlags.get<  sJ    S6S7S48S59r;   Nr]   rI   r;   r9   SetCookieFalsyFlagsr  ;  s    :r;   r  c                       e Zd Zd Zy)8CookieTest.get_handlers.<locals>.SetCookieDeprecatedArgsc                 .    | j                  dddd       y )Nr8   r  Tr   )HttpOnlypATHr   rB   s    r9   r\   z<CookieTest.get_handlers.<locals>.SetCookieDeprecatedArgs.getC  s    S4fEr;   Nr]   rI   r;   r9   SetCookieDeprecatedArgsr  B  s    Fr;   r  /set/get/set_domain/special_char/set_overwrite/set_max_age/set_expires_days/set_falsy_flags/set_deprecatedr   )
rC   r   r   r   r   r  r  r  r  r  s
             r9   r?   zCookieTest.get_handlers  s    	2~ 	2	#~ 	#	W^ 	W	0. 	0	* 	*	:^ 	:	?. 	?	:. 	:	Fn 	F %&%&239:8934 "=>!45 78

 
	
r;   c                     | j                  d      }| j                  t        |j                  j	                  d            g d       y )Nr   
Set-Cookie)zbytes=zxcv; Path=/zstr=asdf; Path=/zunicode=qwer; Path=/)r   r}   sortedheadersget_listr   s     r9   test_set_cookiezCookieTest.test_set_cookieS  s:    ::f%8##,,\:;N	
r;   c                 *   | j                  dddi      }| j                  |j                  d       | j                  dddi      }| j                  |j                  d       | j                  dddi      }| j                  |j                  d       y )	Nr!  Cookiefoo=barr,  ru   z	foo="bar"z/=exception;   defaultr   r}   r   r   s     r9   test_get_cookiezCookieTest.test_get_cookieZ  s    ::fx.C:D/::fx.E:F/::fx.H:I
3r;   c                 ~    | j                  d      }| j                  |j                  j                  d      dg       y )Nr"  r*  z,unicode_args=blah; Domain=foo.com; Path=/foor   r}   r,  r-  r   s     r9   test_set_cookie_domainz!CookieTest.test_set_cookie_domaind  s8    ::m,%%l3;<	
r;   c                    | j                  d      }t        |j                  j                  d            }| j	                  t        |      d       | j	                  |d   d       | j	                  |d   d       | j                  |d   d	v |d          g d
}|D ]U  \  }}t        j                  d|       | j                  dd|i      }| j	                  |j                  t        |             W y )Nr#  r*     r   zequals="a=b"; Path=/rv   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!  r0  r2  )r   r+  r,  r-  r}   lenr   loggingdebugr   r   )rC   r   r,  dataheaderexpecteds         r9   test_cookie_special_charz#CookieTest.test_cookie_special_chark  s    ::o.))22<@AWq)%;<%<=AJTTAJ	


 !%FHMM+v.zz&8V2DzEHX]]DN; !%r;   c                     | j                  d      }|j                  j                  d      }| j                  t	        |      ddg       y )Nr$  r*  za=e; Path=/zc=d; Domain=example.com; Path=/r   r,  r-  r}   r+  rC   r   r,  s      r9   test_set_cookie_overwritez$CookieTest.test_set_cookie_overwrite  sD    ::./""++L97Om-NO	
r;   c                     | j                  d      }|j                  j                  d      }| j                  t	        |      dg       y )Nr%  r*  zfoo=bar; Max-Age=10; Path=/rC  rD  s      r9   test_set_cookie_max_agez"CookieTest.test_set_cookie_max_age  s>    ::n-""++L9+H*IJr;   c                    | j                  d      }|j                  j                  d      }|J t        j                  d|      }|J t
        j
                  j                  t
        j                  j                        t        j                  d      z   }t        j                  j                  |j                         d         }| j                  t        ||z
  j!                               dk         y )Nr&  r*  z(foo=bar; expires=(?P<expires>.+); Path=/r  daysexpires)r   r,  r\   r   r   datetimenowtimezoneutc	timedeltaemailutilsparsedate_to_datetime	groupdictr   abstotal_secondsrC   r   r?  r   rK  header_expiress         r9   test_set_cookie_expires_daysz'CookieTest.test_set_cookie_expires_days  s    ::12!!%%l3!!!CVL   ##''(9(9(=(=>ASASB
 
 ::5??;LY;WXW~5DDFG"LMr;   c                    | j                  d      }t        |j                  j                  d            }| j	                  |d   j                         d       | j	                  |d   j                         d       | j	                  |d   j                         d       | j	                  |d	   j                         d
       y )Nr'  r*  r   za=1; path=/; securerv   zb=1; path=/r   zc=1; httponly; path=/r:  zd=1; path=/)r   r+  r,  r-  r}   lowerrD  s      r9   test_set_cookie_false_flagsz&CookieTest.test_set_cookie_false_flags  s    ::01))22<@A 	))+-BC))+];))+-DE))+];r;   c                     t               5  | j                  d      }d d d        j                  j                  d      }| j	                  |d       y # 1 sw Y   7xY w)Nr(  r*  za=b; HttpOnly; Path=/foo)r   r   r,  r\   r}   )rC   r   r?  s      r9   test_set_cookie_deprecatedz%CookieTest.test_set_cookie_deprecated  sL    !zz"34H "!!%%l3!;< "!s   AAN)rK   rL   rM   r?   r.  r5  r8  rA  rE  rG  rY  r\  r^  rI   r;   r9   r   r     s8    A
F
4
<2
K
N<=r;   r   c                   (    e Zd Zd Zd Zed        Zy)AuthRedirectRequestHandlerc                     || _         y r2   	login_url)rC   rc  s     r9   
initializez%AuthRedirectRequestHandler.initialize  s	    "r;   c                     | j                   S r2   rb  rB   s    r9   get_login_urlz(AuthRedirectRequestHandler.get_login_url  s    ~~r;   c                 &    | j                  d       y )N  )
send_errorrB   s    r9   r\   zAuthRedirectRequestHandler.get  s     	r;   N)rK   rL   rM   rd  rf  r$   r\   rI   r;   r9   r`  r`    s     #  r;   r`  c                       e Zd Zd Zd Zd Zy)AuthRedirectTestc                 N    dt         t        d      fdt         t        d      fgS )N	/relativez/loginrb  	/absolutezhttp://example.com/login)r`  rf   rB   s    r9   r?   zAuthRedirectTest.get_handlers  s0    4dX6NO*9:
 	
r;   c                     | j                  | j                  d      d      }| j                  |j                  d       | j                  |j                  d   d       y )Nrm  Ffollow_redirects.  Locationz/login?next=%2Frelative)r   r   r}   r   r,  r   s     r9   test_relative_auth_redirectz,AuthRedirectTest.test_relative_auth_redirect  sM    ::dll;7%:P,))*57PQr;   c                     | j                  | j                  d      d      }| j                  |j                  d       | j	                  t        j                  d|j                  d         |j                  d          y )Nrn  Frp  rr  zIhttp://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2Fabsoluters  )r   r   r}   r   r   r   r   r,  r   s     r9   test_absolute_auth_redirectz,AuthRedirectTest.test_absolute_auth_redirect  sj    ::dll;7%:P,HH\  , Z(	
r;   N)rK   rL   rM   r?   rt  rv  rI   r;   r9   rk  rk    s    
R
	
r;   rk  c                   <    e Zd Zd Zej
                  d        Zd Zy)ConnectionCloseHandlerc                     || _         y r2   r   r   s     r9   rd  z!ConnectionCloseHandler.initialize  s	    	r;   c              #      K   | j                   j                          | j                   j                  j                          y wr2   )r   on_handler_waitingcleanup_eventwaitrB   s    r9   r\   zConnectionCloseHandler.get  s/     		$$&ii%%**,,   AAc                 8    | j                   j                          y r2   )r   on_connection_closerB   s    r9   r  z*ConnectionCloseHandler.on_connection_close  s    		%%'r;   N)rK   rL   rM   rd  r   r   r\   r  rI   r;   r9   rx  rx    s$     	]]- -(r;   rx  c                   $    e Zd Zd Zd Zd Zd Zy)ConnectionCloseTestc                 H    t               | _        dt        t        |       fgS )NrR   r   )r   r|  rx  rf   rB   s    r9   r?   z ConnectionCloseTest.get_handlers  s!    "W,do>??r;   c                    t        j                   t         j                  t         j                  d      }|j                  d| j	                         f       t        |      | _        | j                  j                  d       | j                          | j                  j                          | j                  j                  d        y )Nr   	127.0.0.1s   GET / HTTP/1.0

c                  ,    t        j                  d      S Nr   )r   sleeprI   r;   r9   <lambda>z;ConnectionCloseTest.test_connection_close.<locals>.<lambda>  s    ciilr;   )socketAF_INETSOCK_STREAMconnectget_http_portr   streamr[   r}  r|  setio_looprun_sync)rC   ss     r9   test_connection_closez)ConnectionCloseTest.test_connection_close  s    MM&..&*<*<a@			; 2 2 456qk34		 23r;   c                 b    t        j                  d       | j                  j                          y )Nzhandler waiting)r<  r=  r  closerB   s    r9   r{  z&ConnectionCloseTest.on_handler_waiting  s    '(r;   c                 N    t        j                  d       | j                          y )Nzconnection closed)r<  r=  stoprB   s    r9   r  z'ConnectionCloseTest.on_connection_close  s    )*		r;   N)rK   rL   rM   r?   r  r{  r  rI   r;   r9   r  r    s    @4r;   r  c                       e Zd Zd Zy)EchoHandlerc           	         | j                   j                  D ]  }t        |      t        k7  rt	        dt        |      z        | j                   j                  |   D ]+  }t        |      t
        k7  st	        dt        |      z         | j                  |      D ]+  }t        |      t        k7  st	        dt        |      z          |D ]+  }t        |      t        k7  st	        dt        |      z         | j                  t        | j                   j                  |t        | j                   j                                     y )Nzincorrect type for key: %rzincorrect type for value: %rzincorrect type for path arg: %rr4   	path_argsargs)request	argumentstyper   	Exceptionr   get_argumentsr   r[   rf   r4   r   )rC   r  keybvaluesvalueargs         r9   r\   zEchoHandler.get  s   
 <<))CCyC <tCy HII,,005<5(#$BT&\$QRR 6 ,,S1<</#$BT&\$QRR 2 * CCyL( ADI MNN  	

\\&&#&t||'='=>	
r;   Nr]   rI   r;   r9   r  r    s    
r;   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)RequestEncodingTestc                 "    dt         fdt         fgS )Nz/group/(.*)z/slashes/([^/]*)/([^/]*))r  rB   s    r9   r?   z RequestEncodingTest.get_handlers  s    ,/I;.WXXr;   c                 J    t        | j                  |      j                        S r2   )r   r   r   r   s     r9   
fetch_jsonzRequestEncodingTest.fetch_json  s    4::d+0011r;   c           	          | j                  | j                  d      t        ddgi              | j                  | j                  d      t        ddgddgi             y )Nz
/group/%3F?r  z/group/%3F?%3F=%3Fr}   r  rf   rB   s    r9   test_group_question_markz,RequestEncodingTest.test_group_question_mark  s[    OOL)lse"=	
 	OO01lse3,G	
r;   c                 V    | j                  | j                  d      ddgddgid       y )Nz/group/%C3%A9?arg=%C3%A9z/group/%C3%A9   ér  r  r}   r  rB   s    r9   test_group_encodingz'RequestEncodingTest.test_group_encoding)  s4    OO67'&Z
+	
r;   c                     | j                  | j                  d      t        dddgi              | j                  | j                  d      t        dddgi              y )Nz/slashes/foo/barrt   r  r  z/slashes/a%2Fb/c%2Fdza/bzc/dr  rB   s    r9   test_slashesz RequestEncodingTest.test_slashes4  s^     	OO./(UENL	
 	OO23,RP	
r;   c                 p    t        t        d      5  | j                  d       d d d        y # 1 sw Y   y xY w)Nz.*Invalid unicodez/group/?arg=%25%e9)r   r   r   rB   s    r9   
test_errorzRequestEncodingTest.test_error@  s(     w 34JJ+, 544   ,5N)	rK   rL   rM   r?   r  r  r  r  r  rI   r;   r9   r  r    s!    Y2	
	


-r;   r  c                   $    e Zd Zd Zd Zd Zd Zy)TypeCheckHandlerc                    i | _         | j                  d| j                         t               | j                  d| j	                  d      t
               | j                  dt        | j                  j                               d   t               | j                  dt        | j                  j                               d   j                  t               t        | j                  j                               dgk7  r&t        d| j                  j                         z        | j                  d	| j                  d      t               | j                  d
| j                  d      t               | j                  d| j                   t               | j                  d| j#                         t               | j                  d| j%                  dd      t               | j                  d| j'                         t               y )Nstatusargumentrt   
cookie_keyr   cookie_valuer   z%unexpected values for cookie keys: %rr~   rk   
xsrf_tokenxsrf_form_htmlreverse_url	typecheckrequest_summary)errors
check_type
get_statusintget_argumentr   listcookieskeysr   valuesrm   r  r~   r   rk   r  r  r  _request_summaryrB   s    r9   preparezTypeCheckHandler.prepareH  sm   $//"3S9 	
D$5$5e$<lKd4<<+<+<+>&?&BCHT\\-@-@-B(CA(F(L(LcR !!#$07$,,:K:K:MM  	+T-C-CF-KUSdoof&=sCdoou=($*=*=*?Et'7'7U'KSQ)4+@+@+BCHr;   c                 h    | j                  d|t               | j                  | j                         y Npath_componentr  r   r[   r  rC   r  s     r9   r\   zTypeCheckHandler.getc  s%     	(.,G

4;;r;   c                 h    | j                  d|t               | j                  | j                         y r  r  r  s     r9   r   zTypeCheckHandler.posti  s#    (.,G

4;;r;   c                 P    t        |      }||k7  rd|d|| j                  |<   y y )Nz	expected z, got )r  r  )rC   rj   objexpected_typeactual_types        r9   r  zTypeCheckHandler.check_typem  s+    3iK'9F TDKK (r;   N)rK   rL   rM   r  r\   r   r  rI   r;   r9   r  r  G  s    I6  Ur;   r  c                       e Zd ZddZd Zy)DecodeArgHandlerNc                     t        |      t        k7  rt        dt        |      z        d| j                  j                  v r4|j                  t        | j                  j                  d   d               S |S )Nzunexpected type for value: %rencodingr   )r  r   r  r  r  decoder   )rC   rm   rj   s      r9   decode_argumentz DecodeArgHandler.decode_argumentt  sb    ;%;d5kIJJ///<<
4<<+A+A*+Ma+P QRRLr;   c                 h    d }| j                   ||       || j                  d            d       y )Nc                     t        |       t        k(  r dt        t        j                  |             gS t        |       t
        k(  rd| gS t        d      )Nr   r   zunknown type)r  r   r	   r   b2a_hexr   r  )r  s    r9   describez&DecodeArgHandler.get.<locals>.describe~  sJ    Aw%H,<,<Q,?!@AAaL(!1~%N++r;   rt   r4   query)r[   r  )rC   r  r  s      r9   r\   zDecodeArgHandler.get}  s.    	, 	

HSMHT=N=Nu=U4VWXr;   r2   )rK   rL   rM   r  r\   rI   r;   r9   r  r  s  s    Yr;   r  c                       e Zd Zd Zy)LinkifyHandlerc                 *    | j                  dd       y )Nlinkify.htmlzhttp://example.com)messager   rB   s    r9   r\   zLinkifyHandler.get  s    N,@Ar;   Nr]   rI   r;   r9   r  r    s    Br;   r  c                       e Zd Zd Zy)UIModuleResourceHandlerc                 .    | j                  dddg       y )N	page.htmlrv   r   )entriesr  rB   s    r9   r\   zUIModuleResourceHandler.get  s    K!Q0r;   Nr]   rI   r;   r9   r  r    s    1r;   r  c                       e Zd Zd Zy)OptionalPathHandlerc                 *    | j                  d|i       y )Nr4   rZ   r   s     r9   r\   zOptionalPathHandler.get  s    

FD>"r;   Nr]   rI   r;   r9   r  r    s    #r;   r  c                       e Zd Zd Zy)MultiHeaderHandlerc                     | j                  dd       | j                  dd       | j                  dd       | j                  dd       y )	Nx-overwriter  zX-Overwriter   x-multir:  zX-Multi4)
set_header
add_headerrB   s    r9   r\   zMultiHeaderHandler.get  s:    s+q)	1%	3'r;   Nr]   rI   r;   r9   r  r    s    (r;   r  c                       e Zd Zd Zy)r    c           
      "   | j                  dd       5| j                  dt        t        | j                  d                         y | j                  dd       ,| j                  dt        | j                  d                   y t	        d      )N	permanentrR   )r  r  )r  z(didn't get permanent or status arguments)r  redirectboolr  r  rB   s    r9   r\   zRedirectHandler.get  sy    [$/;MM#c$2C2CK2P.Q)RMSx.:MM#c$*;*;H*E&FMGFGGr;   Nr]   rI   r;   r9   r    r      s    Hr;   r    c                   0    e Zd Zej                  d        Zy)EmptyFlushCallbackHandlerc              #      K   | j                          | j                          | j                  d       | j                          | j                          | j                  d       y w)Nok)r   r[   r   rB   s    r9   r\   zEmptyFlushCallbackHandler.get  sO     
 jjljjl

3jjljjlCs   A,A.N)rK   rL   rM   r   r   r\   rI   r;   r9   r  r    s    ]]	 	r;   r  c                       e Zd Zd Zy)HeaderInjectionHandlerc                     	 | j                  dd       t        d      # t        $ r*}dt        |      v r| j	                  d       n Y d }~y d }~ww xY w)NzX-Foozfoo
X-Bar: bazzDidn't get expected exceptionzUnsafe header value   ok)r  r  
ValueErrorr   r   rC   r  s     r9   r\   zHeaderInjectionHandler.get  sR    	OOG%89;<< 	$A.E" #	s    	A AANr]   rI   r;   r9   r  r    s    r;   r  c                       e Zd Zd Zy)GetArgumentHandlerc                     | j                  dd       dk(  r| j                  }n.| j                  dd       dk(  r| j                  }n| j                   }| j                   |dd             y )Nsourcer  r   rt   r   )r  get_query_argumentget_body_argumentr   rC   r   s     r9   r  zGetArgumentHandler.prepare  s`    Xt,7,,Fx.&8++F&&FF5),-r;   NrK   rL   rM   r  rI   r;   r9   r  r    s    .r;   r  c                       e Zd Zd Zy)GetArgumentsHandlerc           	          | j                  t        | j                  d      | j                  d      | j	                  d                   y )Nrt   r   r  r   )r   rf   r  get_query_argumentsget_body_argumentsrB   s    r9   r  zGetArgumentsHandler.prepare  s@    **51..u5,,U3	
r;   Nr  rI   r;   r9   r  r    s    
r;   r  c                        e Zd ZdZd Z fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )WSGISafeWebTestzWebTest.COOKIE_SECRETc                 P    t        dddd      }t        |d| j                        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
autoescapera   )r   rf   COOKIE_SECRET)rC   loaders     r9   r@   zWSGISafeWebTest.get_app_kwargs  s<     ? 
& "%,,
 	
r;   c                 ^    t         |           t        j                  j	                          y r2   supertearDownr   _template_loadersclearrC   	__class__s    r9   r&  zWSGISafeWebTest.tearDown       ((..0r;   c                    t        dt        d      t        dt        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              g}|S )Nz/typecheck/(.*)r  )rj   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)r%   r  r  r  r  r  r  r    WebRedirectHandlerr  r  r  )rC   urlss     r9   r?   zWSGISafeWebTest.get_handlers  s    !#3+F"$4<H,.>?
N+%'>?&(;<!34_-)"/0
 "/eD
 -"/0
 #%;<!34 "565
8 r;   c                 p     | j                   |i |}|j                          t        |j                        S r2   )r   rethrowr   r   )rC   r  kwargsr   s       r9   r  zWSGISafeWebTest.fetch_json  s2    4::t.v.8==))r;   c                     t        t        | j                  dd            }| j                  ddd|z   i      }t	        |j
                        }| j                  |i        | j                  dddd|z   id	      }y )
Nr   r   z/typecheck/asdf?foo=barr0  zasdf=r2  r   r1  r   r,  r   )r   r'   r!  r   r   r   r}   )rC   r  r   r>  s       r9   
test_typeszWSGISafeWebTest.test_types  s    ! 2 2FFC
 ::%'L:P/Q  
 8==)r"::%w56	  
r;   c                 V   g d}|D ]Q  }| j                  |      }|j                          t        |j                        }| j	                  |ddgddgd       S | j                  d      }|j                          t        |j                        }| j	                  |ddgddgd       y )N)z,/decode_arg/%C3%A9?foo=%C3%A9&encoding=utf-8z'/decode_arg/%E9?foo=%E9&encoding=latin1z*/decode_arg_kw/%E9?foo=%E9&encoding=latin1r   r  r  z/decode_arg/%C3%A9?foo=%C3%A9r   c3a9r   r:  r   r   r}   rC   r8  req_urlr   r>  s        r9   test_decode_argumentz$WSGISafeWebTest.test_decode_argument0  s    

 Gzz'*Hx}}-D#X.)X9NO	  ::=>8==)&(9WfDUVWr;   c                    t        t        d      5  | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)Nz.*Invalid unicode.*z/typecheck/invalid%FFi  z/typecheck/invalid?foo=%FFr   r   r   r}   r   r   s     r9   $test_decode_argument_invalid_unicodez4WSGISafeWebTest.test_decode_argument_invalid_unicodeE  s_    w 56zz"9:HX]]C0zz">?HX]]C0	 766s   AA55A>c                     ddg}|D ]Q  }| j                  |      }|j                          t        |j                        }| j	                  |ddgddgd       S y )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  rA  rB  s        r9   test_decode_argument_plusz)WSGISafeWebTest.test_decode_argument_plusM  si     E>
 Gzz'*Hx}}-D#W-G8LM	 r;   c                    | j                  | j                  j                  dd      d       | j                  | j                  j                  dd      d       | j                  | j                  j                  dd      d       | j                  | j                  j                  dd      d	       | j                  | j                  j                  dd
      d       y )Nr-  rt   z/decode_arg/foo*   z/decode_arg/42r   z/decode_arg/%E9r  z/decode_arg/%C3%A9rI  z/decode_arg/1%20%2B%201)r}   rA   r  rB   s    r9   test_reverse_urlz WSGISafeWebTest.test_reverse_url\  s    --lEBDUV--lB?AQR--lGDFWXHH  x8:N	
 	HH  w79R	
r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr.  s3   <a href="http://example.com">http://example.com</a>r4  r   s     r9   test_uimodule_unescapedz'WSGISafeWebTest.test_uimodule_unescapedg  s(    ::j)MMQ	
r;   c                 ^    | j                  d      }| j                  |j                  d       y )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>r4  r   s     r9   test_uimodule_resourcesz'WSGISafeWebTest.test_uimodule_resourcesm  s+    ::34MM	
r;   c                     | j                  | j                  d      ddi       | j                  | j                  d      dd i       y )Nz/optional_path/foor4   rt   z/optional_path/r  rB   s    r9   test_optional_pathz"WSGISafeWebTest.test_optional_path  s>    )=>P):;fd^Lr;   c                     | j                  d      }| j                  |j                  d   d       | j                  |j                  j                  d      ddg       y )Nr0  r  2r  3r  r7  r   s     r9   test_multi_headerz!WSGISafeWebTest.test_multi_header  sP    ::o.))-8#>))229=SzJr;   c                    | j                  dd      }| j                  |j                  d       | j                  dd      }| j                  |j                  d       | j                  dd      }| j                  |j                  d       y )	Nz/redirect?permanent=1Frp  -  z/redirect?permanent=0rr  z/redirect?status=307i3  r   r}   r   r   s     r9   test_redirectzWSGISafeWebTest.test_redirect  sw    ::5:N,::5:N,::4u:M,r;   c                 <   | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )	Nr1  Frp  rY  rs  r2  r3  rr  r   r}   r   r,  r   s     r9   test_web_redirectz!WSGISafeWebTest.test_web_redirect  s    ::7%:P,))*57NO::o:F,))*57NOr;   c                     | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )Nr4  Frp  rY  rs  r2  r]  r   s     r9   test_web_redirect_double_slashz.WSGISafeWebTest.test_web_redirect_double_slash  sE    ::;e:T,))*57NOr;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr5  r
  r4  r   s     r9   test_header_injectionz%WSGISafeWebTest.test_header_injection  s%    ::12.r;   c                 V   | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       t        j                  j                  t        d            }| j                  dd	|
      }| j                  |j                  d       | j                  dd	|
      }| j                  t        |j                        t        ddgdgdg             y )Nz/get_argument?foo=barru   z/get_argument?foo=r;   r6  r3  rY   rt   r   r      helloz/get_arguments?foo=barr  r  )r   r}   r   urllibparse	urlencoderf   r   )rC   r   r   s      r9   test_get_argumentz!WSGISafeWebTest.test_get_argument  s    ::56/::23,::o.
3 ||%%dw&78::5f4:P1::6vD:Q&%)%yI	
r;   c                 v   t         j                  j                  t        d            }| j	                  dd|      }| j                  |j                  d       | j	                  dd|      }| j                  |j                  d       | j	                  d	d|      }| j                  |j                  d
       y )NrY   rd  z"/get_argument?source=query&foo=barr   r   ru   z/get_argument?source=query&foo=r;   z/get_argument?source=queryr3  rf  rg  rh  rf   r   r}   r   rC   r   r   s      r9   test_get_query_argumentsz(WSGISafeWebTest.test_get_query_arguments  s     ||%%dw&78::0d  
 	/::-f4  
 	,:::6PT:U
3r;   c                    t         j                  j                  t        d            }| j	                  dd|      }| j                  |j                  d       t         j                  j                  t        d            }| j	                  dd|      }| j                  |j                  d       t         j                  j                  t                     }| j	                  dd|      }| j                  |j                  d	       y )
Nr  rd  z#/get_argument?source=body&foo=hellor   r   ru    r;   r3  rk  rl  s      r9   test_get_body_argumentsz'WSGISafeWebTest.test_get_body_arguments  s    ||%%duo6::1&t  
 	/||%%drl3::1&t  
 	,||%%df-::1&t  
 	
3r;   c                     | j                  d      }| j                  d|j                  j                  dd             | j                  d|j                  j                  dd             y )Nr6  Accept-EncodingVaryro  gzipContent-Encoding)r   assertNotInr,  r\   r   s     r9   test_no_gzipzWSGISafeWebTest.test_no_gzip  sX    ::o.*H,<,<,@,@,LM!1!1!5!56H"!MNr;   )rK   rL   rM   r!  r@   r&  r?   r  r>  rD  rG  rJ  rM  rO  rQ  rS  rW  r[  r^  r`  rb  ri  rm  rp  rw  __classcell__r*  s   @r9   r  r    sw    +M
41>*

"X*1	


8MK
-PP
/
(44&Or;   r  c                       e Zd Zd Zd Zy)NonWSGIWebTestsc                     dt         fgS )N/empty_flush)r  rB   s    r9   r?   zNonWSGIWebTests.get_handlers  s    !:;<<r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr}  r
  r4  r   s     r9   test_empty_flushz NonWSGIWebTests.test_empty_flush  s$    ::n-.r;   N)rK   rL   rM   r?   r  rI   r;   r9   r{  r{    s    =/r;   r{  c                   $    e Zd Zd Zd Zd Zd Zy)ErrorResponseTestc                      G d dt               } G d dt               } G d dt               }t        d|      t        d|      t        d	|      gS )
Nc                       e Zd Zd Zy)6ErrorResponseTest.get_handlers.<locals>.DefaultHandlerc                 x    | j                  dd       r#t        t        | j                  d                  ddz   y Nr  rv   r   )r  r!   r  rB   s    r9   r\   z:ErrorResponseTest.get_handlers.<locals>.DefaultHandler.get  s4    $$Xt4#C(9(9((C$DEEAr;   Nr]   rI   r;   r9   DefaultHandlerr    s    r;   r  c                       e Zd Zd Zd Zy)9ErrorResponseTest.get_handlers.<locals>.WriteErrorHandlerc                     | j                  dd       r*| j                  t        | j                  d                   y ddz   y r  )r  ri  r  rB   s    r9   r\   z=ErrorResponseTest.get_handlers.<locals>.WriteErrorHandler.get  s5    $$Xt4OOC(9(9((C$DEEr;   c                     | j                  dd       d|v r%| j                  d|d   d   j                  z         y | j                  d|z         y )NContent-Type
text/plainexc_infozException: %sr   z
Status: %d)r  r[   rK   rC   status_coder;  s      r9   write_errorzEErrorResponseTest.get_handlers.<locals>.WriteErrorHandler.write_error  sJ    ='JJ
1CA1F1O1OOPJJ|k9:r;   NrK   rL   rM   r\   r  rI   r;   r9   WriteErrorHandlerr    s    ;r;   r  c                       e Zd Zd Zd Zy)?ErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandlerc                     ddz   y Nrv   r   rI   rB   s    r9   r\   zCErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.get  s	    Ar;   c                     t        d      )Nzexception in write_errorr  r  s      r9   r  zKErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.write_error
  s     :;;r;   Nr  rI   r;   r9   FailedWriteErrorHandlerr    s    <r;   r  /default/write_error/failed_write_error)r   r%   )rC   r  r  r  s       r9   r?   zErrorResponseTest.get_handlers  sS    	^ 		; 	;	<n 	< 
N+ 12%'>?
 	
r;   c                 
   t        t        d      5  | j                  d      }| j                  |j                  d       | j                  d|j                  v        | j                  d      }| j                  |j                  d       | j                  d|j                  v        | j                  d      }| j                  |j                  d	       | j                  d
|j                  v        d d d        y # 1 sw Y   y xY w)NUncaught exceptionr  rh  s   500: Internal Server Errorz/default?status=503  s   503: Service Unavailablez/default?status=435i  s   435: Unknown)r   r   r   r}   r   r   r   r   s     r9   test_defaultzErrorResponseTest.test_default  s    w 45zz*-HX]]C0OO9X]]JKzz"78HX]]C0OO78==HIzz"78HX]]C0OOOx}}<= 655s   CC99Dc                 r   t        t        d      5  | j                  d      }| j                  |j                  d       | j                  d|j
                         | j                  d      }| j                  |j                  d       | j                  d|j
                         d d d        y # 1 sw Y   y xY w)Nr  r  rh  s   Exception: ZeroDivisionErrorz/write_error?status=503r  s   Status: 503r   r   r   r}   r   r   r   s     r9   test_write_errorz"ErrorResponseTest.test_write_error!  s    w 45zz.1HX]]C0<hmmLzz";<HX]]C0^X]]; 655s   BB--B6c                     t        t        d      5  | j                  d      }| j                  |j                  d       | j                  d|j
                         d d d        y # 1 sw Y   y xY w)Nr  r  rh  r;   r  r   s     r9   test_failed_write_errorz)ErrorResponseTest.test_failed_write_error+  sP    w 45zz"78HX]]C0S(--0 655s   A
A$$A-N)rK   rL   rM   r?   r  r  r  rI   r;   r9   r  r    s     
D><1r;   r  c                      e Zd ZdZej
                  j                  ej
                  j                  e      d      Z	d Z
d Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d  Z'd! Z(d" Z)d# Z*d$ Z+ e,jZ                  ej\                  d%k7  d&      d'        Z/y())StaticFileTests   63a36e950e134b5217e33c763e88840c10a07d80e6057d92b9ac97508de7fb1fa6f0e9b7531e169657165ea764e8963399cb6d921ffe6078425aaafe54c04563staticc                      G d dt               } G d d|      } G d dt               }d|fd|fd	|fd
t        t        d      fgS )Nc                       e Zd Zd Zy)5StaticFileTest.get_handlers.<locals>.StaticUrlHandlerc                 ~    t        | j                  dd            }| j                  | j                  ||             y )Ninclude_versionr  )r  )r  r  r[   
static_url)rC   r4   with_vs      r9   r\   z9StaticFileTest.get_handlers.<locals>.StaticUrlHandler.get=  s3    T../@#FG

4??4?HIr;   Nr]   rI   r;   r9   StaticUrlHandlerr  <  s    Jr;   r  c                       e Zd ZdZy)=StaticFileTest.get_handlers.<locals>.AbsoluteStaticUrlHandlerTN)rK   rL   rM   include_hostrI   r;   r9   AbsoluteStaticUrlHandlerr  A  s    Lr;   r  c                       e Zd Zd Zy)=StaticFileTest.get_handlers.<locals>.OverrideStaticUrlHandlerc                    t        | j                  d            }| | _        | j                  |      }| j                  ||      }||k(  r| j	                  t        d            S | j                  j                  dz   }t        |      }|j                  |d|      }|j                  |d|      }|r|dk(  xr |dk(  }	n|dk(  xr |dk(  }	| j	                  t        |	             y )Nr  )r  Fz://r   )
r  r  r  r  r[   r   r  protocolr;  find)
rC   r4   
do_includeregular_urloverride_urlr  protocol_lengthcheck_regularcheck_overrideresults
             r9   r\   zAStaticFileTest.get_handlers.<locals>.OverrideStaticUrlHandler.getE  s    !$"3"3N"CD
(2N!"ood3#t*M;.::c%j11<<0058"%h- + 0 01o N!-!2!28Q!P+q0H]b5HF+r1Hmq6HF

3v;'r;   Nr]   rI   r;   r9   OverrideStaticUrlHandlerr  D  s    (r;   r  /static_url/(.*)z/abs_static_url/(.*)z/override_static_url/(.*)z/root_static/(.*)rR   )r4   )r   r   rf   )rC   r  r  r  s       r9   r?   zStaticFileTest.get_handlers;  s_    	J~ 	J
	 '7 	 	(~ 	(,  !12#%=>(*BC "3Ts^D	
 	
r;   c                 ,    t        t        d            S )Nr  )static_pathrf   r:   rB   s    r9   r@   zStaticFileTest.get_app_kwargs`  s     122r;   c                    | j                  d      }| j                  d|j                  v        | j                  d      }| j                  d|j                  v        | j                  |j                  j                  d      d       y )N/robots.txt   Disallow: //static/robots.txtr  r  )r   r   r   r}   r,  r\   r   s     r9   test_static_filesz StaticFileTest.test_static_filesc  sj    ::m,(--78::23(--78))--n=|Lr;   c                     | j                  d      }| j                  d|j                  v        | j                  d|j                         | j                  d|j                         y )Nz/robots.txt?v=12345r  zCache-ControlExpires)r   r   r   assertInr,  r   s     r9   test_static_files_cacheablez*StaticFileTest.test_static_files_cacheablek  sP     ::34(--78ox'7'78i!1!12r;   c                    | j                  d      }| j                  |j                  j                  d      d       | j                  d      }| j                  |j                  j                  d      d       | j                  d      }| j	                  |j                  j                  d      t        d      v        y )Nz/static/sample.xml.gzr  zapplication/gzipz/static/sample.xml.bz2zapplication/octet-streamz/static/sample.xml)ztext/xmlzapplication/xml)r   r}   r,  r\   r   r  r   s     r9   test_static_compressed_filesz+StaticFileTest.test_static_compressed_filest  s    ::56))--n=?QR::67  02L	
 ::23  0C8W4XX	
r;   c                 x    | j                  d      }| j                  |j                  d| j                  z          y )Nz/static_url/robots.txts   /static/robots.txt?v=)r   r}   r   robots_txt_hashr   s     r9   test_static_urlzStaticFileTest.test_static_url  s1    ::67(@4CWCW(WXr;   c                     | j                  d      }| j                  |j                  t        | j	                  d            dz   | j
                  z          y )Nz/abs_static_url/robots.txtrR   s   static/robots.txt?v=)r   r}   r   r   r   r  r   s     r9   test_absolute_static_urlz'StaticFileTest.test_absolute_static_url  sH    :::;MM$,,s#$'>>AUAUU	
r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nz(/static_url/robots.txt?include_version=0s   /static/robots.txtr4  r   s     r9   test_relative_version_exclusionz.StaticFileTest.test_relative_version_exclusion  s&    ::HI(=>r;   c                     | j                  d      }| j                  |j                  t        | j	                  d      dz                y )Nz,/abs_static_url/robots.txt?include_version=0rR   static/robots.txt)r   r}   r   r   r   r   s     r9   test_absolute_version_exclusionz.StaticFileTest.test_absolute_version_exclusion  s9    ::LMT\\#->AT-T(UVr;   c                 H    | j                  d       | j                  d       y )NFT)_trigger_include_host_checkrB   s    r9   test_include_host_overridez)StaticFileTest.test_include_host_override  s    ((/((.r;   c                     d}| j                  |t        |      z        }| j                  |j                  t	        t        d                   y )Nz//override_static_url/robots.txt?include_host=%sT)r   r  r}   r   r   r   )rC   r  r4   r   s       r9   r  z*StaticFileTest._trigger_include_host_check  s;    @::dS%667SY8r;   c                     | j                   |ddi|} | j                   |ddi|}t               }t        j                  |j                  |j                        D ]%  }|j                  d      s|j                  |       ' |D ]  }| j                  |j                  j                  |      |j                  j                  |      |d|j                  j                  |      d|j                  j                  |      d        |S )zPerforms 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 differs between GET (z) and HEAD ())	r   r  	itertoolschainr,  
startswithaddr}   r\   )rC   r  r;  head_responseget_responsecontent_headershs          r9   get_and_headzStaticFileTest.get_and_head  s     #

DBB6B!tzz4@@@%!6!68L8LMA||J'##A& N !A%%))!,$$((+m++//2L4H4H4L4LQ4OQ ! r;   c                     | j                  d      }| j                  dd|j                  d   i      }| j                  |j                  d       | j	                  d|j                  v       y )Nr  If-Modified-SinceLast-Modifiedr2  0  Content-Length)r  r,  r}   r   r   rC   	response1	response2s      r9   !test_static_304_if_modified_sincez0StaticFileTest.test_static_304_if_modified_since  sl    %%&:;	%% ()*;*;O*LM & 
	 	-(	0A0AABr;   c                     | j                  d      }| j                  dd|j                  d   i      }| j                  |j                  d       y )Nr  If-None-MatchEtagr2  r  r  r,  r}   r   r  s      r9   test_static_304_if_none_matchz,StaticFileTest.test_static_304_if_none_match  sS    %%&:;	%% ?I<M<Mf<U*V & 
	 	-r;   c                     | j                  d      }| j                  dd|j                  d   d      }| j                  |j                  d       y )Nr  z
"MISMATCH"r  )r  r  r2  r   r  r  s      r9   !test_static_304_etag_modified_bugz0StaticFileTest.test_static_304_etag_modified_bug  sW    %%&:;	%% !-%.%6%6%G & 
	 	-r;   c                 f    | j                  dddi      }| j                  |j                  d       y )Nr  r  zFri, 01 Jan 1960 00:00:00 GMTr2  r   r  r}   r   r   s     r9   'test_static_if_modified_since_pre_epochz6StaticFileTest.test_static_if_modified_since_pre_epoch  s;     $$ (*IJ % 
 	,r;   c                 \   t        j                  t        d            }| j                  ddt	        |j
                  dz
        i      }| j                  |j                  d       | j                  ddt	        |j
                  dz         i      }| j                  |j                  d       y )Nr  r  r  rv   r2  r   r  )r3   statr:   r  r   st_mtimer}   r   )rC   r  r   s      r9   'test_static_if_modified_since_time_zonez6StaticFileTest.test_static_if_modified_since_time_zone  s    
 www234$$ (*:4==1;L*MN % 
 	,$$ (*:4==1;L*MN % 
 	,r;   c                     | j                  d      }| j                  t        |j                  j	                  d            d| j
                  z   dz          y )Nr  r     ")r  r}   r   r,  r\   r  r   s     r9   test_static_etagzStaticFileTest.test_static_etag  sL    $$%9:!!%%f-.t7K7K0Kd0R	
r;   c                    | j                  dddi      }| j                  |j                  d       | j                  |j                  d       | j                  t	        |j
                  j                  d            d| j                  z   dz          | j                  |j
                  j                  d	      d
       | j                  |j
                  j                  d      d       y )Nr  Rangez	bytes=0-9r2     s
   User-agentr  r  r  10Content-Rangezbytes 0-9/26)r  r}   r   r   r   r,  r\   r  r   s     r9   test_static_with_rangez%StaticFileTest.test_static_with_range  s    $$ 7K*@ % 
 	,6!!%%f-.t7K7K0Kd0R	
 	))--.>?F))--o>Or;   c                    | j                  dddi      }| j                  |j                  d       t        j                  j                  | j                  d      }t        |d      5 }| j                  |j                  t        |j                                      d d d        | j                  |j                  j                  d	      d
       | j                  |j                  j                  d      d        y # 1 sw Y   `xY w)Nr  r	  zbytes=0-r2  r   
robots.txtutf-8r  r  26r  r  r}   r   r3   r4   r5   
static_diropenr   r   readr,  r\   rC   r   robots_file_pathfs       r9    test_static_with_range_full_filez/StaticFileTest.test_static_with_range_full_file  s    $$ 7J*? % 

 	,77<<F"W5X]]DN; 6))--.>?F))--o>E 65   )4C<<Dc                    | j                  dddi      }| j                  |j                  d       t        j                  j                  | j                  d      }t        |d      5 }| j                  |j                  t        |j                                      d d d        | j                  |j                  j                  d	      d
       | j                  |j                  j                  d      d        y # 1 sw Y   `xY w)Nr  r	  zbytes=0-10000000r2  r   r  r  r  r  r  r  r  r  s       r9   $test_static_with_range_full_past_endz3StaticFileTest.test_static_with_range_full_past_end  s    $$ 74F*G % 
 	,77<<F"W5X]]DN; 6))--.>?F))--o>E 65r  c           	         | j                  dddi      }| j                  |j                  d       t        j                  j                  | j                  d      }t        |d      5 }| j                  |j                  t        |j                         d	d               d d d        | j                  |j                  j                  d
      d       | j                  |j                  j                  d      d       y # 1 sw Y   `xY w)Nr  r	  zbytes=1-10000000r2  r
  r  r  r  rv   r  25r  zbytes 1-25/26r  r  s       r9   'test_static_with_range_partial_past_endz6StaticFileTest.test_static_with_range_partial_past_end  s    $$ 74F*G % 
 	,77<<F"W5X]]D!",>? 6))--.>?F))--o>P 65s   )7C??Dc                    | j                  dddi      }| j                  |j                  d       | j                  |j                  j	                  d      d       | j                  |j                  j	                  d      d	       y )
Nr  r	  z	bytes=22-r2     : /
r  r  r  bytes 22-25/26r  r}   r   r,  r\   r   s     r9   test_static_with_range_end_edgez.StaticFileTest.test_static_with_range_end_edge  s{    $$ 7K*@ % 
 	1))--.>?E))--o>@PQr;   c                    | j                  dddi      }| j                  |j                  d       | j                  |j                  j	                  d      d       | j                  |j                  j	                  d      d	       y )
Nr  r	  zbytes=-4r2  r"  r  r  r  r#  r$  r   s     r9   test_static_with_range_neg_endz-StaticFileTest.test_static_with_range_neg_end&  s{    $$ 7J*? % 
 	1))--.>?E))--o>@PQr;   c                    | j                  dddi      }| j                  |j                  d       t        j                  j                  | j                  d      }t        |d      5 }| j                  |j                  t        |j                                      d d d        | j                  |j                  j                  d	      d
       | j                  |j                  j                  d      d        y # 1 sw Y   `xY w)Nr  r	  zbytes=-1000000r2  r   r  r  r  r  r  r  r  r  s       r9   %test_static_with_range_neg_past_startz4StaticFileTest.test_static_with_range_neg_past_start.  s    $$ 74D*E % 
 	,77<<F"W5X]]DN; 6))--.>?F))--o>E 65r  c                 f    | j                  dddi      }| j                  |j                  d       y )Nr  r	  r   r2  r   r  r   s     r9   test_static_invalid_rangez(StaticFileTest.test_static_invalid_range9  s1    $$%9GVCT$U,r;   c                     | j                  dddi      }| j                  |j                  j                  d      d       | j                  |j                  d       y )Nr  r	  zbytes=-0r2  r  
bytes */26  )r  r}   r,  r\   r   r   s     r9   +test_static_unsatisfiable_range_zero_suffixz:StaticFileTest.test_static_unsatisfiable_range_zero_suffix=  sX    $$ 7J*? % 
 	))--o>M,r;   c                     | j                  dddi      }| j                  |j                  d       | j                  |j                  j	                  d      d       y )Nr  r	  zbytes=26r2  r.  r  r-  r  r}   r   r,  r\   r   s     r9   -test_static_unsatisfiable_range_invalid_startz<StaticFileTest.test_static_unsatisfiable_range_invalid_startD  sX    $$ 7J*? % 
 	,))--o>Mr;   c                     | j                  dddi      }| j                  |j                  d       | j                  |j                  j	                  d      d       y )Nr  r	  z
bytes=10-3r2  r.  r  r-  r1  r   s     r9   3test_static_unsatisfiable_range_end_less_than_startzBStaticFileTest.test_static_unsatisfiable_range_end_less_than_startK  sX    $$ 7L*A % 
 	,))--o>Mr;   c                 H   | j                  dd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d   d       | j                  t        |j                  d         d	| j                  z   d	z          y )
Nr  r  r   r   r;   r  r  r  r  r   r}   r   r   r,  r   r  r   s     r9   test_static_headzStaticFileTest.test_static_headR  s    ::26:B,,))*:;TB!!&)*D43G3G,G$,N	
r;   c                 N   | j                  ddddi      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d   d	       | j                  t        |j                  d
         d| j                  z   dz          y )Nr  r  r	  	bytes=1-4)r   r,  r
  r;   r  r  r  r  r7  r   s     r9   test_static_head_rangez%StaticFileTest.test_static_head_range\  s    :: ';9O  
 	,,))*:;SA!!&)*D43G3G,G$,N	
r;   c                 j   | j                  ddd| j                  z   dz   d      }| j                  |j                  d       | j                  |j                  d       | j                  d|j                  v       | j                  t        |j                  d	         d| j                  z   dz          y )
Nr  r:  r  )r	  r  r2  r  r;   r  r  )r  r  r}   r   r   r   r,  r   r   s     r9   test_static_range_if_none_matchz.StaticFileTest.test_static_range_if_none_matchg  s    $$ $!%(<(<!<t!C % 
 	,,(0@0@@A!!&)*D43G3G,G$,N	
r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nz/static/blarg  r  r   s     r9   test_static_404zStaticFileTest.test_static_404v  s&    $$_5,r;   c                     | j                   j                          t               | _         t        t        d      5  | j                  d      }d d d        | j                  j                  d       y # 1 sw Y   &xY w)Nz.*not in root static directoryz/static/../static_foo.txt  )http_clientr  r   r   r   r  r}   r   r   s     r9   test_path_traversal_protectionz-StaticFileTest.test_path_traversal_protectionz  sc     	 02w @A(()DEH B 	, BAs   A11A:posixznon-posix OSc                 Z   t         j                  j                  t         j                  j                  t         j                  j	                  t
                    d      }| j                  dt        j                  j                  |      z         }| j                  |j                  d       y )Nr  z/root_staticr   )r3   r4   r5   r6   abspathr7   r  rf  rg  r   r}   r   )rC   r4   r   s      r9   test_root_static_pathz$StaticFileTest.test_root_static_path  sp     ww||GGOOBGGOOH568K
 $$^fll6H6H6N%NO,r;   N)0rK   rL   rM   r  r3   r4   r5   r6   r7   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)  r+  r/  r2  r4  r8  r;  r=  r@  rD  unittestskipIfrj   rH  rI   r;   r9   r  r  2  s   	L  bggooh7BJ#
J3M3
Y
?W/9
*C.	.--$

PF	F	QRR	F--NN
	

-- X__RWW'8	- 9	-r;   r  c                   $    e Zd Zd Zd Zd Zd Zy)StaticDefaultFilenameTestc                 B    t        t        d      t        d            S Nr  
index.htmldefault_filename)r  static_handler_argsr  rB   s    r9   r@   z(StaticDefaultFilenameTest.get_app_kwargs      ) $l C
 	
r;   c                     g S r2   rI   rB   s    r9   r?   z&StaticDefaultFilenameTest.get_handlers  rJ   r;   c                     | j                  dd      }| j                  |j                  d       | j                  d|j                         y )N/static/dir/Frp  r   s   this is the index
r   r}   r   r   r   s     r9   test_static_default_filenamez6StaticDefaultFilenameTest.test_static_default_filename  s=    ::nu:E,/?r;   c                     | j                  dd      }| j                  |j                  d       | j                  |j                  d   j                  d             y )N/static/dirFrp  rY  rs  rV  )r   r}   r   r   r,  endswithr   s     r9   test_static_default_redirectz6StaticDefaultFilenameTest.test_static_default_redirect  sJ    ::me:D,((4==nMNr;   N)rK   rL   rM   r@   r?   rX  r\  rI   r;   r9   rL  rL    s    
@
Or;   rL  c                   $    e Zd Zd Zd Zd Zd Zy)StaticDefaultFilenameRootTestc                 ~    t        t        j                  j                  t	        d            t        d      d      S )Nr  rO  rP  rR   )r  rR  static_url_prefix)rf   r3   r4   rG  r:   rB   s    r9   r@   z,StaticDefaultFilenameRootTest.get_app_kwargs  s/    (9: $l C!
 	
r;   c                     g S r2   rI   rB   s    r9   r?   z*StaticDefaultFilenameRootTest.get_handlers  rJ   r;   c                     t               S r2   r   rB   s    r9   get_http_clientz-StaticDefaultFilenameRootTest.get_http_client  s     %&&r;   c                    t         j                  j                  t              }t         j                  j	                  |      \  }}t         j
                  dk(  r| j                  ||       n|}t        t        d      5  | j                  d| dd      }d d d        | j                  j                  d       y # 1 sw Y   &xY w)NrE  z/.*cannot redirect path with two initial slashesz//evil.com/../rZ  Frp  rB  )r3   r4   r6   r7   
splitdriverj   r}   r   r   r   r   )rC   test_dirdrivetailr   s        r9   test_no_open_redirectz3StaticDefaultFilenameRootTest.test_no_open_redirect  s     77??8,gg((2t77gT8,Hw QRzz 
+6!& " H S
 	, SRs   >B;;CN)rK   rL   rM   r@   r?   rc  ri  rI   r;   r9   r^  r^    s    
'
-r;   r^  c                       e Zd Zd Zd Zd Zy)StaticFileWithPathTestc                 B    t        t        d      t        d            S rN  r  rB   s    r9   r@   z%StaticFileWithPathTest.get_app_kwargs  rS  r;   c                 ,    dt         dt        d      ifgS )Nz	/foo/(.*)r4   z
templates/)r   r:   rB   s    r9   r?   z#StaticFileWithPathTest.get_handlers  s    /&',:O1PQRRr;   c                 ^    | j                  d      }| j                  |j                  d       y )Nz/foo/utf8.htmls   Héllo
r4  r   s     r9   
test_servez!StaticFileWithPathTest.test_serve  s&    ::./(9:r;   N)rK   rL   rM   r@   r?   ro  rI   r;   r9   rk  rk    s    
S;r;   rk  c                   $    e Zd Zd Zd Zd Zd Zy)CustomStaticFileTestc                 V     G d dt               } G d dt              }|| _        d|fgS )Nc                   f    e Zd Zed        Zd Zed        Zd Zed
d       Zd Z	d Z
ed	        Zy)>CustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandlerc                 x    | j                  ||      }|j                  d      }|d | }||dz   d  }d|d|d|S )N.rv   z/static/)get_versionrindex)clsrb   r4   version_hashextension_indexbefore_versionafter_versions          r9   make_static_urlzNCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.make_static_url  sR    "x>"&++c"2!%&6!7 $o&9%< =" ! r;   c                 b    |j                  d      }|j                  dd|      }|d | ||d  S )Nrv  r   )rx  )rC   url_pathr{  version_indexs       r9   parse_url_pathzMCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.parse_url_path  s<    "*//#"6 (Q H!).=!98ODT;UVVr;   c                     d|z   S )NzCustomStaticFileTest:rI   ry  rb   r4   s      r9   get_absolute_pathzPCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_absolute_path  s    .55r;   c                     |S r2   rI   )rC   rootabsolute_paths      r9   validate_absolute_pathzUCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.validate_absolute_path  s    $$r;   Nc                 6    ||J |dk(  ryt        d|z        )NCustomStaticFileTest:foo.txtru   unexpected path %rr  )rC   r4   startends       r9   get_contentzJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_content  s.    }4499! 4t ;<<r;   c                 R    | j                   dk(  ryt        d| j                   z        )Nr  r:  r  )r  r  rB   s    r9   get_content_sizezOCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_content_size  s+    %%)GG 4t7I7I IJJr;   c                      y r2   rI   rB   s    r9   get_modified_timezPCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_modified_time  s    r;   c                      y)N42rI   r  s      r9   rw  zJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_version  s    r;   NN)rK   rL   rM   classmethodr~  r  r  r  r  r  r  rw  rI   r;   r9   MyStaticFileHandlerrt    sf    	 	W
 6 6% = =K
  r;   r  c                       e Zd Zd Zy);CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandlerc                 D    | j                  | j                  |             y r2   )r[   r  r   s     r9   r\   z?CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandler.get  s    

4??401r;   Nr]   rI   r;   r9   r  r    s    2r;   r  r  )r   r   static_handler_class)rC   r  r  s      r9   r?   z!CustomStaticFileTest.get_handlers  s5    *	"3 *	X	2~ 	2 %8!#%5677r;   c                 0    t        d| j                        S )Ndummy)r  r  )rf   r  rB   s    r9   r@   z#CustomStaticFileTest.get_app_kwargs  s    d>W>WXXr;   c                 ^    | j                  d      }| j                  |j                  d       y )Nz/static/foo.42.txtru   r4  r   s     r9   ro  zCustomStaticFileTest.test_serve  s%    ::23/r;   c                     t        t        dd      5  | j                  d      }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)NzCould not open static fileF)requiredz/static_url/foo.txts   /static/foo.42.txt)r   r   r   r}   r   r   s     r9   r  z$CustomStaticFileTest.test_static_url  s@    w <uMzz"78HX]],AB NMMs   .A

AN)rK   rL   rM   r?   r@   ro  r  rI   r;   r9   rq  rq    s    38jY0Cr;   rq  c                   .    e Zd Z G d de      Zd Zd Zy)HostMatchingTestc                       e Zd Zd Zd Zy)HostMatchingTest.Handlerc                     || _         y r2   )reply)rC   r  s     r9   rd  z#HostMatchingTest.Handler.initialize"  s	    DJr;   c                 :    | j                  | j                         y r2   )r[   r  rB   s    r9   r\   zHostMatchingTest.Handler.get%  s    JJtzz"r;   N)rK   rL   rM   rd  r\   rI   r;   r9   rT   r  !  s    		#r;   rT   c                 .    dt         j                  ddifgS )Nr   r  wildcard)r  rT   rB   s    r9   r?   zHostMatchingTest.get_handlers(  s    )11GZ3HIJJr;   c                    | j                   j                  ddt        j                  ddifg       | j                   j                  ddt        j                  ddifg       | j                   j                  ddt        j                  dd	ifg       | j                   j                  d
dt        j                  ddifg       | j	                  d      }| j                  |j                  d       | j	                  d      }| j                  |j                  d       | j	                  d      }| j                  |j                  d       | j	                  dddi      }| j                  |j                  d       | j	                  dddi      }| j                  |j                  d       | j	                  dddi      }| j                  |j                  d       | j	                  dddi      }| j                  |j                  d       y )Nwww.example.comr   r  [0]www\.example\.com/bar[1]/baz[2]zwww.e.*e.comz[3]s   wildcardr?  Hostr2     [0]   [1]   [2]zwww.exe.coms   [3])rA   add_handlersr  rT   r   r}   r   r   r   s     r9   test_host_matchingz#HostMatchingTest.test_host_matching+  s   )9)A)AGUCS TU	
 	 F,<,D,DwPUFV#W"X	
 	)9)A)AGUCS TU	
 	f&6&>&>%@PQR	
 ::f%4::f%,::f%,::fv7H.I:J/::fv7H.I:J/::fv7H.I:J/::fv}.E:F/r;   N)rK   rL   rM   r   rT   r?   r  rI   r;   r9   r  r     s    #. #K0r;   r  c                       e Zd Zd Zd Zd Zy)DefaultHostMatchingTestc                     g S r2   rI   rB   s    r9   r?   z$DefaultHostMatchingTest.get_handlersK  rJ   r;   c                 
    ddiS )Ndefault_hostr  rI   rB   s    r9   r@   z&DefaultHostMatchingTest.get_app_kwargsN  s     122r;   c                    | j                   j                  ddt        j                  ddifg       | j                   j                  ddt        j                  ddifg       | j                   j                  dd	t        j                  dd
ifg       | j	                  d      }| j                  |j                  d       | j	                  d      }| j                  |j                  d       | j	                  d	      }| j                  |j                  d       | j	                  dddi      }| j                  |j                  d       d| j                   _        | j	                  d	      }| j                  |j                  d       y )Nr  r   r  r  r  r  r  zwww.test.comr  r  r  r  r?  z	X-Real-Ipr  r2  r  )	rA   r  r  rT   r   r}   r   r   r  r   s     r9   test_default_host_matchingz2DefaultHostMatchingTest.test_default_host_matchingQ  sO   )9)A)AGUCS TU	
 	 F,<,D,DwPUFV#W"X	
 	f&6&>&>%@PQR	
 ::f%/::f%/::f%,::f{K.H:I, .::f%/r;   N)rK   rL   rM   r?   r@   r  rI   r;   r9   r  r  J  s    30r;   r  c                       e Zd Zd Zd Zy)NamedURLSpecGroupsTestc                 0     G d dt               }d|fd|fgS )Nc                       e Zd Zd Zy)8NamedURLSpecGroupsTest.get_handlers.<locals>.EchoHandlerc                 &    | j                  |       y r2   rZ   r   s     r9   r\   z<NamedURLSpecGroupsTest.get_handlers.<locals>.EchoHandler.geto  s    

4 r;   Nr]   rI   r;   r9   r  r  n  s    !r;   r  z/str/(?P<path>.*)z/unicode/(?P<path>.*)r   )rC   r  s     r9   r?   z#NamedURLSpecGroupsTest.get_handlersm  s*    	!. 	!
 !+.$k2
 	
r;   c                     | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       y )Nz/str/foos   fooz/unicode/barru   r4  r   s     r9   test_named_urlspec_groupsz0NamedURLSpecGroupsTest.test_named_urlspec_groupsw  sF    ::j)/::n-/r;   N)rK   rL   rM   r?   r  rI   r;   r9   r  r  l  s    
0r;   r  c                   (    e Zd Z G d de      Zd Zy)ClearHeaderTestc                       e Zd Zd Zy)ClearHeaderTest.Handlerc                     | j                  dd       | j                  dd       | j                  d       | j                  d       y )Nh1rt   h2r  nonexistent)r  clear_headerrB   s    r9   r\   zClearHeaderTest.Handler.get  s:    OOD%(OOD%(d#m,r;   Nr]   rI   r;   r9   rT   r    s    	-r;   rT   c                     | j                  d      }| j                  d|j                  v       | j                  |j                  d   d       y )NrR   r  r  r  )r   r   r,  r}   r   s     r9   test_clear_headerz!ClearHeaderTest.test_clear_header  sA    ::c?H$4$445))$/7r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    s    -. -8r;   r  c                   (    e Zd Z G d de      Zd Zy)Header204Testc                       e Zd Zd Zy)Header204Test.Handlerc                 F    | j                  d       | j                          y )N   )
set_statusr   rB   s    r9   r\   zHeader204Test.Handler.get  s    OOC KKMr;   Nr]   rI   r;   r9   rT   r    s    	r;   rT   c                     | j                  d      }| j                  |j                  d       | j                  d|j                         | j                  d|j                         y )NrR   r  r  Transfer-Encoding)r   r}   r   rv  r,  r   s     r9   test_204_headerszHeader204Test.test_204_headers  sQ    ::c?,)8+;+;<,h.>.>?r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    s    . 
@r;   r  c                   (    e Zd Z G d de      Zd Zy)Header304Testc                       e Zd Zd Zy)Header304Test.Handlerc                 J    | j                  dd       | j                  d       y )NContent-Languageen_USrY   )r  r[   rB   s    r9   r\   zHeader304Test.Handler.get  s    OO.8JJwr;   Nr]   rI   r;   r9   rT   r    s    	 r;   rT   c                    | j                  d      }| j                  |j                  d   d       | j                  |j                  d   d       | j                  dd|j                  d   i      }| j                  |j                  d	       | j	                  d|j                  v       | j	                  d|j                  v       | j	                  d
|j                  v       y )NrR   r  5r  r  r  r  r2  r  r  )r   r}   r,  r   r   r  s      r9   test_304_headerszHeader304Test.test_304_headers  s    JJsO	**+;<cB**+=>HJJ/9+<+<V+DE  
	 	-(	0A0AAB*)2C2CCD+93D3DDEr;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    s     .  
Fr;   r  c                   .    e Zd Z G d de      Zd Zd Zy)StatusReasonTestc                       e Zd Zd Zy)StatusReasonTest.Handlerc                     | j                   j                  j                  dg       }| j                  t	        | j                  d            |rt        |d                y d        y )Nreasonr   r   r  )r  r  r\   r  r  r  r   )rC   r  s     r9   r\   zStatusReasonTest.Handler.get  s]    \\++//"=FOOD%%f-.06z&),  <@  r;   Nr]   rI   r;   r9   rT   r    s    	r;   rT   c                     t               S r2   r   rB   s    r9   rc  z StatusReasonTest.get_http_client      $&&r;   c                 L   | j                  d      }| j                  |j                  d       | j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  |j                  d       | j                  d	      }| j                  |j                  d       | j                  |j                  d
       y )Nz
/?code=304r  zNot Modifiedz/?code=304&reason=FooFooz/?code=682&reason=Bar  Barz
/?code=682Unknown)r   r}   r   r  r   s     r9   test_statuszStatusReasonTest.test_status  s    ::l+,.9::56,%0::56,%0::l+,)4r;   N)rK   rL   rM   r   rT   rc  r  rI   r;   r9   r  r    s    . '5r;   r  c                   (    e Zd Z G d de      Zd Zy)DateHeaderTestc                       e Zd Zd Zy)DateHeaderTest.Handlerc                 &    | j                  d       y rX   rZ   rB   s    r9   r\   zDateHeaderTest.Handler.get      JJwr;   Nr]   rI   r;   r9   rT   r    s    	 r;   rT   c                 >   | j                  d      }t        j                  j                  |j                  d         }| j                  |t        j                  j                  t        j                  j                        z
  t        j                  d      k         y )NrR   Dater   )seconds)r   rQ  rR  rS  r,  r   rL  rM  rN  rO  rP  )rC   r   header_dates      r9   test_date_headerzDateHeaderTest.test_date_header  sr    ::c?kk778H8H8PQ(++//0A0A0E0EFF  +,	
r;   N)rK   rL   rM   r   rT   r   rI   r;   r9   r  r    s     .  
r;   r  c                   :    e Zd Z G d de      Zd Zd Zd Zd Zy)RaiseWithReasonTestc                       e Zd Zd Zy)RaiseWithReasonTest.Handlerc                     t        dd      )Nr  r  r  r!   rB   s    r9   r\   zRaiseWithReasonTest.Handler.get  s    C..r;   Nr]   rI   r;   r9   rT   r    s    	/r;   rT   c                     t               S r2   r   rB   s    r9   rc  z#RaiseWithReasonTest.get_http_client  r  r;   c                     | j                  d      }| j                  |j                  d       | j                  |j                  d       | j	                  d|j
                         y )NrR   r  r  s   682: Foo)r   r}   r   r  r  r   r   s     r9   test_raise_with_reasonz*RaiseWithReasonTest.test_raise_with_reason  sI    ::c?,%0k8==1r;   c                 P    | j                  t        t        dd            d       y )Nr  r  r  zHTTP 682: Foor}   r   r!   rB   s    r9   test_httperror_strz&RaiseWithReasonTest.test_httperror_str  s    Ys59:OLr;   c                 L    | j                  t        t        d            d       y )Nr  zHTTP 682: Unknownr  rB   s    r9    test_httperror_str_from_httputilz4RaiseWithReasonTest.test_httperror_str_from_httputil  s    Ys^,.ABr;   N)	rK   rL   rM   r   rT   rc  r	  r  r  rI   r;   r9   r  r    s$    /. /'2MCr;   r  c                   $    e Zd Zd Zd Zd Zd Zy)ErrorHandlerXSRFTestc                 *    dt         t        d      fgS )N/error  r  )r#   rf   rB   s    r9   r?   z!ErrorHandlerXSRFTest.get_handlers  s     <#)>?@@r;   c                     t        d      S NT)xsrf_cookiesr   rB   s    r9   r@   z#ErrorHandlerXSRFTest.get_app_kwargs      &&r;   c                 d    | j                  ddd      }| j                  |j                  d       y )Nr  r   ro  r   r  rZ  r   s     r9   test_error_xsrfz$ErrorHandlerXSRFTest.test_error_xsrf  s*    ::hvB:?,r;   c                 d    | j                  ddd      }| j                  |j                  d       y )Nz/404r   ro  r   r?  rZ  r   s     r9   test_404_xsrfz"ErrorHandlerXSRFTest.test_404_xsrf  s*    ::fV":=,r;   N)rK   rL   rM   r?   r@   r  r  rI   r;   r9   r  r    s    A'--r;   r  c                   L    e Zd Z G d de      Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)GzipTestCasec                       e Zd Zd Zy)GzipTestCase.Handlerc                     | j                  d      D ]  }| j                  d|        | j                  ddt        j                  z  z          y )Nvaryrs  zhello world!)r  r  r[   r/   
MIN_LENGTH)rC   vs     r9   r\   zGzipTestCase.Handler.get  sD    ''/* 0 JJ}.A.L.L(LMNr;   Nr]   rI   r;   r9   rT   r     s    	Or;   rT   c                     t        dt        j                  j                  t        j                  j	                  t
              d            S )NTr  )rt  r  )rf   r3   r4   r5   r6   r7   rB   s    r9   r@   zGzipTestCase.get_app_kwargs
  s0    277<<0I8#T
 	
r;   c                     | j                  |j                  j                  d|j                  j                  d            d       y )Nru  zX-Consumed-Content-Encodingrt  )r}   r,  r\   r   s     r9   assert_compressedzGzipTestCase.assert_compressed  sB     	  "H$4$4$8$89V$W 		
r;   c                     | j                  d      }| j                  |       | j                  |j                  d   d       y )NrR   rs  rr  r   r(  r}   r,  r   s     r9   	test_gzipzGzipTestCase.test_gzip  s9    ::c?x())&13DEr;   c                     | j                  d      }| j                  |       | j                  |j                  d   d       y )Nr  rs  rr  r*  r   s     r9   test_gzip_staticzGzipTestCase.test_gzip_static  s<     ::m,x())&13DEr;   c                     | j                  dd      }| j                  d|j                         | j                  |j                  d   d       y )NrR   F)use_gzipru  rs  rr  )r   rv  r,  r}   r   s     r9   test_gzip_not_requestedz$GzipTestCase.test_gzip_not_requested%  sG    ::cE:2+X-=-=>))&13DEr;   c                     | j                  d      }| j                  |       | j                  |j                  d   j	                  d      D cg c]  }|j                          c}ddg       y c c}w )Nz/?vary=Accept-Languagers  ,Accept-Languagerr  r   r(  r}   r,  splitstriprC   r   r  s      r9   test_vary_already_presentz&GzipTestCase.test_vary_already_present*  si    ::67x( ( 0 0 8 > >s CD C1QWWY CD 12	
D   A0c                     | j                  d      }| j                  |       | j                  |j                  d   j	                  d      D cg c]  }|j                          c}g d       y c c}w )Nz"/?vary=Accept-Language&vary=Cookiers  r2  )r3  r0  rr  r4  r7  s      r9   "test_vary_already_present_multiplez/GzipTestCase.test_vary_already_present_multiple2  sc    ::BCx( ( 0 0 8 > >s CD C1QWWY CD<	
Dr9  N)rK   rL   rM   r   rT   r@   r(  r+  r-  r0  r8  r;  rI   r;   r9   r  r    s6    O. O


F
FF


r;   r  c                   4    e Zd Z G d de      Zd Zd Zd Zy)PathArgsInPrepareTestc                       e Zd Zd Zd Zy)PathArgsInPrepareTest.Handlerc                 d    | j                  t        | j                  | j                               y )Nr  r;  )r[   rf   r  path_kwargsrB   s    r9   r  z%PathArgsInPrepareTest.Handler.prepare>  s    JJt8H8HIJr;   c                 2    |dk(  sJ | j                          y )Nrt   r   r   s     r9   r\   z!PathArgsInPrepareTest.Handler.getA  s    5= =KKMr;   NrK   rL   rM   r  r\   rI   r;   r9   rT   r?  =  s    	K	r;   rT   c                 :    d| j                   fd| j                   fgS )Nz	/pos/(.*)z/kw/(?P<path>.*)rS   rB   s    r9   r?   z"PathArgsInPrepareTest.get_handlersE  s     dll+.@$,,-OPPr;   c                     | j                  d      }|j                          t        |j                        }| j	                  |dgi d       y )Nz/pos/foort   rA  rA  rC   r   r>  s      r9   test_poszPathArgsInPrepareTest.test_posH  sA    ::j)8==)2>?r;   c                     | j                  d      }|j                          t        |j                        }| j	                  |g ddid       y )Nz/kw/foor4   rt   rA  rA  rH  s      r9   test_kwzPathArgsInPrepareTest.test_kwN  sC    ::i(8==)vuoFGr;   N)rK   rL   rM   r   rT   r?   rI  rK  rI   r;   r9   r=  r=  <  s     . Q@Hr;   r=  c                   (    e Zd Z G d de      Zd Zy)ClearAllCookiesTestc                       e Zd Zd Zy)ClearAllCookiesTest.Handlerc                 F    | j                          | j                  d       y Nok)clear_all_cookiesr[   rB   s    r9   r\   zClearAllCookiesTest.Handler.getW  s    ""$JJtr;   Nr]   rI   r;   r9   rT   rO  V  s    	r;   rT   c                 Z   | j                  dddi      }t        |j                  j                  d            }| j	                  |d   j                  d      xs |d   j                  d             | j	                  |d	   j                  d
      xs |d	   j                  d             y )NrR   r0  zfoo=bar; baz=xyzzyr2  r*  r   zbaz=;zbaz="";rv   zfoo=;zfoo="";)r   r+  r,  r-  r   r  )rC   r   set_cookiess      r9   test_clear_all_cookiesz*ClearAllCookiesTest.test_clear_all_cookies[  s    ::cH6J+K:LX--66|DEN%%g.V+a.2K2KI2V	
 	N%%g.V+a.2K2KI2V	
r;   N)rK   rL   rM   r   rT   rV  rI   r;   r9   rM  rM  U  s    . 
	
r;   rM  c                       e Zd Zy)PermissionErrorNrK   rL   rM   rI   r;   r9   rX  rX  g  s    r;   rX  c                   4    e Zd Z G d de      Zd Zd Zd Zy)ExceptionHandlerTestc                       e Zd Zd Zd Zd Zy)ExceptionHandlerTest.Handlerc                 ~    | j                  d      }|dk(  rt        dd      |dk(  rddz   y |dk(  rt        d	      y )
Nexchttp  zno longer herezerorv   r   
permissionznot allowed)r  r!   rX  )rC   r_  s     r9   r\   z ExceptionHandlerTest.Handler.getm  sM    ##E*Cf}%566A$%m44 %r;   c                     d|v r<|d   \  }}}t        |t              r#| j                  d       | j                  d       y t	        j
                  | |fi | y )Nr  rB  rX  )
isinstancerX  r  r[   r   r  )rC   r  r;  typrm   tbs         r9   r  z(ExceptionHandlerTest.Handler.write_errorv  sU    V#!'
!3UBe_5OOC(JJ01&&t[CFCr;   c                     t        |t              r$t        j                  d|j                  d          y t        j                  | |||       y )Nz&custom logging for PermissionError: %sr   )re  rX  r   warningr  r   log_exceptionrC   rf  rm   rg  s       r9   rj  z*ExceptionHandlerTest.Handler.log_exception  s8    %1 H%**UV-X,,T3rBr;   N)rK   rL   rM   r\   r  rj  rI   r;   r9   rT   r]  l  s    	5	D	Cr;   rT   c                     t        t        d      5  | j                  d      }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)Nz.*no longer herez
/?exc=httpra  rF  r   s     r9   test_http_errorz$ExceptionHandlerTest.test_http_error  s=     w 23zz,/HX]]C0 433   .AAc                     t        t        d      5  | j                  d      }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)Nr  z
/?exc=zerorh  r   r   r   r}   r   r   s     r9   test_unknown_errorz'ExceptionHandlerTest.test_unknown_error  s;    w 45zz,/HX]]C0 655rn  c                     t        t        d      5  | j                  d      }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)Nz/custom logging for PermissionError: not allowedz/?exc=permissionrB  rp  r   s     r9   test_known_errorz%ExceptionHandlerTest.test_known_error  s?     w QRzz"45HX]]C0 SRRrn  N)rK   rL   rM   r   rT   rm  rq  rs  rI   r;   r9   r[  r[  k  s    C. C2111r;   r[  c                   (    e Zd Z G d de      Zd Zy)BuggyLoggingTestc                       e Zd Zd Zd Zy)BuggyLoggingTest.Handlerc                     ddz   y r  rI   rB   s    r9   r\   zBuggyLoggingTest.Handler.get  	    Er;   c                     ddz   y r  rI   rk  s       r9   rj  z&BuggyLoggingTest.Handler.log_exception  ry  r;   N)rK   rL   rM   r\   rj  rI   r;   r9   rT   rw    s    		r;   rT   c                 p    t        t        d      5  | j                  d       d d d        y # 1 sw Y   y xY w)Nz.*rR   )r   r   r   rB   s    r9   test_buggy_log_exceptionz)BuggyLoggingTest.test_buggy_log_exception  s%     w%JJsO &%%r  N)rK   rL   rM   r   rT   r|  rI   r;   r9   ru  ru    s    . r;   ru  c                   D     e Zd ZdZ G d de      Zd Z fdZd Z xZ	S )UIMethodUIModuleTestz`Test that UI methods and modules are created correctly and
    associated with the handler.
    c                       e Zd Zd Zd Zy)UIMethodUIModuleTest.Handlerc                 &    | j                  d       y r   r  rB   s    r9   r\   z UIMethodUIModuleTest.Handler.get  s    KK
#r;   c                 $    | j                  d      S )Nrm   )r  rB   s    r9   rm   z"UIMethodUIModuleTest.Handler.value  s    $$W--r;   N)rK   rL   rM   r\   rm   rI   r;   r9   rT   r    s    	$	.r;   rT   c                 d    d } G d dt               }t        ddi      }t        |d|id|i      S )Nc                 0    d|d| j                         dS )NzIn my_ui_method() with handler value rv  )rm   )r   xs     r9   my_ui_methodz9UIMethodUIModuleTest.get_app_kwargs.<locals>.my_ui_method  s    CDgmmoVVr;   c                       e Zd Zd Zy)5UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModulec                     d|dt        j                  t        j                  | j                        j                         dS )NzIn MyModule(r  rv  )typingcastr~  rT   r   rm   )rC   r  s     r9   r   z<UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModule.render  s1    KK 4 < <dllKQQS r;   NrK   rL   rM   r   rI   r;   r9   MyModuler    s    r;   r  r   z1{{ my_ui_method(42) }} {% module MyModule(123) %}r  )r  
ui_methods
ui_modulesr*   r   rf   )rC   r  r  r"  s       r9   r@   z#UIMethodUIModuleTest.get_app_kwargs  sK    	W	x 	 LM
 "&5"H-
 	
r;   c                 ^    t         |           t        j                  j	                          y r2   r$  r)  s    r9   r&  zUIMethodUIModuleTest.tearDown  s     ((..0r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nz/?value=asdfsV   In my_ui_method(42) with handler value asdf. In MyModule(123) with handler value asdf.r4  r   s     r9   test_ui_methodz#UIMethodUIModuleTest.test_ui_method  s*    ::n-MM9	
r;   )
rK   rL   rM   rN   r   rT   r@   r&  r  rx  ry  s   @r9   r~  r~    s#    .. .
(1

r;   r~  c                   (    e Zd Z G d de      Zd Zy)GetArgumentErrorTestc                       e Zd Zd Zy)GetArgumentErrorTest.Handlerc                     	 | j                  d       | j                  i        y # t        $ r2}| j                  |j                  |j                  d       Y d }~y d }~ww xY w)Nrt   arg_namelog_message)r  r[   r"   r  r  r  s     r9   r\   z GetArgumentErrorTest.Handler.get  sO    S!!%(

2' S



1==QRRSs   "% 	A (AA Nr]   rI   r;   r9   rT   r    s    	Sr;   rT   c                 v    | j                  d      }| j                  t        |j                        ddd       y )NrR   rt   zMissing argument foor  )r   r}   r   r   r   s     r9   test_catch_errorz%GetArgumentErrorTest.test_catch_error  s2    ::c?&/EF	
r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    s    S. S
r;   r  c                   (    e Zd Z G d de      Zd Zy)SetLazyPropertiesTestc                   $    e Zd Zd Zd Zd Zd Zy)SetLazyPropertiesTest.Handlerc                 F    d| _         t        j                  d      | _        y )NBenr  )current_userr   r\   rB   s    r9   r  z%SetLazyPropertiesTest.Handler.prepare  s     %D **W-DKr;   c                     t               r2   rF   rB   s    r9   get_user_localez-SetLazyPropertiesTest.Handler.get_user_locale      %''r;   c                     t               r2   rF   rB   s    r9   get_current_userz.SetLazyPropertiesTest.Handler.get_current_user  r  r;   c                 p    | j                  d| j                  d| j                  j                  d       y )NzHello z (r  )r[   r  r   r   rB   s    r9   r\   z!SetLazyPropertiesTest.Handler.get  s#    JJ$*;*;T[[=M=MNOr;   N)rK   rL   rM   r  r  r  r\   rI   r;   r9   rT   r    s    	.	(	(	Pr;   rT   c                 ^    | j                  d      }| j                  |j                  d       y )NrR   s   Hello Ben (en_US)r4  r   s     r9   test_set_propertiesz)SetLazyPropertiesTest.test_set_properties  s&     ::c?(<=r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    s    P. P>r;   r  c                   l     e Zd Zd Z fdZd Z ej                  d      d        Zd Z	d Z
d Z xZS )	GetCurrentUserTestc                 ~     G d dt               } G d dt               }t        ddddd	      }t        |||d
      S )Nc                       e Zd Zd Zy)<GetCurrentUserTest.get_app_kwargs.<locals>.WithoutUserModulec                      y)Nro  rI   rB   s    r9   r   zCGetCurrentUserTest.get_app_kwargs.<locals>.WithoutUserModule.render  s    r;   Nr  rI   r;   r9   WithoutUserModuler     s    r;   r  c                       e Zd Zd Zy)9GetCurrentUserTest.get_app_kwargs.<locals>.WithUserModulec                 ,    t        | j                        S r2   )r   r  rB   s    r9   r   z@GetCurrentUserTest.get_app_kwargs.<locals>.WithUserModule.render  s    4,,--r;   Nr  rI   r;   r9   WithUserModuler    s    .r;   r  ro  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  )rC   r  r  r"  s       r9   r@   z!GetCurrentUserTest.get_app_kwargs  sT    	 		.X 	. %'"6,N)H	
 ""0%6
 	
r;   c                 ^    t         |           t        j                  j	                          y r2   r$  r)  s    r9   r&  zGetCurrentUserTest.tearDown  r+  r;   c                      G d dt               } G d d|      } G d d|      } G d d|      } G d	 d
|      } G d d|      }d|fd|fd|fd|fgS )Nc                       e Zd Zd Zd Zy);GetCurrentUserTest.get_handlers.<locals>.CurrentUserHandlerc                     d| _         y )NFhas_loaded_current_userrB   s    r9   r  zCGetCurrentUserTest.get_handlers.<locals>.CurrentUserHandler.prepare  s
    /4,r;   c                     d| _         y)NTro  r  rB   s    r9   r  zLGetCurrentUserTest.get_handlers.<locals>.CurrentUserHandler.get_current_user!  s    /3,r;   N)rK   rL   rM   r  r  rI   r;   r9   CurrentUserHandlerr    s    5r;   r  c                       e Zd Zd Zy);GetCurrentUserTest.get_handlers.<locals>.WithoutUserHandlerc                 n    | j                  d       | j                  t        | j                               y )Nr  render_stringr   r   r  rB   s    r9   r\   z?GetCurrentUserTest.get_handlers.<locals>.WithoutUserHandler.get&  s(    ""#67C < <=>r;   Nr]   rI   r;   r9   WithoutUserHandlerr  %      ?r;   r  c                       e Zd Zd Zy)8GetCurrentUserTest.get_handlers.<locals>.WithUserHandlerc                 n    | j                  d       | j                  t        | j                               y )Nr  r  rB   s    r9   r\   z<GetCurrentUserTest.get_handlers.<locals>.WithUserHandler.get+  s(    ""#34C < <=>r;   Nr]   rI   r;   r9   WithUserHandlerr  *  r  r;   r  c                       e Zd Zd Zy)AGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandlerc                     | j                   S r2   )uirB   s    r9   get_template_namespacezXGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandler.get_template_namespace0  s     wwr;   N)rK   rL   rM   r  rI   r;   r9   CurrentUserModuleHandlerr  /  s    r;   r  c                       e Zd Zd Zy)AGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandlerc                 n    | j                  d       | j                  t        | j                               y )Nr  r  rB   s    r9   r\   zEGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandler.get7  s(    ""#=>C < <=>r;   Nr]   rI   r;   r9   WithoutUserModuleHandlerr  6  r  r;   r  c                       e Zd Zd Zy)>GetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandlerc                 n    | j                  d       | j                  t        | j                               y )Nr  r  rB   s    r9   r\   zBGetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandler.get<  s(    ""#:;C < <=>r;   Nr]   rI   r;   r9   WithUserModuleHandlerr  ;  r  r;   r  /without_user
/with_user/without_user_module/with_user_moduler   )rC   r  r  r  r  r  r  s          r9   r?   zGetCurrentUserTest.get_handlers  s~    	 		?!3 	?
	?0 	?
	'9 		?'? 	?
	?$< 	? 01?+#%=> "78	
 	
r;   z	needs fixc                 ^    | j                  d      }| j                  |j                  d       y )Nr     Falser4  r   s     r9   test_get_current_user_is_lazyz0GetCurrentUserTest.test_get_current_user_is_lazyG  s&     ::o.1r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr     Truer4  r   s     r9   test_get_current_user_worksz.GetCurrentUserTest.test_get_current_user_worksM  s$    ::l+0r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr  r  r4  r   s     r9   ,test_get_current_user_from_ui_module_is_lazyz?GetCurrentUserTest.test_get_current_user_from_ui_module_is_lazyQ  s%    ::451r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr  r  r4  r   s     r9   *test_get_current_user_from_ui_module_worksz=GetCurrentUserTest.test_get_current_user_from_ui_module_worksU  s%    ::120r;   )rK   rL   rM   r@   r&  r?   rI  skipr  r  r  r  rx  ry  s   @r9   r  r    sA    
21)
V X]];2  2
121r;   r  c                   (    e Zd Z G d de      Zd Zy)UnimplementedHTTPMethodsTestc                       e Zd Zy)$UnimplementedHTTPMethodsTest.HandlerNrY  rI   r;   r9   rT   r  [  s    r;   rT   c                     dD ]1  }| j                  d|      }| j                  |j                  d       3 dD ]2  }| j                  d|d      }| j                  |j                  d       4 y )N)r  r  DELETEOPTIONSrR   r6    r   PUTr;   r   rZ  )rC   r   r   s      r9   #test_unimplemented_standard_methodsz@UnimplementedHTTPMethodsTest.test_unimplemented_standard_methods^  sf    :Fzz#fz5HX]]C0 ; &Fzz#f3z?HX]]C0 &r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r  Z  s    . 1r;   r  c                   .    e Zd Z G d de      Zd Zd Zy)#UnimplementedNonStandardMethodsTestc                       e Zd Zd Zy)+UnimplementedNonStandardMethodsTest.Handlerc                 &    | j                  d       y NotherrZ   rB   s    r9   r  z1UnimplementedNonStandardMethodsTest.Handler.otheri  s     JJwr;   N)rK   rL   rM   r  rI   r;   r9   rT   r  h  s    	 r;   rT   c                 d    | j                  ddd      }| j                  |j                  d       y )NrR   PATCHr;   r   r  rZ  r   s     r9   test_unimplemented_patchz<UnimplementedNonStandardMethodsTest.test_unimplemented_patchn  s,     ::c':<,r;   c                 d    | j                  ddd      }| j                  |j                  d       y )NrR   OTHERTr   allow_nonstandard_methodsr  rZ  r   s     r9   test_unimplemented_otherz<UnimplementedNonStandardMethodsTest.test_unimplemented_othert  s*    ::c'T:R,r;   N)rK   rL   rM   r   rT   r  r  rI   r;   r9   r  r  g  s     .  --r;   r  c                   (    e Zd Z G d de      Zd Zy)AllHTTPMethodsTestc                   &    e Zd Zd ZexZxZxZxZZy)AllHTTPMethodsTest.Handlerc                 ~    | j                   j                  J | j                  | j                   j                         y r2   )r  r   r[   rB   s    r9   r   z!AllHTTPMethodsTest.Handler.method{  s.    <<&&222JJt||**+r;   N)	rK   rL   rM   r   r\   deleteoptionsr   putrI   r;   r9   rT   r  z  s"    	, /544f4w4r;   rT   c                 `   | j                  dd      }| j                  |j                  d       dD ]:  }| j                  d|      }| j                  |j                  t        |             < dD ];  }| j                  d|d      }| j                  |j                  t        |             = y )NrR   r  r6  r;   )r  r  r  r  r   )r   r}   r   r   )rC   r   r   s      r9   test_standard_methodsz(AllHTTPMethodsTest.test_standard_methods  s    ::c&:1,2Fzz#fz5HX]]DL9 3 &Fzz#f3z?HX]]DL9 &r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r	  r	  y  s    5. 5:r;   r	  c                   .    e Zd Z G d de      Zd Zd Zy)PatchMethodTestc                   6    e Zd Zej                  dz   Zd Zd Zy)PatchMethodTest.Handler)r  c                 &    | j                  d       y )NpatchrZ   rB   s    r9   r  zPatchMethodTest.Handler.patch  r  r;   c                 &    | j                  d       y r  rZ   rB   s    r9   r  zPatchMethodTest.Handler.other  r  r;   N)rK   rL   rM   r   SUPPORTED_METHODSr  r  rI   r;   r9   rT   r    s#    *<< @
 
	 	 r;   rT   c                 d    | j                  ddd      }| j                  |j                  d       y )NrR   r  r;   r   s   patchr4  r   s     r9   
test_patchzPatchMethodTest.test_patch  s*    ::c':<1r;   c                 d    | j                  ddd      }| j                  |j                  d       y )NrR   r  Tr  s   otherr4  r   s     r9   
test_otherzPatchMethodTest.test_other  s*    ::c'T:R1r;   N)rK   rL   rM   r   rT   r  r  rI   r;   r9   r  r    s    	 . 	 22r;   r  c                   (    e Zd Z G d de      Zd Zy)FinishInPrepareTestc                       e Zd Zd Zd Zy)FinishInPrepareTest.Handlerc                 &    | j                  d       y )Nr   rD  rB   s    r9   r  z#FinishInPrepareTest.Handler.prepare  s    KKr;   c                     t        d      )Nzshould not reach this methodr  rB   s    r9   r\   zFinishInPrepareTest.Handler.get  s     :;;r;   NrE  rI   r;   r9   rT   r!    s    	 	<r;   rT   c                 ^    | j                  d      }| j                  |j                  d       y )NrR   s   doner4  r   s     r9   test_finish_in_preparez*FinishInPrepareTest.test_finish_in_prepare  s#    ::c?0r;   N)rK   rL   rM   r   rT   r%  rI   r;   r9   r  r    s    <. <1r;   r  c                       e Zd Zd Zd Zy)Default404Testc                     dt         fgS Nr   r   rB   s    r9   r?   zDefault404Test.get_handlers  s    ())r;   c                     | j                  d      }| j                  |j                  d       | j                  |j                  d       y )NrR   r?  sE   <html><title>404: Not Found</title><body>404: Not Found</body></html>rW  r   s     r9   test_404zDefault404Test.test_404  s=    ::c?,MM2	
r;   N)rK   rL   rM   r?   r+  rI   r;   r9   r'  r'    s    *
r;   r'  c                       e Zd Zd Zd Zd Zy)Custom404Testc                     dt         fgS r)  r   rB   s    r9   r?   zCustom404Test.get_handlers      ())r;   c                 8     G d dt               }t        |      S )Nc                       e Zd Zd Zy)6Custom404Test.get_app_kwargs.<locals>.Custom404Handlerc                 H    | j                  d       | j                  d       y )Nr?  zcustom 404 response)r  r[   rB   s    r9   r\   z:Custom404Test.get_app_kwargs.<locals>.Custom404Handler.get  s    $

01r;   Nr]   rI   r;   r9   Custom404Handlerr2    s    2r;   r4  )default_handler_class)r   rf   )rC   r4  s     r9   r@   zCustom404Test.get_app_kwargs  s    	2~ 	2
 *:;;r;   c                     | j                  d      }| j                  |j                  d       | j                  |j                  d       y )NrR   r?  s   custom 404 responserW  r   s     r9   r+  zCustom404Test.test_404  s8    ::c?,(>?r;   N)rK   rL   rM   r?   r@   r+  rI   r;   r9   r-  r-    s    *<@r;   r-  c                       e Zd Zd Zd Zd Zy)DefaultHandlerArgumentsTestc                     dt         fgS r)  r   rB   s    r9   r?   z(DefaultHandlerArgumentsTest.get_handlers  r/  r;   c                 8    t        t        t        d            S )NrB  r  )r5  default_handler_args)rf   r#   rB   s    r9   r@   z*DefaultHandlerArgumentsTest.get_app_kwargs  s    ".!%#!6
 	
r;   c                 ^    | j                  d      }| j                  |j                  d       y )NrR   rB  rZ  r   s     r9   test_403z$DefaultHandlerArgumentsTest.test_403  s#    ::c?,r;   N)rK   rL   rM   r?   r@   r=  rI   r;   r9   r8  r8    s    *
-r;   r8  c                       e Zd Zd Zd Zy)HandlerByNameTestc                 ,    dt         fdt        dd      gS )N/hello1)/hello2"tornado.test.web_test.HelloHandler/hello3rC  )rV   r%   rB   s    r9   r?   zHandlerByNameTest.get_handlers  s$     %=	?@
 	
r;   c                    | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       y )NrA  re  rB  rD  r4  rC   resps     r9   test_handler_by_namez&HandlerByNameTest.test_handler_by_name  sh    zz)$H-zz)$H-zz)$H-r;   N)rK   rL   rM   r?   rH  rI   r;   r9   r?  r?    s    
.r;   r?  c                   X    e Zd Zd Zd Zed        Zed        Zed        Zed        Z	y)StreamingRequestBodyTestc                     t          G d dt                     }t          G d dt                     }t          G d dt                     }d|t        |       fd	|fd
|t        |       fgS )Nc                   $    e Zd Zd Zd Zd Zd Zy)CStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandlerc                     || _         y r2   r   r   s     r9   rd  zNStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.initialize  	     	r;   c                 N    | j                   j                  j                  d        y r2   )r   prepared
set_resultrB   s    r9   r  zKStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.prepare  s    		""--d3r;   c                 N    | j                   j                  j                  |       y r2   )r   r>  rR  rC   r>  s     r9   data_receivedzQStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.data_received  s    		))$/r;   c                 p    | j                   j                  j                  d        | j                  i        y r2   )r   finishedrR  r[   rB   s    r9   r\   zGStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.get 	  s%    		""--d3

2r;   N)rK   rL   rM   rd  r  rU  r\   rI   r;   r9   StreamingBodyHandlerrM    s    !40r;   rX  c                       e Zd Zd Zy)AStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandlerc                     t        d      )N  r  rB   s    r9   r  zIStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandler.prepare	  s      n$r;   Nr  rI   r;   r9   EarlyReturnHandlerrZ  	  s    %r;   r]  c                   $     e Zd Zd Z fdZ xZS )DStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandlerc                     || _         y r2   r   r   s     r9   rd  zOStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.initialize	  rO  r;   c                 l    t         |           | j                  j                  j	                  d        y r2   )r%  r  r   close_futurerR  r)  s    r9   r  zXStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.on_connection_close	  s&    +-		&&11$7r;   )rK   rL   rM   rd  r  rx  ry  s   @r9   CloseDetectionHandlerr_  	  s    !8 8r;   rc  z/stream_bodyr   z/early_returnz/close_detection)r,   r   rf   )rC   rX  r]  rc  s       r9   r?   z%StreamingRequestBodyTest.get_handlers  s    		> 	 
	 
	% 	% 
	% 
	8N 	8 
	8 14T?C01!6$H
 	
r;   c                 :   t        j                   t         j                  t         j                  d      }|j                  d| j	                         f       t        |      }|j                  d|z   dz          |r|j                  d       |j                  d       |S )Nr   r  s   GET s    HTTP/1.1
s   Connection: close
s   Transfer-Encoding: chunked

)r  r  r  r  r  r   r[   )rC   r%   connection_closer  r  s        r9   r  z StreamingRequestBodyTest.connect	  sy    MM&..&*<*<a@			; 2 2 456!Ws]%556LL12:;r;   c              #   L  K   t               | _        t               | _        t               | _        | j	                  dd      }| j                   |j                  d       | j                  }| j                  |d       t               | _        |j                  d       | j                  }| j                  |d       |j                  d       | j                   |j                         }| j                  |j                  d	             |j                          y w)
Ns   /stream_bodyTre  	   4
asdf
s   asdfs	   4
qwer
s   qwers   0

s   {})r   rQ  r>  rW  r  r[   r}   read_until_closer   r[  r  rC   r  r>  s      r9   test_streaming_bodyz,StreamingRequestBodyTest.test_streaming_body%	  s     H	oEmm%&YYw'H	%&YYw'\"mm,,..e,-s   D"D$c              #      K   | j                  dd      }|j                         }| j                  |j                  d             y w)N   /early_returnFrg     HTTP/1.1 401)r  ri  r   r  rj  s      r9   test_early_returnz*StreamingRequestBodyTest.test_early_return<	  s?     .G,,..89s   AA	c              #      K   | j                  dd      }|j                  d       |j                         }| j                  |j	                  d             y w)Nrm  Frg  rh  rn  )r  r[   ri  r   r  rj  s      r9   test_early_return_with_dataz4StreamingRequestBodyTest.test_early_return_with_dataB	  sL     .G%&,,..89s   AAc              #      K   t               | _        | j                  dd      }|j                          | j                   y w)Ns   /close_detectionFrg  )r   rb  r  r  )rC   r  s     r9   test_close_during_uploadz1StreamingRequestBodyTest.test_close_during_uploadI	  s8     "H1EJr~  N)
rK   rL   rM   r?   r  r   rk  ro  rq  rs  rI   r;   r9   rJ  rJ    s]    $
L	  , : :
 : :    r;   rJ  c                   ~    e Zd Zd Zej
                  d        Zej                  d        Z	ej                  d        Z
y)BaseFlowControlHandlerc                 .    || _         d | _        g | _        y r2   )r   r   methodsr   s     r9   rd  z!BaseFlowControlHandler.initializeW	  s    	r;   c              #      K   | j                   +| j                  j                  d|d| j                          || _         | j                  j	                  |       	 d  d | _         y # d | _         w xY ww)Nzentered method z
 while in )r   r   failrw  appendr  s     r9   	in_methodz BaseFlowControlHandler.in_method\	  sX     ;;"IINNfdkkRSF#	DK$DKs   AA5A) !A5)	A22A5c              #   f   K   | j                   j                  d       t        j                   y w)Nr  )rw  rz  r   momentrB   s    r9   r  zBaseFlowControlHandler.prepareg	  s$      	I&jjs   /1c              #      K   | j                  d      5  t        j                   d d d        | j                  t	        | j
                               y # 1 sw Y   /xY ww)Nr   rw  )r{  r   r}  r[   rf   rw  rB   s    r9   r   zBaseFlowControlHandler.postn	  s>     ^^F#** $

4-. $#s   A!A.A!AA!N)rK   rL   rM   rd  
contextlibcontextmanagerr{  r   r   r  r   rI   r;   r9   ru  ru  U	  sQ    
   	]]  	]]/ /r;   ru  c                   x    e Zd Zd Zd Zdej                  fdZdej                  fdZdej                  fdZ	y)#BaseStreamingRequestFlowControlTestc                     t        dd      S )Nr  T)
chunk_sizedecompress_requestr   rB   s    r9   get_httpserver_optionsz:BaseStreamingRequestFlowControlTest.get_httpserver_optionsv	  s     rd;;r;   c                     t               S r2   r   rB   s    r9   rc  z3BaseStreamingRequestFlowControlTest.get_http_client{	  r  r;   rC   c                     | j                  ddd      }|j                          | j                  t        |j                        t        g d             y )NrR   abcdefghijklmnopqrstuvwxyzr   )r   r   r  rU  rU  rU  r   r  )r   r:  r}   r   r   rf   r   s     r9   test_flow_control_fixed_bodyz@BaseStreamingRequestFlowControlTest.test_flow_control_fixed_body	  sJ    ::c(DV:T&	
r;   c                     g dt         j                  fd       }| j                  d|d      }|j                          | j	                  t        |j                        t        g d             y )N)s   abcds   efghs   ijklc              3   0   K   D ]  } | |        y wr2   rI   )r[   ichunkss     r9   body_producerzYBaseStreamingRequestFlowControlTest.test_flow_control_chunked_body.<locals>.body_producer	  s     Ah s   rR   r   )r  r   r  r  )r   r   r   r:  r}   r   r   rf   )rC   r  r   r  s      @r9   test_flow_control_chunked_bodyzBBaseStreamingRequestFlowControlTest.test_flow_control_chunked_body	  sg    ,		 
	 ::cv:N&	
r;   c                 X   t               }t        j                  d|      }|j                  d       |j	                          |j                         }| j                  d|dddi      }|j                          | j                  t        |j                        t        g d	
             y )Nw)modefileobjs   abcdefghijklmnopqrstuvwxyzrR   r   ru  rt  )r   r   r,  r  r  )r0   rt  GzipFiler[   r  getvaluer   r:  r}   r   r   rf   )rC   bytesio	gzip_filecompressed_bodyr   s        r9   !test_flow_control_compressed_bodyzEBaseStreamingRequestFlowControlTest.test_flow_control_compressed_body	  s    )MMsG<	56!**,:: '0	  
 	&	
r;   N)
rK   rL   rM   r  rc  r  Anyr  r  r  rI   r;   r9   r  r  u	  s<    <
'

6:: 
 
VZZ 
.


 
r;   r  c                       e Zd Zd Zy)(DecoratedStreamingRequestFlowControlTestc                 @     G d dt               }d|t        |       fgS )Nc                   0    e Zd Zej                  d        Zy)ZDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandlerc              3   |   K   | j                  d      5  t        j                   d d d        y # 1 sw Y   y xY ww)NrU  )r{  r   r}  rT  s     r9   rU  zhDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandler.data_received	  s'     ^^O4**$ 544s   <0	<9<N)rK   rL   rM   r   r   rU  rI   r;   r9   DecoratedFlowControlHandlerr  	  s    ]]% %r;   r  rR   r   ru  rf   )rC   r  s     r9   r?   z5DecoratedStreamingRequestFlowControlTest.get_handlers	  s&    	%*@ 	% 14T?CDDr;   NrK   rL   rM   r?   rI   r;   r9   r  r  	  s    Er;   r  c                       e Zd Zd Zy)%NativeStreamingRequestFlowControlTestc                 @     G d dt               }d|t        |       fgS )Nc                       e Zd Zd Zy)TNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandlerc                    K   | j                  d      5  dd l}|j                  d       d {    d d d        y 7 # 1 sw Y   y xY ww)NrU  r   )r{  asyncior  )rC   r>  r  s      r9   rU  zbNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandler.data_received	  s=     ^^O4"!--*** 54 + 54s%   A	=;=	A	=AA	N)rK   rL   rM   rU  rI   r;   r9   NativeFlowControlHandlerr  	  s    +r;   r  rR   r   r  )rC   r  s     r9   r?   z2NativeStreamingRequestFlowControlTest.get_handlers	  s&    	+'= 	+ .$@AAr;   Nr  rI   r;   r9   r  r  	  s    Br;   r  c                       e Zd Zd Zd Zd Zy)IncorrectContentLengthTestc                 j    | d | _          G fddt              } G fddt              }d|fd|fgS )Nc                       e Zd Z fdZy)8IncorrectContentLengthTest.get_handlers.<locals>.TooHighc                     | j                  dd       	 | j                  d       y # t        $ r}|_         d }~ww xY w)Nr  r  rR  r  r   r  server_errorrC   r  r   s     r9   r\   z<IncorrectContentLengthTest.get_handlers.<locals>.TooHigh.get	  s>     0$7KK%  ()D%   ' 	=8=Nr]   r   s   r9   TooHighr  	      r;   r  c                       e Zd Z fdZy)7IncorrectContentLengthTest.get_handlers.<locals>.TooLowc                     | j                  dd       	 | j                  d       y # t        $ r}|_         d }~ww xY w)Nr  rU  rY   r  r  s     r9   r\   z;IncorrectContentLengthTest.get_handlers.<locals>.TooLow.get	  s>     0#6KK(  ()D%r  Nr]   r   s   r9   TooLowr  	  r  r;   r  /high/low)r  r   )rC   r  r  r   s      @r9   r?   z'IncorrectContentLengthTest.get_handlers	  s?     	n 		^ 	 '"VV$455r;   c                 \   t        t        d      5  t        t        d      5  | j                  t              5  | j                  dd       d d d        d d d        d d d        | j                  t        | j                        d       y # 1 sw Y   ?xY w# 1 sw Y   CxY w# 1 sw Y   GxY w)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   r}   r   r  rB   s    r9   test_content_length_too_highz7IncorrectContentLengthTest.test_content_length_too_high	  s     w LM5
 &&7JJwDJ9 8 N 	!!"$V	
 87  NM9   B"BB
BB"
BBB	B""B+c                 \   t        t        d      5  t        t        d      5  | j                  t              5  | j                  dd       d d d        d d d        d d d        | j                  t        | j                        d       y # 1 sw Y   ?xY w# 1 sw Y   CxY w# 1 sw Y   GxY w)Nr  r  r  Tr  z,Tried to write more data than Content-Lengthr  rB   s    r9   test_content_length_too_lowz6IncorrectContentLengthTest.test_content_length_too_low
  s     w LM5
 &&7JJv4J8 8 N 	!!"$R	
 87  NMr  N)rK   rL   rM   r?   r  r  rI   r;   r9   r  r  	  s    62
 
r;   r  c                   (    e Zd Z G d de      Zd Zy)ClientCloseTestc                       e Zd Zd Zy)ClientCloseTest.Handlerc                     | j                   j                  j                  d      r@| j                   j                  j                  j                          | j                  d       y | j                  d       y )NzHTTP/1rY   requires HTTP/1.x)r  rx   r  
connectionr  r  r[   rB   s    r9   r\   zClientCloseTest.Handler.get
  sS    ||##..x8 ''..446

7# 

./r;   Nr]   rI   r;   r9   rT   r  
  s    	0r;   rT   c                    | j                  t        t        j                  f      5  | j	                  dd      }|j
                  dk(  r| j                  d       | j                  |j                  d       d d d        y # 1 sw Y   y xY w)NrR   Tr  s   requires HTTP/1.xr  iW  )	r  r   rI  SkipTestr   r   skipTestr}   r   r   s     r9   test_client_closez!ClientCloseTest.test_client_close'
  sh    1B1BCDzz#4z8H}} 4412X]]C0	 EDDs   AA??BN)rK   rL   rM   r   rT   r  rI   r;   r9   r  r  
  s    0. 01r;   r  c                   d    e Zd ZdZddddZd Zd Zd Zd	 Zd
 Z	d Z
d Zd Zd Zd Zd Zd Zy)SignedValueTestzIt's a secret to everybody	asdfbasdf123123122342342)r   rv   r   c                 (    | j                         dz
  S )Ni 0* )presentrB   s    r9   pastzSignedValueTest.past3
  s    ||~
**r;   c                      y)Ni m|MrI   rB   s    r9   r  zSignedValueTest.present6
  s    r;   c                 F   t        t        j                  ddd| j                        }| j	                  |d       t        t        j                  ddd| j                        }| j	                  |d       t        t        j                  dd| j                        }| j	                  ||       t        t        j                  d|d| j                  	      }| j	                  |d
       t        t        j                  d|d| j                  	      }| j	                  |d
       y )Nr  rm   rv   )rx   clocks<   dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4fr   se   2|1:0|10:1300000000|3:key|8:dmFsdWU=|3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152r  )rz   r     value)r'   r  SECRETr  r}   r(   )rC   	signed_v1	signed_v2signed_default
decoded_v1
decoded_v2s         r9   test_known_valuesz!SignedValueTest.test_known_values9
  s   '""E7AT\\
	 	V	
 (""E7AT\\
	 	P	
 -""E7$,,
 	3(""E9!4<<

 	X.(""E9!4<<

 	X.r;   c                    t        t        j                  dd| j                        }t        t        j                  dd| j                        }t	        t        j                  d|| j                        }| j                  |d        t	        t        j                  d|| j                        }| j                  |d        y )Nkey1rm   r  key2)r'   r  r  r  r(   assertIs)rC   signed1signed2decoded1decoded2s        r9   test_name_swapzSignedValueTest.test_name_swapY
  s    %""FG4<<
 &""FG4<<
 '""FG4<<
 	h%&""FG4<<
 	h%r;   c                 6   t        t        j                  dd| j                        }t	        t        j                  d|| j                        }| j                  |d       t	        t        j                  d|| j                        }| j                  |d        y )Nr  rm   r  r  )r'   r  r  r  r(   r}   r  r  )rC   signeddecoded_pastdecoded_presents       r9   test_expiredzSignedValueTest.test_expiredj
  s}    $""FG499
 +""FF$))
 	x0-""FF$,,
 	ot,r;   c                      d fd} j                   |d              j                   |d              j                   |d              j                   |d             y )N@3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152c                 ^    dt        t        j                  d| z   j                        k(  S Nr  r  r  r(   r  r  r  )prefixrC   r   s    r9   validatez8SignedValueTest.test_payload_tampering.<locals>.validate{
  /    2&&v|4<<   r;   %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)rC   r  r   s   ` @r9   test_payload_tamperingz&SignedValueTest.test_payload_tamperingw
  s]    P	
 	!HIJ"IJK"HIJ"JKLr;   c                 ,    d fd} j                   |d              j                   |d              j                   |d              j                   |d              j                   |d              j                   |d             y )	Nr  c                 ^    dt        t        j                  d| z   j                        k(  S r  r  )r   r  rC   s    r9   r  z:SignedValueTest.test_signature_tampering.<locals>.validate
  r   r;   r   00000000000000000000000000000000@4d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152@3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e153?3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e15A3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e1538r  )rC   r  r  s   ` @r9   test_signature_tamperingz(SignedValueTest.test_signature_tampering
  s    8	
 	WX	
 	(+,WX	
 	WX	
 	VW	
 	S	
r;   c                     d}t        t        j                  d|| j                        }t	        t        j                  d|| j                        }| j                  ||       y )Nr   r  r  )r'   r  r  r  r(   r}   rC   rm   r  decodeds       r9   test_non_asciizSignedValueTest.test_non_ascii
  sU    $""E5
 &""E6
 	(r;   c                     d}t        t        j                  d|| j                  d      }t	        t        j                  d|| j                        }| j                  ||       y Nr   r  r   r  rd   r  r'   r  SECRET_DICTr  r(   r}   r  s       r9   *test_key_versioning_read_write_default_keyz:SignedValueTest.test_key_versioning_read_write_default_key
  X    $''T\\WX
 &''dll
 	(r;   c                     d}t        t        j                  d|| j                  d      }t	        t        j                  d|| j                        }| j                  ||       y )Nr   r  rv   r  r  r  r  s       r9   .test_key_versioning_read_write_non_default_keyz>SignedValueTest.test_key_versioning_read_write_non_default_key
  r  r;   c                    d}t        t        j                  d|| j                  d      }t        j                  j	                         }|j                  d       t        |d|| j                        }| j                  d |       y r  )r'   r  r  r  r   r   r(   r}   )rC   rm   r  newkeysr  s        r9   test_key_versioning_invalid_keyz/SignedValueTest.test_key_versioning_invalid_key
  sl    $''T\\WX
 "--224A%gufDLLQw'r;   c                     d}t        t        j                  d|| j                  d      }t	        |      }| j                  d|       y )Nr   r  rv   r  )r'   r  r  r  r)   r}   )rC   rm   r  rd   s       r9   test_key_version_retrievalz*SignedValueTest.test_key_version_retrieval
  sC    $''T\\WX
 07K(r;   N)rK   rL   rM   r  r  r  r  r  r  r  r  r  r  r  r  r  r  rI   r;   r9   r  r  /
  sR    )F!jY?K+/@&"-M"
@)))()r;   r  c                        e Zd Z G d de      Zd Z fdZddZddZd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )XSRFTestc                       e Zd Zd Zd Zy)XSRFTest.Handlerc                     t        | j                  dd            }|| j                  d<   | j                  | j                         y )Nrx   rU  xsrf_cookie_version)r  r  rb   r[   r  )rC   rx   s     r9   r\   zXSRFTest.Handler.get
  s:    $++Is;<G 4;DMM/0JJt'r;   c                 &    | j                  d       y rQ  rZ   rB   s    r9   r   zXSRFTest.Handler.post
      JJtr;   NrK   rL   rM   r\   r   rI   r;   r9   rT   r"  
  s    	(	r;   rT   c                     t        d      S r  r   rB   s    r9   r@   zXSRFTest.get_app_kwargs
  r  r;   c                 L    t         |           | j                         | _        y r2   r%  setUp	get_tokenr  r)  s    r9   r+  zXSRFTest.setUp
      ..*r;   c                     || j                  |      }nd }| j                  |dnd|z  |      }|j                          t        |j                        S )NrR   z/?version=%dr2  cookie_headersr   r:  r	   r   )rC   	old_tokenrx   r,  r   s        r9   r,  zXSRFTest.get_token
  s]     )))4GG::?C')AG  
 	(--((r;   c                 ,    || j                   }dd|z   iS )Nr0  z_xsrf=r  rC   tokens     r9   r0  zXSRFTest.cookie_headers
  s     =OOE(U*++r;   c                     t        t        d      5  | j                  ddd      }d d d        | j                  j                  d       y # 1 sw Y   &xY wN.*'_xsrf' argument missingrR   r   r;   r   rB  rF  r   s     r9   test_xsrf_fail_no_tokenz XSRFTest.test_xsrf_fail_no_token
  C    w <=zz#f3z?H >, >=   AAc           
         t        t        d      5  | j                  ddt        j                  j                  t        | j                                    }d d d        | j                  j                  d       y # 1 sw Y   &xY wN!.*XSRF cookie does not match POSTrR   r   _xsrfr   rB  
r   r   r   rf  rg  rh  rf   r  r}   r   r   s     r9   test_xsrf_fail_body_no_cookiez&XSRFTest.test_xsrf_fail_body_no_cookie  g    w CDzz\\++Dt,GH " H E 	, ED   AA<<Bc                    t        t        d      5  | j                  dd| j                         t        j
                  j                  t        d                  }d d d        | j                  j                  d       y # 1 sw Y   &xY w)Nz%.*'_xsrf' argument has invalid formatrR   r   3|r?  r=  rB  )
r   r   r   r0  rf  rg  rh  rf   r}   r   r   s     r9   &test_xsrf_fail_argument_invalid_formatz/XSRFTest.test_xsrf_fail_argument_invalid_format
  so    w GHzz++-\\++Dt,<=	 " H I 	, IHs   ABB
c                 2   t        t        d      5  | j                  dd| j                  d      t        j
                  j                  t        | j                                    }d d d        | j                  j                  d       y # 1 sw Y   &xY w)	Nr>  rR   r   rF  r5  r?  r=  rB  )r   r   r   r0  rf  rg  rh  rf   r  r}   r   r   s     r9   $test_xsrf_fail_cookie_invalid_formatz-XSRFTest.test_xsrf_fail_cookie_invalid_format  sx    w CDzz++$+7\\++Dt,GH	 " H E 	, EDs   ABBc                     t        t        d      5  | j                  ddd| j                               }d d d        | j	                  j
                  d       y # 1 sw Y   &xY w)Nr8  rR   r   r;   r   r   r,  rB  )r   r   r   r0  r}   r   r   s     r9   test_xsrf_fail_cookie_no_bodyz&XSRFTest.test_xsrf_fail_cookie_no_body  sV    w <=zzFd6I6I6K " H > 	,	 >=s   $AA#c           	          | j                  ddt        j                  j                  t	        d            | j                  d            }| j                  |j                  d       y )NrR   r   deadbeefr?  rI  rL  r   r   rf  rg  rh  rf   r0  r}   r   r   s     r9   test_xsrf_success_short_tokenz&XSRFTest.test_xsrf_success_short_token%  sY    ::'':(>?''j'9	  
 	,r;   c           	          | j                  ddt        j                  j                  t	        d            | j                  d            }| j                  |j                  d       y )NrR   r   xoxor?  rI  rL  r   rP  r   s     r9   test_xsrf_success_non_hex_tokenz(XSRFTest.test_xsrf_success_non_hex_token.  sY    ::''6(:;''f'5	  
 	,r;   c           	          | j                  ddt        j                  j                  t	        | j
                              | j                               }| j                  |j                  d       y NrR   r   r?  rL  r   	r   rf  rg  rh  rf   r  r0  r}   r   r   s     r9   test_xsrf_success_post_bodyz$XSRFTest.test_xsrf_success_post_body7  sX    ::''4??(CD'')	  
 	,r;   c                     | j                  dt        j                  j                  t	        | j
                              z   dd| j                               }| j                  |j                  d       y )Nz/?r?  r   r;   rL  r   rW  r   s     r9   test_xsrf_success_query_stringz'XSRFTest.test_xsrf_success_query_string@  s]    ::6<<))$T__*EFF'')	  
 	,r;   c                     | j                  dddt        d| j                  ifi | j                               }| j	                  |j
                  d       y )NrR   r   r;   zX-XsrftokenrL  r   )r   rf   r  r0  r}   r   r   s     r9   test_xsrf_success_headerz!XSRFTest.test_xsrf_success_headerI  sY    ::0%%'	  
 	,r;   c                     d}t               }t        |      D ]!  }|j                  | j                                # | j	                  t        |      |       y )Nr  )r  ranger  r,  r}   r;  )rC   
NUM_TOKENStokensr  s       r9   test_distinct_tokenszXSRFTest.test_distinct_tokensU  sD    
z"AJJt~~'( #Vj1r;   c                 x   | j                         }| j                  |fD ]i  }| j                  ddt        j                  j                  t        |            | j                  |            }| j                  |j                  d       k | j                  |f|| j                  ffD ]  \  }}t        t        d      5  | j                  ddt        j                  j                  t        |            | j                  |            }d d d        | j                  j                  d        y # 1 sw Y   (xY w)NrR   r   r?  rL  r   r>  rB  )r,  r  r   rf  rg  rh  rf   r0  r}   r   r   r   )rC   token2r5  r   cookie_token
body_tokens         r9   test_cross_userzXSRFTest.test_cross_user]  s   !oov.Ezz\\++Du,=>++E2	 " H X]]C0 / __f%T__%)
$L* 7$GH::!//:0FG //=	 &  I X]]C0)
 IHs   =AD00D9	c           
         | j                   }t        |g      }t        d      D ]  }| j                  |      }|j	                  |       | j                  ddt        j                  j                  t        | j                               | j                  |            }| j                  |j                  d        | j                  t        |      d       y )N   rR   r   r?  rL  r      )r  r  r^  r,  r  r   rf  rg  rh  rf   r0  r}   r   r;  )rC   r5  tokens_seenr  r   s        r9   test_refresh_tokenzXSRFTest.test_refresh_tokenv  s    5'l
 qANN5)EOOE"zz\\++Dt,GH++E2	 " H X]]C0  	[)1-r;   c           
      h   | j                  | j                  d      | j                  d             | j                  d      }t        d      D ]%  }| j                  | j                  |d      |       ' | j                  |      }| j                  ||       | j                  || j                  |             ||f||ffD ]l  \  }}| j	                  ddt
        j                  j                  t        |            | j                  |            }| j                  |j                  d       n y )	Nrv   rw   rh  rR   r   r?  rL  r   )assertNotEqualr,  r^  r}   r   rf  rg  rh  rf   r0  r   )rC   v1_tokenr  v2_tokenrd  re  r   s          r9   test_versioningzXSRFTest.test_versioning  s   DNN1N5t~~a~7PQ >>!>,qAT^^Ha^@(K  >>(+Hh/HdnnX&>? +3H)=(?S(T$L*zz\\++Dz,BC++L9	 " H X]]C0 )Ur;   r  r2   )rK   rL   rM   r   rT   r@   r+  r,  r0  r9  rB  rG  rJ  rM  rQ  rT  rX  rZ  r\  ra  rf  rk  rp  rx  ry  s   @r9   r   r   
  si    	. 	'+	),
-
--------
-212.(1r;   r   c                   \     e Zd Z G d de      Zd Z fdZd
dZd
dZd Z	d Z
d	 Z xZS )XSRFCookieNameTestc                       e Zd Zd Zd Zy)XSRFCookieNameTest.Handlerc                 :    | j                  | j                         y r2   r[   r  rB   s    r9   r\   zXSRFCookieNameTest.Handler.get      JJt'r;   c                 &    | j                  d       y rQ  rZ   rB   s    r9   r   zXSRFCookieNameTest.Handler.post  r&  r;   Nr'  rI   r;   r9   rT   rt    s    	(	r;   rT   c                 "    t        ddddi      S )NTz__Host-xsrfr  )r  xsrf_cookie_namexsrf_cookie_kwargsr   rB   s    r9   r@   z!XSRFCookieNameTest.get_app_kwargs  s    * ($/
 	
r;   c                 L    t         |           | j                         | _        y r2   r*  r)  s    r9   r+  zXSRFCookieNameTest.setUp  r-  r;   c                     || j                  |      }nd }| j                  d|      }|j                          t        |j                        S )NrR   r2  r/  )rC   r1  r,  r   s       r9   r,  zXSRFCookieNameTest.get_token  sJ     )))4GG::c7:3(--((r;   c                 ,    || j                   }dd|z   iS )Nr0  z__Host-xsrf=r3  r4  s     r9   r0  z!XSRFCookieNameTest.cookie_headers  s     =OOE.5011r;   c                     t        t        d      5  | j                  ddd      }d d d        | j                  j                  d       y # 1 sw Y   &xY wr7  rF  r   s     r9   r9  z*XSRFCookieNameTest.test_xsrf_fail_no_token  r:  r;  c           
         t        t        d      5  | j                  ddt        j                  j                  t        | j                                    }d d d        | j                  j                  d       y # 1 sw Y   &xY wr=  rA  r   s     r9   rB  z0XSRFCookieNameTest.test_xsrf_fail_body_no_cookie  rC  rD  c           	          | j                  ddt        j                  j                  t	        | j
                              | j                               }| j                  |j                  d       y rV  rW  r   s     r9   rX  z.XSRFCookieNameTest.test_xsrf_success_post_body  sX    ::''4??(CD'')  
 	,r;   r2   )rK   rL   rM   r   rT   r@   r+  r,  r0  r9  rB  rX  rx  ry  s   @r9   rr  rr    s2    . 
+)2
-
--r;   rr  c                   .    e Zd Z G d de      Zd Zd Zy)XSRFCookieKwargsTestc                       e Zd Zd Zy)XSRFCookieKwargsTest.Handlerc                 :    | j                  | j                         y r2   rv  rB   s    r9   r\   z XSRFCookieKwargsTest.Handler.get  rw  r;   Nr]   rI   r;   r9   rT   r    s    	(r;   rT   c                 2    t        dt        dd            S )NTr   )r  rn   )r  r{  r   rB   s    r9   r@   z#XSRFCookieKwargsTest.get_app_kwargs  s    $ST2U
 	
r;   c                    | j                  d      }| j                  d|j                  d   j                                | j                  d|j                  d   j                                |j                  j	                  d      }|J t        j                  d|      }|J t        j                  j                  t        j                  j                        t        j                  d      z   }t        j                  j                  |j                         d         }|j                   *|j#                  t        j                  j                  	      }| j%                  t'        ||z
  j)                               d
k         y )NrR   z	httponly;r*  zexpires=z.*; expires=(?P<expires>.+);.*r   rI  rK  )tzinfor  )r   r  r,  r[  r\   r   r   rL  rM  rN  rO  rP  rQ  rR  rS  rT  r  replacer   rU  rV  rW  s         r9   test_xsrf_httponlyz'XSRFCookieKwargsTest.test_xsrf_httponly  s;   ::c?k8#3#3L#A#G#G#IJj("2"2<"@"F"F"HI!!%%l3!!!96B   ##''(9(9(=(=>ASASB
 
 ::5??;LY;WX  (+338;L;L;P;P3QNW~5DDFG"LMr;   N)rK   rL   rM   r   rT   r@   r  rI   r;   r9   r  r    s    (. (

Nr;   r  c                   (    e Zd Z G d de      Zd Zy)FinishExceptionTestc                       e Zd Zd Zy)FinishExceptionTest.Handlerc                     | j                  d       | j                  dd       | j                  dd      rt        d      | j	                  d       t               )Nr\  WWW-AuthenticateBasic realm="something"finish_valuero  zauthentication required)r  r  r  r+   r[   rB   s    r9   r\   zFinishExceptionTest.Handler.get  sN    OOC OO.0IJ  4677

45hr;   Nr]   rI   r;   r9   rT   r    s    	r;   rT   c                     dD ]v  }| j                  |      }| j                  |j                  d       | j                  d|j                  j	                  d             | j                  d|j
                         x y )N)rR   z/?finish_value=1r\  r  r  s   authentication required)r   r}   r   r,  r\   r   )rC   ur   s      r9   test_finish_exceptionz)FinishExceptionTest.test_finish_exception  si    *Azz!}HX]]C0)8+;+;+?+?@R+S 7G +r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    s    . Hr;   r  c                       e Zd Zd Zd Zd Zy)DecoratorTestc                 N     G d dt               } G d dt               }d|fd|fgS )Nc                       e Zd Zed        Zy)6DecoratorTest.get_handlers.<locals>.RemoveSlashHandlerc                      y r2   rI   rB   s    r9   r\   z:DecoratorTest.get_handlers.<locals>.RemoveSlashHandler.get      r;   N)rK   rL   rM   r-   r\   rI   r;   r9   RemoveSlashHandlerr    s     r;   r  c                       e Zd Zed        Zy)3DecoratorTest.get_handlers.<locals>.AddSlashHandlerc                      y r2   rI   rB   s    r9   r\   z7DecoratorTest.get_handlers.<locals>.AddSlashHandler.get  r  r;   N)rK   rL   rM   r.   r\   rI   r;   r9   AddSlashHandlerr    s     r;   r  /removeslash/	/addslashr   )rC   r  r  s      r9   r?   zDecoratorTest.get_handlers  s2    	 	
	n 	
 !"45_7UVVr;   c                 <   | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )	Nr  Frp  rY  rs  z/removeslashz/removeslash/?foo=barz/removeslash?foo=barr]  r   s     r9   test_removeslashzDecoratorTest.test_removeslash  s    ::o:F,))*5~F::5:N,))*57MNr;   c                 <   | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )	Nr  Frp  rY  rs  z
/addslash/z/addslash?foo=barz/addslash/?foo=barr]  r   s     r9   test_addslashzDecoratorTest.test_addslash'  s    ::kE:B,))*5|D::1E:J,))*57KLr;   N)rK   rL   rM   r?   r  r  rI   r;   r9   r  r    s    WOMr;   r  c                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)	CacheTestc                 *     G d dt               }d|fgS )Nc                       e Zd Zd Zd Zy)+CacheTest.get_handlers.<locals>.EtagHandlerc                 &    | j                  |       y r2   rZ   )rC   computed_etags     r9   r\   z/CacheTest.get_handlers.<locals>.EtagHandler.get4  s    

=)r;   c                      | j                   d   S r  )_write_bufferrB   s    r9   compute_etagz8CacheTest.get_handlers.<locals>.EtagHandler.compute_etag7  s    ))!,,r;   N)rK   rL   rM   r\   r  rI   r;   r9   EtagHandlerr  3  s    *-r;   r  z
/etag/(.*)r   )rC   r  s     r9   r?   zCacheTest.get_handlers2  s    	-. 	- {+,,r;   c                 2    d}d}| j                  ||d       y )N"xyzzy"*r  
_test_etagrC   r  etagss      r9   test_wildcard_etagzCacheTest.test_wildcard_etag<  s    !uc2r;   c                 2    d}d}| j                  ||d       y )Nr  r  r  r  s      r9   test_strong_etag_matchz CacheTest.test_strong_etag_matchA  s    !uc2r;   c                 2    d}d}| j                  ||d       y )N"xyzzy1""xyzzy1", "xyzzy2"r  r  r  s      r9   test_multiple_strong_etag_matchz)CacheTest.test_multiple_strong_etag_matchF  s    "$uc2r;   c                 2    d}d}| j                  ||d       y )Nr  r  r   r  r  s      r9   test_strong_etag_not_matchz$CacheTest.test_strong_etag_not_matchK  s    !uc2r;   c                 2    d}d}| j                  ||d       y )Nr  r  r   r  r  s      r9   #test_multiple_strong_etag_not_matchz-CacheTest.test_multiple_strong_etag_not_matchP  s    !$uc2r;   c                 2    d}d}| j                  ||d       y )Nr  
W/"xyzzy1"r  r  r  s      r9   test_weak_etag_matchzCacheTest.test_weak_etag_matchU      "uc2r;   c                 2    d}d}| j                  ||d       y )N"xyzzy2"W/"xyzzy1", W/"xyzzy2"r  r  r  s      r9   test_multiple_weak_etag_matchz'CacheTest.test_multiple_weak_etag_matchZ      "(uc2r;   c                 2    d}d}| j                  ||d       y )Nr  r  r   r  r  s      r9   test_weak_etag_not_matchz"CacheTest.test_weak_etag_not_match_  r  r;   c                 2    d}d}| j                  ||d       y )Nz"xyzzy3"r  r   r  r  s      r9   !test_multiple_weak_etag_not_matchz+CacheTest.test_multiple_weak_etag_not_matchd  r  r;   c                 l    | j                  d|z   d|i      }| j                  |j                  |       y )Nz/etag/r  r2  rZ  )rC   r  r  r  r   s        r9   r  zCacheTest._test_etagi  s:    ::}$.F  
 	4r;   N)rK   rL   rM   r?   r  r  r  r  r  r  r  r  r  r  rI   r;   r9   r  r  1  s9    -3
3
3
3
3
3
3
3
3
5r;   r  c                   (    e Zd Z G d de      Zd Zy)RequestSummaryTestc                       e Zd Zd Zy)RequestSummaryTest.Handlerc                 d    d | j                   _        | j                  | j                                y r2   )r  	remote_ipr   r  rB   s    r9   r\   zRequestSummaryTest.Handler.getr  s%     &*DLL"KK--/0r;   Nr]   rI   r;   r9   rT   r  q  s    	1r;   rT   c                 ^    | j                  d      }| j                  |j                  d       y )NrR   s   GET / (None)r4  rF  s     r9   test_missing_remote_ipz)RequestSummaryTest.test_missing_remote_ipy  s#    zz#O4r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r  p  s    1. 15r;   r  c                       e Zd Zd Zy)HTTPErrorTestc                    t        dd      }t        j                  |      }| j                  ||       | j                  |j                  |j                         | j                  |j
                  |j
                         y )NrB  zGo awayr  )r!   r   assertIsNotr}   r  r  )rC   r  e2s      r9   	test_copyzHTTPErrorTest.test_copy  s[    c),YYq\B7299-r;   N)rK   rL   rM   r  rI   r;   r9   r  r  ~  s    .r;   r  c                       e Zd Zd Zy)ApplicationTestc                 `    t        g       }|j                  dd      }|j                          y )Nr   r  )address)r   listenr  )rC   rA   servers      r9   test_listenzApplicationTest.test_listen  s&    "oA{3r;   N)rK   rL   rM   r  rI   r;   r9   r  r    s    r;   r  c                       e Zd Zd Zd Zd Zy)URLSpecReverseTestc                     | j                  dt        dd       j                                | j                  dt        dd       j                                y )Nz/favicon.icoz/favicon\.icoz^/favicon\.ico$r}   r%   reverserB   s    r9   test_reversezURLSpecReverseTest.test_reverse  sD    -=t)D)L)L)NO-?)F)N)N)PQr;   c                     dg}|D ]6  }t        |d       }	 |j                         }| j                  d|d|       8 y # t        $ r Y Ew xY w)Nz^/api/v\d+/foo/(\w+)$z.did not get expected exception when reversing z
. result: )r%   r  ry  r  )rC   pathsr4   url_specr  s        r9   test_non_reversiblez&URLSpecReverseTest.test_non_reversible  s^    
 **D4H!))+		$(&2   s   'A  	AAc                     | j                  dt        dd       j                  d             | j                  dt        dd       j                  d             y )Nz/api/v1/foo/barz^/api/v1/foo/(\w+)$r  z/api.v1/foo/5/icon.pngz/api\.v1/foo/([0-9]+)/icon\.pngrh  r  rB   s    r9   test_reverse_argumentsz)URLSpecReverseTest.test_reverse_arguments  sQ    s#94@HHO	
 	$2D9AA!D	
r;   N)rK   rL   rM   r  r  r  rI   r;   r9   r  r    s    R$
r;   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)RedirectHandlerTestc                 B    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})r7  rB   s    r9   r?   z RedirectHandlerTest.get_handlers  s;    '%9(5/*BC!#5~7NO
 	
r;   c                     | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )Nr  Frp  rY  rs  r  r]  r   s     r9   test_basic_redirectz'RedirectHandlerTest.test_basic_redirect  sC    ::fu:=,))*5v>r;   c                     | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )Nz/src?foo=barFrp  rY  rs  z/dst?foo=barr]  r   s     r9   test_redirect_with_argumentz/RedirectHandlerTest.test_redirect_with_argument  sC    ::nu:E,))*5~Fr;   c                     | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )Nz/src2?foo2=bar2Frp  rY  rs  z/dst2?foo=bar&foo2=bar2r]  r   s     r9   %test_redirect_with_appending_argumentz9RedirectHandlerTest.test_redirect_with_appending_argument  sE    ::/%:H,))*57PQr;   c                     | j                  dd      }| j                  |j                  d       | j                  |j                  d   d       y )Nz/a/b/cFrp  rY  rs  z/b/a/cr]  r   s     r9   test_redirect_patternz)RedirectHandlerTest.test_redirect_pattern  sC    ::h:?,))*5x@r;   N)rK   rL   rM   r?   r  r  r  r  rI   r;   r9   r  r    s    
?
G
R
Ar;   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)AcceptLanguageTestz)Test evaluation of Accept-Language headerc                     t        j                  t        j                  j	                  t        j                  j                  t              d      d        G d dt              }d|fgS )Ngettext_translationstornado_testc                       e Zd Zd Zy)>AcceptLanguageTest.get_handlers.<locals>.AcceptLanguageHandlerc                     | j                  d| j                         j                  j                  dd             | j	                  d       y )Nr  _-r;   )r  get_browser_localer   r  r   rB   s    r9   r\   zBAcceptLanguageTest.get_handlers.<locals>.AcceptLanguageHandler.get  s>    &(?(?(A(F(F(N(NsTW(X C r;   Nr]   rI   r;   r9   AcceptLanguageHandlerr    s    !r;   r  rR   )r   load_gettext_translationsr3   r4   r5   r6   r7   r   )rC   r  s     r9   r?   zAcceptLanguageTest.get_handlers  sT    ((GGLL24JK	

	!N 	! '(
 	
r;   c                     | j                  dddi      }| j                  |j                  d   d       | j                  dddi      }| j                  |j                  d   d       y )NrR   r3  zfr-FR;q=0.9r2  r  zfr-FRzfr-FR; q=0.9r   r}   r,  r   s     r9   test_accept_languagez'AcceptLanguageTest.test_accept_language  sj    ::c,=}+M:N))*<=wG::c,=~+N:O))*<=wGr;   c                 l    | j                  dddi      }| j                  |j                  d   d       y )NrR   r3  z	fr-FR;q=0r2  r  en-USr  r   s     r9   test_accept_language_ignorez.AcceptLanguageTest.test_accept_language_ignore  s6    ::c,={+K:L))*<=wGr;   c                 l    | j                  dddi      }| j                  |j                  d   d       y )NrR   r3  z
fr-FR;q=-1r2  r  r  r  r   s     r9   test_accept_language_invalidz/AcceptLanguageTest.test_accept_language_invalid  s6    ::c,=|+L:M))*<=wGr;   N)rK   rL   rM   rN   r?   r  r  r  rI   r;   r9   r  r    s    3
"HHHr;   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    r7  r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r   r  r   rL  email.utilsrQ  rt  ior0   r  r<  r3   r   r  r  rI  urllib.parserf  r:   r=   rP   rV   r_   TestCaserr   r   r   r   r`  rk  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r{  r  r  rL  r^  rk  rq  r  r  r  r  r  r  r  r  r  r  r  r=  rM  r  rX  r[  ru  r~  r  r  r  r  r  r	  r  r  r'  r-  r8  r?  rJ  ru  objectr  r  r  r  r  r  r   rr  r  r  r  r  r  r  r  r  r  r  rI   r;   r9   <module>r*     s   %   / - %   ( ; ' Q Q 0 1     ,          	 	    7# $	%K 	%> 
$~ $,1S** 1Sj,E** ,E^.9k .9b\= \=~
 

{ 
8
(^ 
(+ 0
. 
6--+ --`)U~ )UXY~ Y*B^ B
1n 1
#. #
( (Hn H 	^ 	. .
. 
JOk JOZ/k /?1 ?1D_-[ _-DO O*"-K "-J;[ ;@C; @CF'0{ '0T0k 0D0[ 0&8+ 8
@) 
@F) F*5, 58
* 
C/ C,-; -&7
( 7
tHK H2
/ 
$	i 	,10 ,1^, +
0 +
\
0 
">1 >,Y1 Y1x
1#8 
1-*? -$:. :&2+ 2*1/ 1 
[ 
@K @$-+ -. .$[ { [ D /^ / />J
& J
Z
E'
EB'B8
!6 8
v1+ 1.g)h'' g)TH1$ H1X7-. 7-tN0 N8H/ H*MK MB<5 <5~5. 5.H%% .m 
** 
BA+ A:!H !Hr;   