
    Xhy                    <	   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 dFe'      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\eM      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 dheN      Zw G di djeM      Zx G dk dleN      Zy G dm dneM      Zz G do dpeN      Z{ G dq dre|      Z} G ds dteN      Z~ G du dveN      Z G dw dxeN      Z G dy dzeN      Z G d{ d|eN      Z G d} d~eM      Z G d deN      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 d      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    I/var/www/html/myenv/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 |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 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assertIsNotNonegroupr}   r&   rg   rb   r   r
   r   r   assertIsNoner~   )rC   r   cookier   	timestampsigs         r9   &test_cookie_tampering_future_timestampz9SecureCookieV1Test.test_cookie_tampering_future_timestamp   sn   *,!!%)9)9/)JTU!V!!%(<fEU#   KKN	kk!n ##,,_=	 	
 	 ##,,_=)#	 	
 #'i01=3E2FG#
 w <= 	Og7717MN	O 	O 	Os   ;#E''E0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
%ON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   
assertTrue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.get5  s    ub9r;   Nr]   rI   r;   r9   SetCookieMaxAgeHandlerr  4  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.get9  s    u2>r;   Nr]   rI   r;   r9   SetCookieExpiresDaysHandlerr  8  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.getD  s    S4fEr;   Nr]   rI   r;   r9   SetCookieDeprecatedArgsr  C  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_cookieT  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_cookie[  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_domaine  s8    ::m,%%l3;<	
r;   c                    | j                  d      }t        |j                  j                  d            }| j	                  t        |      d       | j	                  |d   d       | j	                  |d   d       | j                  |d   d	|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#  r2  r4  )r   r-  r.  r/  r}   lenassertInloggingdebugr   r   )rC   r   r.  dataheaderexpecteds         r9   test_cookie_special_charz#CookieTest.test_cookie_special_charl  s    ::o.))22<@AWq)%;<%<=AJF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=/rF  rG  s      r9   test_set_cookie_max_agez"CookieTest.test_set_cookie_max_age  s>    ::n-""++L9+H*IJr;   c                 0   | j                  d      }|j                  j                  d      }| j                  |       |J t	        j
                  d|      }| j                  |       |J t        j                  j                  t        j                  j                        t        j                  d      z   }t        j                  j                  |j                         d         }| j                  t!        ||z
  j#                               d       y )Nr(  r,  z(foo=bar; expires=(?P<expires>.+); Path=/r  daysexpires)r   r.  r\   r   r   r   datetimenowtimezoneutc	timedeltaemailutilsparsedate_to_datetime	groupdict
assertLessabstotal_secondsrC   r   rB  r   rN  header_expiress         r9   test_set_cookie_expires_daysz'CookieTest.test_set_cookie_expires_days  s    ::12!!%%l3V$!!!CVLU#   ##''(9(9(=(=>ASASB
 
 ::5??;LY;WXW~5DDFGLr;   c                    | j                  d      }t        |j                  j                  d            }| j	                  |d   d       | j	                  |d   d       | j	                  |d   d       | j	                  |d	   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}   rG  s      r9   test_set_cookie_false_flagsz&CookieTest.test_set_cookie_false_flags  s~    ::01))22<@A%:;]3%<=]3r;   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   rB  s      r9   test_set_cookie_deprecatedz%CookieTest.test_set_cookie_deprecated  sS    ! 	5zz"34H	5!!%%l3!;<	5 	5s   AAN)rK   rL   rM   r?   r0  r7  r:  rD  rH  rJ  r]  r_  ra  rI   r;   r9   r   r     s8    A
F
4
<4
K
M4=r;   r   c                   (    e Zd Zd Zd Zed        Zy)AuthRedirectRequestHandlerc                     || _         y r2   	login_url)rC   rf  s     r9   
initializez%AuthRedirectRequestHandler.initialize  s	    "r;   c                     | j                   S r2   re  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   rg  ri  r$   r\   rI   r;   r9   rc  rc    s     #  r;   rc  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/loginre  	/absolutezhttp://example.com/login)rc  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 )Nrp  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 )Nrq  Frs  ru  zIhttp://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2Fabsoluterv  )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?   rw  ry  rI   r;   r9   rn  rn    s    
R
	
r;   rn  c                   <    e Zd Zd Zej
                  d        Zd Zy)ConnectionCloseHandlerc                     || _         y r2   r   r   s     r9   rg  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   rg  r   r   r\   r  rI   r;   r9   r{  r{    s$     	]]- -(r;   r{  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  r{  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l r;   )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        urt	        dt        |      z        | j                   j                  |   D ]*  }t        |      t
        ust	        dt        |      z         | j                  |      D ]*  }t        |      t        ust	        dt        |      z          |D ]*  }t        |      t        u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,   
 <<)) 	SCCy# <tCy HII,,005 S<u,#$BT&\$QRRS ,,S1 S<|3#$BT&\$QRRS	S  	OCCy, ADI MNN	O 	

\\&&#&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_slashes6  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_errorB  s1     w 34 	-JJ+,	- 	- 	-   ,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.prepareJ  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.gete  s%     	(.,G

4;;r;   c                 h    | j                  d|t               | j                  | j                         y r  r  r  s     r9   r   zTypeCheckHandler.postk  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_typeo  s3    3iK'"+M?& NDKK (r;   N)rK   rL   rM   r  r\   r   r  rI   r;   r9   r  r  I  s    I6  Or;   r  c                       e Zd ZddZd Zy)DecodeArgHandlerNc                     t        |      t        u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_argumentv  sb    ;e#;d5kIJJ///<<
4<<+A+A*+Ma+P QRRLr;   c                 h    d }| j                   ||       || j                  d            d       y )Nc                     t        |       t        u r dt        t        j                  |             gS t        |       t
        u 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  u  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)NX-Foozfoo
