+
    Dfj)                       R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHtHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHtHt ^ RIHt ^ RIHt ^ RIHt ^ RI H!t! ^ RI"H#t# ^ RI$H%t%H&t& ^ RI'H(t(H)t)H*t* ^ RI+H,t, ^ RI-H.t.  ! R R4      t/ ! R R4      t0 ! R R]!4      t1 ! R R4      t2 ! R R]2]!4      t3 ! R R]24      t4 ! R  R!]4]!4      t5 ! R" R#]4]!4      t6 ! R$ R%]2]!4      t7 ! R& R']2]!4      t8R# )(z 
Tests for L{twisted.web.wsgi}.
N)exc_info)quote)verifyObject)reactor)IPv4AddressIPv6Address)DeferredgatherResults)ConnectionLost)EventLoggingObserver)LoggerglobalLogPublisher)Failure)getThreadID)
ThreadPool)TestCase)server)	IResourceResource)RequestSiteversion)DummyChannel)WSGIResourcec                   8   a  ] tR t^!t o Rt]! 4       tR tRtV t	R# )SynchronousThreadPoola  
A single-threaded implementation of part of the L{ThreadPool} interface.
This implementation calls functions synchronously rather than running
them in a thread pool.  It is used to make the tests which are not
directly for thread-related behavior deterministic.
c                r     V! V/ VB  R#   \          d     T P                  P                  R4        R# i ; i)zX
Call C{f(*a, **kw)} in this thread rather than scheduling it to be
called in a thread.
z<Callable passed to SynchronousThreadPool.callInThread failedN)BaseException_logfailureselffakws   &&*,</usr/lib/python3/dist-packages/twisted/web/test/test_wsgi.pycallInThread"SynchronousThreadPool.callInThread+   s8    
	qKBK 	 IIN		s    &66 N)
__name__
__module____qualname____firstlineno____doc__r   r   r&   __static_attributes____classdictcell____classdict__s   @r%   r   r   !   s      8D     r   c                   *   a  ] tR t^;t o RtR tRtV tR# )SynchronousReactorThreadsa  
A single-threaded implementation of part of the L{IReactorThreads}
interface.  This implementation assumes that it will only be invoked
from the reactor thread, so it calls functions synchronously rather than
trying to schedule them to run in the reactor thread.  It is used in
conjunction with L{SynchronousThreadPool} to make the tests which are
not directly for thread-related behavior deterministic.
c                    V! V/ VB  R# )zM
Call C{f(*a, **kw)} in this thread which should also be the reactor
thread.
Nr(   r    s   &&*,r%   callFromThread(SynchronousReactorThreads.callFromThreadE   s    
 	
1r2   r(   Nr)   r*   r+   r,   r-   r6   r.   r/   r0   s   @r%   r4   r4   ;   s      r2   r4   c                   8   a  ] tR t^Mt o R tR tR tR tRtV t	R# )WSGIResourceTestsc                L    \        \        4       \        4       R 4      V n        R# )z
Create a L{WSGIResource} with synchronous threading objects and a no-op
application object.  This is useful for testing certain things about
the resource implementation which are unrelated to WSGI.
c                     R # Nr(   environstartResponses   &&r%   <lambda>)WSGIResourceTests.setUp.<locals>.<lambda>W   s    4r2   N)r   r4   r   resourcer!   s   &r%   setUpWSGIResourceTests.setUpN   s     %%'!#/
r2   c                    \        \        V P                  4       V P                  V P                  P                  4       R# )zG
L{WSGIResource} implements L{IResource} and stops resource traversal.
N)r   r   rC   
assertTrueisLeafrD   s   &r%   test_interfaces!WSGIResourceTests.test_interfacesZ   s(     	Y.,,-r2   c           	         V P                  \        V P                  P                  R\	        \        4       R4      4       V P                  \        V P                  P                  R\        4       4       R# )z
A L{WSGIResource} cannot have L{IResource} children.  Its
C{getChildWithDefault} and C{putChild} methods raise L{RuntimeError}.
   fooFN)assertRaisesRuntimeErrorrC   getChildWithDefaultr   r   putChildr   rD   s   &r%   test_unsupported"WSGIResourceTests.test_unsupporteda   sS    
 	MM--LNE*		
 	,(>(>
Sr2   c                  a \         P                  ! V \        4      p ! R R\        4      o ! R R\        4      pV3R lp ! V3R lR4      p\        V! 4       \        4       V4      V n        V P                  P                  V! \        4       R4      4       V P                  ^\        V4      4       V^ ,          R	,          pV P                  VP                  S4       V P                  S4       R
# )z
If an exception is thrown by the application, and then in the
exception handling code, verify it should be propagated to the
provided L{ThreadPool}.
c                       ] tR t^vtRtRtR# )IWSGIResourceTests.test_applicationAndRequestThrow.<locals>.ArbitraryErrorz#
An arbitrary error for this class
r(   N)r)   r*   r+   r,   r-   r.   r(   r2   r%   ArbitraryErrorrV   v   s    r2   rW   c                   6   a  ] tR t^{t o RtR tR tR tRtV t	R# )PWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequestz4
An L{IRequest} request whose finish method throws.
c                d    \         P                  ! V .VO5/ VB  R V n        R V n        RV n        R# ) s   www.example.com/stuffN)r   __init__prepathpostpathuri)r!   argskwargss   &*,r%   r\   YWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.__init__   s/      777! "3r2   c                    R# )z9
Return loopback address.

@return: loopback ip address.
	127.0.0.1r(   rD   s   &r%   getClientIP\WSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.getClientIP   s     #r2   c                    \        RRR4      # )z0
Return a fake Address

@return: A fake address
TCPrd   i0u  )r   rD   s   &r%   getHostXWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.getHost   s     #5+u==r2   )r^   r]   r_   N)
r)   r*   r+   r,   r-   r\   re   ri   r.   r/   r0   s   @r%   FinishThrowingRequestrY   {   s     4#> >r2   rk   c                   < S! 4       h)zg
An application object that throws an exception.

@param environ: unused

@param startResponse: unused
r(   )r?   r@   rW   s   &&r%   applicationFWSGIResourceTests.test_applicationAndRequestThrow.<locals>.application   s     !""r2   c                   2   <a  ] tR t^t o RtV3R ltRtV tR# )QWSGIResourceTests.test_applicationAndRequestThrow.<locals>.ThrowingReactorThreadszP
An L{IReactorThreads} implementation whose callFromThread raises
an exception.
c                   < S! 4       h)zZ
Raise an exception to the caller.

@param f: unused

@param a: unused

@param kw: unused
r(   )r!   r"   r#   r$   rW   s   &&*,r%   r6   `WSGIResourceTests.test_applicationAndRequestThrow.<locals>.ThrowingReactorThreads.callFromThread   s     %&&r2   r(   Nr8   )r1   rW   s   @r%   ThrowingReactorThreadsrp      s     

' 
'r2   rs   Flog_failureN)r   createWithCleanupr   	Exceptionr   r   r   rC   renderr   assertEqualslenassertIsInstancevalueflushLoggedErrors)r!   logObserverrk   rm   rs   r"   rW   s   &     @r%   test_applicationAndRequestThrow1WSGIResourceTests.test_applicationAndRequestThrown   s     +<<TCUV	Y 	
	>G 	>6	#	' 	'$ %"$&;&={
 	2<>5IJ!S-.N=)agg~6~.r2   )rC   N)
r)   r*   r+   r,   rE   rJ   rR   r~   r.   r/   r0   s   @r%   r:   r:   M   s!     

.TL/ L/r2   r:   c                   b   a  ] tR t^t o Rt]tR tR. RR3R ltR t	]
3R ltR tRR	 ltR
tV tR# )WSGITestsMixinz
@ivar channelFactory: A no-argument callable which will be invoked to
    create a new HTTP channel to associate with request objects.
c                B    \        4       V n        \        4       V n        R # r=   )r   
threadpoolr4   r   rD   s   &r%   rE   WSGITestsMixin.setUp   s    /102r2   Nr[   c                   R p\        V P                  V P                  V! 4       4      pVP                  4        V F'  p\	        4       pVP                  V! V4      V4       TpK)  	  V! 4       p\        V4      Vn        V! VR4      pV	 F.  w  ppVP                  P                  V! V4      V! V4      4       K0  	  VP                  ^ 4       V
'       d7   VP                  P                  V
4       VP                  P                  ^ 4       RRP                  V Uu. uF  p\        W4      NK  	  up4      ,           pVeZ   TRRP                  V UUu. uF-  w  ppRP                  \        VV4      \        VV4      .4      NK/  	  upp4      ,           ,          pVP!                  V! V4      V! V4      RV! V4      ,           4       V# u upi u uppi )a  
@param method: A C{str} giving the request method to use.

@param version: A C{str} like C{'1.1'} giving the request version.

@param resourceSegments: A C{list} of unencoded path segments which
    specifies the location in the resource hierarchy at which the
    L{WSGIResource} will be placed, eg C{['']} for I{/}, C{['foo',
    'bar', '']} for I{/foo/bar/}, etc.

@param requestSegments: A C{list} of unencoded path segments giving the
    request URI.

@param query: A C{list} of two-tuples of C{str} giving unencoded query
    argument keys and values.

@param headers: A C{list} of two-tuples of C{str} giving request header
    names and corresponding values.

@param safe: A C{str} giving the bytes which are to be considered
    I{safe} for inclusion in the request URI and not quoted.

@return: A L{Deferred} which will be called back with a two-tuple of
    the arguments passed which would be passed to the WSGI application
    object for this configuration and request (ie, the environment and
    start_response callable).
c                 T    \        V \        4      '       d   V # V P                  R 4      # )z
iso-8859-1)
isinstancebytesencode)strings   &r%   _toByteString4WSGITestsMixin.lowLevelRender.<locals>._toByteString   s%     &%((}}\22r2   F/?&=s   HTTP/)r   r   r   reverser   rQ   r   siterequestHeadersaddRawHeader	gotLengthcontentwriteseekjoinurlquoterequestReceived)r!   requestFactoryapplicationFactorychannelFactorymethodr   resourceSegmentsrequestSegmentsqueryheadersbodysafer   rootsegtmpchannelrequestkvr_   s   &&&&&&&&&&&&         r%   lowLevelRenderWSGITestsMixin.lowLevelRender   s   T	3 DLL$//;M;OP  "#C*CLLs+T2D $
 !"Dz %0DAq""//a0@-PQBRS !OO!!$'OO  #CHH_M_chs1_MNN3PUVPUfq!8At,hq$.?@APUV  C 	&!=#5x-PWBX7X	
  N Ws   G
3Gc                   a \        4       oV3R  lpVP                  RV P                  4      pV P                  ! \        W4.VO5/ VB  S# )c                     < V3R  lp V # )c                  V   < V w  rSP                  V 4       V! R . 4       \        R4      # 200 OKr(   callbackiter)r`   r?   r@   results   *  r%   rm   FWSGITestsMixin.render.<locals>.applicationFactory.<locals>.application  s*    )-&%h+Bxr2   r(   rm   r   s    r%   r   1WSGITestsMixin.render.<locals>.applicationFactory  s      r2   r   )r   popr   r   r   )r!   r#   r$   r   r   r   s   &*,  @r%   rw   WSGITestsMixin.render  sH    	  0$2E2EFG%7R!RrRr2   c                0   aa \        4       oVV3R  lpSV3# )c                  V   < S! V / VB pVP                  4       P                  S4       V# r=   )notifyFinishchainDeferred)r#   r$   r   drequestClasss   *, r%   r   <WSGITestsMixin.requestFactoryFactory.<locals>.requestFactory)  s0    "A,,G
   "003Nr2   r   )r!   r   r   r   s   &f @r%   requestFactoryFactory$WSGITestsMixin.requestFactoryFactory&  s    J	 .  r2   c                4    VP                  R ^4      ^,          # )   

)split)r!   responses   &&r%   getContentFromResponse%WSGITestsMixin.getContentFromResponse4  s    ~~k1-a00r2   c                >  aa \        4       oVV3R lp\        V P                  V P                  V4      p\	        4       pVP                  RV4       V P                  4       p\        V4      Vn         ! R R\        4      pV! VRR7      pVP                  ^ 4       VS3# )a  
Prepare a L{Request} which, when a request is received, captures the
C{environ} and C{start_response} callable passed to a WSGI app.

