
    <|h:                     x   d dl mZ  ej                          d dlmZ d dlmZ d dlZd dlZd dl	m
Z d dlZd dlZd dlmZ d dlmZ d dl Z d dlmZmZ d dlmZ d d	l mZ d d
l mZ d dlmZ  G d dee      ZdZej<                  ZdddZ G d de       Z!d Z"d Z# G d de$      Z%e%jL                  Z' G d dejP                        Z( G d de$      Z) G d de)e(      Z* G d de*      Z+ G d  d!e*      Z, G d" d#e,      Z- G d$ d%e*      Z. G d& d'e)e(      Z/ G d( d)e)e(      Z0 G d* d+e(      Z1 G d, d-e(      Z2 G d. d/e(      Z3 G d0 d1e(      Z4 G d2 d3e4      Z5 G d4 d5e(      Z6 G d6 d7e(      Z7 G d8 d9e(      Z8 G d: d;e(      Z9 G d< d=e(      Z:d dl;Z  e<e jz                  d>      Z>e>r G d? d@e:      Z? G dA dBe:      Z@e>r G dC dDe?e@      ZA G dE dFe(      ZB G dG dHe(      ZC G dI dJeC      ZD G dK dLe(      ZE G dM dNeE      ZF G dO dPeE      ZG G dQ dRe(      ZH G dS dTe(      ZI G dU dVeI      ZJ G dW dXe(      ZK G dY dZe(      ZL G d[ d\e(      ZM G d] d^e(      ZN G d_ d`e(      ZO G da dbe(      ZP G dc ddeK      ZQ G de dfe(      ZR G dg dhe(      ZS G di dje(      ZT G dk dle(      ZU G dm dne(      ZV G do dpe(      ZW G dq dre(      ZX G ds dte(      ZY G du dve(      ZZ G dw dxe(      Z[ddyZ\ G dz d{ej                        Z^ G d| d}e(      Z_ G d~ de(      Z` G d de(      Zaebdk(  r ej                          yy)    )monkey)contextmanager)parse_qsN)BytesIO)	validator)PY3PYPY)ExpectedException)socket)pywsgi)Inputc                       e Zd ZdZy)ExpectedAssertionErrorzAn expected assertion errorN)__name__
__module____qualname____doc__     X/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/tests/test__pywsgi.pyr   r   ,   s    %r   r   Content-LengthOKInternal Server Error)     c                       e Zd Zy)ConnectionClosedNr   r   r   r   r   r   r   r   8   s    r   r   c                    | j                         }|st        |j                  d      }i }	 | j                         j                         }|s	 ||fS |j                  d      }	 |j	                  dd      \  }}|j                         |D ch c]  }|j                          c}vsJ d|d|d|       |||<   #  t        d|        xY wc c}w )Nlatin-1:    zFailed to split: zHeader :z sent more than once: )readliner   decodestripsplitprintlower)fdresponse_lineheaderslinekeyvaluexs          r   read_headersr1   <   s    KKMM!((3MG
{{}""$ '!! {{9%	D!,JC yy{g">1779">>~jmotv}@~~> 	423">s   $B= C=Cc              #   4  K   	 | j                         }|j                         }t        |d      }|dk(  r'| j                  d      }|dk(  sJ t	        |             y | j                  |      }| | j                  d      }|dk(  sJ t	        |             w)N   r         
)r$   r&   intreadrepr)r*   r-   
chunk_sizecrlfdatas        r   iread_chunksr<   Q   s     
{{}ZZ\
R(
?771:D7?.DJ.?wwz"
wwqzw*T
* s   BBc                   R    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
e	 	 dd
       Zy	)Responsec                 ~   || _         || _        d | _        d| _        	 |d d j	                  dd      \  }}| _        t        |      | _        |j	                  d      \  }| _        |dk(  sJ t        |             | j                  dv sJ t        | j                               y # t        $ r t        d|z          w xY w)	NF r4   /HTTP)1.01.1z	Error: %r)status_liner,   bodychunksr'   reasonr6   codeversionr8   	Exceptionr(   )selfrF   r,   rK   rJ   rC   s         r   __init__zResponse.__init__b   s    &		)4Sb)9)?)?Q)G&GT4;D	DI!(s!3D$,6>-4:-><<>1E43EE1 	++,	s   BB# #B<c              #   `   K   | j                    | j                   | j                   y wN)rF   r,   rG   rM   s    r   __iter__zResponse.__iter__q   s%     lliis   ,.c                     | j                   j                  | j                  | j                  | j                  | j
                  f}d|z  S )Nz0<%s status_line=%r headers=%r body=%r chunks=%r>)	__class__r   rF   r,   rG   rH   )rM   argss     r   __str__zResponse.__str__v   s<    '')9)94<<TXT_T_`ADHHr   c                     t        |d      r)| j                  |v sJ d| j                  d|d|        y | j                  |k(  sJ d| j                  d|d|        y )N__contains__zUnexpected code:  (expected )
)hasattrrJ   )rM   rJ   s     r   
assertCodezResponse.assertCodez   sZ    4(99$gQUQZQZ\`bf&gg$99$gQUQZQZ\`bf&gg$r   c                 V    | j                   |k(  sJ d| j                   d|d|        y )NzUnexpected reason: rY   rZ   )rI   )rM   rI   s     r   assertReasonzResponse.assertReason   s)    {{f$mSWS^S^`fhl&mm$r   c                 V    | j                   |k(  sJ d| j                   d|d|        y )NzUnexpected version: rY   rZ   )rK   )rM   rK   s     r   assertVersionzResponse.assertVersion   s)    ||w&rVZVbVbdkmq(rr&r   c           	      l    | j                   j                  |d      }||k(  sJ d|d|d|d|        y )NFzUnexpected header r!   rY   rZ   )r,   get)rM   headerr/   
real_values       r   assertHeaderzResponse.assertHeader   s=    \\%%fe4
U" 	]<BJPUW[\	]"r   c                     t        |t              rt        r|j                  d      }| j                  |k(  sJ d| j                  d|d|        y )NasciizUnexpected body: rY   rZ   )
isinstancestrr   encoderG   )rM   rG   s     r   
assertBodyzResponse.assertBody   s@    dC S;;w'DyyD cTYYX\^b"cc r   Nc                    t        |      \  }}	 | ||	      }
||
j                  |       |dk(  rt        j                  |      }||
j	                  |       ||
j                  |       |
j                  dk(  r|
S |-t        |t              rt        |      }|
j                  d|       d|	j                  dd      v rMt        |	v rt        d       t        t        |            |
_        dj!                  |
j                        |
_        nFt        |	v r)t        |	t                 }|j%                  |      |
_        n|j%                         |
_        ||
j'                  |       |"||
j                  k(  sJ ||
j                  f       |
S )	zo
        Read an HTTP response, optionally perform assertions,
        and return the Response object.
        defaultd   r   chunkedTransfer-Encoding zhWARNING: server used chunked transfer-encoding despite having Content-Length header (libevent 1.x's bug)r   )r1   r\   REASONSrb   r^   r`   rJ   rh   r6   ri   re   CONTENT_LENGTHr(   listr<   rH   joinrG   r7   rk   )clsr*   rJ   rI   rK   rG   rH   content_length_status_liner,   rM   nums               r   r7   zResponse.read   sk    !-R 0g<)OOD!Y[[&Ff%w'99K%.#.!$^!4.?$7<<(  A  B|B/0DK-DIw&gn-.CDI	DIOOD!T[[(?64;;*??(r   )r   rm   rE   NNN)r   r   r   rN   rR   rV   r\   r^   r`   re   rk   classmethodr7   r   r   r   r>   r>   `   sJ    
Ihns]
d
 :?48' 'r   r>   c                       e Zd ZdZ ee      ZdZej                  Z	ej                  Z G d dej                        Zd Zd Zd Zej$                  rej&                  rd Z fdZd	 Zed
        Zed        Zd ZdZi ZddZ xZS )TestCaseNc                       e Zd ZeZy)TestCase.handler_classN)r   r   r   r   ApplicationErrorr   r   r   handler_classr~      s    1r   r   c                 f    dd l }|j                  d      }|j                  |j                         |S )Nr   zgevent.tests.pywsgi)logging	getLoggersetLevelCRITICAL)rM   r   loggers      r   init_loggerzTestCase.init_logger   s-    ""#89(()r   c                     | j                         x}| _        t        j                  | j                  df|||| j
                        | _        y )Nr   )log	error_logr   )r   r   r   
WSGIServerlisten_addrr   server)rM   applicationr   s      r   init_serverzTestCase.init_server   sH    #//11''q!&,,	
r   c                    | j                   }| j                  | j                  |      }| j                  |       | j                  j	                          | j                  j
                  s"t        d       | j                  j
                  s"| j                  j
                  | _        | j                  sJ t        j                  j                  |        y )NzWaiting on server port)r   r   r   r   startserver_portr(   port	greentestr|   setUprM   r   s     r   r   zTestCase.setUp   s    &&>>%..5K%++))*+ ++))KK++	yyy  &r   c                 b    | j                   j                  t        j                  |             |S rP   )close_on_teardownappendweakrefref)rM   resources     r   _close_on_teardownzTestCase._close_on_teardown   s$    ""))'++h*?@Or   c                     | j                   D cg c]  } |        |        c}| _         t        t        |           y c c}w rP   )r   superr|   _tearDownCloseOnTearDown)rM   rrT   s     r   r   z!TestCase._tearDownCloseOnTearDown   s7    373I3I%]aQS_ac%]D"(D:< &^s
   A	Ac                 n   t         j                  j                  |        | j                  Bt        j
                  j                  d      5  | j                  j                          d d d        d | _        t         j                  r%dd l	}|j                          |j                          y y # 1 sw Y   FxY w)N      ?r   )r   r|   tearDownr   geventTimeout	start_newstopr	   gccollect)rM   r   s     r   r   zTestCase.tearDown   s    ##D);;"))#. #  "#>>JJLJJL # #s   B++B4c              #   $   K   t        j                   j                   j                  f      }t        r+j
                   fd G fddt              } |       }	 | |j                          y # |j                          w xY ww)Nc                      d|v r|j                  d      |d<   d|v r | i |S d|d<    | i |}|j                  fd}||_        j                  |       |S )Nbufsize	bufferingmoderwbc                 V    t        | t              r| j                  d      }  |       S Nrg   )rh   ri   rj   )r;   _rconn_writes    r   writez1TestCase.connect.<locals>.makefile.<locals>.write  s&    !$,#{{73'--r   )popr   r   )rU   kwargsrconnr   r   conn_makefilerM   s       @r   makefilez"TestCase.connect.<locals>.makefile  sz    &*0**Y*?F;'V#($9&99 "'v%t6v6${{. $''.r   c                       e Zd Z fdZy)TestCase.connect.<locals>.proxyc                 *    |dk(  rS t        |      S )Nr   )getattr)rM   nameconnr   s     r   __getattribute__z0TestCase.connect.<locals>.proxy.__getattribute__!  s    z)'"4..r   N)r   r   r   r   )r   r   s   r   proxyr      s    /r   r   )r   create_connectionconnect_addrr   r   r   objectclose)rM   resultr   r   r   r   s   `  @@@r   connectzTestCase.connect  sm     ''):):DII(FG MMM*/ /
 WF	LLLNFLLNs   AB&A; *B;BBc              #      K   | j                         5 }	 |j                  d      }| |j                          	 d d d        y # j                          w xY w# 1 sw Y   y xY ww)Nr"   r   )r   r   r   )rM   sockr   s      r   r   zTestCase.makefile+  sZ     \\^ 	tq1	 	
 	 	s1   A&AAA	A&AAA#A&c                     | j                         5 }|j                  d      5 }|j                  d       t        |g|i |cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)Nr"   r   #GET / HTTP/1.1