X-Bar: bazDidn't get expected exception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)SetHeaderHandlerc                    t        dd      D cg c]  }t        |       }}|j                  t        d             |j                  d       |D ]%  }	 | j	                  dd|z   dz          t        d       | j	                  dd
       | j                  d       y c c}w # t        $ r}d	t        |      vr Y d }~md }~ww xY w)Nr          	r  rt   r  r  r   r  )	rangechrappendremover  r  r  r   r   )rC   r  illegal_charscharr  s        r9   r\   zSetHeaderHandler.get  s    ).q$8AQ88SY'T"! 	D)=> ?@@	 	$E 9  (A6 7s   B#B!!	C*B==C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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   r9  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              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/set_header)r%   r  r  r  r  r  r  r    WebRedirectHandlerr  r!  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6/07
: r;   c                 p     | j                   |i |}|j                          t        |j                        S r2   )r   rethrowr   r   )rC   r  kwargsr   s       r9   r  zWSGISafeWebTest.fetch_json1  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=barr2  zasdf=r4  r   r3  r   r.  r   )r   r'   r4  r   r   r   r}   )rC   r  r   rA  s       r9   
test_typeszWSGISafeWebTest.test_types6  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   rN  r   r   r}   rC   rL  req_urlr   rA  s        r9   test_decode_argumentz$WSGISafeWebTest.test_decode_argumentG  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_unicode\  sh    w 56 	1zz"9:HX]]C0zz">?HX]]C0		1 	1 	1s   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  rU  rV  s        r9   test_decode_argument_plusz)WSGISafeWebTest.test_decode_argument_plusd  sn     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%A9r]  z/decode_arg/1%20%2B%201)r}   rA   r  rB   s    r9   test_reverse_urlz WSGISafeWebTest.test_reverse_urls  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 )NrA  s3   <a href="http://example.com">http://example.com</a>r6  r   s     r9   test_uimodule_unescapedz'WSGISafeWebTest.test_uimodule_unescaped~  s(    ::j)MMQ	
r;   c                 ^    | j                  d      }| j                  |j                  d       y )NrB  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>r6  r   s     r9   test_uimodule_resourcesz'WSGISafeWebTest.test_uimodule_resources  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 )NrC  r  2r  3r  r9  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=1Frs  -  z/redirect?permanent=0ru  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 )	NrD  Frs  rm  rv  rE  rF  ru  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 )NrG  Frs  rm  rv  rE  rq  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 )NrH  r  r6  r   s     r9   test_header_injectionz%WSGISafeWebTest.test_header_injection  s%    ::12.r;   c                 ^    | j                  d      }| j                  |j                  d       y )NrJ  r  r6  r   s     r9   test_set_headerzWSGISafeWebTest.test_set_header  s$    ::m,.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;   rI  r5  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   rz  z"/get_argument?source=query&foo=barr   r   ru   z/get_argument?source=query&foo=r;   z/get_argument?source=queryr5  r|  r}  r~  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  rz  z#/get_argument?source=body&foo=hellor   r   ru   r  r;   r5  r  r  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 )NrI  Accept-EncodingVaryr  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   r4  r@   r9  r?   r  rR  rX  r[  r^  ra  rc  re  rg  rk  ro  rr  rt  rv  rx  r  r  r  r  __classcell__r=  s   @r9   r/  r/    s}    +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  r6  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  rl  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_coderO  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                         | 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)NUncaught exceptionr  rk  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MM7Gzz"78HX]]C0MM5x}}Ezz"78HX]]C0MM/8==9	: 	: 	:s   CC66C?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  rk  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]];	< 	< 	<s   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  rk  r;   r  r   s     r9   test_failed_write_errorz)ErrorResponseTest.test_failed_write_errorF  sY    w 45 	1zz"78HX]]C0S(--0	1 	1 	1s   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+d% Z, e-j\                  ej^                  d&k7  d'      d(        Z0y))*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.getX  s3    T../@#FG