@param application: An optional WSGI application callable that accepts
    the familiar C{environ} and C{start_response} args and returns an
    iterable of body content. If not supplied, C{start_response} will
    be called with a "200 OK" status and no headers, and no content
    will be yielded.

@return: A two-tuple of (C{request}, C{deferred}). The former is a
    Twisted L{Request}. The latter is a L{Deferred} which will be
    called back with a two-tuple of the arguments passed to a WSGI
    application (i.e. the C{environ} and C{start_response} callable),
    or will errback with any error arising within the WSGI app.
c                    <  Sf   V! R. 4       \        R4      pMS! W4      pSP                  W34       V#   \         d(    SP                  4        T! R. 4       \        R4      u # i ; i)Nr   z	500 Errorr(   )r   r   r   errback)r?   r@   r   rm   r   s   && r%   outerApplication7WSGITestsMixin.prepareRequest.<locals>.outerApplicationJ  so    &!(B/"2hG)'AG  89 !   k2.Bx s   !8 /A*)A*s   resc                   .   a  ] tR tRt o RtRR ltRtV tR# )4WSGITestsMixin.prepareRequest.<locals>.CannedRequestia  ze
Convenient L{Request} derivative which has canned values for all
of C{requestReceived}'s arguments.
c                2    \         P                  ! WW#R 7      # ))commandpathr   )r   r   )r!   r   r   r   s   &&&&r%   r   DWSGITestsMixin.prepareRequest.<locals>.CannedRequest.requestReceivedg  s    .. r2   r(   N)   GET   /res   1.1)r)   r*   r+   r,   r-   r   r.   r/   r0   s   @r%   CannedRequestr   a  s     
 r2   r   F)queued)r   r   r   r   r   rQ   r   r   r   r   r   )	r!   rm   r   rC   r   r   r   r   r   s	   &f      @r%   prepareRequestWSGITestsMixin.prepareRequest7  s    " 	  doo?OPzfh'%%'Dz		G 		  6!r2   )r   r   r=   )r)   r*   r+   r,   r-   r   r   rE   r   rw   r   r   r   r   r.   r/   r0   s   @r%   r   r      sI     
 "N3 KZ  29 !18 8r2   r   c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t R t!R  t"R! t#R"t$V t%R## )$EnvironTestsir  zv