Host: localhost

)r   r   r   	read_http)rM   rU   r   r   r*   s        r   urlopenzTestCase.urlopen4  sz    \\^ 	6tq) 6RDE 5d5f56 6	6 	66 6 6	6 	6 	6s"   A- A	A-A 	A--A6rE   c                     | j                   j                         }|j                  |       |}dj                  d |j	                         D              }|r|dz   n|}d}|t        ||| j                  |      z  }|S )N
c              3   &   K   | ]	  }d |z    yw)z%s: %sNr   ).0items     r   	<genexpr>z*TestCase.format_request.<locals>.<genexpr>B  s     J$hoJs   zE%(method)s %(path)s HTTP/%(http_ver)s
Host: localhost
%(headers)s
)methodpathhttp_verr,   )DEFAULT_EXTRA_CLIENT_HEADERScopyupdateru   itemsdictHTTP_CLIENT_VERSION)rM   r   r   r,   def_headersr   s         r   format_requestzTestCase.format_request=  s    77<<>7#++J'--/JJ&-'F"7 	 $--	
 
 r   )GETrB   )r   r   r   r   staticmethodr   r   r   DEFAULT_BIND_ADDRr   DEFAULT_LOCAL_HOST_ADDRr   r   WSGIHandlerr   r   r   r   CPYTHONPY2r   r   r   r   r   r   r   r   r   r   __classcell__rT   s   @r   r|   r|      s    FY'IK --K 44L2** 2

' Y]]		=	 $ $L  6  #% r   r|   c                   Z    e Zd ZdZdZdZd Zd Zd Z e	j                  d      d        Zy)	CommonTestMixinr   Fc                 f   | j                         5 }|j                  | j                                t        |d      }|j                  j                  d      dk(  r)| j                  | j                  d       |d fcd d d        S | j                  | j                         | j                  r|j                  dd       |j                  | j                  d             t        |d	d
d      }|j                  | j                                t        |d      }||fcd d d        S # 1 sw Y   y xY w)Nhello worldrG   
Connectionr   ,Server closed connection, not expecting that
keep-alive	/notexistr     	Not Found	not foundrJ   rI   rG   )r   r   r   r   r,   rb   
assertTrueEXPECT_CLOSEassertFalseEXPECT_KEEPALIVEre   )rM   r*   responsedne_responses       r   
test_basiczCommonTestMixin.test_basicX  s   ]]_ 	*HHT((*+ -8H##L1W< 1 13ab~	* 	* T../$$%%lLAHHT((k(:;$Rc+KXLHHT((*+ -8H\)	* 	* 	*s   A*D'BD''D0c                    t        d      }| j                         5 }|j                  | j                         | j                  d      z          t	        |d       	 t
        j                  j                  d|      }	 t	        |dd	d
       |j                          	 d d d        y # |j                          w xY w# | j                  $ r Y /t         $ r}||ur Y d }~Ad }~ww xY w# 1 sw Y   y xY w)Nz@HTTP pipelining not supported; the second request is thrown awayr   r   r   r   r   )	exceptionr   r   r   r   )
AssertionErrorr   r   r   r   r   r   r   r   PIPELINE_NOT_SUPPORTED_EXS)rM   r   r*   timeoutexs        r   test_pipelinezCommonTestMixin.test_pipelinek  s    "#ef	]]_ 	HHT((*T-@-@k-@-RRSb}-
 ..223)2L$bs;[QMMO	 	 MMO22 ! Y& '	 	sZ   A C(!B=?B(B=C((B::B==C%C(C%C C( C%%C((C1c                    | j                         5 }|j                  | j                                t        |      }|j                  j                  d      dk(  r&| j                  | j                  d       	 d d d        y | j                  | j                         | j                  r|j                  dd       |j                  | j                  d             t        |       |j                  | j                                	 |j                         }| j                  |d|       d d d        y # t        j                  $ r }|j                  d   t        vr Y d }~7d }~ww xY w# 1 sw Y   y xY w)Nr   r   r   r   )r   zAThe remote side is expected to close the connection, but it sent r   )r   r   r   r   r,   rb   r   r   r   r   re   r$   r   errorrU   CONN_ABORTED_ERRORS)rM   r*   r   r   r  s        r   test_connection_closez%CommonTestMixin.test_connection_close}  s?   ]]_ 	!HHT((*+ }H##L1W< 1 13ab	! 	! T../$$%%lLAHHT((G(<=bMHHT((*+	!
    !+	! 	!" << 771:%88 9#	! 	!s=   A&E) BE)D3E)3E&E!E)!E&&E))E2zNot surec                 N   g }t        d      D ]  }|j                  d        dj                  |      }| j                         5 }d|z  }|j	                  |       |j                         }|j                  d      d   }| j                  |d       d d d        y # 1 sw Y   y xY w)Ni  r   rB   z%GET /%s HTTP/1.0
Host: localhost

rA   r"   414)ranger   ru   r   r   r$   r'   assertEqual)rM   
path_parts_r   r*   requestr   statuss           r   test_006_reject_long_urlsz)CommonTestMixin.test_006_reject_long_urls  s    
t 	&Af%	&xx
#]]_ 	,CdJGHHW[[]F\\#&q)FVU+	, 	, 	,s   ABB$N)r   r   r   r  r   r   r   r  r  unittestskipr  r   r   r   r   r   S  sA    !#L*&$!6 X]]:, ,r   r   c                   :     e Zd ZdZdZddZd Z fdZd Z xZ	S )TestNoChunksNc                     |r+| j                  | j                  j                  d             y | j                  | j                  d          y )Nwsgi.input_terminated)r   last_environrb   r   )rM   input_terminateds     r   _check_environzTestNoChunks._check_environ  s=    OOD--112IJKT../FGHr   c                     || _         |d   }|dk(  r |ddg       ddgS |dk(  r |ddd	g      } |d
       ddgS  |ddg       ddgS )N	PATH_INFOrB   200 OKzContent-Typez
text/plain   hello    world
/websocketz101 Switching Protocols)r   r   r   s   upgrading tos	   websocket404 Not Found   not    found)r  )rM   envstart_responser   r   s        r   r   zTestNoChunks.application  s    ;3;8&D%EFx((<"#<$B %<	$=>E #J#\22)G(HI""r   c                 
   t         t        |          \  }}| j                          | j	                  |j
                         |j                  dd       |.| j	                  |j
                         |j                  dd       y y )Nr   119)r   r  r   r  r   rH   re   )rM   r   r   rT   s      r   r   zTestNoChunks.test_basic  sv    !&|T!E!G,).5#\001%%&6< $r   c                 (   | j                         5 }|j                  | j                  d             t        |ddd      }d d d        | j	                  j
                         | j                          |j                  dd       y # 1 sw Y   GxY w)	Nr   r   r   r   r   r   r   r)  )r   r   r   r   r   rH   r  re   rM   r*   r   s      r   test_dnezTestNoChunks.test_dne  s    ]]_ 	UHHT((k(:; #kTH	U 	).4	U 	Us   1BB)T)