4??4?HIr;   Nr]   rI   r;   r9   StaticUrlHandlerr  W  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  \  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.get`  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  _  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_handlersV  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                         | j                  d      }| j                  d|j                         | 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_files~  sd    ::m,nhmm4::23nhmm4))--n=|Lr;   c                     | j                  d      }| j                  d|j                         | j                  d|j                         | j                  d|j                         y )Nz/robots.txt?v=12345r  zCache-ControlExpires)r   r>  r   r.  r   s     r9   test_static_files_cacheablez*StaticFileTest.test_static_files_cacheable  sM     ::34nhmm4ox'7'78i!1!12r;   c                 p   | j                  d      }| j                  |j                  j                  d      d       | j                  d      }| j                  |j                  j                  d      d       | j                  d      }| j	                  |j                  j                  d      ddh       y )	Nz/static/sample.xml.gzr  zapplication/gzipz/static/sample.xml.bz2zapplication/octet-streamz/static/sample.xmlztext/xmlzapplication/xml)r   r}   r.  r\   r>  r   s     r9   test_static_compressed_filesz+StaticFileTest.test_static_compressed_files  s    ::56))--n=?QR::67  02L	
 ::23  0:?P2Q	
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.txtr6  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  rO  head_responseget_responsecontent_headershs          r9   get_and_headzStaticFileTest.get_and_head  s     #

DBB6B!tzz4@@@%!6!68L8LM 	'A||J'##A&	' ! 	A%%))!,$$((+m++//2L4H4H4L4LQ4OQ	 r;   c                     | j                  d      }| j                  dd|j                  d   i      }| j                  |j                  d       | j	                  d|j                         y )Nr  If-Modified-SinceLast-Modifiedr4  0  Content-Length)r  r.  r}   r   r  rC   	response1	response2s      r9   !test_static_304_if_modified_sincez0StaticFileTest.test_static_304_if_modified_since  sk    %%&:;	%% ()*;*;O*LM & 
	 	-)9+<+<=r;   c                     | j                  d      }| j                  dd|j                  d   i      }| j                  |j                  d       y )Nr  If-None-MatchEtagr4  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  r4  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!nv@l!dr4  r   r  r}   r   r   s     r9   )test_static_304_if_modified_since_invalidz8StaticFileTest.test_static_304_if_modified_since_invalid  s8    $$ ()4 % 
 	,r;   c                 f    | j                  dddi      }| j                  |j                  d       y )Nr  r  zFri, 01 Jan 1960 00:00:00 GMTr4  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   r4  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-9r4     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             y # 1 sw Y   _xY w)Nr  r  zbytes=0-r4  r   
robots.txtutf-8r  r  26r"  r  r}   r   r3   r4   r5   
static_diropenr   r   readr.  r\   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;	<))--.>?F(**..?@	< 	<   )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             y # 1 sw Y   _xY w)Nr  r  zbytes=0-10000000r4  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;	<))--.>?F(**..?@	< 	<r1  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-10000000r4  r   r%  r&  r'  rv   r  25r"  zbytes 1-25/26)r  r}   r   r3   r4   r5   r*  r+  r   r   r,  r.  r\   r-  s       r9   'test_static_with_range_partial_past_endz6StaticFileTest.test_static_with_range_partial_past_end5  s    $$ 74F*G % 
 	,77<<F"W5 	@X]]D!",>?	@))--.>?F))--o>P	@ 	@s   )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-r4     : /
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=-4r4  r8  r  r  r"  r9  r:  r   s     r9   test_static_with_range_neg_endz-StaticFileTest.test_static_with_range_neg_endH  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             y # 1 sw Y   _xY w)Nr  r  zbytes=-1000000r4  r   r%  r&  r'  r  r(  r"  r)  r-  s       r9   %test_static_with_range_neg_past_startz4StaticFileTest.test_static_with_range_neg_past_startP  s    $$ 74D*E % 
 	,77<<F"W5 	<X]]DN;	<))--.>?F(**..?@	< 	<r1  c                 f    | j                  dddi      }| j                  |j                  d       y )Nr  r  r   r4  r   r  r   s     r9   test_static_invalid_rangez(StaticFileTest.test_static_invalid_range[  s1    $$%9GVCT$U,r;   c                     | j                  dddi      }| j                  |j                  j                  d      d       | j                  |j                  d       y )Nr  r  zbytes=-0r4  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=26r4  rD  r"  rC  r  r}   r   r.  r\   r   s     r9   -test_static_unsatisfiable_range_invalid_startz<StaticFileTest.test_static_unsatisfiable_range_invalid_startf  sX    $$ 7J*? % 
 	,))--o>Mr;   c                     | j                  dddi      }| j                  |j                  d       | j                  |j                  j	                  d      d       y )Nr  r  z
bytes=10-3r4  rD  r"  rC  rG  r   s     r9   3test_static_unsatisfiable_range_end_less_than_startzBStaticFileTest.test_static_unsatisfiable_range_end_less_than_startm  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_headt  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  rM  r   s     r9   test_static_head_rangez%StaticFileTest.test_static_head_range~  s    :: ';9O  
 	,,))*:;SA!!&)*D43G3G,G$,N	
r;   c                 h   | j                  ddd| j                  z   dz   d      }| j                  |j                  d       | j                  |j                  d       | j                  d|j                         | j                  t        |j                  d	         d| j                  z   dz          y )
Nr  rP  r  )r  r  r4  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_match  s    $$ $!%(<(<!<t!C % 
 	,,)8+;+;<!!&)*D43G3G,G$,N	
r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nz/static/blarg  r  r   s     r9   test_static_404zStaticFileTest.test_static_404  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_protection  sl     	 02w @A 	F(()DEH	F 	,	F 	Fs   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  r|  r}  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)1rK   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#  r0  r3  r6  r;  r=  r?  rA  rE  rH  rJ  rN  rQ  rS  rV  rZ  unittestskipIfrj   r^  rI   r;   r9   r  r  M  s   	L  bggooh7BJ#
J3M3
Y
?W/9
*>.	.---$

PA	A	QRR	A--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/Frs  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/dirFrs  rm  rv  rl  )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?   rn  rr  rI   r;   r9   rb  rb    s    
@
Or;   rb  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  re  rf  rR   )r  rh  static_url_prefix)rf   r3   r4   r]  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)Nr[  z/.*cannot redirect path with two initial slashesz//evil.com/../rp  Frs  rX  )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   >B;;CN)rK   rL   rM   r@   r?   ry  r  rI   r;   r9   rt  rt    s    
'
-r;   rt  c                       e Zd Zd Zd Zd Zy)StaticFileWithPathTestc                 B    t        t        d      t        d            S rd  r  rB   s    r9   r@   z%StaticFileWithPathTest.get_app_kwargs  ri  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
r6  r   s     r9   
test_servez!StaticFileWithPathTest.test_serve  s&    ::./(9:r;   N)rK   rL   rM   r@   r?   r  rI   r;   r9   r  r    s    
S;r;   r  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                     | j                  ||      }|j                  d      }|d | }||dz   d  }dj                  |||      S )N.rv   z/static/{}.{}.{})get_versionrindexformat)clsrb   r4   version_hashextension_indexbefore_versionafter_versions          r9   make_static_urlzNCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.make_static_url  s[    "x>"&++c"2!%&6!7 $o&9%< =)00" ! r;   c                 b    |j                  d      }|j                  dd|      }|d |  ||d   S )Nr  r   )r  )rC   url_pathr  version_indexs       r9   parse_url_pathzMCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.parse_url_path  sB    "*//#"6 (Q H">M23H_=M4N3OPPr;   c                     d|z   S )NzCustomStaticFileTest:rI   r  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   r  zJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_version)  s    r;   NN)rK   rL   rM   classmethodr  r  r  r  r  r  r  r  rI   r;   r9   MyStaticFileHandlerr    sf    	 	Q
 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_kwargs5  s    d>W>WXXr;   c                 ^    | j                  d      }| j                  |j                  d       y )Nz/static/foo.42.txtru   r6  r   s     r9   r  zCustomStaticFileTest.test_serve8  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<  sL    w <uM 	Czz"78HX]],AB	C 	C 	Cs   .A

AN)rK   rL   rM   r?   r@   r  r  rI   r;   r9   r  r    s    38jY0Cr;   r  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   rg  z#HostMatchingTest.Handler.initializeD  s	    DJr;   c                 :    | j                  | j                         y r2   )r[   r  rB   s    r9   r\   zHostMatchingTest.Handler.getG  s    JJtzz"r;   N)rK   rL   rM   rg  r\   rI   r;   r9   rT   r  C  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_handlersJ  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   wildcardrU  Hostr4     [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_matchingM  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  B  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_handlersm  rJ   r;   c                 
    ddiS )Ndefault_hostr  rI   rB   s    r9   r@   z&DefaultHostMatchingTest.get_app_kwargsp  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  rU  z	X-Real-Ipr  r4  r  )	rA   r  r  rT   r   r}   r   r   r  r   s     r9   test_default_host_matchingz2DefaultHostMatchingTest.test_default_host_matchings  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  l  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.get  s    

4 r;   Nr]   rI   r;   r9   r  r    s    !r;   r  z/str/(?P<path>.*)z/unicode/(?P<path>.*)r   )rC   r  s     r9   r?   z#NamedURLSpecGroupsTest.get_handlers  s*    	!. 	!
 !+.$k2
 	
r;   c                     | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       y )Nz/str/foos   fooz/unicode/barru   r6  r   s     r9   test_named_urlspec_groupsz0NamedURLSpecGroupsTest.test_named_urlspec_groups  sF    ::j)/::n-/r;   N)rK   rL   rM   r?   r  rI   r;   r9   r  r    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                         | j                  |j                  d   d       y )NrR   r  r  r  r   r  r.  r}   r   s     r9   test_clear_headerz!ClearHeaderTest.test_clear_header  s@    ::c?x//0))$/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   r  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                         | j	                  d|j                         | j	                  d
|j                         y )NrR   r  5r  r  r  r  r4  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  
	 	-)9+<+<=+Y->->?,i.?.?@r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    s     .  
A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   ry  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   ry  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             y )NrR   Dater   )seconds)r   rT  rU  rV  r.  rX  rO  rP  rQ  rR  rS  )rC   r   header_dates      r9   test_date_headerzDateHeaderTest.test_date_header  sm    ::c?kk778H8H8PQ(++//0A0A0E0EFFq)	
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   ry  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   ry  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   r  r   r+  rn  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   r  r   rU  rn  r   s     r9   test_404_xsrfz"ErrorHandlerXSRFTest.test_404_xsrf  s*    ::fV":=,r;   N)rK   rL   rM   r?   r@   r2  r4  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varyr  zhello world!)r  r  r[   r/   
MIN_LENGTH)rC   vs     r9   r\   zGzipTestCase.Handler.get&  sI    ''/ +*+ JJ}.A.L.L(LMNr;   Nr]   rI   r;   r9   rT   r8  %  s    	Or;   rT   c                     t        dt        j                  j                  t        j                  j	                  t
              d            S )NTr  )r  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 )Nr  zX-Consumed-Content-Encodingr  )r}   r.  r\   r   s     r9   assert_compressedzGzipTestCase.assert_compressed1  sB     	  "H$4$4$8$89V$W 		
r;   c                     | j                  d      }| j                  |       | j                  |j                  d   d       y )NrR   r  r  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  r  r  rB  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_gzipr  r  r  r  r   s     r9   test_gzip_not_requestedz$GzipTestCase.test_gzip_not_requestedG  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-Languager  ,Accept-Languager  r   r@  r}   r.  splitstriprC   r   r  s      r9   test_vary_already_presentz&GzipTestCase.test_vary_already_presentL  sc    ::67x( ( 0 0 8 > >s CD1QWWY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=Cookier  rJ  )rK  r2  r  rL  rO  s      r9   "test_vary_already_present_multiplez/GzipTestCase.test_vary_already_present_multipleT  s]    ::BCx( ( 0 0 8 > >s CD1QWWYD<	
DrQ  N)rK   rL   rM   r   rT   r@   r@  rC  rE  rH  rP  rS  rI   r;   r9   r6  r6  $  s6    O. O


F
FF


r;   r6  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  rO  )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.getc  s    5= =KKMr;   NrK   rL   rM   r  r\   rI   r;   r9   rT   rW  _  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_handlersg  s     dll+.@$,,-OPPr;   c                     | j                  d      }|j                          t        |j                        }| j	                  |dgi d       y )Nz/pos/foort   rY  rU  rC   r   rA  s      r9   test_poszPathArgsInPrepareTest.test_posj  sA    ::j)8==)2>?r;   c                     | j                  d      }|j                          t        |j                        }| j	                  |g ddid       y )Nz/kw/foor4   rt   rY  rU  r`  s      r9   test_kwzPathArgsInPrepareTest.test_kwp  sC    ::i(8==)vuoFGr;   N)rK   rL   rM   r   rT   r?   ra  rc  rI   r;   r9   rU  rU  ^  s     . Q@Hr;   rU  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.gety  s    ""$JJtr;   Nr]   rI   r;   r9   rT   rg  x  s    	r;   rT   c                    | j                  dddi      }t        |j                  j                  d            }| j	                  |d   j                  d             | j	                  |d   j                  d	             y )
NrR   r2  zfoo=bar; baz=xyzzyr4  r,  r   zbaz="";rv   zfoo="";)r   r-  r.  r/  r   r  )rC   r   set_cookiess      r9   test_clear_all_cookiesz*ClearAllCookiesTest.test_clear_all_cookies}  sk    ::cH6J+K:LX--66|DEA11)<=A11)<=r;   N)rK   rL   rM   r   rT   rn  rI   r;   r9   re  re  w  s    . 
>r;   re  c                       e Zd Zy)PermissionErrorNrK   rL   rM   rI   r;   r9   rp  rp    s    r;   rp  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!   rp  )rC   rw  s     r9   r\   z ExceptionHandlerTest.Handler.get  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  rX  rp  )
isinstancerp  r  r[   r   r  )rC   r  rO  typrm   tbs         r9   r  z(ExceptionHandlerTest.Handler.write_error  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   )r}  rp  r   warningr  r   log_exceptionrC   r~  rm   r  s       r9   r  z*ExceptionHandlerTest.Handler.log_exception  s8    %1 H%**UV-X,,T3rBr;   N)rK   rL   rM   r\   r  r  rI   r;   r9   rT   ru    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=httpry  rZ  r   s     r9   test_http_errorz$ExceptionHandlerTest.test_http_error  sF     w 23 	1zz,/HX]]C0	1 	1 	1   .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=zerork  r   r   r   r}   r   r   s     r9   test_unknown_errorz'ExceptionHandlerTest.test_unknown_error  sD    w 45 	1zz,/HX]]C0	1 	1 	1r  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=permissionrX  r  r   s     r9   test_known_errorz%ExceptionHandlerTest.test_known_error  sG     w QR 	1zz"45HX]]C0	1 	1 	1r  N)rK   rL   rM   r   rT   r  r  r  rI   r;   r9   rs  rs    s    C. C2111r;   rs  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   r  s       r9   r  z&BuggyLoggingTest.Handler.log_exception  r  r;   N)rK   rL   rM   r\   r  rI   r;   r9   rT   r    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   r  r    s    . r;   r  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(z) with handler value r  )rm   )r   xs     r9   my_ui_methodz9UIMethodUIModuleTest.get_app_kwargs.<locals>.my_ui_method  s    %aS(=gmmo=NaPPr;   c                       e Zd Zd Zy)5UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModulec                     dj                  |t        j                  t        j                  | j
                        j                               S )Nz&In MyModule({}) with handler value {}.)r  typingcastr  rT   r   rm   )rC   r  s     r9   r   z<UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModule.render  s:    ?FF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  )r2  