Tests for the values in the C{environ} C{dict} passed to the application
object by L{twisted.web.wsgi.WSGIResource}.
c                   a aa VV V3R  lpV# )c                 B   < V w  rSP                  VS,          S4       S# r=   assertEqual)r   r?   r@   keyr!   r{   s   &  r%   assertEnvironKeyEqual;EnvironTests.environKeyEqual.<locals>.assertEnvironKeyEqualy  s$    %+"GWS\51Lr2   r(   )r!   r   r{   r   s   fff r%   environKeyEqualEnvironTests.environKeyEqualx  s    	
 %$r2   c                `   a  S P                  RR. R.4      pV 3R lpVP                  V4       V# )zm
L{WSGIResource} calls the application object with an C{environ}
parameter which is exactly of type C{dict}.
GET1.1r[   c                    < V w  rSP                  \        V4      \        4       V F  pSP                  V\        4       K  	  R # r=   )assertIdenticaltypedictrz   str)r   r?   r@   namer!   s   &   r%   
cbRendered3EnvironTests.test_environIsDict.<locals>.cbRendered  s9    %+"G  g5%%dC0  r2   )rw   addCallback)r!   r   r   s   f  r%   test_environIsDictEnvironTests.test_environIsDict  s3    
 KKub2$/	1 	
j!r2   c                    V P                  RR. R.4      pVP                  V P                  RR4      4       V P                  RR. R.4      pVP                  V P                  RR4      4       \        W.4      # )z
The C{'REQUEST_METHOD'} key of the C{environ} C{dict} passed to the
application contains the HTTP method in the request (RFC 3875, section
4.1.12).
r   r   r[   REQUEST_METHODPOSTrw   r   r   r	   )r!   getposts   &  r%   test_requestMethodEnvironTests.test_requestMethod  su     kk%RD1,,-=uEF {{65"rd3--.>GHc[))r2   c                    R Fl  pV P                  4       w  r#VP                  V4       VP                  V P                  RR4      4       V P	                  V P                  V4      \        4       Kn  	  R# )zl
The C{'REQUEST_METHOD'} key of the C{environ} C{dict} passed to the
application is always a native string.
r   r   N)r   r   r   r   r   r   rz   successResultOfr   )r!   r   r   r   s   &   r%    test_requestMethodIsNativeString-EnvironTests.test_requestMethodIsNativeString  sc    
 $F"113OG##F+t334DeLM!!$"6"6v">D	 $r2   c                   V P                  RR. R.4      pVP                  V P                  RR4      4       V P                  RRR.R.4      pVP                  V P                  RR4      4       V P                  RRR.R.4      pVP                  V P                  RR4      4       V P                  RRRR.RR.4      pVP                  V P                  RR4      4       V P                  RRR.RR	.4      pVP                  V P                  RR4      4       V P                  RR. RO. RO4      pVP                  V P                  RR
4      4       \        WW4WV.4      # )z
The C{'SCRIPT_NAME'} key of the C{environ} C{dict} passed to the
application contains the I{abs_path} (RFC 2396, section 3) to this
resource (RFC 3875, section 4.1.13).
r   r   r[   SCRIPT_NAMEr   fooz/fooz/foo/bar   /foo///barÿr  r   s   barr   )r!   r   
emptyChildleaf	containerinternal	unencodeds   &      r%   test_scriptNameEnvironTests.test_scriptName  sP    {{5%bT2--mR@A[[tbT:
t33M3GH{{5%%5':--mVDEKKuubkE2;G	d22='JK;;ueeWuenET11-HIKK524L
	
 	d22=BRSTdUVVr2   c                B   V P                  4       w  rVP                  RR7       VP                  V P                  RR4      4       V P	                  V P                  V4      \        4       V P                  4       w  rV P                  \        VP                  RR7       R# )zi
The C{'SCRIPT_NAME'} key of the C{environ} C{dict} passed to the
application is always a native string.
r   r   r  z/resN	r   r   r   r   rz   r  r   rN   	TypeErrorr!   r   r   s   &  r%   test_scriptNameIsNativeString*EnvironTests.test_scriptNameIsNativeString  s    
 --/W-4//vFGd226:C@ --/)W%<%<6Jr2   c                   V P                  RR4      pV P                  RR. R.4      pVP                  V P                  RR4      4       V P                  RRR.R.4      pVP                  V4       V P                  RRR.R.4      pVP                  V4       V P                  RRRR.RR.4      pVP                  V4       V P                  RRR.RR.4      pVP                  V P                  RR4      4       V P                  RRR.RR.4      pVP                  V P                  RR4      4       V P                  RR. . R
O4      pVP                  V P                  RR	4      4       \        W$WVWx.4      # )z
The C{'PATH_INFO'} key of the C{environ} C{dict} passed to the
application contains the suffix of the request URI path which is not
included in the value for the C{'SCRIPT_NAME'} key (RFC 3875, section
4.1.5).
	PATH_INFOr[   r   r   r   r  r  z/barr	  r
  )r   rw   r   r	   )	r!   assertKeyEmptyr   r  r  r  internalLeafinternalContainerr  s	   &        r%   test_pathInfoEnvironTests.test_pathInfo  sq    --k2>{{5%bT2--k3?@[[tbT:
~.{{5%%5':(KKuubkE2;G	n-{{5%%5%.I  !5!5k6!JK KKuugr{K%%d&:&:;&LMKKub2JK	d22;@PQR2CO
 	
r2   c                B   V P                  4       w  rVP                  RR7       VP                  V P                  RR4      4       V P	                  V P                  V4      \        4       V P                  4       w  rV P                  \        VP                  RR7       R# )zg
The C{'PATH_INFO'} key of the C{environ} C{dict} passed to the
application is always a native string.
s   /res/foo/barr  r  z/foo/barz/res/foo/barNr  r  s   &  r%   test_pathInfoIsNativeString(EnvironTests.test_pathInfoIsNativeString  s    
 --/_54//ZHId226:C@ --/)W%<%<>Rr2   c           	     N   V P                  RR. R.R4      pVP                  V P                  RR4      4       V P                  RR. R.. 4      pVP                  V P                  RR4      4       V P                  RR. R.R.4      pVP                  V P                  RR4      4       V P                  RR. R.R.4      pVP                  V P                  RR4      4       V P                  RR. R.R.RR	7      pVP                  V P                  RR
4      4       \        WW4V.4      # )z
The C{'QUERY_STRING'} key of the C{environ} C{dict} passed to the
application contains the portion of the request URI after the first
I{?} (RFC 3875, section 4.1.7).
r   r   r[   NQUERY_STRINGfoo=barz%2F=%2Fr   )r   zfoo=?barr  r  )r   r   )r  z?barr   )r!   missingemptypresentr  doubleQuestions   &     r%   test_queryStringEnvironTests.test_queryString
  s+    ++eUBd;D00DEE5"rdB7$..~rBC++eUB~6FGD00KLKKub2$E	d22>9MN
 5"rd_$5C % 
 	""4#7#7
#STgg.QRRr2   c                B   V P                  4       w  rVP                  RR7       VP                  V P                  RR4      4       V P	                  V P                  V4      \        4       V P                  4       w  rV P                  \        VP                  RR7       R# )zj
The C{'QUERY_STRING'} key of the C{environ} C{dict} passed to the
application is always a native string.
s   /res?foo=barr  r$  r%  z/res?foo=barNr  r  s   &  r%   test_queryStringIsNativeString+EnvironTests.test_queryStringIsNativeString&  s    
 --/_54//	JKd226:C@ --/)W%<%<>Rr2   c                    V P                  RR. R.4      pVP                  V P                  RR4      4       V P                  RR. R.RR.4      pVP                  V P                  RR4      4       \        W.4      # )z
The C{'CONTENT_TYPE'} key of the C{environ} C{dict} passed to the
application contains the value of the I{Content-Type} request header
(RFC 3875, section 4.1.3).
r   r   r[   CONTENT_TYPEN	x-foo/bar)content-typer2  r   r!   r'  r)  s   &  r%   test_contentTypeEnvironTests.test_contentType5  s     ++eUB5D00DE++5"rdD+H*I
 	D00MNg/00r2   c                    R F  pV P                  4       w  r#VP                  P                  RV4       VP                  4        VP	                  V P                  RR4      4       V P                  V P                  V4      \        4       K  	  R# )zj
The C{'CONTENT_TYPE'} key of the C{environ} C{dict} passed to the
application is always a native string.
r2  s   Content-Typer1  N)s	   x-foo/barr2  	r   r   r   r   r   r   rz   r  r   )r!   contentTyper   r   s   &   r%   test_contentTypeIsNativeString+EnvironTests.test_contentTypeIsNativeStringE  sv    
 5K"113OG""//M##%t33NKPQ!!$"6"6v">D 5r2   c                    V P                  RR. R.4      pVP                  V P                  RR4      4       V P                  RR. R.RR.4      pVP                  V P                  RR4      4       \        W.4      # )z
The C{'CONTENT_LENGTH'} key of the C{environ} C{dict} passed to the
application contains the value of the I{Content-Length} request header
(RFC 3875, section 4.1.2).
r   r   r[   CONTENT_LENGTHN1234)content-lengthr>  r   r4  s   &  r%   test_contentLengthEnvironTests.test_contentLengthQ  s     ++eUB5D001A2FG++5"rdD+E*F
 	D001A6JKg/00r2   c                    R F  pV P                  4       w  r#VP                  P                  RV4       VP                  4        VP	                  V P                  RR4      4       V P                  V P                  V4      \        4       K  	  R# )zl
The C{'CONTENT_LENGTH'} key of the C{environ} C{dict} passed to the
application is always a native string.
r>  s   Content-Lengthr=  N)s   1234r>  r8  )r!   contentLengthr   r   s   &   r%    test_contentLengthIsNativeString-EnvironTests.test_contentLengthIsNativeStringa  sx    
 -M"113OG""//0A=Q##%t334DfMN!!$"6"6v">D -r2   c                    V P                  RR. R.4      pVP                  V P                  RR4      4       V P                  RR. R.RR.4      pVP                  V P                  RR4      4       \        W.4      # )	a/  
The C{'SERVER_NAME'} key of the C{environ} C{dict} passed to the
application contains the best determination of the server hostname
possible, using either the value of the I{Host} header in the request
or the address the server is listening on if that header is not
present (RFC 3875, section 4.1.14).
r   r   r[   SERVER_NAMEz10.0.0.1Nexample.org)hostrH  r   r4  s   &  r%   test_serverNameEnvironTests.test_serverNamem  s~     ++eUB5 	D00
KL++eUBd=T<UVD00NOg/00r2   c                   a R Fv  oV P                  4       w  rV3R lVn        VP                  4        VP                  V P	                  RR4      4       V P                  V P                  V4      \        4       Kx  	  R# )zi
The C{'SERVER_NAME'} key of the C{environ} C{dict} passed to the
application is always a native string.
host.example.comc                     < S # r=   r(   )
serverNames   r%   rA   <EnvironTests.test_serverNameIsNativeString.<locals>.<lambda>  s    r2   rG  N)s   host.example.comrM  )r   getRequestHostnamer   r   r   rz   r  r   )r!   r   r   rO  s   &  @r%   test_serverNameIsNativeString*EnvironTests.test_serverNameIsNativeString  sn    
 BJ"113OG *<G&##%t33MCUVW!!$"6"6v">D Br2   c                   a RoV3R lpWn         V P                  RR. R.4      pVP                  V P                  R\	        S4      4      4       V# )z
The C{'SERVER_PORT'} key of the C{environ} C{dict} passed to the
application contains the port number of the server which received the
request (RFC 3875, section 4.1.15).
iB0  c                  r   < \        4       p \         P                  ! 4       V n        SV P                  n        V # r=   )r   rh   	transportport)r   
portNumbers    r%   makeChannel1EnvironTests.test_serverPort.<locals>.makeChannel  s.    "nG , 0 0 2G%/G"Nr2   r   r   r[   SERVER_PORT)r   rw   r   r   r   )r!   rY  r   rX  s   &  @r%   test_serverPortEnvironTests.test_serverPort  sO     
	 *KKub2$/	d**=#j/JKr2   c                    V P                  4       w  rVP                  4        VP                  V P                  RR4      4       V P	                  V P                  V4      \        4       R# )zi
The C{'SERVER_PORT'} key of the C{environ} C{dict} passed to the
application is always a native string.
r[  80Nr  r  s   &  r%   test_serverPortIsNativeString*EnvironTests.test_serverPortIsNativeString  sV    
 --/!4//tDEd226:C@r2   c                    V P                  RR. R.4      pVP                  V P                  RR4      4       V P                  RR. R.4      pVP                  V P                  RR4      4       \        W.4      # )z
The C{'SERVER_PROTOCOL'} key of the C{environ} C{dict} passed to the
application contains the HTTP version number received in the request
(RFC 3875, section 4.1.16).
r   z1.0r[   SERVER_PROTOCOLzHTTP/1.0r   zHTTP/1.1r   )r!   oldnews   &  r%   test_serverProtocol EnvironTests.test_serverProtocol  sq     kk%RD1,,->
KLkk%RD1,,->
KLcZ((r2   c                    R Fu  pV P                  4       w  r#R Vn        VP                  RR7       VP                  V P	                  RR4      4       V P                  V P                  V4      \        4       Kw  	  R# )zm
The C{'SERVER_PROTOCOL'} key of the C{environ} C{dict} passed to the
application is always a native string.
r   r   c                     R # r=   r(   )datas   &r%   rA   @EnvironTests.test_serverProtocolIsNativeString.<locals>.<lambda>  s    r2   )r   rc  N)r   r   )r   r   r   r   r   rz   r  r   )r!   serverProtocolr   r   s   &   r%   !test_serverProtocolIsNativeString.EnvironTests.test_serverProtocolIsNativeString  so    
 ,N"113OG .GM##F#3t334EuMN!!$"6"6v">D ,r2   c                |    R pV P                  RR. R.VR7      pVP                  V P                  RR4      4       V# )z
The C{'REMOTE_ADDR'} key of the C{environ} C{dict} passed to the
application contains the address of the client making the request.
c                  0    \        \        R RR4      R7      # rh   192.168.1.1i80  peerr   r   r(   r2   r%   r   4EnvironTests.test_remoteAddr.<locals>.channelFactory      [u%MNNr2   r   r   r[   r   REMOTE_ADDRrr  rw   r   r   r!   r   r   s   &  r%   test_remoteAddrEnvironTests.test_remoteAddr  sB    	O KKub2$~KN	d**=-HIr2   c                |    R pV P                  RR. R.VR7      pVP                  V P                  RR4      4       V# )z
The C{'REMOTE_ADDR'} key of the C{environ} C{dict} passed to
the application contains the address of the client making the
request when connecting over IPv6.
c                  0    \        \        R RR4      R7      # )rh   ::1i  rs  )r   r   r(   r2   r%   r   8EnvironTests.test_remoteAddrIPv6.<locals>.channelFactory  s    [t%DEEr2   r   r   r[   rx  ry  r  rz  r{  s   &  r%   test_remoteAddrIPv6 EnvironTests.test_remoteAddrIPv6  sB    	F KKub2$~KN	d**=%@Ar2   c                |    R pV P                  RR. R.VR7      pVP                  V P                  RR4      4       V# )z
The C{'REMOTE_PORT'} key of the C{environ} C{dict} passed to the
application contains the port of the client making the request.
c                  0    \        \        R RR4      R7      # rq  ru  r(   r2   r%   r   4EnvironTests.test_remotePort.<locals>.channelFactory  rw  r2   r   r   r[   rx  REMOTE_PORT12344rz  r{  s   &  r%   test_remotePortEnvironTests.test_remotePort  sB    	O KKub2$~KN	d**='BCr2   c           	       a  S P                  RR. R.RRR.4      pV 3R lpVP                  V4       S P                  RR. R.RRR.4      pVP                  S P                  RR4      4       S P                  RR. R.RR.4      pVP                  S P                  R	R4      4       S P                  RR. R.RR.4      pVP                  S P                  RR
4      4       \        WWE.4      # )z
HTTP request headers are copied into the C{environ} C{dict} passed to
the application with a C{HTTP_} prefix added to their names.
r   r   r[   Nbazc                 t   < V w  rSP                  VR ,          R4       SP                  VR,          R4       R# )HTTP_FOOr  HTTP_BAZquuxNr   )r   r?   r@   r!   s   &  r%   r   -EnvironTests.test_headers.<locals>.cbRendered  s5    %+"GWZ0%8WZ0&9r2   r  zbar,bazHTTP_FOO_BARzbar 	bazr&  r  r  )r  r  )zfoo-barr  )r  zbar
	bazr   )r!   singleValuer   
multiValue
withHyphen	multiLines   f     r%   test_headersEnvironTests.test_headers  s    
 kk5"rdD>?*K
	:
 	
+[[5"rdD>>*J

 	t33J	JK[[rB4@R?ST
t33NEJKKKub2$?T>UV	d22:{KLkzMNNr2   c                r    V P                  RR. R.4      pVP                  V P                  RR4      4       V# )z
The C{'wsgi.version'} key of the C{environ} C{dict} passed to the
application has the value C{(1, 0)} indicating that this is a WSGI 1.0
container.
r   r   r[   zwsgi.version)       rz  )r!   versionDeferreds   & r%   test_wsgiVersionEnvironTests.test_wsgiVersion  s;     ++eUB=##D$8$8$PQr2   c                r    V P                  RR. R.4      pVP                  V P                  RR4      4       V# )zd
The C{'wsgi.run_once'} key of the C{environ} C{dict} passed to the
application is set to C{False}.
r   r   r[   zwsgi.run_onceFrz  )r!   onces   & r%   test_wsgiRunOnceEnvironTests.test_wsgiRunOnce  s:    
 {{5%bT2--ouEFr2   c                r    V P                  RR. R.4      pVP                  V P                  RR4      4       V# )zf
The C{'wsgi.multithread'} key of the C{environ} C{dict} passed to the
application is set to C{True}.
r   r   r[   zwsgi.multithreadTrz  )r!   threads   & r%   test_wsgiMultithread!EnvironTests.test_wsgiMultithread$  s;    
 UE2t44//0BDIJr2   c                r    V P                  RR. R.4      pVP                  V P                  RR4      4       V# )zh
The C{'wsgi.multiprocess'} key of the C{environ} C{dict} passed to the
application is set to C{False}.
r   r   r[   zwsgi.multiprocessFrz  )r!   processs   & r%   test_wsgiMultiprocess"EnvironTests.test_wsgiMultiprocess-  s;    
 ++eUB5D001DeLMr2   c                   R p\         V n        V P                  RR. R.4      pVP                  V P	                  RR4      4       Wn        V P                  RR. R.4      pVP                  V P	                  RR4      4       \        W#.4      # )zn
The C{'wsgi.url_scheme'} key of the C{environ} C{dict} passed to the
application has the request URL scheme.
c                  N    \        4       p \         P                  ! 4       V n        V # r=   )r   SSLrV  r   s    r%   r   7EnvironTests.test_wsgiURLScheme.<locals>.channelFactory>  s    "nG , 0 0 2GNr2   r   r   r[   zwsgi.url_schemehttphttps)r   r   rw   r   r   r	   )r!   r   httpDeferredhttpsDeferreds   &   r%   test_wsgiURLSchemeEnvironTests.test_wsgiURLScheme6  s    	
 +{{5%bT:  !5!56G!PQ,E5"rd;!!$"6"67H'"RSl:;;r2   c                   a a \         P                  ! S \        4      oS P                  RR. R.4      pVV 3R lpVP	                  V4       V# )a0  
The C{'wsgi.errors'} key of the C{environ} C{dict} passed to the
application is a file-like object (as defined in the U{Input and Errors
Streams<http://www.python.org/dev/peps/pep-0333/#input-and-error-streams>}
section of PEP 333) which converts bytes written to it into events for
the logging system.
r   r   r[   c                 :  < V w  rVR ,          pVP                  R4       VP                  R.4       VP                  4        SP                  S^ ,          R,          R4       SP                  S^ ,          R,          R4       SP	                  S^ ,          R,          4       SP                  S^,          R,          R	4       SP                  S^,          R,          R4       SP	                  S^,          R,          4       SP                  \        S4      ^4       R# )
wsgi.errorssome message
another
message
messagesystemwsgiisErrorN)r  )r  )r   
writelinesflushr   rH   ry   )r   r?   startApplicationerrorseventsr!   s   &   r%   cbErrors.EnvironTests.test_wsgiErrors.<locals>.cbErrorsY  s    (.%G]+FLL)*345LLNVAYy13FGVAYx0&9OOF1Ii01VAYy13JKVAYx0&9OOF1Ii01S[!,r2   )r   ru   r   rw   r   )r!   r  r  r  s   f  @r%   test_wsgiErrorsEnvironTests.test_wsgiErrorsM  sH     &77>PQUE2t4	- 	8$r2   c                    V P                  4       w  rVP                  4        V P                  V4      w  r4VR,          pV P                  \        VP
                  R4      pV P                  R\        V4      4       R# )z
The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
permits writes of only native strings in Python 3, and raises
C{TypeError} for writes of non-native strings.
r  s   fredz1write() argument must be str, not b'fred' (bytes)N)r   r   r  rN   r  r   r   r   )r!   r   r   r?   _r  errors   &      r%   0test_wsgiErrorsAcceptsOnlyNativeStringsInPython3=EnvironTests.test_wsgiErrorsAcceptsOnlyNativeStringsInPython3j  sk     --/!))&1
'!!)V\\7C?U	
r2   rx  N)&r)   r*   r+   r,   r-   r   r   r   r  r  r  r  r!  r+  r.  r5  r:  r@  rD  rJ  rR  r\  r`  rf  rm  r|  r  r  r  r  r  r  r  r  r  r  r.   r/   r0   s   @r%   r   r   r  s     
%"* 	EW<K 
DSS8S1 
E1 
E1$E(A)EO:<.:
 