r   r   r   r   r  r  r   r   r,  r   r   s   @r   r  r    s$     ILI#$=5r   r  c                       e Zd Zd Zd Zy)TestConnectionUpgradesc                    | j                         5 }|j                  | j                  dd             t        |d      }d d d        | j	                  d       | j                  j                         y # 1 sw Y   7xY w)Nr!  upgrade)r   r   e   rJ   Fr  r   r   r   r   r  r   rH   r+  s      r   test_connection_upgradez.TestConnectionUpgrades.test_connection_upgrade  so    ]]_ 	/HHT((ly(QR #.H	/ 	U3)	/ 	/   0A77B c                    | j                         5 }|j                  | j                  dd             t        |d      }d d d        | j	                  d       | j                  j                         y # 1 sw Y   7xY w)Nr!  	websocket)r   Upgrader1  r2  Fr3  r4  r+  s      r   test_upgrade_websocketz-TestConnectionUpgrades.test_upgrade_websocket  so    ]]_ 	/HHT((lK(PQ #.H	/ 	U3)	/ 	/r6  N)r   r   r   r5  r:  r   r   r   r.  r.    s    **r   r.  c                       e Zd ZdZefZdZy)TestNoChunks10rD   TN)r   r   r   r   r   r  r   r   r   r   r<  r<    s    "2!4Lr   r<  c                       e Zd ZddiZdZdZy)TestNoChunks10KeepAliver   r   FTN)r   r   r   r   r   r   r   r   r   r>  r>    s    l$  Lr   r>  c                       e Zd Zd Zy)TestExplicitContentLengthc                     || _         | j                  |j                  d             |d   }|dk(  r |dddg       ddgS  |d	dd
g       ddgS )Nr  r  rB   r  r  )r   r(  r  r   r"  )r   r)  r#  r$  )r  r   rb   )rM   r%  r&  r   s       r   r   z%TestExplicitContentLength.application  si     789;3;8&DF^%_`x(()GI`(ab""r   Nr   r   r   r   r   r   r   r@  r@    s    	#r   r@  c                       e Zd Zed        Zy)	TestYieldc              #   Z   K   | d   }|dk(  r |ddg       d y  |ddg       d y w)Nr  rB   r  r  s   hello worldr"  	   not foundr   r%  r&  r   s      r   r   zTestYield.application  s?     ;3;8&D%EF  ?-K,LMs   )+Nr   r   r   r   r   r   r   r   rD  rD    s     r   rD  c                        e Zd ZdZed        Zy)TestBytearrayNc                     | d   }|dk(  r  |ddg       t        d      t        d      gS  |ddg       t        d      gS )	Nr  rB   r  r  r  r   r"  rF  	bytearrayrG  s      r   r   zTestBytearray.application  sR    ;3;8&D%EFi()H*=>>)G(HI,'((r   )r   r   r   r   r   r   r   r   r   rJ  rJ    s    I) )r   rJ  c                   "    e Zd Zed        Zd Zy)TestMultiLineHeaderc                 .    d| d   v sJ  |ddg       dgS )Nztest.submitCONTENT_TYPEr  r  s   okr   r%  r&  s     r   r   zTestMultiLineHeader.application"  s*    N 3333x"@!ABwr   c                     dj                  d      }| j                         5 }|j                  |       t        |       ddd       y# 1 sw Y   yxY w)z
issue #116r   )POST / HTTP/1.0Host: localhostz9Content-Type: multipart/related; boundary="====XXXX====";z$ type="text/xml";start="test.submit"zContent-Length: 0rq   rq   Nru   r   r   r   rM   r  r*   s      r   test_multiline_116z&TestMultiLineHeader.test_multiline_116(  sJ    ++   ]]_ 	HHWbM	 	 	s   AAN)r   r   r   r   r   rX  r   r   r   rO  rO  !  s     
r   rO  c                   "    e Zd Zed        Zd Zy)
TestGetArgc                     | d   j                  d      }t        r|j                  d      }t        |      j	                  ddg      d   } |ddg       d	|d
|j                  d      gS )N
wsgi.input   rg   ar"   r   r  r  za is z
, body is )r7   r   r%   r   rb   rj   )r%  r&  rG   r^  s       r   r   zTestGetArg.application8  sl    < %%a(;;w'DTNsQC(+x"@!AB*+T2::7CDDr   c                     dj                  d      }| j                         5 }|j                  |       |j                  d       t        |d       d d d        y # 1 sw Y   y xY w)Nr   )rT  rU  zContent-Length: 3rq   za=a01234567890123456789za is a, body is a=ar   rV  rW  s      r   test_007_get_argzTestGetArg.test_007_get_argA  s_     ++   ]]_ 	6HHW HH+,b45	6 	6 	6s   0AA$N)r   r   r   r   r   ra  r   r   r   rZ  rZ  6  s    E E6r   rZ  c                   ,    e Zd ZdZd Zd ZdZd Zd Zy)TestCloseIterNc                      |ddg       | S Nr  r  r   rM   r%  r&  s      r   r   zTestCloseIter.applicationW  s    x"@!ABr   c              #   .   K   t        d       d y w)N   Hello World   !rL  rQ   s    r   rR   zTestCloseIter.__iter__[  s     ''
   Fc                 .    | xj                   dz  c_         y )Nr"   )closedrQ   s    r   r   zTestCloseIter.closea  s    qr   c                     d| _         | j                         5 }|j                  d       t        |dddg       d d d        | j	                  | j                   d       y # 1 sw Y   &xY w)NFr   s   Hello World!rh  ri  rG   rH   r"   )rl  r   r   r   r  rM   r*   s     r   test_close_is_calledz"TestCloseIter.test_close_is_calledd  sa    ]]_ 	OHH@Ab7MN	O 	a(		O 	Os   "AA()	r   r   r   r   r   rR   rl  r   rp  r   r   r   rc  rc  R  s$     I F)r   rc  c                   ,    e Zd Zg dZd Zd Zd Zd Zy)TestChunkedApp)s   thiss   iss   chunkedc                 8    dj                  | j                        S )Nr   )ru   rH   rQ   s    r   rG   zTestChunkedApp.bodyp  s    xx$$r   c              #      K   | j                  |j                  d              |ddg       | j                  E d {    y 7 w)Nr  r  r  )r   rb   rH   rf  s      r   r   zTestChunkedApp.applications  s7      789x"@!AB;;s   :AAAc                    | j                         5 }|j                  d       t        || j                         d       }d d d        j	                  dd       | j                  |j                  | j                         y # 1 sw Y   BxY w)N6GET / HTTP/1.1
Host: localhost
Connection: close

rn  rp   ro   )r   r   r   rG   re   r  rH   r+  s      r   test_chunked_responsez$TestChunkedApp.test_chunked_responsex  sr    ]]_ 	DHHUV $))+dCH	D 	19=$++6	D 	Ds   .B  B	c           	         | j                         5 }|j                  d       t        |      }d d d        | j                  j                  | j	                                | j                  |j
                  j                  d      d        |j
                  j                  d      }|3| j                  |t        t        | j	                                            y y # 1 sw Y   xY w)Nz6GET / HTTP/1.0
Host: localhost
Connection: close

rp   r   )	r   r   r   r  rG   r,   rb   ri   len)rM   r*   r   rw   s       r   test_no_chunked_http_1_0z'TestChunkedApp.test_no_chunked_http_1_0  s    ]]_ 	%HHUV }H	% 			4))--.ABDI!))--.>?%^STYY[1A-BC &	% 	%s   CC%N)r   r   r   rH   rG   r   rw  rz  r   r   r   rr  rr  l  s    )F%
7Dr   rr  c                       e Zd Zddz  gdz  Zy)TestBigChunks   ai    r]  N)r   r   r   rH   r   r   r   r|  r|    s    Tk]QFr   r|  c                       e Zd Zd Zd Zd Zy)TestNegativeReadc                     | j                  |j                  d              |ddg       |d   dk(  r|d   j                  d      }|gS y )Nr  r  r  r  z/readr\  )r   rb   r7   )rM   r%  r&  r;   s       r   r   zTestNegativeRead.application  sT     789x"@!AB{w&|$))"-D6M 'r   c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)Nsl   POST /read HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked

2
oh
4
 hai
0

oh hair   r   r   r   rM   r;   r*   s      r   test_negative_chunked_readz+TestNegativeRead.test_negative_chunked_read  @    5 ]]_ 	)HHTNbx(	) 	) 	)	   ;Ac                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)NsT   POST /read HTTP/1.1
Host: localhost
Connection: close
Content-Length: 6

oh hair  r   r  r  s      r   test_negative_nonchunked_readz.TestNegativeRead.test_negative_nonchunked_read  @     ]]_ 	)HHTNbx(	) 	) 	)r  N)r   r   r   r   r  r  r   r   r   r  r    s    ))r   r  c                   ,    e Zd ZdZed        Zd Zd Zy)TestNegativeReadlineNc                 V     |ddg       | d   dk(  r| d   j                  d      }|gS y )Nr  r  r  z	/readliner\  r  )r$   )r%  r&  r;   s      r   r   z TestNegativeReadline.application  s>    x"@!AB{{*|$--b1D6M +r   c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)Nsp   POST /readline HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked

2
oh
4
 hai
0

r  r   r  r  s      r   test_negative_chunked_readlinez3TestNegativeReadline.test_negative_chunked_readline  r  r  c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)NsX   POST /readline HTTP/1.1
Host: localhost
Connection: close
Content-Length: 6

oh hair  r   r  r  s      r   !test_negative_nonchunked_readlinez6TestNegativeReadline.test_negative_nonchunked_readline  r  r  )r   r   r   r   r   r   r  r  r   r   r   r  r    s#    I ))r   r  c                   l    e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Z ej                  d
      d        Z ej                  d
      d        Z ej                  d
      d        Z ej                  d
      d        Z ej                  d
      d        Z ej                  d
      d        Z xZS )TestChunkedPostr   c                 0    t         |           d| _        y )Nr   )r   r   callsrM   rT   s    r   r   zTestChunkedPost.setUp  s    