ui_methods
ui_modulesr*   r   rf   )rC   r  r  r5  s       r9   r@   z#UIMethodUIModuleTest.get_app_kwargs  sK    	Q	x 	 LM
 "&5"H-
 	
r;   c                 ^    t         |           t        j                  j	                          y r2   r7  r<  s    r9   r9  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.r6  r   s     r9   test_ui_methodz#UIMethodUIModuleTest.test_ui_method  s*    ::n-MM9	
r;   )
rK   rL   rM   rN   r   rT   r@   r9  r  r  r  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 1 12"T[[5E5E4FaHIr;   N)rK   rL   rM   r  r  r  r\   rI   r;   r9   rT   r    s    	.	(	(	Jr;   rT   c                 ^    | j                  d      }| j                  |j                  d       y )NrR   s   Hello Ben (en_US)r6  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    J. J>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)Nr  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  r  z{{ current_user }}z {% module WithoutUserModule() %}z{% module WithUserModule() %})without_user.htmlwith_user.htmlwithout_user_module.htmlwith_user_module.html)r  r  )r2  r  r  )rC   r  r  r5  s       r9   r@   z!GetCurrentUserTest.get_app_kwargs  sT    	 		.X 	. %'"6,N)H	
 ""0%6
 	
r;   c                 ^    t         |           t        j                  j	                          y r2   r7  r<  s    r9   r9  zGetCurrentUserTest.tearDown6  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)NTr  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.getD  s(    ""#67C < <=>r;   Nr]   rI   r;   r9   WithoutUserHandlerr  C      ?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.getI  s(    ""#34C < <=>r;   Nr]   rI   r;   r9   WithUserHandlerr  H  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_namespaceN  s     wwr;   N)rK   rL   rM   r  rI   r;   r9   CurrentUserModuleHandlerr  M  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.getU  s(    ""#=>C < <=>r;   Nr]   rI   r;   r9   WithoutUserModuleHandlerr  T  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.getZ  s(    ""#:;C < <=>r;   Nr]   rI   r;   r9   WithUserModuleHandlerr  Y  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     Falser6  r   s     r9   test_get_current_user_is_lazyz0GetCurrentUserTest.test_get_current_user_is_lazye  s&     ::o.1r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr     Truer6  r   s     r9   test_get_current_user_worksz.GetCurrentUserTest.test_get_current_user_worksk  s$    ::l+0r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr  r  r6  r   s     r9   ,test_get_current_user_from_ui_module_is_lazyz?GetCurrentUserTest.test_get_current_user_from_ui_module_is_lazyo  s%    ::451r;   c                 ^    | j                  d      }| j                  |j                  d       y )Nr  r  r6  r   s     r9   *test_get_current_user_from_ui_module_worksz=GetCurrentUserTest.test_get_current_user_from_ui_module_workss  s%    ::120r;   )rK   rL   rM   r@   r9  r?   r_  skipr  r  r  r  r  r  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.HandlerNrq  rI   r;   r9   rT   r  y  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   rL    r   PUTr;   r   rn  )rC   r   r   s      r9   #test_unimplemented_standard_methodsz@UnimplementedHTTPMethodsTest.test_unimplemented_standard_methods|  sp    : 	1Fzz#fz5HX]]C0	1 & 	1Fzz#f3z?HX]]C0	1r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r  x  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.other  s     JJwr;   N)rK   rL   rM   r  rI   r;   r9   rT   r    s    	 r;   rT   c                 d    | j                  ddd      }| j                  |j                  d       y )NrR   PATCHr;   r   r  rn  r   s     r9   test_unimplemented_patchz<UnimplementedNonStandardMethodsTest.test_unimplemented_patch  s,     ::c':<,r;   c                 d    | j                  ddd      }| j                  |j                  d       y )NrR   OTHERTr   allow_nonstandard_methodsr  rn  r   s     r9   test_unimplemented_otherz<UnimplementedNonStandardMethodsTest.test_unimplemented_other  s*    ::c'T:R,r;   N)rK   rL   rM   r   rT   r  r  rI   r;   r9   r  r    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"    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  rL  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,2 	:Fzz#fz5HX]]DL9	: & 	:Fzz#f3z?HX]]DL9	:r;   N)rK   rL   rM   r   rT   r(  rI   r;   r9   r   r     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   patchr6  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   otherr6  r   s     r9   
test_otherzPatchMethodTest.test_other  s*    ::c'T:R1r;   N)rK   rL   rM   r   rT   r2  r4  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   r\  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;   Nr]  rI   r;   r9   rT   r8    s    	 	<r;   rT   c                 ^    | j                  d      }| j                  |j                  d       y )NrR   s   doner6  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   r6  r6    s    <. <1r;   r6  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   rU  sE   <html><title>404: Not Found</title><body>404: Not Found</body></html>rm  r   s     r9   test_404zDefault404Test.test_404  s=    ::c?,MM2	
r;   N)rK   rL   rM   r?   rB  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 )NrU  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   Custom404HandlerrI    s    2r;   rK  )default_handler_class)r   rf   )rC   rK  s     r9   r@   zCustom404Test.get_app_kwargs  s    	2~ 	2
 *:;;r;   c                     | j                  d      }| j                  |j                  d       | j                  |j                  d       y )NrR   rU  s   custom 404 responserm  r   s     r9   rB  zCustom404Test.test_404  s8    ::c?,(>?r;   N)rK   rL   rM   r?   r@   rB  rI   r;   r9   rD  rD    s    *<@r;   rD  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  rF  r;   c                 8    t        t        t        d            S )NrX  r,  )rL  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   rX  rn  r   s     r9   test_403z$DefaultHandlerArgumentsTest.test_403  s#    ::c?,r;   N)rK   rL   rM   r?   r@   rT  rI   r;   r9   rO  rO    s    *