r2   r   c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )InputStreamTestMixini{  z
A mixin for L{TestCase} subclasses which defines a number of tests against
L{_InputStream}.  The subclass is expected to create a file-like object to
be wrapped by an L{_InputStream} under test.
c                F    \        V P                  P                   R 24      h)z.getFile must be implemented)NotImplementedError	__class__r)   rD   s   &r%   getFileType InputStreamTestMixin.getFileType  s%    !~~&&''CD
 	
r2   c                   a V P                  4       o ! V3R  lR\        4      pR pV! V4      w  rVV P                  VV\        RR. R.R. V4
       V# )c                   .   <a  ] tR tRt o V3R ltRtV tR# )LInputStreamTestMixin._renderAndReturnReaderResult.<locals>.CustomizedRequesti  c                    < S! 4       V n         R # r=   r   )r!   lengthr9  s   &&r%   r   VInputStreamTestMixin._renderAndReturnReaderResult.<locals>.CustomizedRequest.gotLength  s      +}r2   r  N)r)   r*   r+   r,   r   r.   r/   )r1   r9  s   @r%   CustomizedRequestr    s     - -r2   r  c                 0   a a \        4       oV V3R  lpSV3# )c                     < VV3R  lp V # )c                  p   < V w  rSP                  S! VR ,          4      4       V! R. 4       \        R4      # )z
wsgi.inputr   r(   r   )r`   r?   r@   readerr   s   *  r%   rm   }InputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactory.<locals>.applicationFactory.<locals>.application  s4    -1*GOOF7<+@$AB!(B/8Or2   r(   )rm   r  r   s    r%   r   hInputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactory.<locals>.applicationFactory  s    $ #"r2   r   )r  r   r   s   f @r%   appFactoryFactoryLInputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactory  s    ZF# ---r2   PUTr   r[   N)r  r   r   r   )r!   r  r   r  r  r   
appFactoryr9  s   &&&    @r%   _renderAndReturnReaderResult1InputStreamTestMixin._renderAndReturnReaderResult  se    &&(	- 	-	. *&1D	
 r2   c                h    RpV P                  R V4      pVP                  V P                  V4       V# )zQ
Calling L{_InputStream.read} with no arguments returns the entire input
stream.
   some bytes are herec                 "    V P                  4       # r=   readinputs   &r%   rA   3InputStreamTestMixin.test_readAll.<locals>.<lambda>  s
    EJJLr2   r  r   r   r!   r   r   s   &  r%   test_readAll!InputStreamTestMixin.test_readAll  s5    
 '--.H%P	d&&.r2   c                h    RpV P                  R V4      pVP                  V P                  R4       V# )z
Calling L{_InputStream.read} with an integer returns that many bytes
from the input stream, as long as it is less than or equal to the total
number of bytes available.
s   hello, world.c                 $    V P                  ^4      #    r  r  s   &r%   rA   4InputStreamTestMixin.test_readSome.<locals>.<lambda>  s    EJJqMr2   s   helr  r  s   &  r%   test_readSome"InputStreamTestMixin.test_readSome  s5     !--.I5Q	d&&/r2   c                p   a RoV P                  V3R lS4      pVP                  V P                  S4       V# )z
Calling L{_InputStream.read} with an integer that is greater than the
total number of bytes in the input stream returns all bytes in the
input stream.
r  c                 F   < V P                  \        S4      ^,           4      # r  )r  ry   )r  r   s   &r%   rA   8InputStreamTestMixin.test_readMoreThan.<locals>.<lambda>  s    %**SZ!^4r2   r  )r!   r   r   s   & @r%   test_readMoreThan&InputStreamTestMixin.test_readMoreThan  s:     '--4e
 	
d&&.r2   c                x    RpR pV P                  W!4      pVP                  V P                  VR,          4       V# )z
Calling L{_InputStream.read} a second time returns bytes starting from
the position after the last byte returned by the previous read.
s   some bytes, helloc                 D    V P                  ^4       V P                  4       # r  r  r  s   &r%   r  1InputStreamTestMixin.test_readTwice.<locals>.read  s    JJqM::<r2   :r  NNr  )r!   r   r  r   s   &   r%   test_readTwice#InputStreamTestMixin.test_readTwice  s=    
 %	  --d:	d&&b	2r2   c                h    RpV P                  R V4      pVP                  V P                  V4       V# )za
Calling L{_InputStream.read} with L{None} as an argument returns all
bytes in the input stream.
s   the entire streamc                 $    V P                  R 4      # r=   r  r  s   &r%   rA   4InputStreamTestMixin.test_readNone.<locals>.<lambda>  s    EJJt<Lr2   r  r  s   &  r%   test_readNone"InputStreamTestMixin.test_readNone  s5    
 %--.LeT	d&&.r2   c                h    RpV P                  R V4      pVP                  V P                  V4       V# )zl
Calling L{_InputStream.read} with a negative integer as an argument
returns all bytes in the input stream.
s   all of the inputc                 $    V P                  R4      # r  r  r  s   &r%   rA   8InputStreamTestMixin.test_readNegative.<locals>.<lambda>  s    EJJrNr2   r  r  s   &  r%   test_readNegative&InputStreamTestMixin.test_readNegative  s5    
 $--.JER	d&&.r2   c                h    RpV P                  R V4      pVP                  V P                  R4       V# )z[
Calling L{_InputStream.readline} with no argument returns one line from
the input stream.
s   hello
worldc                 "    V P                  4       # r=   readliner  s   &r%   rA   4InputStreamTestMixin.test_readline.<locals>.<lambda>  s    ENN<Lr2   s   hello
r  r  s   &  r%   test_readline"InputStreamTestMixin.test_readline  s5    
  --.LeT	d&&
3r2   c                h    RpV P                  R V4      pVP                  V P                  R4       V# )a  
Calling L{_InputStream.readline} with an integer returns at most that
many bytes, even if it is not enough to make up a complete line.

COMPATIBILITY NOTE: the size argument is excluded from the WSGI
specification, but is provided here anyhow, because useful libraries
such as python stdlib's cgi.py assume their input file-like-object
supports readline with a size argument. If you use it, be aware your
application may not be portable to other conformant WSGI servers.
s   goodbye
worldc                 $    V P                  ^4      # r  r  r  s   &r%   rA   8InputStreamTestMixin.test_readlineSome.<locals>.<lambda>	  s    ENN1<Mr2   s   goor  r  s   &  r%   test_readlineSome&InputStreamTestMixin.test_readlineSome  s5     "--.MuU	d&&/r2   c                h    RpV P                  R V4      pVP                  V P                  R4       V# )z
Calling L{_InputStream.readline} with an integer which is greater than
the number of bytes in the next line returns only the next line.
s   some lines
of textc                 $    V P                  ^4      # )   r  r  s   &r%   rA   <InputStreamTestMixin.test_readlineMoreThan.<locals>.<lambda>      ENN2<Nr2   s   some lines
r  r  s   &  r%   test_readlineMoreThan*InputStreamTestMixin.test_readlineMoreThan  s6    
 '--.NPUV	d&&8r2   c                j    RpR pV P                  W!4      pVP                  V P                  R4       V# )zp
Calling L{_InputStream.readline} a second time returns the line
following the line returned by the first call.
s    first line
second line
last linec                 B    V P                  4        V P                  4       # r=   r  r  s   &r%   r  9InputStreamTestMixin.test_readlineTwice.<locals>.readline  s    NN>>##r2   s   second line
r  )r!   r   r  r   s   &   r%   test_readlineTwice'InputStreamTestMixin.test_readlineTwice  s:    
 6	$ --h>	d&&(89r2   c                h    RpV P                  R V4      pVP                  V P                  R4       V# )zf
Calling L{_InputStream.readline} with L{None} as an argument returns
one line from the input stream.
s%   this is one line
this is another linec                 $    V P                  R 4      # r=   r  r  s   &r%   rA   8InputStreamTestMixin.test_readlineNone.<locals>.<lambda>,  s    ENN4<Pr2   s   this is one line
r  r  s   &  r%   test_readlineNone&InputStreamTestMixin.test_readlineNone&  s7    
 :--.PRWX	d&&(=>r2   c                h    RpV P                  R V4      pVP                  V P                  R4       V# )zq
Calling L{_InputStream.readline} with a negative integer as an argument
returns one line from the input stream.
s   input stream line one
line twoc                 $    V P                  R4      # r  r  r  s   &r%   rA   <InputStreamTestMixin.test_readlineNegative.<locals>.<lambda>6  r"  r2   s   input stream line one
r  r  s   &  r%   test_readlineNegative*InputStreamTestMixin.test_readlineNegative0  s7    
 3--.NPUV	d&&(BCr2   c                l    RpV P                  R V4      pVP                  V P                  . RO4       V# )zh
Calling L{_InputStream.readlines} with no arguments returns a list of
all lines from the input stream.
s   alice
bob
carolc                 "    V P                  4       # r=   	readlinesr  s   &r%   rA   5InputStreamTestMixin.test_readlines.<locals>.<lambda>@  s    EOO<Mr2   )s   alice
s   bob
s   carolr  r  s   &  r%   test_readlines#InputStreamTestMixin.test_readlines:  s6    
 %--.MuU	d&&(HIr2   c                `   a  RpS P                  R V4      pV 3R lpVP                  V4       V# )z