r   c                 p   | xj                   dz  c_         | j                  j                  d              |ddg       d   dk(  rd   j                  d      }|gS d   d	k(  rt	        t        fd
d            }|S d   dk(  rt	        t        fdd            S dd   j                  d      gS )Nr"   r  r  r  r  z/ar\     z/bc                  ,     d   j                  d      S )Nr\  r  r7   r%  s   r   <lambda>z-TestChunkedPost.application.<locals>.<lambda>  s    c,&7&<&<Q&? r   r   z/cc                  ,     d   j                  d      S )Nr\  r"   r  r  s   r   r  z-TestChunkedPost.application.<locals>.<lambda>  s    S%6%;%;A%> r   s   We should not get hererg   )r  r   rb   r7   rt   iterrj   )rM   r%  r&  r;   liness    `   r   r   zTestChunkedPost.application  s    

a
 789x"@!AB{t#|$))!,D6M{t#?EFEL{t#>DEE)3{+;+B+B7+KLLr   c                    d}| j                         5 }|j                  |       t        |d       d d d        | j                         5 }|j                  |j                  dd             t        |d       d d d        | j                         5 }|j                  |j                  dd             t        |d       d d d        y # 1 sw Y   xY w# 1 sw Y   ]xY w# 1 sw Y   y xY w)Nsi   POST /a HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked

2
oh
4
 hai
0

r  r   s   /as   /bs   /c)r   r   r   replacer  s      r   test_014_chunked_postz%TestChunkedPost.test_014_chunked_post  s    5 ]]_ 	)HHTNbx(	)
 ]]_ 	)HHT\\%/0bx(	) ]]_ 	)HHT\\%/0bx(	) 	)	) 	)
	) 	)	) 	)s#   C	
/C/C!	CC!C*c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)Nst   POST /a HTTP/1.1
Host: localhost
Connection: close
Content-Length: 12
Transfer-Encoding: chunked

{"hi": "ho"}  r2  r  r  s      r   #test_229_incorrect_chunk_no_newlinez3TestChunkedPost.test_229_incorrect_chunk_no_newline  s@    
  ]]_ 	$HHTNbs#	$ 	$ 	$r  c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)Nsv   POST /a HTTP/1.1
Host: localhost
Connection: close
Content-Length: 12
Transfer-Encoding: chunked

{"hi": "ho"}
r  r2  r  r  s      r    test_229_incorrect_chunk_non_hexz0TestChunkedPost.test_229_incorrect_chunk_non_hex  s@    $ ]]_ 	$HHTNbs#	$ 	$ 	$r  c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)Nsw   POST /a HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked

2;token="oh hi"
oh
4
 hai
0

r  r   r  r  s      r   !test_229_correct_chunk_quoted_extz1TestChunkedPost.test_229_correct_chunk_quoted_ext  sA    C ]]_ 	)HHTNbx(	) 	) 	)r  c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)Nu   POST /a HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked

2;token=oh_hi
oh
4
 hai
0

r  r   r  r  s      r    test_229_correct_chunk_token_extz0TestChunkedPost.test_229_correct_chunk_token_ext  sA    A ]]_ 	)HHTNbx(	) 	) 	)r  c                     d}|j                  dddz        }| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)Nr  s   oh_his   _oh_hii  r  r2  )r  r   r   r   r  s      r   +test_229_incorrect_chunk_token_ext_too_longz;TestChunkedPost.test_229_incorrect_chunk_token_ext_too_long  sV    A ||Hi$&67]]_ 	$HHTNbs#	$ 	$ 	$s   AAzMaybe hangsc                    d}d}| j                         5 }|j                  |       t        |d       |j                  |       t        |d       d d d        | j                  | j                  d       y # 1 sw Y   &xY w)Ns   POST /a HTTP/1.1
Host: localhost
Connection: keep-alive
Transfer-Encoding: chunked

2
oh
4
 hai
0
trailer1: value1
trailer2: value2

sg   POST /a HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked

2
oh
4
 bye
0
r  r   oh byer4   r   r   r   r  r  )rM   data1data2r*   s       r   test_trailers_keepalive_ignoredz/TestChunkedPost.test_trailers_keepalive_ignored#  sx     	  	 ]]_ 	)HHUObx(HHUObx(		) 	Q'	) 	)s   =A77B c                     d}| j                         5 }|j                  |       t        |d       | j                  t              5  t        |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Ns   POST /a HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked

2
oh
4
 hai
0
GETpath2a:123 HTTP/1.1
Host: a.com
Connection: close

r  r   )r   r   r   assertRaisesr   r  s      r   test_trailers_close_ignoredz+TestChunkedPost.test_trailers_close_ignoredG  ss     	" ]]_ 	HHTNbx(""#34 "	 	 	 	s#   4A0A$A0$A-	)A00A9c                 (   d}|dt         j                  z  z  }| j                         5 }|j                  |       t	        |d       | j                  t              5  t	        |d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Ns|   POST /a HTTP/1.1
Host: localhost
Connection: keep-alive
Transfer-Encoding: chunked

2
oh
4
 hai
0
trailer2: value2   tr  r   r  )r   MAX_REQUEST_LINEr   r   r   r  r   r  s      r   test_trailers_too_longz&TestChunkedPost.test_trailers_too_long`  s    
  	 	v.... ]]_ 	-HHTNbx(""#34 -"8,-	- 	-- -	- 	-s#   4BA<+B<B	BBc                 0   d}| j                         5 }|j                  |       t        |d       | j                  t              5  t        |       d d d        d d d        | j                  | j                  d       y # 1 sw Y   .xY w# 1 sw Y   2xY w)Ns   POST /a HTTP/1.1
Host: localhost
Connection: keep-alive
Transfer-Encoding: chunked

2
oh
4
 hai
0GET /path2?a=:123 HTTP/1.1
Host: a.com
Connection: close

r  r   r"   r   r   r   r  r   r  r  r  s      r   =test_trailers_request_smuggling_missing_last_chunk_keep_alivezMTestChunkedPost.test_trailers_request_smuggling_missing_last_chunk_keep_alivey  s     	" ]]_ 	HHTNbx(""#34 "	 	Q' 	 	s#   4BB B B		BBc                 4   d}| j                         5 }|j                  |       t        |d       | j                  t              5  t        |d       d d d        d d d        | j                  | j                  d       y # 1 sw Y   .xY w# 1 sw Y   2xY w)Ns   POST /a HTTP/1.1
Host: localhost
Connection: keep-alive
Transfer-Encoding: chunked

2
oh
4
 hai
0
Header: value
GET /path2?a=:123 HTTP/1.1
Host: a.com
Connection: close

r  r   r  r2  r"   r  r  s      r   ,test_trailers_request_smuggling_header_firstz<TestChunkedPost.test_trailers_request_smuggling_header_first  s     	 ]]_ 	(HHTNbx(""#34 ("3'(	( 	Q'( (	( 	(s#   4BBBB	BBc                     d}| j                         5 }|j                  |       t        |d       t        |d       d d d        | j                  | j                  d       y # 1 sw Y   &xY w)Ns   POST /a HTTP/1.1
Host: localhost
Connection: keep-alive
Transfer-Encoding: chunked

2
oh
4
 hai
0

Header: valueGET /path2?a=:123 HTTP/1.1
Host: a.com
Connection: close

r  r   r  r2  r"   r  r  s      r   >test_trailers_request_smuggling_request_terminates_then_headerzNTestChunkedPost.test_trailers_request_smuggling_request_terminates_then_header  sc     	  ]]_ 	$HHTNbx(bs#	$
 	Q'	$ 	$s   ,A$$A-)r   r   r   r  r   r   r  r  r  r  r  r  r   skipOnWindowsr  r  r  r  r  r  r   r   s   @r   r  r    s    EM")"$
$))$ Y]+!( ,!(F Y]+ ,0 Y]+- ,-0 Y]+( ,(@ Y]+( ,(2 Y]+( ,(r   r  c                   N    e Zd ZdZdZ e eeez               Zd Zd Z	d Z
d Zy)TestUseWrites   abcdes   endc                 |   |d   dk(  r6 |ddd| j                   fg      } || j                         | j                  gS |d   dk(  r) |ddg      } || j                         | j                  gS |d   dk(  r; |ddg      } || j                          || j                         | j                  gS t        d      )	Nr  z/explicit-content-lengthr  r  r   z/no-content-lengthz/no-content-length-twicezInvalid url)rw   rG   rL   end)rM   r%  r&  r   s       r   r   zTestUseWrite.application  s    {99"8.L/?ATAT.U.W XE$)) z !55"8.L-MNE$)) z !;;"8.L-MNE$))$)) z M**r   c                    | j                         5 }|j                  d       t        || j                  | j                  z         }d d d        j                  d| j                         |j                  dd       y # 1 sw Y   8xY w)NzMGET /explicit-content-length HTTP/1.1
Host: localhost
Connection: close

r   r   rp   F)r   r   r   rG   r  re   rw   r+  s      r   test_explicit_content_lengthz)TestUseWrite.test_explicit_content_length  sv    ]]_ 	@HHlm $))dhh*>?H	@ 	.0C0CD159		@ 	@s   6A>>Bc                     | j                         5 }|j                  d       t        || j                  | j                  z         }d d d        j                  dd       |j                  dd       y # 1 sw Y   .xY w)NzGGET /no-content-length HTTP/1.1
Host: localhost
Connection: close

r   r   Frp   ro   )r   r   r   rG   r  re   r+  s      r   test_no_content_lengthz#TestUseWrite.test_no_content_length  sp    ]]_ 	@HHfg $))dhh*>?H	@ 	.619=	@ 	@s   6A44A=c                    | j                         5 }|j                  d       t        || j                  | j                  z   | j                  z         }d d d        j                  dd       |j                  dd       | j                  |j                  | j                  | j                  | j                  g       y # 1 sw Y   kxY w)NzMGET /no-content-length-twice HTTP/1.1
Host: localhost
Connection: close

r   r   Frp   ro   )r   r   r   rG   r  re   r  rH   r+  s      r   test_no_content_length_twicez)TestUseWrite.test_no_content_length_twice  s    ]]_ 	LHHlm $))dii*?$((*JKH	L 	.619=499dii*JK	L 	Ls   AB>>CN)r   r   r   rG   r  ri   ry  rw   r   r  r  r  r   r   r   r  r    s3    D
CTCZ)N":>Lr   r  c                       e Zd Zej                  j                  ej                  j                  e      d      Zej                  j                  ej                  j                  e      d      Z	d Z
ddZd Zy)HttpsTestCaseztest_server.crtztest_server.keyc                     t        j                  | j                  df|| j                  | j                        | _        y )Nr   certfilekeyfile)r   r   r   r  r  r   r   s     r   r   zHttpsTestCase.init_server  s1    '')9)91(={15Vr   Nc           	      *   dd l }| j                         5 }|j                  |      5 }|j                  d      5 }|j	                  d|z         |E|j	                  dt        |      z         |j	                  |       |j                  d      ||d<   n|j	                  d       |j                          t        |fi |cd d d        cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)Nr   r"   r   z %s / HTTP/1.1
Host: localhost
zContent-Length: %s

rG   r   )	sslr   wrap_socketr   r   ry  rb   flushr   )rM   r   	post_bodyr   r  raw_sockr   r*   s           r   r   zHttpsTestCase.urlopen  s    \\^ 	3x* 3d]]1]- 3HHCfLM ,!=I!NO+!::f-5-6F6N(HHJ$R2623 33 3	3 	33 3 33 3 3	3 	3 	3s@   D	C4BC	C4	D	C'#C4+	D	4C=	9D		Dc                 d    |d   dk(  s
J |d           |ddg       |d   j                  d      gS )Nzwsgi.url_schemehttpsr  r  r\  
   r  rM   environr&  s      r   r   zHttpsTestCase.application  sH    ()W4Pg>O6PP4x"@!AB%**2.//r   )r   N)r   r   r   osr   ru   dirname__file__r  r  r   r   r   r   r   r   r  r    sV    ww||BGGOOH57HIHggll277??846GHGV3"0r   r  create_default_contextc                       e Zd Zd Zy)HttpsSslContextTestCasec                     ddl m}  |       }|j                  | j                  | j                         t        j                  | j                  df||      | _        y )Nr   )_create_unverified_contextr  )ssl_context)	