-r;   rO  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/hello3rZ  )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 )NrX  r{  rY  r[  r6  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?   r_  rI   r;   r9   rV  rV    s    
.r;   rV  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   rg  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   rA  ri  rC   rA  s     r9   data_receivedzQStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.data_received	  s    		))$/r;   c                 p    | j                   j                  j                  d        | j                  i        y r2   )r   finishedri  r[   rB   s    r9   r\   zGStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.get	  s%    		""--d3

2r;   N)rK   rL   rM   rg  r  rl  r\   rI   r;   r9   StreamingBodyHandlerrd  	  s    !40r;   ro  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   EarlyReturnHandlerrq  "	  s    %r;   rt  c                   $     e Zd Zd Z fdZ xZS )DStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandlerc                     || _         y r2   r   r   s     r9   rg  zOStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.initialize+	  rf  r;   c                 l    t         |           | j                  j                  j	                  d        y r2   )r8  r  r   close_futureri  r<  s    r9   r  zXStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.on_connection_close.	  s&    +-		&&11$7r;   )rK   rL   rM   rg  r  r  r  s   @r9   CloseDetectionHandlerrv  )	  s    !8 8r;   rz  z/stream_bodyr   z/early_returnz/close_detection)r,   r   rf   )rC   ro  rt  rz  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
Host: 127.0.0.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.connect8	  sy    MM&..&*<*<a@			; 2 2 456!Ws]%HHI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r|  	   4
asdf
s   asdfs	   4
qwer
s   qwers   0