Calling L{_InputStream.readlines} with an integer as an argument
returns a list of lines from the input stream with the argument serving
as an approximate bound on the total number of bytes to read.
s   123
456
789
0c                 $    V P                  ^4      # )   r6  r  s   &r%   rA   9InputStreamTestMixin.test_readlinesSome.<locals>.<lambda>K  s    EOOA<Nr2   c                 >   < SP                  V R ,          RR.4       R# ):N   Ns   123
s   456
Nr   )linesr!   s   &r%   cbLines8InputStreamTestMixin.test_readlinesSome.<locals>.cbLinesM  s     U2Y8(<=r2   )r  r   )r!   r   r   rB  s   f   r%   test_readlinesSome'InputStreamTestMixin.test_readlinesSomeD  s6     $--.NPUV	>
 	
gr2   c                l    RpV P                  R V4      pVP                  V P                  . RO4       V# )z
Calling L{_InputStream.readlines} with an integer which is greater than
the total number of bytes in the input stream returns a list of all
lines from the input.
s"   one potato
two potato
three potatoc                 $    V P                  ^d4      # )d   r6  r  s   &r%   rA   =InputStreamTestMixin.test_readlinesMoreThan.<locals>.<lambda>\  s    EOOC<Pr2   )s   one potato
s   two potato
s   three potator  r  s   &  r%   test_readlinesMoreThan+InputStreamTestMixin.test_readlinesMoreThanU  s<     8--.PRWX	Q	
 r2   c                n    RpR pV P                  W!4      pVP                  V P                  RR.4       V# )z
Calling L{_InputStream.readlines} after a call to L{_InputStream.read}
returns lines starting at the byte after the last byte returned by the
C{read} call.
s   hello
world
fooc                 D    V P                  ^4       V P                  4       # )   )r  r7  r  s   &r%   r7  ?InputStreamTestMixin.test_readlinesAfterRead.<locals>.readlinesj  s    JJqM??$$r2   s   orld
rM   r  )r!   r   r7  r   s   &   r%   test_readlinesAfterRead,InputStreamTestMixin.test_readlinesAfterReadb  s>     %	% --i?	d&&F(;<r2   c                l    RpV P                  R V4      pVP                  V P                  RR.4       V# )za
Calling L{_InputStream.readlines} with L{None} as an argument returns
all lines from the input.
s   one fish
two fish
c                 $    V P                  R 4      # r=   r6  r  s   &r%   rA   9InputStreamTestMixin.test_readlinesNone.<locals>.<lambda>y  s    %//$/r2   s	   one fish
s	   two fish
r  r  s   &  r%   test_readlinesNone'InputStreamTestMixin.test_readlinesNoner  s>    
 (--/
 	
d&&(FGr2   c                l    RpV P                  R V4      pVP                  V P                  RR.4       V# )zv
Calling L{_InputStream.readlines} with a negative integer as an
argument returns a list of all lines from the input.
s   red fish
blue fish
c                 $    V P                  R4      # r  r6  r  s   &r%   rA   =InputStreamTestMixin.test_readlinesNegative.<locals>.<lambda>  s    EOOB<Or2   s	   red fish
s
   blue fish
r  r  s   &  r%   test_readlinesNegative+InputStreamTestMixin.test_readlinesNegative~  s;    
 )--.OQVW	d&&(GHr2   c                l    RpV P                  R V4      pVP                  V P                  RR.4       V# )zF
Iterating over L{_InputStream} produces lines from the input stream.
   green eggs
and ham
c                     \        V 4      # r=   )listr  s   &r%   rA   4InputStreamTestMixin.test_iterable.<locals>.<lambda>  s    DKr2   s   green eggs
   and ham
r  r  s   &  r%   test_iterable"InputStreamTestMixin.test_iterable  s:     )--.GO	d&&,(GHr2   c                n    RpR pV P                  W!4      pVP                  V P                  RR.4       V# )z
Iterating over L{_InputStream} after calling L{_InputStream.read}
produces lines from the input stream starting from the first byte after
the last byte returned by the C{read} call.
r]  c                 :    V P                  ^4       \        V 4      # r  )r  r_  r  s   &r%   iterate<InputStreamTestMixin.test_iterableAfterRead.<locals>.iterate  s    JJqM;r2   s   en eggs
ra  r  )r!   r   rf  r   s   &   r%   test_iterableAfterRead+InputStreamTestMixin.test_iterableAfterRead  s>     )	 --g=	d&&|(DEr2   r(   N)r)   r*   r+   r,   r-   r  r  r  r  r  r  r	  r  r  r  r#  r(  r-  r2  r9  rD  rJ  rP  rU  rZ  rb  rh  r.   r/   r0   s   @r%   r  r  {  s~     

%N	 " 
 r2   r  c                   *   a  ] tR tRt o RtR tRtV tR# )InputStreamBytesIOTestsi  zG
Tests for L{_InputStream} when it is wrapped around an L{io.BytesIO}.
c                    ^ RI Hp V# )r  )BytesIO)iorm  )r!   rm  s   & r%   r  #InputStreamBytesIOTests.getFileType  s
    r2   r(   Nr)   r*   r+   r,   r-   r  r.   r/   r0   s   @r%   rk  rk    s      r2   rk  c                   *   a  ] tR tRt o RtR tRtV tR# )InputStreamTemporaryFileTestsi  zR
Tests for L{_InputStream} when it is wrapped around a L{tempfile.TemporaryFile}.
c                "    \         P                  # r=   )tempfileTemporaryFilerD   s   &r%   r  )InputStreamTemporaryFileTests.getFileType  s    %%%r2   r(   Nrp  r0   s   @r%   rr  rr    s     & &r2   rr  c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )StartResponseTestsi  z`
Tests for the I{start_response} parameter passed to the application object
by L{WSGIResource}.
c                   a a \        4       oR pS P                  4       w  r#VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )zw
The response status passed to the I{start_response} callable is written
as the status of the response to the request.
c                      R  p V # )c                 *    V! R . 4       \        R4      # )z107 Strange messager(   r   r>   s   &&r%   rm   OStartResponseTests.test_status.<locals>.applicationFactory.<locals>.application  s    3R8Bxr2   r(   rm   s    r%   r   :StartResponseTests.test_status.<locals>.applicationFactory        r2   c                    < SP                  SP                  P                  P                  4       P	                  R 4      4       R# )s   HTTP/1.1 107 Strange messageNrH   rV  writtengetvalue
startswithignoredr   r!   s   &r%   r   2StartResponseTests.test_status.<locals>.cbRendered  s5    OO!!))224??3r2   c                     < S # r=   r(   r  s   r%   rA   0StartResponseTests.test_status.<locals>.<lambda>      Gr2   r   r   r[   Nr   r   r   r   r!   r   r   r   r   r   s   f    @r%   test_statusStartResponseTests.test_status  si    
 .	 !668	 	
j!D
	
 r2   c                   a a RoV3R lpS P                  V4      w  r#VP                  4        V 3R lpS P                  V\        4      P	                  V4      # )zp
The response status passed to the I{start_response} callable MUST be a
native string in Python 2 and Python 3.
s   200 OKc                 ,   < V! S. 4       \        R4      # )Nr(   r|  )r?   r@   statuss   &&r%   rm   EStartResponseTests.test_statusMustBeNativeString.<locals>.application  s    &"%8Or2   c                 >   < SP                  R \        V 4      4       R# )z)status must be str, not b'200 OK' (bytes)Nr   r   r  r!   s   &r%   checkMessageFStartResponseTests.test_statusMustBeNativeString.<locals>.checkMessage  s    H#e*Ur2   r   r   assertFailurer  r   )r!   rm   r   r   r  r  s   f    @r%   test_statusMustBeNativeString0StartResponseTests.test_statusMustBeNativeString  sU    
 	 --k:!	V !!&)4@@NNr2   c                   a aaa S P                  \        RR 4       \        4       oV3R lpS P                  4       w  rEVVV 3R lpVP	                  V4       S P                  VVV3R lRR. R.R	. 4	       V# )
z
Verify that if the response headers given by C{appHeaders} are passed
to the I{start_response} callable, then the response header lines given
by C{expectedHeaders} plus I{Server} and I{Date} header lines are
included in the response.
datetimeToStringc                      R # )Tuesdayr(   r(   r2   r%   rA   1StartResponseTests._headersTest.<locals>.<lambda>  s    yr2   c                     < V3R  lp V # )c                 ,   < V! R S4       \        R4      # r   r|  )r?   r@   
appHeaderss   &&r%   rm   PStartResponseTests._headersTest.<locals>.applicationFactory.<locals>.application  s    h
3Bxr2   r(   )rm   r  s    r%   r   ;StartResponseTests._headersTest.<locals>.applicationFactory  s      r2   c                 8  < SP                   P                  P                  4       pVP                  R ^4      w  r#VP                  R4      R,          pVP	                  4        SRR\
        ,           R.,           pVP	                  4        SP                  WE4       R# )r   s   
:r  NNs   Date: Tuesdays   Server: s   Transfer-Encoding: chunkedN)rV  r  r  r   sortr   r   )	r  r   r   restheaderLinesallExpectedHeadersr   expectedHeadersr!   s	   &     r%   r   3StartResponseTests._headersTest.<locals>.cbRendered  s    ((0099;H$NN;:MG!--04K!0 g%-4 "
 ##%[=r2   c                     < S # r=   r(   r  s   r%   rA   r    r  r2   r   r   r[   N)patchr   r   r   r   r   )r!   r  r  r   r   r   r   r   s   fff    @r%   _headersTestStartResponseTests._headersTest  s{     	

6-/@A.	 !668	> 	
j!D
	
 r2   c                .    V P                  RR.RR.4      # )z
The headers passed to the I{start_response} callable are included in
the response as are the required I{Date} and I{Server} headers and the
necessary connection (hop to hop) header I{Transfer-Encoding}.
s	   Baz: quuxs   Foo: barr&  r  r  rD   s   &r%   r  StartResponseTests.test_headers'  s&       _-k/J
 	
r2   c                   a a R.oV3R lpS P                  V4      w  r#VP                  4        V 3R lpS P                  V\        4      P	                  V4      # )zJ
The headers passed to the I{start_response} callable MUST be a
sequence.
c                 >   < V! R \        S4      4       \        R4      # r   r|  )r?   r@   r   s   &&r%   rm   BStartResponseTests.test_headersMustBeSequence.<locals>.application8  s    (DM28Or2   c                 >   < SP                  \        V 4      R 4       R# )zKheaders must be a list, not <(list_?|sequence)iterator .+> [(]\1iterator[)]NassertRegexr   r  s   &r%   r  CStartResponseTests.test_headersMustBeSequence.<locals>.checkMessage?  s    E
Cr2   r   r{   r  )r!   rm   r   r   r  r   s   f    @r%   test_headersMustBeSequence-StartResponseTests.test_headersMustBeSequence1  sW    
 $$	 --k:!	 !!&)4@@NNr2   c                   R pV P                  V4      w  r#\        P                  ! RR7      ;_uu_ 4       pVP                  4        V P	                  V4      pRRR4       V P                  ^\        X4      4       V P                  \        V^ ,          P                  4       V P                  R\        V^ ,          P                  4      4       R#   + '       g   i     L; i)an  
According to PEP-3333, the headers passed to the I{start_response}
callable MUST be a plain list:

  The response_headers argument ... must be a Python list; i.e.
  type(response_headers) is ListType

However, for bug-compatibility, any sequence is accepted. In both
Python 2 and Python 3, only a warning is issued when a sequence other
than a list is encountered.
c                 *    V! R R4       \        R4      # )r   ))notr_  r(   r|  r>   s   &&r%   rm   EStartResponseTests.test_headersShouldBePlainList.<locals>.applicationU  s    ($678Or2   TrecordNz8headers should be a list, not (('not', 'list'),) (tuple)r   warningscatch_warningsr   r  r   ry   RuntimeWarningcategoryr   r  r!   rm   r   r   caughts   &    r%   test_headersShouldBePlainList0StartResponseTests.test_headersShouldBePlainListH  s    	 --k:$$D11V##%))&1F 2 	CK(););<Fq	!!"	
 21   "CC 	c                   a a RoV3R lpS P                  V4      w  r#VP                  4        V 3R lpS P                  V\        4      P	                  V4      # )zJ
Each header passed to the I{start_response} callable MUST be a
sequence.
c                 @   < V! R \        S4      .4       \        R4      # r   r|  )r?   r@   headers   &&r%   rm   FStartResponseTests.test_headersMustEachBeSequence.<locals>.applicationl  s    (T&\N38Or2   c                 >   < SP                  \        V 4      R 4       R# )z[header must be a [(]str, str[)] tuple, not <(tuple_?|sequence)iterator .+> [(]\1iterator[)]Nr  r  s   &r%   r  GStartResponseTests.test_headersMustEachBeSequence.<locals>.checkMessages  s    E
Dr2   r  r  )r!   rm   r   r   r  r  s   f    @r%   test_headersMustEachBeSequence1StartResponseTests.test_headersMustEachBeSequencee  sT    
 "	 --k:!	 !!&)4@@NNr2   c                   R pV P                  V4      w  r#\        P                  ! RR7      ;_uu_ 4       pVP                  4        V P	                  V4      pRRR4       V P                  ^\        X4      4       V P                  \        V^ ,          P                  4       V P                  R\        V^ ,          P                  4      4       R#   + '       g   i     L; i)ah  