gevent.sslr  load_cert_chainr  r  r   r   r   r   )rM   r   r  contexts       r   r   z#HttpsSslContextTestCase.init_server#  sO     >02G##T]]DLL#Q ++T-=-=q,A,7WNDKr   N)r   r   r   r   r   r   r   r  r  "  s    	Nr   r  c                   ,    e Zd Z eed      rd Zd Zyy)	TestHttpsr  c                 b    | j                  dd      }| j                  |j                  d       y )NPOSTabc)r   r  r   r  rG   rM   r   s     r   test_012_ssl_serverzTestHttps.test_012_ssl_server5  s(    \\5\AFV[[%0r   c                 \    | j                         }| j                  |j                  d       y )Nrq   r  r  s     r   test_013_empty_returnzTestHttps.test_013_empty_return9  s!    \\^FV[["-r   N)r   r   r   r[   r   r  r  r   r   r   r  r  1  s    vu	1	. r   r  c                       e Zd Zy)TestHttpsWithContextNr   r   r   r   r  r  >  s    r   r  c                       e Zd ZdZd Zd Zy)TestInternationalNc                     d}t         r|j                  d      }| j                  |d   |       | j                  |d   d        |ddg       g S )Ns   /приветr    r  QUERY_STRINGzC%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81=%D0%BE%D1%82%D0%B2%D0%B5%D1%82
200 PASSEDr  )r   r%   r  )rM   r  r&  
path_bytess       r   r   zTestInternational.applicationD  sX    I
#**95J-z:02wx|&D%EF	r   c           	          | j                         5 }|j                  dj                  dd             |j                         5 }t	        |dddd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)	Ns   GET /%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82?%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81=%D0%BE%D1%82%D0%B2%D0%B5%D1%82 HTTP/1.1
Host: localhost
Connection: close

   
r5   PASSEDFrq   r   )rI   rH   rG   rw   )r   sendallr  r   r   )rM   r   r*   s      r   testzTestInternational.testO  s    \\^ 	XtLL GE7  XB"Xe"UVWX	X 	XX X	X 	Xs#   2A1A%A1%A.	*A11A:r   r   r   r   r   r  r   r   r   r  r  A  s    I		Xr   r  c                   D     e Zd ZdZdZdZeZ fdZ fdZ	d Z
d Z xZS )"TestNonLatin1HeaderFromApplicationFNs   Ὂ3c                 8    t         t        |           g | _        y rP   )r   r  r   errorsr  s    r   r   z(TestNonLatin1HeaderFromApplication.setUpb  s    0$=?r   c                 8    g | _         t        t        |           y rP   )r  r   r  r   r  s    r   r   z+TestNonLatin1HeaderFromApplication.tearDownf  s    0$@Br   c                     	  |ddd| j                   fg       g S #  | j                  j                  t        j                         d d         xY w)Nr  r  zCustom-Headerr4   )rc   r  r   sysexc_infor  s      r   r   z.TestNonLatin1HeaderFromApplication.applicationj  sU    	<:,dkk:<= 		KKs||~bq12s	    3Ac                 P   | j                         5 }| j                          |j                  d       |j                         5 }| j                  r|t        |dd       | j                  t        j                         | j                  t        | j                        d       | j                  d   \  }}| j                  |t               n3t        |dd	       | j                  t        | j                        d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)
Ns   GET / HTTP/1.1

r   r   )rJ   rI   )
where_typer"   r   r   r   )r   expect_one_errorr  r   should_errorr   assert_errorr   SecureEnvironr  ry  r  assertIsInstanceUnicodeError)rM   r   r*   r  vs        r   r  z'TestNonLatin1HeaderFromApplication.testu  s    \\^ 	:t!!#LL67 	:B$$bs3JK%%1E1E%F$$S%5q9;;q>DAq))!\:bs8<$$S%5q9	:	: 	:	: 	:	: 	:s$   2DB<D?DD	DD%)r   r   r   error_fatalr   rc   r   r  r   r   r   r  r   r   s   @r   r  r  [  s,    KIFLC	:r   r  c                       e Zd ZdZdZy))TestNonLatin1UnicodeHeaderFromApplicationu   Ὂ3TN)r   r   r   rc   r  r   r   r   r  r    s    F Lr   r  c                       e Zd ZdZd Zd Zy)TestInputReadlineNc                    |d   }g }	 |j                         }|sn7t        r|j                  d      n|}|j                  t	        |      dz          J |dg        t        r|D cg c]  }|j                  d       c}S |S c c}w Nr\  rg   rA   z	200 hello)r$   r   r%   r   r8   rj   rM   r  r&  inputr  r-   ls          r   r   zTestInputReadline.application  s    %>>#D+.4;;w'DDLLdc)*  	{B'5851a!1CeC1s   &Bc                     | j                         5 }d}|j                  dt        |      d|       |j                          t	        |dd       d d d        y # 1 sw Y   y xY w)Nzhello

world
123zEPOST / HTTP/1.1
Host: localhost
Connection: close
Content-Length: z

helloz'hello\n' '\n' 'world\n' '123' )rI   rG   )r   r   ry  r  r   )rM   r*   contents      r   r  zTestInputReadline.test  s]    ]]_ 	U+GHH7:7|WN OHHJb/ST	U 	U 	Us   AAA$r  r   r   r   r  r    s    
 I
DUr   r  c                       e Zd Zd Zy)TestInputIterc                     |d   }g }|D ]<  }|s n8t         r|j                  d      n|}|j                  t        |      dz          >  |dg        t         r|D cg c]  }|j	                  d       c}S |S c c}w r  )r   r%   r   r8   rj   r  s          r   r   zTestInputIter.application  s}    % 	+D+.4;;w'DDLLdc)*		+
 	{B'5851a!1CeC1s   A9NrB  r   r   r   r#  r#    s    	Dr   r#  c                       e Zd Zd Zy)TestInputReadlinesc                 (   |d   }|j                         D cg c]  }t        r|j                  d      n| }}|D cg c]  }t        |      dz    }} |dg        t        r|D cg c]  }|j	                  d       c}S |S c c}w c c}w c c}w r  )	readlinesr   r%   r8   rj   )rM   r  r&  r  r  r  r-   s          r   r   zTestInputReadlines.application  s    %:?//:KLQc'"q0LL.34ddc!44{B'5851a!1CeC M41s    BB
(BNrB  r   r   r   r&  r&    s    Dr   r&  c                       e Zd ZdZd Zd Zy)
TestInputNNc                 @    |d   j                  d        |dg        g S )Nr\     r  r  r  s      r   r   zTestInputN.application  s$    ""1%x$	r   c                 $    | j                          y rP   r   rQ   s    r   r  zTestInputN.test      r   r  r   r   r   r*  r*    s     I
r   r*  c                   *    e Zd Z e       ZdZd Zd Zy)TestErrorInApplicationFc                 N    t        j                  d      | _        | j                  )NzTestError.applicationr   r
   r  rf  s      r   r   z"TestErrorInApplication.application  s    001HI
jjr   c                     | j                          | j                  d       | j                  t        j                  | j
                         y )Nr   r2  )r  r   r  r   r
   r  rQ   s    r   r  zTestErrorInApplication.test  s6    #)55tzzBr   N)r   r   r   r   r  r  r   r  r   r   r   r1  r1    s    HEKCr   r1  c                       e Zd Zd Zy)TestError_after_start_responsec                 b    t        j                  d      | _         |ddg       | j                  )Nz*TestError_after_start_response.applicationr  r  r3  rf  s      r   r   z*TestError_after_start_response.application  s-    001]^
x"@!ABjjr   NrB  r   r   r   r6  r6    s    r   r6  c                   "    e Zd Zed        Zd Zy)TestEmptyYieldc              #   0   K    |ddg       d d y wNr  r  r   r   rR  s     r   r   zTestEmptyYield.application  s     x"@!AB		   c                     g }| j                         5 }|j                  d       t        |d|       |j                         }d d d        | j	                  dd|z         y # 1 sw Y    xY w)Nrv  rq   rn  r   zgot garbage: %rr   r   r   r7   r  rM   rH   r*   garbages       r   test_errzTestEmptyYield.test_err  se    ]]_ 	 HHUVbr&1ggiG	  	#'87'BC	  	 s   0A""A+Nr   r   r   r   r   rA  r   r   r   r9  r9    s     
	Dr   r9  c                   "    e Zd Zed        Zd Zy)TestFirstEmptyYieldc              #   0   K    |ddg       d d y w)Nr  r  r      hellor   rR  s     r   r   zTestFirstEmptyYield.application  s     x"@!AB	r<  c                     dg}| j                         5 }|j                  d       t        |d|       |j                         }d d d        | j	                  d       y # 1 sw Y   xY w)NrF  rv  r   rn  r   r>  r?  s       r   rA  zTestFirstEmptyYield.test_err  s_    ]]_ 	 HHUVbwv6ggiG	  	#&	  	 s   0AA(NrB  r   r   r   rD  rD    s     
	'r   rD  c                   "    e Zd Zed        Zd Zy)TestEmptyYield304c              #   .   K    |dg        d d y w)N304 Not modifiedr   r   rR  s     r   r   zTestEmptyYield304.application  s     )2.		rj  c                     | j                         5 }|j                  d       t        |ddd       |j                         }d d d        | j	                  d       y # 1 sw Y   xY w)Nrv  i0  rq   F)rJ   rG   rH   r   r>  )rM   r*   r@  s      r   rA  zTestEmptyYield304.test_err  sZ    ]]_ 	 HHUVbsE:ggiG	  	#&		  	 s   1AA&NrB  r   r   r   rI  rI    s     
'r   rI  c                       e Zd ZdZd Zd Zy)TestContentLength304Nc                     	  |ddg       t        d      # t         $ r} |dg        |j                  cY d }~S d }~ww xY w)NrK  )r   100z
200 Raisedz)start_response did not fail but it should)r   rU   )rM   r%  r&  r  s       r   r   z TestContentLength304.application$  sI    	-0I/JK HII  	<,77N	s   
 	?:??c                     d}| j                         5 }|j                  d       t        |dd|d       |j                         }d d d        | j	                  d       y # 1 sw Y   xY w)NzGInvalid Content-Length for 304 response: '100' (must be absent or zero)rv  r   RaisedF)rJ   rI   rG   rH   r   r>  )rM   rG   r*   r@  s       r   rA  zTestContentLength304.test_err,  sa    X]]_ 	 HHUVbs8$uMggiG		 
 	#&	  	 s   2A  A)r   r   r   r   r   rA  r   r   r   rN  rN  !  s    IJ'r   rN  c                       e Zd ZdZd Zd Zy)TestBody304Nc                      |dg        dgS )NrK  s   bodyr   rf  s      r   r   zTestBody304.application9  s    )2.yr   c                 (   | j                         5 }|j                  d       | j                  t              5 }t	        |       d d d        j
                  }| j                  t        |      d       d d d        y # 1 sw Y   9xY w# 1 sw Y   y xY w)Nrv  "The 304 response must have no body)r   r   r  r   r   r   r  ri   rM   r*   excr  s       r   rA  zTestBody304.test_err=  s    ]]_ 	LHHUV"">2 c"BSW&JK	L 	L 	L 	Ls"   'BA</B<B	BBrS  r   r   r   rU  rU  6  s    ILr   rU  c                        e Zd ZdZdZd Zd Zy)TestWrite304Nc                      |dg       }d| _         	  |d       y # t        $ r}d| _         t        |j                   d }~ww xY w)NrK  FrG   T)error_raisedr   r   rU   )rM   r%  r&  r   r  s        r   r   zTestWrite304.applicationJ  sJ    126!	3&M 	3 $D("''22	3s    	A=Ac                 `   | j                         5 }|j                  d       | j                  t              5 }t	        |       d d d        j
                  }d d d        | j                  t              d       | j                  | j                  d       y # 1 sw Y   UxY w# 1 sw Y   MxY w)Ns6   GET / HTTP/1.1