s   {})r   rh  rA  rn  r  r[   r}   read_until_closer   rq  r  rC   r  rA  s      r9   test_streaming_bodyz,StreamingRequestBodyTest.test_streaming_bodyC	  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_returnFr~     HTTP/1.1 401)r  r  r   r  r  s      r9   test_early_returnz*StreamingRequestBodyTest.test_early_returnZ	  s?     .G,,..89s   AA	c              #      K   | j                  dd      }|j                  d       |j                         }| j                  |j	                  d             y w)Nr  Fr~  r  r  )r  r[   r  r   r  r  s      r9   test_early_return_with_dataz4StreamingRequestBodyTest.test_early_return_with_data`	  sL     .G%&,,..89s   AAc              #      K   t               | _        | j                  dd      }|j                          | j                   y w)Ns   /close_detectionFr~  )r   ry  r  r  )rC   r  s     r9   test_close_during_uploadz1StreamingRequestBodyTest.test_close_during_uploadg	  s8     "H1EJr  N)
rK   rL   rM   r?   r  r   r  r  r  r  rI   r;   r9   ra  ra  	  s]    $
L	  , : :
 : :    r;   ra  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   rg  z!BaseFlowControlHandler.initializeu	  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   failr  r  r&  s     r9   	in_methodz BaseFlowControlHandler.in_methodz	  s`     ;;"IINN_VHJt{{mLMF#	DK$DKs   AA5A) !A5)	A22A5c              #   f   K   | j                   j                  d       t        j                   y w)Nr  )r  r  r   momentrB   s    r9   r  zBaseFlowControlHandler.prepare	  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   r  )r  r   r  r[   rf   r  rB   s    r9   r   zBaseFlowControlHandler.post	  sE     ^^F# 	**	

4-.	 	s   A!A.A!AA!N)rK   rL   rM   rg  
contextlibcontextmanagerr  r   r   r  r   rI   r;   r9   r  r  s	  sQ    
   	]]  	]]/ /r;   r  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_options	  s     rd;;r;   c                     t               S r2   r   rB   s    r9   ry  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  rl  rl  rl  r   r  )r   rN  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   rN  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   r  r  )r   r   r.  r  r  )r0   r  GzipFiler[   r  getvaluer   rN  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  ry  r  Anyr  r  r  rI   r;   r9   r  r  	  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)Nrl  )r  r   r  rk  s     r9   rl  zhDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandler.data_received	  s0     ^^O4 %**$% % %s   <0	<9<N)rK   rL   rM   r   r   rl  rI   r;   r9   DecoratedFlowControlHandlerr  	  s    ]]% %r;   r  rR   r   r  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)Nrl  r   )r  asyncior  )rC   rA  r  s      r9   rl  zbNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandler.data_received	  sF     ^^O4 +"!--***+ + ++ +s%   A	=;=	A	=AA	N)rK   rL   rM   rl  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  rj  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  ri  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::	: 	!!"$V	
: :: :	: 	:9   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 	95 9
 &&7 9JJv4J899	9 	!!"$R	
9 99 9	9 	9r  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.get8
  sS    ||##..x8 ''..446

7# 

./r;   Nr]   rI   r;   r9   rT   r  7
  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   r_  SkipTestr   r   skipTestr}   r   r   s     r9   test_client_closez!ClientCloseTest.test_client_closeE
  sp    1B1BCD 	1zz#4z8H}} 4412X]]C0		1 	1 	1s   AA??BN)rK   rL   rM   r   rT   r  rI   r;   r9   r  r  6
  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.pastQ
  s    ||~
**r;   c                      y)Ni m|MrI   rB   s    r9   r  zSignedValueTest.presentT
  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_valuesW
  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                  |       t	        t        j                  d|| j                        }| j                  |       y )Nkey1rm   r  key2)r'   r  r  r  r(   r   )rC   signed1signed2decoded1decoded2s        r9   test_name_swapzSignedValueTest.test_name_swapw
  s    %""FG4<<
 &""FG4<<
 '""FG4<<
 	(#&""FG4<<
 	(#r;   c                 4   t        t        j                  dd| j                        }t	        t        j                  d|| j                        }| j                  |d       t	        t        j                  d|| j                        }| j                  |       y )Nr  rm   r  r  )r'   r  r  r  r(   r}   r  r   )rC   signeddecoded_pastdecoded_presents       r9   test_expiredzSignedValueTest.test_expired
  s}    $""FG499
 +""FF$))
 	x0-""FF$,,
 	/*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_tampering
  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                  |       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
  sj    $''T\\WX
 "--224A%gufDLLQ'"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.  r1  r3  rI   r;   r9   r  r  M
  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   ri  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 ri  rZ   rB   s    r9   r   zXSRFTest.Handler.post       JJtr;   NrK   rL   rM   r\   r   rI   r;   r9   rT   r7  
  s    	(	r;   rT   c                     t        d      S r.  r   rB   s    r9   r@   zXSRFTest.get_app_kwargs  r0  r;   c                 L    t         |           | j                         | _        y r2   r8  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=%dr4  cookie_headersr   rN  r	   r   )rC   	old_tokenrx   r.  r   s        r9   rA  zXSRFTest.get_token
  s]     )))4GG::?C')AG  
 	(--((r;   c                 ,    || j                   }dd|z   iS )Nr2  z_xsrf=r  rC   tokens     r9   rE  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   rX  rZ  r   s     r9   test_xsrf_fail_no_tokenz XSRFTest.test_xsrf_fail_no_token  N    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   rX  
r   r   r   r|  r}  r~  rf   r  r}   r   r   s     r9   test_xsrf_fail_body_no_cookiez&XSRFTest.test_xsrf_fail_body_no_cookie  l    w CD 	zz\\++Dt,GH " H	 	,	 	   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|rT  rQ  rX  )
r   r   r   rE  r|  r}  r~  rf   r}   r   r   s     r9   &test_xsrf_fail_argument_invalid_formatz/XSRFTest.test_xsrf_fail_argument_invalid_format(  st    w GH 	zz++-\\++Dt,<=	 " H	 	,	 	s   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)	NrS  rR   r   r[  rJ  rT  rQ  rX  )r   r   r   rE  r|  r}  r~  rf   r  r}   r   r   s     r9   $test_xsrf_fail_cookie_invalid_formatz-XSRFTest.test_xsrf_fail_cookie_invalid_format2  s}    w CD 	zz++$+7\\++Dt,GH	 " H	 	,	 	s   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)NrM  rR   r   r;   r   r   r.  rX  )r   r   r   rE  r}   r   r   s     r9   test_xsrf_fail_cookie_no_bodyz&XSRFTest.test_xsrf_fail_cookie_no_body<  s]    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   deadbeefrT  r^  ra  r   r   r|  r}  r~  rf   rE  r}   r   r   s     r9   test_xsrf_success_short_tokenz&XSRFTest.test_xsrf_success_short_tokenC  sY    ::'':(>?''j'9	  
 	,r;   c           	          | j                  ddt        j                  j                  t	        d            | j                  d            }| j                  |j                  d       y )NrR   r   xoxorT  r^  ra  r   re  r   s     r9   test_xsrf_success_non_hex_tokenz(XSRFTest.test_xsrf_success_non_hex_tokenL  sY    ::''6(:;''f'5	  
 	,r;   c           	          | j                  ddt        j                  j                  t	        | j
                              | j                               }| j                  |j                  d       y NrR   r   rT  ra  r   	r   r|  r}  r~  rf   r  rE  r}   r   r   s     r9   test_xsrf_success_post_bodyz$XSRFTest.test_xsrf_success_post_bodyU  sX    ::''4??(CD'')	  
 	,r;   c                     | j                  dt        j                  j                  t	        | j
                              z   dd| j                               }| j                  |j                  d       y )Nz/?rT  r   r;   ra  r   rl  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-Xsrftokenra  r   )r   rf   r  rE  r}   r   r   s     r9   test_xsrf_success_headerz!XSRFTest.test_xsrf_success_headerg  sY    ::0%%'	  
 	,r;   c                     d}t               }t        |      D ]!  }|j                  | j                                # | j	                  t        |      |       y )Nr  )r  r  r  rA  r}   r=  )rC   
NUM_TOKENStokensr  s       r9   test_distinct_tokenszXSRFTest.test_distinct_tokenss  sI    
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   rT  ra  r   rS  rX  )rA  r  r   r|  r}  r~  rf   rE  r}   r   r   r   )rC   token2rJ  r   cookie_token
body_tokens         r9   test_cross_userzXSRFTest.test_cross_user{  s    !oov. 	1Ezz\\++Du,=>++E2	 " H X]]C0	1 __f%T__%)
 	1$L* 7$GH ::!//:0FG //=	 &  X]]C0	1 s   =AD00D9	c           
         | j                   }|h}t        d      D ]  }| j                  |      }|j                  |       | j	                  ddt
        j                  j                  t        | j                               | j                  |            }| j                  |j                  d        | j                  t        |      d       y )N   rR   r   rT  ra  r      )r  r  rA  r  r   r|  r}  r~  rf   rE  r}   r   r=  )rC   rJ  tokens_seenr  r   s        r9   test_refresh_tokenzXSRFTest.test_refresh_token  s    g
 q 
	1ANN5)EOOE"zz\\++Dt,GH++E2	 " H X]]C0
	1 	[)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   r|  rR   r   rT  ra  r   )assertNotEqualrA  r  r}   r   r|  r}  r~  rf   rE  r   )rC   v1_tokenr  v2_tokenrx  ry  r   s          r9   test_versioningzXSRFTest.test_versioning  s   DNN1N5t~~a~7PQ >>!>,q 	LAT^^Ha^@(K	L >>(+Hh/HdnnX&>? +3H)=(?S(T 	1$L*zz\\++Dz,BC++L9	 " H X]]C0	1r;   r  r2   )rK   rL   rM   r   rT   r@   r@  rA  rE  rN  rW  r\  r_  rb  rf  ri  rm  ro  rq  ru  rz  r  r  r  r  s   @r9   r5  r5  
  si    	. 	'+	),
-
--------
-212.(1r;   r5  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 ri  rZ   rB   s    r9   r   zXSRFCookieNameTest.Handler.post  r;  r;   Nr<  rI   r;   r9   rT   r    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  rB  r;   c                     || j                  |      }nd }| j                  d|      }|j                          t        |j                        S )NrR   r4  rD  )rC   rF  r.  r   s       r9   rA  zXSRFCookieNameTest.get_token  sJ     )))4GG::c7:3(--((r;   c                 ,    || j                   }dd|z   iS )Nr2  z__Host-xsrf=rH  rI  s     r9   rE  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rL  rZ  r   s     r9   rN  z*XSRFCookieNameTest.test_xsrf_fail_no_token  rO  rP  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rR  rV  r   s     r9   rW  z0XSRFCookieNameTest.test_xsrf_fail_body_no_cookie  rX  rY  c           	          | j                  ddt        j                  j                  t	        | j
                              | j                               }| j                  |j                  d       y rk  rl  r   s     r9   rm  z.XSRFCookieNameTest.test_xsrf_success_post_body  sX    ::''4??(CD'')  
 	,r;   r2   )rK   rL   rM   r   rT   r@   r@  rA  rE  rN  rW  rm  r  r  s   @r9   r  r    s2    . 
+)2
-
--r;   r  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   r  rB   s    r9   r\   z XSRFCookieKwargsTest.Handler.get  r  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   rL  rN  )tzinfor  )r   r>  r.  lowerr\   r   r   rO  rP  rQ  rR  rS  rT  rU  rV  rW  r  replacer   rY  rZ  r[  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               )Nrs  WWW-AuthenticateBasic realm="something"finish_valuer  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=1rs  r  r  s   authentication required)r   r}   r   r.  r\   r   )rC   ur   s      r9   test_finish_exceptionz)FinishExceptionTest.test_finish_exception$  sp    * 	HAzz!}HX]]C0)8+;+;+?+?@R+S 7G	H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.get1      r;   N)rK   rL   rM   r-   r\   rI   r;   r9   RemoveSlashHandlerr  0  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.get6  r  r;   N)rK   rL   rM   r.   r\   rI   r;   r9   AddSlashHandlerr  5  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  Frs  rm  rv  z/removeslashz/removeslash/?foo=barz/removeslash?foo=barrq  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  Frs  rm  rv  z
/addslash/z/addslash?foo=barz/addslash/?foo=barrq  r   s     r9   test_addslashzDecoratorTest.test_addslashE  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.getR  s    

=)r;   c                      | j                   d   S r  )_write_bufferrB   s    r9   compute_etagz8CacheTest.get_handlers.<locals>.EtagHandler.compute_etagU  s    ))!,,r;   N)rK   rL   rM   r\   r  rI   r;   r9   EtagHandlerr  Q  s    *-r;   r  z
/etag/(.*)r   )rC   r  s     r9   r?   zCacheTest.get_handlersP  s    	-. 	- {+,,r;   c                 2    d}d}| j                  ||d       y )N"xyzzy"*r  
_test_etagrC   r  etagss      r9   test_wildcard_etagzCacheTest.test_wildcard_etagZ  s    !uc2r;   c                 2    d}d}| j                  ||d       y )Nr  r  r  r  s      r9   test_strong_etag_matchz CacheTest.test_strong_etag_match_  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_matchd  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_matchi  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_matchn  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_matchs      "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_matchx      "(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_match  r  r;   c                 l    | j                  d|z   d|i      }| j                  |j                  |       y )Nz/etag/r  r4  rn  )rC   r  r  r  r   s        r9   r  zCacheTest._test_etag  s:    ::}$.F  
 	4r;   N)rK   rL   rM   r?   r  r  r  r  r  r  r  r  r  r  rI   r;   r9   r  r  O  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.get  s%     &*DLL"KK--/0r;   Nr]   rI   r;   r9   rT   r    s    	1r;   rT   c                 ^    | j                  d      }| j                  |j                  d       y )NrR   s   GET / (None)r6  r]  s     r9   test_missing_remote_ipz)RequestSummaryTest.test_missing_remote_ip  s#    zz#O4r;   N)rK   rL   rM   r   rT   r  rI   r;   r9   r  r    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 )NrX  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  r  r  )rC   pathsr4   url_specr  s        r9   test_non_reversiblez&URLSpecReverseTest.test_non_reversible  sc    
 ** 
	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\.pngr|  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})rK  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  Frs  rm  rv  r  rq  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=barFrs  rm  rv  z/dst?foo=barrq  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=bar2Frs  rm  rv  z/dst2?foo=bar&foo2=bar2rq  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/cFrs  rm  rv  z/b/a/crq  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   rK  zfr-FR;q=0.9r4  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   rK  z	fr-FR;q=0r4  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   rK  z
fr-FR;q=-1r4  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    rK  r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r   r  r   rO  email.utilsrT  r  ior0   r  r?  r3   r   r  r  r_  urllib.parser|  r:   r=   rP   rV   r_   TestCaserr   r   r   r   rc  rn  r{  r  r  r  r  r  r  r  r  r  r  r  r  r!  r)  r/  r  r  r  rb  rt  r  r  r  r  r  r  r  r  r   r  r  r(  r6  rU  re  r  rp  rs  r  r  r  r  r  r  r  r   r*  r6  r>  rD  rO  rV  ra  r  r  r  r  r  r  r  r5  r  r  r  r  r  r  r  r  r  r  r  rI   r;   r9   <module>r>     s   %   / - %   ( ; ' Q Q 0 1     ,          	 	    7# $	%K 	%> 
$~ $,2S** 2Sl,E** ,E^.9k .9b]= ]=@
 

{ 
8
(^ 
(+ 0
. 
6--+ --`)O~ )OXY~ Y*B^ B
1n 1
#. #
( (Hn H 	^ 	~ (. .
. 
OOk OOd/k /?1 ?1Df-[ f-RO O*"-K "-J;[ ;@C; @CF'0{ '0T0k 0D0[ 0&8+ 8
@) 
@A) A*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;   