According to PEP-3333, each header passed to the I{start_response}
callable should be a tuple:

  The response_headers argument is a list of (header_name,
  header_value) tuples

However, for bug-compatibility, any 2 element sequence is also
accepted. In both Python 2 and Python 3, only a warning is issued when
a sequence other than a tuple is encountered.
c                 0    V! R RR..4       \        R4      # )r   r  tupler(   r|  r>   s   &&r%   rm   EStartResponseTests.test_headersShouldEachBeTuple.<locals>.application  s    (eW%5$678Or2   Tr  Nz@header should be a (str, str) tuple, not ['not', 'tuple'] (list)r  r  s   &    r%   test_headersShouldEachBeTuple0StartResponseTests.test_headersShouldEachBeTuple|  s    	 --k:$$D11V##%))&1F 2 	CK(););<Nq	!!"	
 21r  c                   a  R pS P                  V4      w  r#VP                  4        V 3R lpS P                  V\        4      P	                  V4      # )zo
Each header passed to the I{start_response} callable MUST hold a key
and a value, and ONLY a key and a value.
c                 ,    V! R R.4       \        R4      # )r   )toomanycooksr(   r|  r>   s   &&r%   rm   MStartResponseTests.test_headersShouldEachHaveKeyAndValue.<locals>.application  s    (%=$>?8Or2   c                 >   < SP                  R \        V 4      4       R# )z?header must be a (str, str) tuple, not ('too', 'many', 'cooks')Nr  r  s   &r%   r  NStartResponseTests.test_headersShouldEachHaveKeyAndValue.<locals>.checkMessage  s    TE
r2   r  r!   rm   r   r   r  s   f    r%   %test_headersShouldEachHaveKeyAndValue8StartResponseTests.test_headersShouldEachHaveKeyAndValue  sM    	 --k:!	 !!&)4@@NNr2   c                   a a RoV3R lpS P                  V4      w  r#VP                  4        VV 3R lpS P                  V\        4      P	                  V4      # )zm
Each header key passed to the I{start_response} callable MUST be at
native string in Python 2 and Python 3.
s   keyc                 2   < V! R SR3.4       \        R4      # )r   r{   r(   r|  )r?   r@   r   s   &&r%   rm   HStartResponseTests.test_headerKeyMustBeNativeString.<locals>.application  s    (c7^$458Or2   c                 H   < SP                  R S: R2\        V 4      4       R# )z&header must be (str, str) tuple, not (z
, 'value')Nr  )r  r   r!   s   &r%   r  IStartResponseTests.test_headerKeyMustBeNativeString.<locals>.checkMessage  s$    8zJE
r2   r  )r!   rm   r   r   r  r   s   f    @r%    test_headerKeyMustBeNativeString3StartResponseTests.test_headerKeyMustBeNativeString  sT    
 	 --k:!	 !!&)4@@NNr2   c                   a a RoV3R lpS P                  V4      w  r#VP                  4        V V3R lpS P                  V\        4      P	                  V4      # )zo
Each header value passed to the I{start_response} callable MUST be at
native string in Python 2 and Python 3.
s   valuec                 2   < V! R RS3.4       \        R4      # )r   r   r(   r|  )r?   r@   r{   s   &&r%   rm   JStartResponseTests.test_headerValueMustBeNativeString.<locals>.application  s    (eU^$458Or2   c                 H   < SP                  R S: R2\        V 4      4       R# )z-header must be (str, str) tuple, not ('key', )Nr  )r  r!   r{   s   &r%   r  KStartResponseTests.test_headerValueMustBeNativeString.<locals>.checkMessage  s$    ?yJE
r2   r  )r!   rm   r   r   r  r{   s   f    @r%   "test_headerValueMustBeNativeString5StartResponseTests.test_headerValueMustBeNativeString  sT    
 	 --k:!	 !!&)4@@NNr2   c                *    V P                  R.R.4      # )z
If I{Content-Type} is included in the headers passed to the
I{start_response} callable, one I{Content-Type} header is included in
the response.
s   Content-Type: monkeys are great)r3  zmonkeys are greatr  rD   s   &r%   #test_applicationProvidedContentType6StartResponseTests.test_applicationProvidedContentType  s#       23/0
 	
r2   c                *    V P                  . RO. 4      # )z{
If either I{Server} or I{Date} is included in the headers passed to the
I{start_response} callable, they are disregarded.
))r   r  )Serverr  )dater  )dATEr  r  rD   s   &r%   %test_applicationProvidedServerAndDate8StartResponseTests.test_applicationProvidedServerAndDate  s    
   TVX
 	
r2   c                   a aaa \        4       o. oVV3R loV3R lpS P                  4       w  r#VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )	z
Nothing is written in response to a request when the I{start_response}
callable is invoked.  If the iterator returned by the application
object produces only empty strings, the response is written after the
last element is produced.
c                  n   < SP                  S P                  P                  P                  4       4       R # r=   appendrV  r  r  r   intermediateValuess   r%   r  :StartResponseTests.test_delayedUntilReturn.<locals>.record  &    %%g&7&7&?&?&H&H&JKr2   c                     < V3R  lp V # )c              3   <   <"   V! R RR.4       Rx  S! 4        R# 5i)r   r2   Nr&  r  r(   r?   r@   r  s   &&r%   rm   [StartResponseTests.test_delayedUntilReturn.<locals>.applicationFactory.<locals>.application  s     h(IJ	   r(   rm   r  s    r%   r   FStartResponseTests.test_delayedUntilReturn.<locals>.applicationFactory  s    
 r2   c                 .   < SP                  SR .4       R# )r2   Nr   r  r  r!   s   &r%   r   >StartResponseTests.test_delayedUntilReturn.<locals>.cbRendered  s    /#7r2   c                     < S # r=   r(   r  s   r%   rA   <StartResponseTests.test_delayedUntilReturn.<locals>.<lambda>  r  r2   r   r   r[   Nr  r!   r   r   r   r   r   r  r  s   f    @@@r%   test_delayedUntilReturn*StartResponseTests.test_delayedUntilReturn  su     .	L	 !668	8 	
j!D
	
 r2   c                   a aaa \        4       o. oVV3R loV3R lpS P                  4       w  r#VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )	z
Nothing is written in response to a request when the I{start_response}
callable is invoked.  Once a non-empty string has been produced by the
iterator returned by the application object, the response status and
headers are written.
c                  n   < SP                  S P                  P                  P                  4       4       R # r=   r  r  s   r%   r  ;StartResponseTests.test_delayedUntilContent.<locals>.record$  r  r2   c                     < V3R  lp V # )c              3   P   <"   V! R R.4       Rx  S! 4        Rx  S! 4        R# 5i)r   r2   rM   Nr&  r(   r
  s   &&r%   rm   \StartResponseTests.test_delayedUntilContent.<locals>.applicationFactory.<locals>.application(  s'     h(89	   #&r(   r  s    r%   r   GStartResponseTests.test_delayedUntilContent.<locals>.applicationFactory'       r2   c                 h   < SP                  S^ ,          4       SP                  S^,          4       R# )r  N)assertFalserH   r  s   &r%   r   ?StartResponseTests.test_delayedUntilContent.<locals>.cbRendered3  s)    /23OO.q12r2   c                     < S # r=   r(   r  s   r%   rA   =StartResponseTests.test_delayedUntilContent.<locals>.<lambda><  r  r2   r   r   r[   Nr  r  s   f    @@@r%   test_delayedUntilContent+StartResponseTests.test_delayedUntilContent  su     .	L	 !668	3 	
j!D
	
 r2   c                   a aaa \        4       o. oVV3R loV3R lpS P                  4       w  r#VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )	zr
Content produced by the iterator returned by the application object is
written to the request as it is produced.
c                  n   < SP                  S P                  P                  P                  4       4       R # r=   r  r  s   r%   r  /StartResponseTests.test_content.<locals>.recordP  r  r2   c                     < V3R  lp V # )c              3   P   <"   V! R R.4       Rx  S! 4        Rx  S! 4        R# 5i)r   rM      barNr?  6r(   r
  s   &&r%   rm   PStartResponseTests.test_content.<locals>.applicationFactory.<locals>.applicationT  s(     h)@(ABr  r(   r  s    r%   r   ;StartResponseTests.test_content.<locals>.applicationFactoryS  r  r2   c                    < SP                  SP                  S^ ,          4      R4       SP                  SP                  S^,          4      R4       R# r  rM   s   foobarNr   r   r  s   &r%   r   3StartResponseTests.test_content.<locals>.cbRendered_  I    T889KA9NOQWX++,>q,ABIr2   c                     < S # r=   r(   r  s   r%   rA   1StartResponseTests.test_content.<locals>.<lambda>j  r  r2   r   r   r[   Nr  r  s   f    @@@r%   test_contentStartResponseTests.test_contentG  su    
 .	L	 !668	 	
j!D
	
 r2   c                   a a \        4       oR pS P                  4       w  r#VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )z
If the I{start_response} callable is invoked multiple times before a
data for the response body is produced, the values from the last call
are used.
c                      R  p V # )c                 <    V! R . 4       V! R. 4       \        R4      # )100 Fooz200 Barr(   r|  r>   s   &&r%   rm   ^StartResponseTests.test_multipleStartResponse.<locals>.applicationFactory.<locals>.application~  s    i,i,Bxr2   r(   r~  s    r%   r   IStartResponseTests.test_multipleStartResponse.<locals>.applicationFactory}       
 r2   c                    < SP                  SP                  P                  P                  4       P	                  R 4      4       R# )s   HTTP/1.1 200 Bar
Nr  r  s   &r%   r   AStartResponseTests.test_multipleStartResponse.<locals>.cbRendered  3    OO!!))224??@WXr2   c                     < S # r=   r(   r  s   r%   rA   ?StartResponseTests.test_multipleStartResponse.<locals>.<lambda>  r  r2   r   r   r[   Nr  r  s   f    @r%   test_multipleStartResponse-StartResponseTests.test_multipleStartResponseu  si     .	 !668	
 	
j!D
	
 r2   c                   a a \        4       oR pS P                  4       w  r#VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )z
If the I{start_response} callable is invoked with a third positional
argument before the status and headers have been written to the
response, the status and headers become the newly supplied values.
c                      R  p V # )c                 L    V! R . \         \        R4      R34       \        R4      # )r=  r  Nr(   )rv   r   r>   s   &&r%   rm   cStartResponseTests.test_startResponseWithException.<locals>.applicationFactory.<locals>.application  s#    ii59I4-PQBxr2   r(   r~  s    r%   r   NStartResponseTests.test_startResponseWithException.<locals>.applicationFactory  r  r2   c                    < SP                  SP                  P                  P                  4       P	                  R 4      4       R# )s   HTTP/1.1 100 Foo
Nr  r  s   &r%   r   FStartResponseTests.test_startResponseWithException.<locals>.cbRendered  rC  r2   c                     < S # r=   r(   r  s   r%   rA   DStartResponseTests.test_startResponseWithException.<locals>.<lambda>  r  r2   r   r   r[   Nr  r  s   f    @r%   test_startResponseWithException2StartResponseTests.test_startResponseWithException  si     .	 !668	
 	
j!D
	
 r2   c                ,  a aaa \        4       o ! R R\        4      p V! 4       h  \         d    \        4       o Mi ; i. oTT3R lpS P	                  4       w  r4TTTT 3R lpTP                  T4       S P                  TTT3R lRR. R.R	. 4	       T# )
z
If the I{start_response} callable is invoked with a third positional
argument after the status and headers have been written to the
response, the supplied I{exc_info} values are re-raised to the
application.
c                       ] tR tRtRtR# )PStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.SomeExceptioni  r(   N)r)   r*   r+   r,   r.   r(   r2   r%   SomeExceptionrU    s    r2   rV  c                     < VV3R  lp V # )c              3      <"   V! R . 4       Rx   V! R. S4       R#   \          d    SP                  \        4       4        R# i ; i5i)r   rM   z500 ERRN)r   r  r   )r?   r@   excInforeraiseds   &&r%   rm   jStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.applicationFactory.<locals>.application  sB     h+0!)R9$ 0OOHJ/0s%   A	
 A	$AA	AA	r(   )rm   rY  rZ  s    r%   r   UStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.applicationFactory  s    0 r2   c                   < SP                  SP                  P                  P                  4       P	                  R 4      4       SP                  S^ ,          ^ ,          S^ ,          4       SP                  S^ ,          ^,          S^,          4       S^ ,          ^,          P                  pS^,          pSP                  \        P                  ! V4      ^,          \        P                  ! V4      ^ ,          4       R# )s   HTTP/1.1 200 OK