Host: localhost
Connection: close

rX  zwrite() must raise)
r   r   r  r   r   r   r  ri   r   r^  rY  s       r   rA  zTestWrite304.test_errS  s    ]]_ 	HHVW"">2 c"B		 	R"FG))+?@ 	 	s"   'B$BB$B!	B$$B-)r   r   r   r   r^  r   rA  r   r   r   r\  r\  F  s    IL3Ar   r\  c                       e Zd Zed        Zy)TestEmptyWritec                 :     |ddg      } |d        |d       g S r;  r   )r%  r&  r   s      r   r   zTestEmptyWrite.application`  s%    x*H)IJc
c
	r   NrH  r   r   r   ra  ra  ^  s     r   ra  c                       e Zd ZdZdZej                  j                  sJ  G d dej                        Zd Zd Z	d Z
d Zy)BadRequestTestsNc                       e Zd Zd Zy)BadRequestTests.handler_classc                     t        d      )NzShould not print a tracebackr   rQ   s    r   _print_unexpected_excz3BadRequestTests.handler_class._print_unexpected_excp  s     !?@@r   N)r   r   r   ri  r   r   r   r   rf  o  s    	Ar   r   c                 Z    | j                  |d   | j                          |ddg       dgS )Nrs   r  r  rF  )r  rw   rf  s      r   r   zBadRequestTests.applications  s4    -.0C0CDx"@!ABzr   c                     d| _         | j                         5 }|j                  d| j                   z         t        |d       d d d        y # 1 sw Y   y xY w)Nz-1007GET / HTTP/1.1
Host: localhost
Content-Length: %s

r   r  r2  rw   r   r   r   ro  s     r   test_negative_content_lengthz,BadRequestTests.test_negative_content_lengthx  sM    $]]_ 	+HHVY]YlYllmbz*	+ 	+ 	+   ,AAc                     d| _         | j                         5 }|j                  d| j                   z         t        |d       d d d        y # 1 sw Y   y xY w)Nr  rl  rm  r2  rn  ro  s     r   test_illegal_content_lengthz+BadRequestTests.test_illegal_content_length~  sM    #]]_ 	+HHVY]YlYllmbz*	+ 	+ 	+rp  c                     d}| j                         5 }|j                  |       t        |d       d d d        y # 1 sw Y   y xY w)NzGET / HTTP %
r  r2  r  )rM   bad_requestr*   s      r   "test_bad_request_line_with_percentz2BadRequestTests.test_bad_request_line_with_percent  s?     )]]_ 	$HH[!bs#	$ 	$ 	$r  )r   r   r   r   rw   r|   r   ri  r   ro  rr  ru  r   r   r   rd  rd  h  sI    IN!!7777A.. A
++$r   rd  c                   Z    e Zd ZdZdZd ZddZddZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)ChunkedInputTestsrq   Nc                    |d   }g }|d   }|dk(  r|j                  d      }|g}nQ|dk(  r|D ]  }|j                  |        n3|dk(  r#|j                  d       |j                  d       nt        d	       |d
dg       |S )Nr\  r  z/short-readr  z/linesz/pingr"   s   pongzbad pathr  r  )r7   r   RuntimeError)rM   r%  r&  r  r   pidr0   s           r   r   zChunkedInputTests.application  s    L!

2AsH8^ #"#7]JJqMOOG$z**x"@!ABr   c                 8    || j                   }t        ||      S )Ndirt)r~  chunk_encode)rM   rH   r~  s      r   r  zChunkedInputTests.chunk_encode  s    <99DF..r   c                 ,    | j                  g d|      S )N)thisz is ro   z
linez 2
line3rq   r}  )r  )rM   r~  s     r   rG   zChunkedInputTests.body  s      !_fj kkr   c                 @    |j                  d       t        |d       y )NzGET /ping HTTP/1.1

pongr   )r   r   ro  s     r   pingzChunkedInputTests.ping  s    
-."6"r   c                 &    | j                  |       y rP   )r  ro  s     r   ping_if_possiblez"ChunkedInputTests.ping_if_possible  s    		"r   c                 $   | j                         }d|z   }| j                         5 }|j                  d      5 }|j                  |       t	        |d       | j                  |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NsN   POST /short-read HTTP/1.1
transfer-encoding: Chunked
Content-Length:1000

r"   r   
this is chr   )rG   r   r   r   r   r  )rM   rG   reqr   r*   s        r   #test_short_read_with_content_lengthz5ChunkedInputTests.test_short_read_with_content_length  s    yy{gjnn\\^ 	*tq) *R"<0%%b)	*	* 	** *	* 	*s"   B0A:)B:B	?BBc                     | j                         }d|z   }| j                         5 }|j                  |       t        |d       | j	                  |       d d d        y # 1 sw Y   y xY w)NsK   POST /short-read HTTP/1.1
transfer-encoding: Chunked
Content-Length:0

r  r   rG   r   r   r   r  rM   rG   r  r*   s       r   (test_short_read_with_zero_content_lengthz:ChunkedInputTests.test_short_read_with_zero_content_length  s]    yy{dgkk ]]_ 	&HHSMb|,!!"%		& 	& 	&   0AA(c                     | j                         }d|z   }| j                         5 }|j                  |       t        |d       | j	                  |       d d d        y # 1 sw Y   y xY w)N9   POST /short-read HTTP/1.1
transfer-encoding: Chunked

r  r   r  r  s       r   test_short_readz!ChunkedInputTests.test_short_read  s[    yy{PSWW]]_ 	&HHSMb|,!!"%		& 	& 	&r  c                     | j                  d      }d|z   }| j                         5 }|j                  |       t        |d       | j	                  |       d d d        y # 1 sw Y   y xY w)Nz; here is dirt blar}  s3   POST /ping HTTP/1.1
transfer-encoding: Chunked

r  r   r  r  s       r   	test_dirtzChunkedInputTests.test_dirt  s`    yy3y4JTQ]]_ 	&HHSMbv&!!"%		& 	& 	&s   0A!!A*c                     | j                         }dt        |      z  }|j                  d      }||z  }| j                         5 }|j	                  |       t        |d       d d d        y # 1 sw Y   y xY w)NzHPOST /lines HTTP/1.1
Content-Length: %s
transfer-encoding: Chunked

r    zthis is chunked
line 2
line3r   )rG   ry  rj   r   r   r   r  s       r   test_chunked_readlinez'ChunkedInputTests.test_chunked_readline  so    yy{`dghldmnjj#t]]_ 	AHHSMb?@	A 	A 	As   A--A6c                    | j                          d}d|z   }| j                         5 }|j                  dd      5 }|j                  |       |j	                          d d d        d d d        j	                          ~~t        j                         j                  j                          t        j                  d       t        j                  rzdd l}|j                          t        j                  d       t        j                         j                  j                          |j                          t        j                  d       | j                  t        d       y # 1 sw Y   xY w# 1 sw Y   xY w)	Ns   4
thir  r"   wb)r   r   g{Gz?r   z1unexpected end of file while parsing chunked data)r  r   r   r   r   r   get_hubloop
update_nowsleepr   r	   r   r   r  IOError)rM   rG   r  r   r*   r   s         r   test_close_before_finishedz,ChunkedInputTests.test_close_before_finished  s   PSWW\\^ 	tqt4 
	 	

((*T>> JJLLLNN!!,,.JJLLL 	'#VWM 	 	s"   E/"E"E/"E,	'E//E9rP   )r   r   r   r~  r   r   r  rG   r  r  r  r  r  r  r  r  r   r   r   rw  rw    sF    DI*/l#*	&&&A+Xr   rw  c                       e Zd ZdZd Zd Zy)Expect100ContinueTestsNc           	          t        |d         }|dkD  r |dddg       dgS |d   j                  d      }||d   j                  |dz
        z  } |d	d
t        t        |            fdg       |gS )Nrs   i   z417 Expectation Failed)r   7r  s   failurer\  r"   r  r   )r6   r7   ri   ry  )rM   r  r&  rw   texts        r   r   z"Expect100ContinueTests.application  s    W%567D 36MOm5no< |$))!,%**>A+=>>x#3ST^"DFd!efvr   c                     | j                         5 }|j                  d       t        |dd       |j                  d       t        |d       t        |d	       d d d        y # 1 sw Y   y xY w)
NzOPUT / HTTP/1.1
Host: localhost
Content-length: 1025
Expect: 100-continue

i  failure)rJ   rG   zSPUT / HTTP/1.1
Host: localhost
Content-length: 7
Expect: 100-continue

testingrn   r2  testingr   r  ro  s     r   test_continuez$Expect100ContinueTests.test_continue(  s\    ]]_ 	*HHpqbs3HHtubs#by)	* 	* 	*s   AA%%A.)r   r   r   r   r   r  r   r   r   r  r    s    I*r   r  c                       e Zd ZdZd Zd Zy)MultipleCookieHeadersTestNc                 l    | j                  |d   d       | j                  |d   d        |dg        g S )NHTTP_COOKIEzname1="value1"; name2="value2"HTTP_COOKIE2znameA="valueA"; nameB="valueB"r  )r  r  s      r   r   z%MultipleCookieHeadersTest.application6  s=    /1QR02RSx$	r   c                     | j                         5 }|j                  dj                  dd             t        |       d d d        y # 1 sw Y   y xY w)Nz~GET / HTTP/1.1
Host: localhost
Cookie: name1="value1"
Cookie2: nameA="valueA"
Cookie2: nameB="valueB"
Cookie: name2="value2"