N)	rH   rV  r  r  r  r   tb_next	traceback
extract_tb)r  tb1tb2r   rY  rZ  r!   s   &  r%   r   MStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.cbRendered  s    OO!!))224??@VW Xa[^WQZ8Xa[^WQZ8 1+a.((C!*CY11#6q99;O;OPS;TUV;WXr2   c                     < S # r=   r(   r  s   r%   rA   KStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.<lambda>  r  r2   r   r   r[   N)r   rv   r   r   r   r   r   )	r!   rV  r   r   r   r   r   rY  rZ  s	   f     @@@r%   &test_startResponseWithExceptionTooLate9StartResponseTests.test_startResponseWithExceptionTooLate  s     .	I 		!/! 	!jG	! 		 !668
	Y 
	Y 	
j!D
	
 s   & >>c                   a aaa \        4       o. oVV3R loV3R lpS P                  4       w  r#VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )	zz
I{start_response} returns the I{write} callable which can be used to
write bytes to the response body without buffering.
c                  n   < SP                  S P                  P                  P                  4       4       R # r=   r  r  s   r%   r  -StartResponseTests.test_write.<locals>.record  r  r2   c                     < V3R  lp V # )c                 j   < V! R R.4      pV! R4       S! 4        V! R4       S! 4        \        R4      # )r=  rM   r,  r-  r(   r|  )r?   r@   r   r  s   && r%   rm   NStartResponseTests.test_write.<locals>.applicationFactory.<locals>.application  s4    %i2I1JKffBxr2   r(   r  s    r%   r   9StartResponseTests.test_write.<locals>.applicationFactory
  s      r2   c                    < SP                  SP                  S^ ,          4      R4       SP                  SP                  S^,          4      R4       R# r2  r3  r  s   &r%   r   1StartResponseTests.test_write.<locals>.cbRendered  r5  r2   c                     < S # r=   r(   r  s   r%   rA   /StartResponseTests.test_write.<locals>.<lambda>"  r  r2   r   r   r[   Nr  r  s   f    @@@r%   
test_writeStartResponseTests.test_write  su    
 .	L		 !668	 	
j!D
	
 r2   c                   a  R pS P                  V4      w  r#VP                  4        V 3R lpS P                  V\        4      P	                  V4      # )zR
The C{write} callable returned from C{start_response} only accepts
byte strings.
c                 :    V! R . 4      pV! R4       \        R4      # )r   bogusr(   r|  r?   r@   r   s   && r%   rm   HStartResponseTests.test_writeAcceptsOnlyByteStrings.<locals>.application3  s    !(B/E'N8Or2   c                 >   < SP                  R \        V 4      4       R# )z0Can only write bytes to a transport, not 'bogus'Nr  r  s   &r%   r  IStartResponseTests.test_writeAcceptsOnlyByteStrings.<locals>.checkMessage;  s    BCJr2   r  r  s   f    r%    test_writeAcceptsOnlyByteStrings3StartResponseTests.test_writeAcceptsOnlyByteStrings-  sM    	
 --k:!	
 !!&)4@@NNr2   r(   N)r)   r*   r+   r,   r-   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r8  rF  rQ  rf  rs  r|  r.   r/   r0   s   @r%   rx  rx    s     
%NO&/b
O.
:O.
:O*O,O,	

)V,\,\%N$L:x-^O Or2   rx  c                   r   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tRtV tR# )ApplicationTestsiC  zX
Tests for things which are done to the application object and the iterator
it returns.
c                    \         V n         \        4       V n        V P                  P                  4        V P	                  V P                  P
                  4       R # r=   )r   r   r   start
addCleanupstoprD   s   &r%   enableThreadsApplicationTests.enableThreadsI  s8    $,,,-r2   c           	        a aa \        4       o ! R R4      pV! 4       oV3R lpS P                  4       w  r4VVV 3R lpVP                  V4       S P                  WBV3R lRR. R.4       V# )	z
If the application object returns an iterator which also has a I{close}
method, that method is called after iteration is complete.
c                   2   a  ] tR tRt o R tR tR tRtV tR# )+ApplicationTests.test_close.<locals>.ResultiV  c                    R V n         R# )TNopenrD   s   &r%   r\   4ApplicationTests.test_close.<locals>.Result.__init__W  s	     	r2   c              3  r   "   \        ^4       F#  pV P                  '       g   K  RV3,          x  K%  	  R# 5ir  s   %dN)ranger  )r!   is   & r%   __iter__4ApplicationTests.test_close.<locals>.Result.__iter__Z  s(     qAyyy#qdl* "s   77c                    R V n         R# )FNr  rD   s   &r%   close1ApplicationTests.test_close.<locals>.Result.close_  s	    !	r2   r  N	r)   r*   r+   r,   r\   r  r  r.   r/   r0   s   @r%   Resultr  V  s     !+
" "r2   r  c                     < V3R  lp V # )c                    < V! R R.4       S# )r   r?  3r(   )r?   r@   r   s   &&r%   rm   LApplicationTests.test_close.<locals>.applicationFactory.<locals>.applicatione  s    h)@(ABr2   r(   r   s    r%   r   7ApplicationTests.test_close.<locals>.applicationFactoryd  s     r2   c                    < SP                  SP                  SP                  P                  P	                  4       4      R 4       SP                  SP                  4       R# )s   012N)r   r   rV  r  r  r!  r  )r  r   r   r!   s   &r%   r   /ApplicationTests.test_close.<locals>.cbRenderedm  sK    ++G,=,=,E,E,N,N,PQ V[[)r2   c                     < S # r=   r(   r  s   r%   rA   -ApplicationTests.test_close.<locals>.<lambda>w  s    r2   r   r   r[   r  )r!   r  r   r   r   r   r   r   s   f     @@r%   
test_closeApplicationTests.test_closeO  sp    
 .
	" 
	" 	 !668	* 	
j!rTVSW	
 r2   c           	        a a S P                  4        . oV3R lpS P                  4       w  r#VV 3R lpVP                  V4       S P                  W1\        RR. R.4       V# )z]
The application object is invoked and iterated in a thread which is not
the reactor thread.
c                     < V3R  lp V # )c                 d   < V3R  lpSP                  \        4       4       V! RR.4       V! 4       # )c               3   ~   <"   \        ^4       F(  p SP                  \        4       4       RV 3,          x  K*  	  R# 5ir  )r  r  r   )r  invokeds    r%   r   pApplicationTests.test_applicationCalledInThread.<locals>.applicationFactory.<locals>.application.<locals>.result  s.     "1X{}5#qdl* &s   :=r   r  )r  r   )r?   r@   r   r  s   && r%   rm   `ApplicationTests.test_applicationCalledInThread.<locals>.applicationFactory.<locals>.application  s-    +
 {}-h)@(ABxr2   r(   )rm   r  s    r%   r   KApplicationTests.test_applicationCalledInThread.<locals>.applicationFactory  s      r2   c                    < SP                  \        4       S4       SP                  \        \	        S4      4      ^4       R# )r  N)assertNotInr   r   ry   setr  r  r!   s   &r%   r   CApplicationTests.test_applicationCalledInThread.<locals>.cbRendered  s.    []G4SW.2r2   r   r   r[   )r  r   r   r   r   )r!   r   r   r   r   r  s   f    @r%   test_applicationCalledInThread/ApplicationTests.test_applicationCalledInThread|  sg    
 		 !668	3 	
j!eUBQSPT	
 r2   c           	        a a S P                  4        . o ! V3R lR\        4      pR pS P                  V4      w  r4VV 3R lpVP                  V4       S P	                  WB\
        RR. R.4       V# )zp
The I{write} callable returned by I{start_response} calls the request's
C{write} method in the reactor thread.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )CApplicationTests.test_writeCalledFromThread.<locals>.ThreadVerifieri  c                b   < SP                  \        4       4       \        P                  ! W4      # r=   r  r   r   r   r!   r   r  s   &&r%   r   IApplicationTests.test_writeCalledFromThread.<locals>.ThreadVerifier.write       {}-}}T11r2   r(   Nr)   r*   r+   r,   r   r.   r/   r1   r  s   @r%   ThreadVerifierr         2 2r2   r  c                      R  p V # )c                 :    V! R . 4      pV! R4       \        R4      # )r   rM   r(   r|  rx  s   && r%   rm   \ApplicationTests.test_writeCalledFromThread.<locals>.applicationFactory.<locals>.application  s    %h3fBxr2   r(   r~  s    r%   r   GApplicationTests.test_writeCalledFromThread.<locals>.applicationFactory  r@  r2   c                 P   < SP                  \        S4      \        4       04       R # r=   r   r  r   r  s   &r%   r   ?ApplicationTests.test_writeCalledFromThread.<locals>.cbRendered      S\KM?;r2   r   r   r[   r  r   r   r   r   r   r!   r  r   r   r   r   r  s   f     @r%   test_writeCalledFromThread+ApplicationTests.test_writeCalledFromThread  su    
 		2W 	2
	 !66~F	< 	