r  r   )r   r   r  r   ro  s     r   r  zMultipleCookieHeadersTest.test<  sJ    ]]_ 	HH 
 &gdF35 bM	 	 	s   -AAr  r   r   r   r  r  2  s    Ir   r  c                   ,    e Zd ZdZdZd Zd Zd Zd Zy)TestLeakInputNc                 J    t         j                  |        d | _        d | _        y rP   )r|   r   _leak_wsgi_input_leak_environrQ   s    r   r   zTestLeakInput.tearDownL  s     $ $!r   c           	          |d   }|d   | _         || _        |dk(  rt        j                  d      |d<   d} |ddt	        t        |            fd	g       |gS )
Nr  r\  z/leak-framer   _leaks   foobarr  r   r  )r  r  r
  	_getframeri   ry  )rM   r  r&  rz  r  s        r   r   zTestLeakInput.applicationQ  sf    [! ' 5$"}}Q/GGx#3ST^"DFd!efvr   c                     | j                         5 }|j                  d       |j                         }d d d        | j                  j	                  d      |       y # 1 sw Y   +xY w)Ns%   GET / HTTP/1.0
Connection: close

   HTTP/1.1 200 OK)r   r   r7   r   
startswithrM   r*   r{  s      r   !test_connection_close_leak_simplez/TestLeakInput.test_connection_close_leak_simple\  sT    ]]_ 	HHCD	A	 	%78!<	 	s   "AA&c                    | j                         5 }|j                  d       |j                         }d d d        | j                  j	                  d      |       | j
                  j                  d       y # 1 sw Y   FxY w)Ns/   GET /leak-frame HTTP/1.0
Connection: close

r  r  )r   r   r7   r   r  r  r   r  s      r    test_connection_close_leak_framez.TestLeakInput.test_connection_close_leak_frameb  sh    ]]_ 	HHMN	A	 	%78!<w'		 	s   "A88B)	r   r   r   r  r  r   r   r  r  r   r   r   r  r  G  s!    M"
	=(r   r  c                   F    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)TestHTTPResponseSplittingNr  r   c                     t         j                  |        d | _        t        j                  | _        t        j
                  | _        y rP   )r|   r   	start_excr  r  r,   rQ   s    r   r   zTestHTTPResponseSplitting.setUpr  s/    t/66088r   c                 <    t         j                  |        d | _        y rP   )r|   r   r  rQ   s    r   r   z"TestHTTPResponseSplitting.tearDownx  s    $r   c                     	  || j                   | j                         d | _        y# t        $ r}|| _        Y d }~yd }~ww xY w)Nr   )r  r,   r  rL   )rM   r  r&  es       r   r   z%TestHTTPResponseSplitting.application|  sE    	"4;;5 "DN	  	DNN 		s   ' 	A<Ac                 "   | j                         5 }|j                  d       |j                          d d d        | j                  | j                  t
               | j                  | j                  j                  d   |       y # 1 sw Y   SxY w)N#GET / HTTP/1.0
Host: localhost

r   )r   r   r7   r  r  
ValueErrorr  rU   )rM   messager*   s      r   _assert_failurez)TestHTTPResponseSplitting._assert_failure  sm    ]]_ 	HH@AGGI	 	dnnj9,,Q/9		 	s   "BBc                 4    d| _         | j                  d       y )Nz0200 OK
Connection: close
Content-Length: 0

z$carriage return or newline in status)r  r  rQ   s    r   test_newline_in_statusz0TestHTTPResponseSplitting.test_newline_in_status  s    PCDr   c                 6    dg| _         | j                  d       y )N)TestzHi
Connection: closez*carriage return or newline in header valuer,   r  rQ   s    r   test_newline_in_header_valuez6TestHTTPResponseSplitting.test_newline_in_header_value  s    ;<IJr   c                 6    dg| _         | j                  d       y )N)zTest
Hiz)carriage return or newline in header namer  rQ   s    r   test_newline_in_header_namez5TestHTTPResponseSplitting.test_newline_in_header_name  s    *+HIr   )r   r   r   r   r  r,   r  r   r   r   r  r  r  r  r   r   r   r  r  i  s>     IFGI9:EKJr   r  c                       e Zd ZdZd Zd Zy)TestInvalidEnvironNc                     |j                         D ]1  \  }}|dv s|j                  d      s|dk7  s"t        d|d|        |dg        g S )N)rs   rQ  HTTP_	HTTP_HOSTz!Unexpected environment variable: =r  )r   r  r   )rM   r  r&  r.   r/   s        r   r   zTestInvalidEnviron.application  s_    !--/ 	%JC88CNN7<S+%0U2$ % %	%
 	x$	r   c                    | j                         5 }|j                  d       t        |       d d d        | j                         5 }|j                  d       t        |       d d d        y # 1 sw Y   ?xY w# 1 sw Y   y xY w)Nr  r   r  ro  s     r   r  zTestInvalidEnviron.test  sq    ]]_ 	HH@AbM	 ]]_ 	HH@AbM	 		 		 	s   A,A8,A58Br  r   r   r   r  r    s    Ir   r  c                       e Zd ZdZd Zd Zy)TestInvalidHeadersDroppedNc                 <    | j                  d|        |dg        g S )NHTTP_X_AUTH_USERr  )assertNotInr  s      r   r   z%TestInvalidHeadersDropped.application  s"    +W5x$	r   c                     | j                         5 }|j                  d       t        |       d d d        y # 1 sw Y   y xY w)Nz$GET / HTTP/1.0
x-auth_user: bob