j!eUBQSPT	
 r2   c           	        a a S P                  4        . o ! V3R lR\        4      pR pS P                  V4      w  r4VV 3R lpVP                  V4       S P	                  WB\
        RR. R.4       V# )zw
Strings produced by the iterator returned by the application object are
written to the request in the reactor thread.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )MApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.ThreadVerifieri  c                b   < SP                  \        4       4       \        P                  ! W4      # r=   r  r  s   &&r%   r   SApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.ThreadVerifier.write  r  r2   r(   Nr  r  s   @r%   r  r    r  r2   r  c                      R  p V # )c              3   (   "   V! R . 4       Rx  R# 5i)r   rM   Nr(   r>   s   &&r%   rm   fApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.applicationFactory.<locals>.application  s     h+s   r(   r~  s    r%   r   QApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.applicationFactory  s     r2   c                 P   < SP                  \        S4      \        4       04       R # r=   r  r  s   &r%   r   IApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.cbRendered  r  r2   r   r   r[   r  r  s   f     @r%   $test_iteratedValuesWrittenFromThread5ApplicationTests.test_iteratedValuesWrittenFromThread  su    
 		2W 	2
	 !66~F	< 	
j!eUBQSPT	
 r2   c           	        a a S P                  4        . o ! V3R lR\        4      pR pS P                  V4      w  r4VV 3R lpVP                  V4       S P	                  WB\
        RR. R.4       V# )zI
The response status is set on the request object in the reactor thread.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )EApplicationTests.test_statusWrittenFromThread.<locals>.ThreadVerifieri  c                d   < SP                  \        4       4       \        P                  ! WV4      # r=   )r  r   r   setResponseCode)r!   coder  r  s   &&&r%   r  UApplicationTests.test_statusWrittenFromThread.<locals>.ThreadVerifier.setResponseCode  s$    {}-..t7CCr2   r(   N)r)   r*   r+   r,   r  r.   r/   r  s   @r%   r  r    s     D Dr2   r  c                      R  p V # )c                 *    V! R . 4       \        R4      # r   r|  r>   s   &&r%   rm   ^ApplicationTests.test_statusWrittenFromThread.<locals>.applicationFactory.<locals>.application  s    h+Bxr2   r(   r~  s    r%   r   IApplicationTests.test_statusWrittenFromThread.<locals>.applicationFactory  r  r2   c                 P   < SP                  \        S4      \        4       04       R # r=   r  r  s   &r%   r   AApplicationTests.test_statusWrittenFromThread.<locals>.cbRendered  r  r2   r   r   r[   r  r  s   f     @r%   test_statusWrittenFromThread-ApplicationTests.test_statusWrittenFromThread  sw     		DW 	D
	 !66~F	< 	
j!eUBQSPT	
 r2   c           	        a a  ! R R\         4      pRS n        V 3R loV3R lpS P                  V4      w  r4V 3R lpVP                  V4       S P	                  WB\
        RR. R	.4       S P                  V\        4      # )
zi
If the request connection is lost while the application object is being
iterated, iteration is stopped.
c                   *   a  ] tR tRt o RtR tRtV tR# )SApplicationTests.test_connectionClosedDuringIteration.<locals>.UnreliableConnectioni  zj
This is a request which pretends its connection is lost immediately
after the first write is done to it.
c                L    V P                  \        \        R 4      4      4       R# )zNo more connectionN)connectionLostr   r
   )r!   r   s   &&r%   r   YApplicationTests.test_connectionClosedDuringIteration.<locals>.UnreliableConnection.write  s    ##GN;O,P$QRr2   r(   N)r)   r*   r+   r,   r-   r   r.   r/   r0   s   @r%   UnreliableConnectionr    s     
S Sr2   r  Fc               3   8   <"   R x  RS n         \        R4      h5i)rM   TzShould not have gotten here)badIterrv   rD   s   r%   appIterFApplicationTests.test_connectionClosedDuringIteration.<locals>.appIter  s     LDL9::s   c                     < V3R  lp V # )c                 $   < V! R . 4       S! 4       # )r   r(   )r?   r@   r  s   &&r%   rm   fApplicationTests.test_connectionClosedDuringIteration.<locals>.applicationFactory.<locals>.application  s    h+y r2   r(   )rm   r  s    r%   r   QApplicationTests.test_connectionClosedDuringIteration.<locals>.applicationFactory  s    ! r2   c                 @   < SP                  SP                  R 4       R# )z!Should not have resumed iterationN)r!  r  )r  r!   s   &r%   r   IApplicationTests.test_connectionClosedDuringIteration.<locals>.cbRendered!  s    T\\+NOr2   r   r   r[   )r   r  r   r   r   r   r  r
   )r!   r  r   r   r   r   r  s   f     @r%   $test_connectionClosedDuringIteration5ApplicationTests.test_connectionClosedDuringIteration  s    	S7 	S 	;
	 !667KL	P 	
j!eUBQSPT	
 !!!^44r2   c                   a aa \        4       oV3R  lpS P                  4       w  r4VV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       V# )c                     < S # r=   r(   r~  s   r%   r   EApplicationTests._internalServerErrorTest.<locals>.applicationFactory/  	    r2   c                    < SP                  \        4      pSP                  \        V4      ^4       SP	                  SP
                  P                  P                  4       P                  R4      4       R# )r  s"   HTTP/1.1 500 Internal Server ErrorN)	r|   rO   r   ry   rH   rV  r  r  r  )r  r  r   r!   s   & r%   r   =ApplicationTests._internalServerErrorTest.<locals>.cbRendered4  sY    ++L9FS[!,OO!!))224??9r2   c                     < S # r=   r(   r  s   r%   rA   ;ApplicationTests._internalServerErrorTest.<locals>.<lambda>C  r  r2   r   r   r[   Nr  )r!   rm   r   r   r   r   r   s   ff    @r%   _internalServerErrorTest)ApplicationTests._internalServerErrorTest,  sg    .	 !668	 	
j!D
	
 r2   c                *    R pV P                  V4      # )z
If the application raises an exception before calling I{start_response}
then the response status is I{500} and the exception is logged.
c                     \        R 4      h This application had some error.rO   r>   s   &&r%   rm   RApplicationTests.test_applicationExceptionBeforeStartResponse.<locals>.applicationT  s    ABBr2   r  r!   rm   s   & r%   ,test_applicationExceptionBeforeStartResponse=ApplicationTests.test_applicationExceptionBeforeStartResponseN  s    	C ,,[99r2   c                *    R pV P                  V4      # )z
If the application calls I{start_response} but then raises an exception
before any data is written to the response then the response status is
I{500} and the exception is logged.
c                 *    V! R . 4       \        R4      hr   r  r  r>   s   &&r%   rm   QApplicationTests.test_applicationExceptionAfterStartResponse.<locals>.application`  s    (B'ABBr2   r
  r  s   & r%   +test_applicationExceptionAfterStartResponse<ApplicationTests.test_applicationExceptionAfterStartResponseY  s    	C ,,[99r2   c                  a aaaaa	a
 \        4       o\        P                  ! S \        4      oV3R  lpS P	                  4       w  po	. o
V	V
3R lpVVVV 3R lpVP                  V4       S P                  VVV3R lRR. R.R. 4	       S P                  SP                  P                  4       S
^ ,          P                  \        \        R4      4      4       V# )	c                     < S # r=   r(   r~  s   r%   r   BApplicationTests._connectionClosedTest.<locals>.applicationFactoryk  r  r2   c                  D   < SP                  S! V / VB 4       SR,          # r  )r  )r#   r$   r   requestss   *,r%   requestFactoryWrapperEApplicationTests._connectionClosedTest.<locals>.requestFactoryWrappers  s#    OONA445B<r2   c                 x  < SP                  ^\        S4      4       S^ ,          pVR,          pSP                  VP                  \        4       SP                  \        4       SP                  P                  P                  4       pSP                  VP                  R4      4       SP                  SV4       R# )r  rt   s   HTTP/1.1 200 OKN)rx   ry   rz   r{   rO   r|   rV  r  r  rH   r  assertIn)r  eventr"   r   r   r}   responseContentr!   s   &   r%   
ebRendered:ApplicationTests._connectionClosedTest.<locals>.ebRenderedw  s    a[!12NEm$A!!!''<8""<0((0099;HOOH//0BCDMM/84r2   c                     < S # r=   r(   r  s   r%   rA   8ApplicationTests._connectionClosedTest.<locals>.<lambda>  r  r2   r   r   r[   NzAll gone)r   r   ru   r   r   
addErrbackr   rH   rV  disconnectedr  r   r
   )r!   rm   r  r   r   r  r  r   r}   r   r  s   fff    @@@@r%   _connectionClosedTest&ApplicationTests._connectionClosedTestf  s    .*<<TCUV	 !668> 	 
	5 
	5 	
Z !D
	
 	))667""7>*+E#FGr2   c                8   a RoV3R lpV P                  VS4      # )z
If the application raises an exception after the response status has
already been sent then the connection is closed and the exception is
logged.
s?   Some bytes, triggering the server to start sending the responsec              3   <   <"   V! R . 4       Sx  \        R4      h5ir  r  )r?   r@   r  s   &&r%   rm   IApplicationTests.test_applicationExceptionAfterWrite.<locals>.application  s"     (B'!!ABBr  r%  )r!   rm   r  s   & @r%   #test_applicationExceptionAfterWrite4ApplicationTests.test_applicationExceptionAfterWrite  s)     O 		C
 ))+GGr2   c                F   a Ro ! V3R lR4      pV P                  VS4      # )z
If the application returns a closeable iterator and the C{close} method
raises an exception when called then the connection is still closed and
the exception is logged.
rM   c                   :   <a  ] tR tRt o R tV3R ltR tRtV tR# )DApplicationTests.test_applicationCloseException.<locals>.Applicationi  c                    V! R . 4       R# )r   Nr(   )r!   r?   r@   s   &&&r%   r\   MApplicationTests.test_applicationCloseException.<locals>.Application.__init__  s    h+r2   c              3     <"   Sx  R # 5ir=   r(   )r!   r  s   &r%   r  MApplicationTests.test_applicationCloseException.<locals>.Application.__iter__  s     %%s   
c                    \        R 4      hr  r  rD   s   &r%   r  JApplicationTests.test_applicationCloseException.<locals>.Application.close  s    "#EFFr2   r(   Nr  )r1   r  s   @r%   Applicationr/    s     ,&G Gr2   r6  r*  )r!   r6  r  s   & @r%   test_applicationCloseException/ApplicationTests.test_applicationCloseException  s+     !	G 	G ))+GGr2   )r  r   r   N)r)   r*   r+   r,   r-   r  r  r  r  r  r  r  r  r  r  r%  r+  r7  r.   r/   r0   s   @r%   r  r  C  s[     
.+Z!F DB@(5T D	::0dH"H Hr2   r  )9r-   rt  r_  r  sysr   urllib.parser   r   zope.interface.verifyr   twisted.internetr   twisted.internet.addressr   r   twisted.internet.deferr   r	   twisted.internet.errorr
   twisted.internet.testingr   twisted.loggerr   r   twisted.python.failurer   twisted.python.threadabler   twisted.python.threadpoolr   twisted.trial.unittestr   twisted.webr   twisted.web.resourcer   r   twisted.web.serverr   r   r   twisted.web.test.test_webr   twisted.web.wsgir   r   r4   r:   r   r   r  rk  rr  rx  r  r(   r2   r%   <module>rK     s        * . $ = : 1 9 5 * 1 0 +  4 5 5 2 ) 4 $m/ m/`r rjF
>8 F
Rd> dN	2H &$8( &J
O J
OZxH~x xHr2   