r  ro  s     r   r  zTestInvalidHeadersDropped.test  s6    ]]_ 	HHABbM	 	 	s	   7A r  r   r   r   r  r    s    I
r   r  c                   F    e Zd ZdZ G d dej
                        Zd Zd Zy)TestHandlerSubclassNc                       e Zd Zd Zy)!TestHandlerSubclass.handler_classc                 B   | j                   j                  d      }|d   dk(  r`|| j                   j                  d      z  }|j                         dk(  r| j                  j	                  d       y | j                  d|       y || j                   j                         z   S )N   r   <      s   <policy-file-request/>   HELLOzInvalid request: %r)rfiler7   r)   r   r  	log_errorr$   )rM   r;   s     r   read_requestlinez2TestHandlerSubclass.handler_class.read_requestline  s    ::??1%DAw'!
 

++::<#<<KK''1  NN#8$?$**--///r   N)r   r   r   r  r   r   r   r   r    s    	0r   r   c                      |dg        g S )Nr  r   r  s      r   r   zTestHandlerSubclass.application  s    x$	r   c                 >   | j                         5 }|j                  d       |j                          | j                  |j	                         d       d d d        | j                         5 }|j                  d       |j                          t        |       d d d        | j                         5 }|j                  d       |j                          | j                  |j	                         d       d d d        y # 1 sw Y   xY w# 1 sw Y   pxY w# 1 sw Y   y xY w)Ns   <policy-file-request/> r  rv  z<policy-file-XXXuest/> r   )r   r   r  r  r7   r   ro  s     r   r  zTestHandlerSubclass.test  s    ]]_ 	2HH23HHJRWWY1	2
 ]]_ 	HHUVHHJbM	
 ]]_ 	-HH12HHJRWWY,		- 	-	2 	2
	 	
	- 	-s%   AC;+-D0AD;DDD)r   r   r   r   r|   r   r   r  r   r   r   r  r    s#    I0.. 0"-r   r  c                   &    e Zd ZdZed        Zd Zy)TestErrorAfterChunkNc              #   P   K    |ddg       d t        j                  d      w)Nr  r  rF  r  )r   r
   rR  s     r   r   zTestErrorAfterChunk.application  s+     x"@!AB))*?@@s   $&c                 8   | j                         5 }| j                          |j                  d       | j                  t              5  t        |       d d d        d d d        | j                  t        j                         y # 1 sw Y   1xY w# 1 sw Y   5xY w)Nz;GET / HTTP/1.1
Host: localhost
Connection: keep-alive

)	r   r  r   r  r  r   r  r   r
   ro  s     r   r  zTestErrorAfterChunk.test  s{    ]]_ 	!!#HHZ["":. "	
 	)556 	 	s#   7BBBB		BB)r   r   r   r   r   r   r  r   r   r   r  r    s     IA A
7r   r  c                 j    |d}d}| D ]'  }dt        |      ||fz  }||j                  d      z  }) |S )Nrq   r   z
%x%s
%s
rg   )ry  rj   )rH   r~  bcr0   s        r   r  r    sO    |A Aa00	QXXg Hr   c                        e Zd ZddZerd 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 xZS )TestInputRawc                     t        |t              rt        |      }d}n't        |t              rt        r|j                  d      }t        t        |      ||      S )NTrg   )rw   chunked_input)rh   rt   r  ri   r   rj   r   StringIO)rM   r;   rw   r  s       r   
make_inputzTestInputRaw.make_input  sI    dD!%D Mc"s;;w'DXd^NR_``r   c                 r    t        |t              r|j                  d      }t        t        |   |||       y r   )rh   ri   rj   r   r  r  )rM   firstsecondmsgrT   s       r   r  zTestInputRaw.assertEqual  s.    &#&w/,1%Er   c                 j    | j                  dd      }| j                  t        |j                         y N1r4   rw   r  r  r  r7   rM   is     r   test_short_postzTestInputRaw.test_short_post  s(    OOCO2'166*r   c                 l    | j                  dd      }| j                  t        |j                  d       y r  r  r  s     r    test_short_post_read_with_lengthz-TestInputRaw.test_short_post_read_with_length  s*    OOCO2'1661-r   c                 j    | j                  dd      }| j                  t        |j                         y r  r  r  r  r$   r  s     r   test_short_post_readlinez%TestInputRaw.test_short_post_readline  s(    OOCO2'1::.r   c                 n    | j                  dd      }|j                         }| j                  |d       y )N12r4   r  r  r7   r  rM   r  r;   s      r   	test_postzTestInputRaw.test_post!  s/    OODO3vvxt$r   c                 p    | j                  dd      }|j                  d      }| j                  |d       y )Nr  r4   r  r  r  r  s      r   test_post_read_with_lengthz'TestInputRaw.test_post_read_with_length&  s1    OODO3vvbzt$r   c                 n    | j                  g d      }|j                         }| j                  |d       y )Nr  2rq   r  r  r  s      r   test_chunkedzTestInputRaw.test_chunked+  s+    OON+vvxt$r   c                 p    | j                  g d      }|j                  d      }| j                  |d       y )Nr  r  r  r  r  s      r   test_chunked_read_with_lengthz*TestInputRaw.test_chunked_read_with_length0  s-    OON+vvbzt$r   c                 j    | j                  ddg      }| j                  t        |j                         y Nr  r  r  r  s     r   test_chunked_missing_chunkz'TestInputRaw.test_chunked_missing_chunk5  s(    OOS#J''166*r   c                 l    | j                  ddg      }| j                  t        |j                  d       y )Nr  r  r  r  r  s     r   +test_chunked_missing_chunk_read_with_lengthz8TestInputRaw.test_chunked_missing_chunk_read_with_length9  s*    OOS#J''1662.r   c                 j    | j                  ddg      }| j                  t        |j                         y r  r  r  s     r   #test_chunked_missing_chunk_readlinez0TestInputRaw.test_chunked_missing_chunk_readline=  s(    OOS#J''1::.r   c                 j    | j                  dd      }| j                  t        |j                         y N2
1Tr  r  r  s     r   test_chunked_short_chunkz%TestInputRaw.test_chunked_short_chunkA  s(    OOHDO9'166*r   c                 l    | j                  dd      }| j                  t        |j                  d       y )Nr#  Tr$  r4   r  r  s     r   )test_chunked_short_chunk_read_with_lengthz6TestInputRaw.test_chunked_short_chunk_read_with_lengthE  s*    OOHDO9'1661-r   c                 j    | j                  dd      }| j                  t        |j                         y r"  r  r  s     r   !test_chunked_short_chunk_readlinez.TestInputRaw.test_chunked_short_chunk_readlineI  s(    OOHDO9'1::.r   c                 H   d}dt         j                  dz   z  }|dz  }||z  }d}d}t        |d      r | j                  |j	                         d       t
        s0t        s*| j                  t        t        |      j                  |       | j                  ||	      }| j                  |j                         d
       | j                  |j                  |      d       | j                  |j                  |      |       | j                  ||z   t        |      dz   	      }| j                  |j                         d
       | j                  |j                  |      d       | j                  |j                  |      |       | j                  |j                  |      d       y )Ns
   asdf
ghij
r}  r  r  s   qjk
l    :;$ 
bit_length#   r  s   asdf
s   ghij
r"      q)r   r  r[   r  r+  r   r	   r  OverflowErrorr  r$   r  ry  )rM   r;   	long_datapartial_datanr  s         r   test_32bit_overflowz TestInputRaw.test_32bit_overflowM  sV    F33b89	U		1l#Q\\^R04mXd^-D-DaHOODO3y1A	2A	2 OOD</D	AONy1A	2A	2 	A-r   )NFrP   )r   r   r   r  r   r  r  r	  r  r  r  r  r  r  r  r   r%  r'  r)  r2  r   r   s   @r   r  r    sZ    a 	F
+./%
%
%
%
+//+./.r   r  c                   "    e Zd Zed        Zd Zy)Test414c                     t        d      )Nzshould not get thererh  rR  s     r   r   zTest414.applicationo  s    344r   c                     ddz  }| j                         5 }|j                  d|z  j                  d             t        |d       d d d        y # 1 sw Y   y xY w)Nr0   i N  z"GET /%s HTTP/1.0
Hello: world

r    i  r2  )r   r   rj   r   )rM   longliner*   s      r   r  zTest414.tests  sS    ;]]_ 	$HHDxOWWXabcbs#	$ 	$ 	$s   1AAN)r   r   r   r   r   r  r   r   r   r4  r4  m  s    5 5$r   r4  c                   J    e Zd Z G d de      Zd Zed        Zd Zd Z	d Z
y)	TestLoggingc                   *    e Zd ZdZdZdZd Zd Zd Zy)TestLogging.LoggerNc                     ||f| _         y rP   )logged)rM   levelr  s      r   r   zTestLogging.Logger.log  s     #,DKr   c                     || _         y rP   )accessedrM   r  s     r   accesszTestLogging.Logger.access  s	    DMr   c                     | j                   S rP   )thingrQ   s    r   	get_thingzTestLogging.Logger.get_thing  s    ::r   )	r   r   r   r@  r=  rD  r   rB  rE  r   r   r   Loggerr;  }  s     	'	 	r   rF  c                 "    | j                         S rP   )rF  rQ   s    r   r   zTestLogging.init_logger  s    {{}r   c                      |ddg       dgS )Nr  r  rF  r   rR  s     r   r   zTestLogging.application  s    x"@!ABzr   c                    | j                  t        | j                  j                  t        j
                               | j                  j                  j                  d       | j                  j                  j                  d       | j                  | j                  j                  j                  d       | j                  | j                  j                  j                  d       y )NrB  r   )   r   )r   rh   r   r   r   LoggingLogAdapterrB  r   r  r@  r=  rQ   s    r   test_proxy_methods_on_logz%TestLogging.test_proxy_methods_on_log  s     	
4;;??F4L4LMNx(g&118<//?r   c                 6   d| j                   j                  _        | j                  | j                   j                  j	                         d       | j                   j                  `| j                  | j                   j                  j	                         d        y )N*   )r   r   rD  r  rE  rQ   s    r   test_set_attributeszTestLogging.test_set_attributes  sb     "224b9KKOO!224d;r   c                     | j                          | j                  j                  j                  d   }| j	                  d|v |       | j	                  d|v|       y )Nr"   z"GET / HTTP/1.1" 200 r  )r   r   r   r=  r   rA  s     r   test_status_logzTestLogging.test_status_log  sK    kkoo$$Q'/36< 	C-r   N)r   r   r   r   rF  r   r   r   rL  rO  rQ  r   r   r   r9  r9  z  s7       @<.r   r9  c                   F     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
 xZS )	TestEnvironNc                 j    t         t        |   |       t        j                  | j
                  _        y rP   )r   rS  r   r   r  r   environ_class)rM   r   rT   s     r   r   zTestEnviron.init_server  s$    k4,[9$*$8$8!r   c                 Z    | j                  |t        j                          |ddg       g S re  )r  r   r  rf  s      r   r   zTestEnviron.application  s+    c6#7#78x"@!AB	r   c                 $    | j                          y rP   r.  rQ   s    r   !test_environ_is_secure_by_defaultz-TestEnviron.test_environ_is_secure_by_default  r/  r   c                    t        j                         }| j                  dt        |             | j                  dt	        |             d|d<   | j                  dt        |             | j                  dt	        |             d|_        | j                  t	        ddi      t	        |             | j                  t        ddi      t        |             |`d|_        | j                  t	        ddi      t	        |             | j                  t        ddi      t        |             d|_        | j                  t	        ddi      t	        |             | j                  t        ddi      t        |             |`y )	Nz'<pywsgi.SecureEnviron dict (keys: 0) atr/   r.   z'<pywsgi.SecureEnviron dict (keys: 1) atF)zmissing valuez<MASKED>r.   )r   r  assertInr8   ri   secure_reprr  whitelist_keys)rM   r  s     r   test_default_secure_reprz$TestEnviron.test_default_secure_repr  s=   &&(?gO?WN ?gO?WN#eW-.G=ug./g?!3eZ013w<@uj12DMB!)eW-.G=ug./g?"r   c                 8    G d dt         j                        } |       }| j                  |j                         d|_        | j                  |j                         | j                  t        i       t        |             | j                  t        i       t        |             d|_        d|_	        d|d<   | j                  t        ddi      t        |             | j                  t        ddi      t        |             ~~dd l
}|j                          y )	Nc                       e Zd ZdZy)>TestEnviron.test_override_class_defaults.<locals>.EnvironClassr   N)r   r   r   	__slots__r   r   r   EnvironClassra    s    Ir   rc  FTrZ  r"   r.   r   )r   r  r   r\  default_secure_reprr   r  ri   r8   default_whitelist_keysr   r   )rM   rc  r  r   s       r   test_override_class_defaultsz(TestEnviron.test_override_class_defaults  s    	6// 	 .++,+0(,,-R#g,/b4=1+/(.6+eQZ#g,7uaj)4=9 2::<r   c                     t         j                  t         j                  fD ]'  }| j                   |       j	                         |       ) y rP   )r   Environr  r  r   )rM   rv   s     r   test_copy_still_securez"TestEnviron.test_copy_still_secure  s8    NNF$8$89 	5C!!#%**,4	5r   c                 &   dd l }dd l}t        j                  t        j                  fD ]  }ddi} ||      }| j                  ||       | j                  ||       | j                  ||       t        d|j                  dz         D ]V  }|j                  ||      }| j                  d|       |j                  |      }| j                  t        |      t               X | j                  |j                  |      |j                  |              y )Nr   r.   r/   r"   s   Environ)picklejsonr   rh  r  r  r  r  HIGHEST_PROTOCOLdumpsr  loadstyper   )	rM   rk  rl  rv   bltinr%  protocolenv_dumploadeds	            r   test_pickle_copy_returns_dictz)TestEnviron.test_pickle_copy_returns_dict  s     	NNF$8$89 	ACG$Ee*C!!#s+UC(S%(!!V%<%<q%@A 5 "<<X6  X6h/  ft45 TZZ.

3@	Ar   )r   r   r   r   r   r   rX  r^  rf  ri  ru  r   r   s   @r   rS  rS    s.     I9
#2 45Ar   rS  __main__rP   )dr   r   	patch_all
contextlibr   urllib.parser   r  r
  ior   r  r   r  wsgiref.validater   gevent.testingr  r   r   r	   gevent.testing.exceptionr
   r   r   gevent.pywsgir   r   r   rs   r  rr   rL   r   r1   r<   r   r>   r7   r   r|   r   r  r.  r<  r>  r@  rD  rJ  rO  rZ  rc  rr  r|  r  r  r  r  r  r  r   r  HAVE_SSLCONTEXTr  r  r  r  r  r  r  r#  r&  r*  r1  r6  r9  rD  rI  rN  rU  r\  ra  rd  rw  r  r  r  r  r  r  r  r  r  BaseTestCaser  r4  r9  rS  r   mainr   r   r   <module>r     s  *      % ! 	 
 "   & "  $ 6   &. & "33  
	 	y 	"*+Xv Xt MM	Sy!! SlQ,f Q,h-5?H -5^*\ *&\ 
n # # 
 
)OX )( *6 68)H )4DX D>N )x )4)8 )6G(h G(T-L8 -L`0H 0@ &**&>?N- N
. 
. 6	 X X4': ':T0R U U8D% DD* D "CX C%; DX D('( '(' ' '8 '*L( L A8 A0^ #$h #$LGX GXT*X *4 * (H  (D-J -J` , (-( (-V7( 7$d.9)) d.N
$h 
$3.( 3.j^A( ^AB zINN r   