+
    Dfj                       R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
Ht ^ RIHtHt ^ RIHtHt ^ RIHt ^ RIHtHtHtHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIH t  ^ RI!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3 ^ RI4H5t5H6t6H7t7H8t8H9t9H:t:H;t;H<t<H=t= ^ RI>H?t? ^ RI@HAtA ^ RIBHCtCHDtD ^ RIEHFtFHGtG  ! R R]H4      tI ! R R]H4      tJ]A! RR./4      tKR tLR tMR tNR tOR tP ! R R] 4      tQ ! R  R!4      tR ! R" R#]R] 4      tS ! R$ R%]R] 4      tT ! R& R'] 4      tU ! R( R)4      tV ! R* R+4      tW ! R, R-] 4      tX]! ]C4       ! R. R/4      4       tY ! R0 R1] 4      tZ ! R2 R3] 4      t[ ! R4 R5] 4      t\ ! R6 R7] 4      t] ! R8 R9] 4      t^R:# );z&
Tests for L{twisted.web._newclient}.
)Optional)implementer)verifyObject)CancelledErrorDeferredfailsucceed)ConnectionDoneConnectionLost)	IConsumerIPushProducer)Protocol)AccumulatingProtocolEventLoggingObserverStringTransport StringTransportWithDisconnection)globalLogPublisher)LineReceiver)Failure)TestCase)BODYDONEHEADERSTATUSUNKNOWN_LENGTH
BadHeadersBadResponseVersionChunkedEncoderConnectionAbortedExcessWriteHTTPClientParser
HTTPParserLengthEnforcingConsumer
ParseErrorRequestNotSentTransportProxyProducerWrongBodyLengthmakeStatefulDispatcher)	HTTP11ClientProtocolPotentialDataLossRequestRequestGenerationFailedRequestTransmissionFailedResponseResponseDoneResponseFailedResponseNeverReceived)	_DataLoss)Headers)IBodyProducer	IResponse)bytesLinearWhitespaceComponentssanitizedBytesc                       ] tR t^CtRtRtR# )ArbitraryExceptionzY
A unique, arbitrary exception type which L{twisted.web._newclient} knows
nothing about.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r9       A/usr/lib/python3/dist-packages/twisted/web/test/test_newclient.pyr8   r8   C   s    rA   r8   c                       ] tR t^JtRtRtR# )AnotherArbitraryExceptionzA
Similar to L{ArbitraryException} but with a different identity.
r9   Nr:   r9   rA   rB   rD   rD   J   s    rA   rD      host   example.comc                \   a a VV 3R lpS P                  W4      pVP                  V4       V# )aU  
Assert that the given L{Deferred} fails with the exception given by
C{mainType} and that the exceptions wrapped by the instance of C{mainType}
it fails with match the list of exception types given by C{reasonTypes}.

This is a helper for testing failures of exceptions which subclass
L{_newclient._WrapperException}.

@param self: A L{TestCase} instance which will be used to make the
    assertions.

@param deferred: The L{Deferred} which is expected to fail with
    C{mainType}.

@param mainType: A L{_newclient._WrapperException} subclass which will be
    trapped on C{deferred}.

@param reasonTypes: A sequence of exception types which will be trapped on
    the resulting C{mainType} exception instance's C{reasons} sequence.

@return: A L{Deferred} which fires with the C{mainType} instance
    C{deferred} fails with, or which fails somehow.
c           	         < \        V P                  S4       F  w  rVP                  V4       K  	  SP                  \	        V P                  4      \	        S4      R V P                   RS R24       V # )zlen(z	) != len())zipreasonstrapassertEquallen)errreasontypereasonTypesselfs   &  rB   cbFailed-assertWrapperExceptionTypes.<locals>.cbFailedn   se    [9LFKK :3;;-yQ7	

 
rA   )assertFailureaddCallback)rS   deferredmainTyperR   rT   ds   f&&f  rB   assertWrapperExceptionTypesr[   U   s+    2 	8.AMM(HrA   c                $    \        W\        V4      # )zc
A simple helper to invoke L{assertWrapperExceptionTypes} with a C{mainType}
of L{ResponseFailed}.
)r[   r/   rS   rX   rR   s   &&&rB   assertResponseFailedr^   }   s    
 't~{SSrA   c                $    \        W\        V4      # )zl
A simple helper to invoke L{assertWrapperExceptionTypes} with a C{mainType}
of L{RequestGenerationFailed}.
)r[   r+   r]   s   &&&rB   assertRequestGenerationFailedr`      s    
 '/ rA   c                $    \        W\        V4      # )zn
A simple helper to invoke L{assertWrapperExceptionTypes} with a C{mainType}
of L{RequestTransmissionFailed}.
)r[   r,   r]   s   &&&rB   assertRequestTransmissionFailedrb      s    
 '1; rA   c                (    \        R^R\        V 4      # )z
Helper function for creating a Response which uses the given transport.
All of the other parameters to L{Response.__init__} are filled with
arbitrary values.  Only use this method if you don't care about any of
them.
   OK   HTTP   rg   )r-   _boringHeaders	transports   &rB   justTransportResponserk      s     OS%KKrA   c                   *   a  ] tR t^t o RtR tRtV tR# )MakeStatefulDispatcherTestsz&
Tests for L{makeStatefulDispatcher}.
c                    ! R R4      pV! 4       pV P                  VP                  4       R4       RVn        V P                  VP                  4       R4       RVn        V P                  \        VP                  4       R# )zs
A method defined with L{makeStatefulDispatcher} invokes a second
method based on the current state of the object.
c                   H   a  ] tR t^t o RtR t]! R]4      tR tR tRt	V t
R# )CMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.FooAc                    R # Nr9   rS   s   &rB   barGMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo.bar   s    rA   quuxc                    R # )ar9   rt   s   &rB   _quux_AKMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo._quux_A       rA   c                    R # )br9   rt   s   &rB   _quux_BKMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo._quux_B   r|   rA   r9   N)r;   r<   r=   r>   _stateru   r'   rz   r   r@   __classdictcell____classdict__s   @rB   Foorp      s,     F )5C rA   r   ry   Br~   CN)rM   ru   r   assertRaisesRuntimeError)rS   r   statefuls   &  rB   test_functionCalledByState6MakeStatefulDispatcherTests.test_functionCalledByState   sc    	 	 5--,5rA   r9   N)r;   r<   r=   r>   r?   r   r@   r   r   s   @rB   rm   rm      s     6 6rA   rm   c                   p   a  ] tR t^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V 3R ltRtV tR# )_HTTPParserTestszh
Base test class for L{HTTPParser} which is responsible for the bulk of
the task of parsing HTTP bytes.
Nc                \   . p\        4       pVP                  Vn        VP                  \	        4       4       V P                  VP                  \        4       VP                  RV P                  ,           4       V P                  VR.4       V P                  VP                  \        4       R# )zR
L{HTTPParser} calls its C{statusReceived} method when it receives a
status line.
   HTTP/1.1 200 OKN)r!   appendstatusReceivedmakeConnectionr   rM   stater   dataReceivedsepr   )rS   statusprotocols   &  rB   test_statusCallback$_HTTPParserTests.test_statusCallback   s    
 <"(-- 1200488;<"4!560rA   c                    / p\        4       pVP                  Vn        VP                  \	        4       4       VP                  R V P                  ,           4       W3# )r   )r!   __setitem__headerReceivedr   r   r   r   rS   headerr   s   &  rB   _headerTestSetup!_HTTPParserTests._headerTestSetup   sN    <"("4"4 120488;<rA   c                   V P                  4       w  rVP                  RV P                  ,           4       VP                  V P                  4       V P                  VRR/4       V P                  VP                  \
        4       R# )zM
L{HTTPParser} calls its C{headerReceived} method when it receives a
header.
s	   X-Foo:bar   X-Foo   barNr   r   r   rM   r   r   r   s   &  rB   test_headerCallback$_HTTPParserTests.test_headerCallback   si    
  002lTXX56 	dhh'(F!34.rA   c                   V P                  4       w  rVP                  RV P                  ,           4       VP                  RV P                  ,           4       VP                  RV P                  ,           4       VP                  V P                  4       V P                  VRR/4       V P                  VP                  \
        4       R# )z|
If a header is split over multiple lines, L{HTTPParser} calls
C{headerReceived} with the entire value once it is received.

   X-Foo: bars    bazs   	quuxr   s   bar baz	quuxNr   r   s   &  rB   test_continuedHeaderCallback-_HTTPParserTests.test_continuedHeaderCallback   s    
  002mdhh67g01i$((23dhh'(,<!=>.rA   c                &   V P                  4       w  rV P                  P                  . RO4      pVP                  RV,           4       VP                  RV,           4       VP                  V P                  4       V P	                  VRRRR/4       R# )zt
Leading and trailing linear whitespace is stripped from the header
value passed to the C{headerReceived} callback.
s   X-Bar:s   X-Foo:r   r   s   X-BarN)s    	 s    bar 	s    	rA   )r   r   joinr   rM   )rS   r   r   values   &   rB   test_fieldContentWhitespace,_HTTPParserTests.test_fieldContentWhitespace   sy    
  002@Ai%/0i%/0dhh'(FHf!EFrA   c                   aa . oV P                  4       w  poVV3R lpVSn        SP                  V P                  4       V P	                  S\
        .4       V P	                  SP                  \        4       R# )zO
After the last header is received, L{HTTPParser} calls
C{allHeadersReceived}.
c                  T   < S P                  SP                  4       \        Sn        R # rs   )r   r   r   )calledr   s   rB   allHeadersReceivedD_HTTPParserTests.test_allHeadersCallback.<locals>.allHeadersReceived  s    MM(..)#HNrA   N)r   r   r   r   rM   r   r   r   )rS   r   r   r   r   s   &  @@rB   test_allHeadersCallback(_HTTPParserTests.test_allHeadersCallback  sd    
 002	$ '9#dhh'&*0rA   c                    V P                  4       w  rVP                  V P                  4       V P                  V/ 4       V P                  VP                  \
        4       R# )zX
If there are no headers in the message, L{HTTPParser} does not call
C{headerReceived}.
Nr   r   s   &  rB   test_noHeaderCallback&_HTTPParserTests.test_noHeaderCallback  sK    
  002dhh'$.rA   c                   \        4       pVP                  \        4       4       VP                  RV P                  ,           4       VP                  RV P                  ,           4       VP                  RV P                  ,           4       VP                  V P                  4       RRR.3.pV P                  V\        VP                  P                  4       4      4       R# )zK
All headers received by L{HTTPParser} are added to
L{HTTPParser.headers}.
r   r   
   X-Foo: bazr   r      bazN)	r!   r   r   r   r   rM   listheadersgetAllRawHeaders)rS   r   expecteds   &  rB   test_headersSavedOnResponse,_HTTPParserTests.test_headersSavedOnResponse#  s    
 < 120488;<mdhh67mdhh67dhh'/014(8(8(I(I(K#LMrA   c                    \        4       p. ROpV F)  pV P                  VP                  V4      RV: R24       K+  	  V P                  VP                  R4      R4       R# )z
L{HTTPParser.isConnectionControlHeader} returns C{True} for headers
which are always connection control headers (similar to "hop-by-hop"
headers from RFC 2616 section 13.5.1) and C{False} for other headers.
z
Expecting z. to be a connection control header, but wasn'ts   datez`Expecting the arbitrarily selected 'date' header to not be a connection control header, but was.N)   content-length
   connections
   keep-alives   tes   trailerss   transfer-encodings   upgrades   proxy-connection)r!   
assertTrueisConnectionControlHeaderassertFalse)rS   r   connHeaderNamesr   s   &   rB   test_connectionControlHeaders._HTTPParserTests.test_connectionControlHeaders1  sc     <	
 &FOO226:"% & 	..w74	
rA   c                    \        4       pVP                  \        4       4       VP                  \	        4       4       V P                  \        VP                  \	        4       4       R# )zQ
L{HTTPParser.switchToBodyMode} raises L{RuntimeError} if called more
than once.
N)r!   r   r   switchToBodyModeobjectr   r   rS   r   s   & rB   test_switchToBodyMode&_HTTPParserTests.test_switchToBodyModeO  sF    
 < 12!!&(+,(A(A68LrA   c                6   < V ^8  d   Qh/ S[ S[,          ;R&   # )   r   )r   bytes)formatr   s   "rB   __annotate___HTTPParserTests.__annotate__   s      
% rA   r9   )r;   r<   r=   r>   r?   r   r   r   r   r   r   r   r   r   r   r   __annotate_func__r@   r   r   s   @rB   r   r      sN     
  C1 //
G1"/N
<MW  rA   r   c                       ] tR tRtRtRtRtR# )$HTTPParserRFCComplaintDelimeterTestsiZ  z4
L{_HTTPParserTests} using standard CR LF newlines.
   
r9   Nr;   r<   r=   r>   r?   r   r@   r9   rA   rB   r   r   Z  s     CrA   r   c                       ] tR tRtRtRtRtR# )'HTTPParserNonRFCComplaintDelimeterTestsib  z-
L{_HTTPParserTests} using bare LF newlines.
   
r9   Nr   r9   rA   rB   r   r   b  s     CrA   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$R# t%R$ t&R%t'V t(R&# )'HTTPClientParserTestsij  zX
Tests for L{HTTPClientParser} which is responsible for parsing HTTP
response messages.
c                `    \        RR4      pV P                  VP                  R4      R4       R# )zR
L{HTTPClientParser.parseVersion} parses a status line into its three
components.
Ns	   CANDY/7.2)s   CANDY   r   )r    rM   parseVersionr   s   & rB   test_parseVersion'HTTPClientParserTests.test_parseVersionp  s,    
 $D$/..|<>NOrA   c                   a aa \        RR4      p\        oVP                  oVVV 3R lpV! R4       V! R4       V! R4       V! R4       V! R4       V! R4       R# )	zZ
L{HTTPClientParser.parseVersion} raises L{ValueError} when passed an
unparsable version.
Nc                 f   < SP                  SSV 4      pSP                  VP                  V 4       R # rs   )r   rM   data)sexcefrS   s   & rB   checkParsing@HTTPClientParserTests.test_parseBadVersion.<locals>.checkParsing  s+    ##Aq!,CSXXq)rA      foos   foo/bar/bazs   foo/s   foo/..s   foo/a.bs	   foo/-1.-1)r    r   r   )rS   r   r   r   r   s   f  @@rB   test_parseBadVersion*HTTPClientParserTests.test_parseBadVersionx  sX    
 $D$/!!	* 	V^$WYZ \"rA   c                z   \        RR\        R4      p\        VR4      pVP                  \	        4       4       VP                  R4       V P                  VP                  P                  R4       V P                  VP                  P                  ^4       V P                  VP                  P                  R4       R# )z
L{HTTPClientParser.statusReceived} parses the version, code, and phrase
from the status line and stores them on the response object.
   GET   /N   HTTP/1.1 200 OK
rd   re   r*   rh   r    r   r   r   rM   responseversioncodephraserS   requestr   s   &  rB   test_responseStatusParsing0HTTPClientParserTests.test_responseStatusParsing  s    
 &$=#GT2 1245**22OD**//5**1159rA   c                z   \        RR\        R4      p\        VR4      pVP                  \	        4       4       VP                  R4       V P                  VP                  P                  R4       V P                  VP                  P                  ^4       V P                  VP                  P                  R4       R# )z
L{HTTPClientParser.statusReceived} can parse a status line without a
phrase (though such lines are a violation of RFC 7230, section 3.1.2;
nevertheless some broken servers omit the phrase).
r   r   Ns   HTTP/1.1 200
rA   re   r   r   s   &  rB    test_responseStatusWithoutPhrase6HTTPClientParserTests.test_responseStatusWithoutPhrase  s     &$=#GT2 1212**22OD**//5**1137rA   c                P   a a \        RR4      oVV 3R lpV! R4       V! R4       R# )zt
L{HTTPClientParser.statusReceived} raises L{ParseError} if it is called
with a status line which cannot be parsed.
Nc                    < SP                  \        SP                  V 4      pSP                  VP                  V 4       R # rs   )r   r#   r   rM   r   )r   r   r   rS   s   & rB   r   BHTTPClientParserTests.test_badResponseStatus.<locals>.checkParsing  s1    ##J0G0GKCSXXq)rA   r   s   HTTP/1.1 bar OK)r    )rS   r   r   s   f @rB   test_badResponseStatus,HTTPClientParserTests.test_badResponseStatus  s+    
 $D$/	* 	V 	'(rA   c                r  a	 / p. p. p. o	\        WP                  4      pVP                  Vn        \	        4       pVP                  V4       VP                  V4       VP                  VP                  n        V	3R lVP                  n	        VP                  V4       V P                  VP                  R4       V P                  VP                  \        4       V P                  V. 4       V P                  VR.4       V P                  S	R.4       V P                  VP                  P                  ^ 4       V# )a  
Assert that L{HTTPClientParser} parses the given C{response} to
C{request}, resulting in a response with no body and no extra bytes and
leaving the transport in the producing state.

@param request: A L{Request} instance which might have caused a server
    to return the given response.
@param status: A string giving the status line of the response to be
    parsed.
@param response: A string giving the response to be parsed.

@return: A C{dict} of headers from the response.
c                  &   < S P                  R 4      # )Tr   )bodyDataFinisheds   rB   <lambda>3HTTPClientParserTests._noBodyTest.<locals>.<lambda>  s    6F6M6Md6SrA   	producingrA   T)r    r   r   r   r   r   r   r   _bodyDataReceived_bodyDataFinishedrM   producerStater   r   length)
rS   r   r   r   r   finishedbodyr   rj   r  s
   &&&&     @rB   _noBodyTest!HTTPClientParserTests._noBodyTest  s
    #G__="("4"4#%		* 	f%.2kk+.S+h'00+>.r"C5))D62**1115rA   c                ~    \        RR\        R4      pRpRpV P                  WV4      pV P                  VRR/4       R# )z
If the response is to a HEAD request, no body is expected, the body
callback is not invoked, and the I{Content-Length} header is passed to
the header callback.
   HEADr   Nr   s   Content-Length: 10

s   Content-Lengths   10)r*   rh   r  rM   )rS   r   r   r   r   s   &    rB   test_headResponse'HTTPClientParserTests.test_headResponse  sF     '4>'4!!'8<"3U!;<rA   c                V    \        RR\        R4      pRpRpV P                  WV4       R# )zh
If the response code is I{NO CONTENT} (204), no body is expected and
the body callback is not invoked.
r   r   Ns   HTTP/1.1 204 NO CONTENT
r   r*   rh   r  rS   r   r   r   s   &   rB   test_noContentResponse,HTTPClientParserTests.test_noContentResponse  s.    
 &$=/(3rA   c                V    \        RR\        R4      pRpRpV P                  WV4       R# )zj
If the response code is I{NOT MODIFIED} (304), no body is expected and
the body callback is not invoked.
r   r   Ns   HTTP/1.1 304 NOT MODIFIED
r   r  r  s   &   rB   test_notModifiedResponse.HTTPClientParserTests.test_notModifiedResponse  s.    
 &$=1(3rA   c                   \        \        RR\        R4      R 4      pVP                  \	        4       4       VP                  R4       VP                  R4       VP                  R4       V P                  VP                  \        / 4      4       V P                  VP                  P                  \        RR	./4      4       V P                  VP                  P                  \        4       R# )
zY
The response headers are added to the response object's C{headers}
L{Headers} instance.
r   r   Nc                     R # rs   r9   rests   &rB   r  <HTTPClientParserTests.test_responseHeaders.<locals>.<lambda>      drA   r   s   X-Foo: bar
r      x-foor   r    r*   rh   r   r   r   rM   connHeadersr2   r   r   assertIdenticalr  r   r   s   & rB   test_responseHeaders*HTTPClientParserTests.test_responseHeaders   s    
 $FD.$79J
 	 1245/0g&--wr{;**22GXx<P4QRX..55~FrA   c                   \        \        RR\        R4      R 4      pVP                  \	        4       4       VP                  R4       VP                  R4       VP                  R4       VP                  R4       V P                  VP                  \        / 4      4       V P                  VP                  P                  \        R	R
./4      4       V P                  VP                  P                  \        4       R# )zo
The multi-line response headers are folded and added to the response
object's C{headers} L{Headers} instance.
r   r   Nc                     R # rs   r9   r&  s   &rB   r  EHTTPClientParserTests.test_responseHeadersMultiline.<locals>.<lambda>  r)  rA   r   s   X-Multiline: a
s       b
r   s   x-multilines   a    br+  r   s   & rB   test_responseHeadersMultiline3HTTPClientParserTests.test_responseHeadersMultiline  s    
 $FD.$79J
 	 124534l+g&--wr{;%%w/L'M	
 	X..55~FrA   c           	        \        \        RR\        R4      R 4      pVP                  \	        4       4       VP                  R4       VP                  R4       VP                  R4       VP                  R4       V P                  VP                  P                  \        / 4      4       V P                  VP                  \        R	R
.RR./4      4       V P                  VP                  P                  ^{4       R# )z^
The connection control headers are added to the parser's C{connHeaders}
L{Headers} instance.
r   r   Nc                     R # rs   r9   r&  s   &rB   r  >HTTPClientParserTests.test_connectionHeaders.<locals>.<lambda>)  r)  rA   r      Content-Length: 123
s   Connection: close
r   r      123r   s   closer    r*   rh   r   r   r   rM   r   r   r2   r,  r  r   s   & rB   test_connectionHeaders,HTTPClientParserTests.test_connectionHeaders#  s    
 $FD.$79J
 	 12458967g&**22GBK@  &-(LM	
 	**1137rA   c                   \        \        RR\        R4      R 4      pVP                  \	        4       4       VP                  R4       VP                  R4       VP                  R4       V P                  VP                  P                  \        RR	./4      4       V P                  VP                  \        / 4      4       V P                  VP                  P                  ^ 4       R# )
z
If a HEAD request is made, the I{Content-Length} header in the response
is added to the response headers, not the connection control headers.
r  r   Nc                     R # rs   r9   r&  s   &rB   r  RHTTPClientParserTests.test_headResponseContentLengthEntityHeader.<locals>.<lambda>=  s    trA   r   r8  r   r   r9  r:  r   s   & rB   *test_headResponseContentLengthEntityHeader@HTTPClientParserTests.test_headResponseContentLengthEntityHeader7  s    
 $GT>48:K
 	 124589g&%%w0AF8/L'M	
 	--wr{;**1115rA   c                   . p\        \        RR\        R4      VP                  4      p\	        4       pVP                  V4       VP                  R4       . pVP                  VP                  n        VP                  R4       VP                  R4       V P                  VP                  R4       V P                  VP                  \        4       VP                  R	4       V P                  VR	.4       V P                  VP                  \        4       VP                  R
4       V P                  VR	R
.4       V P                  VP                  \        4       V P                  VR.4       R# )z
If a response includes a body with a length given by the
I{Content-Length} header, the bytes which make up the body are passed
to the C{_bodyDataReceived} callback on the L{HTTPParser}.
r   r   Nr   s   Content-Length: 10
r   pausedrA   s   xxxxxxs   yyyy)r    r*   rh   r   r   r   r   r   r  rM   r  r   r   r   rS   r  r   rj   r  s   &    rB   test_contentLength(HTTPClientParserTests.test_contentLengthI  s+    #FD.$7
 $%		*45.2kk+78g& 	00(;.h'z*.h'(34.C5)rA   c                   . p\        \        RR\        R4      VP                  4      pVP	                  \        4       4       VP                  R4       . pVP                  VP                  n        VP                  R4       VP                  R4       V P                  VP                  \        4       V P                  V. 4       V P                  VR.4       V P                  VP                  P                  ^ 4       R# )z
If a response includes a I{Content-Length} header indicating zero bytes
in the response, L{Response.length} is set accordingly and no data is
delivered to L{Response._bodyDataReceived}.
r   r   Nr      Content-Length: 0
r   rA   )r    r*   rh   r   r   r   r   r   r  rM   r   r   r  rS   r  r   r  s   &   rB   test_zeroContentLength,HTTPClientParserTests.test_zeroContentLengthh  s     #FD.$7
 	 1245.2kk+67g&.r"C5)**1115rA   c                    \        \        RR\        R4      R4      pVP                  \	        4       4       V P                  \        VP                  R4       R# )z
If a response includes multiple, distinct I{Content-Length} headers,
L{HTTPClientParser.dataReceived} raises L{ValueError} to indicate that
the response is invalid and the transport is now unusable.
r   r   Ns9   HTTP/1.1 200 OK
Content-Length: 1
Content-Length: 2

r    r*   rh   r   r   r   
ValueErrorr   r   s   & rB   )test_multipleDistinctContentLengthHeaders?HTTPClientParserTests.test_multipleDistinctContentLengthHeaders  sL     $GFD.$$OQUV 12!!	
rA   c                   \        \        RR\        R4      R4      pVP                  \	        4       4       VP                  R4       V P                  VP                  P                  ^4       V P                  VP                  \        4       R# )z
If a response includes multiple, yet equal, I{Content-Length} headers,
L{HTTPClientParser.dataReceived} successfully handles and passes single
length for body processing
r   r   Ns9   HTTP/1.1 200 OK
Content-Length: 1
Content-Length: 1

r    r*   rh   r   r   r   rM   r   r  r   r   r   s   & rB   &test_multipleEqualContentLengthHeaders<HTTPClientParserTests.test_multipleEqualContentLengthHeaders  sr     $GFD.$$OQUV 12	
 	**1115.rA   c                    \        \        RR\        R4      R4      pVP                  \	        4       4       V P                  \        VP                  R4       R# )z
If a response includes multiple, distinct I{Content-Length} header
field-values, L{HTTPClientParser.dataReceived} raises L{ValueError} to
indicate that the response is invalid and the transport is now unusable.
r   r   Ns)   HTTP/1.1 200 OK
Content-Length: 1, 2

rM  r   s   & rB   3test_multipleDistinctContentLengthHeaderFieldValuesIHTTPClientParserTests.test_multipleDistinctContentLengthHeaderFieldValues  sJ     $GFD.$$OQUV 12!!F	
rA   c                   \        \        RR\        R4      R4      pVP                  \	        4       4       VP                  R4       V P                  VP                  P                  ^4       V P                  VP                  \        4       R# )z
If a response includes multiple, equal I{Content-Length} header
field-values, L{HTTPClientParser.dataReceived} successfully handles and
passes single content-length header for body processing. Field-values
are considered equal by parsed decimal value.
r   r   Ns+   HTTP/1.1 200 OK
Content-Length: 1, 001

rR  r   s   & rB   0test_multipleEqualContentLengthHeaderFieldValuesFHTTPClientParserTests.test_multipleEqualContentLengthHeaderFieldValues  sp     $GFD.$$OQUV 12H	
 	**1115.rA   c                    \        \        RR\        R4      R4      pVP                  \	        4       4       V P                  \        VP                  R4       R# )z
If the I{Content-Length} header contains anything other than digits
L{HTTPClientParser.dataReceived} raises L{ValueError} to
indicate that the response is invalid and the transport is now unusable.
r   r   Ns'   HTTP/1.1 200 OK
Content-Length: +1

rM  r   s   & rB   test_contentLengthTooPositive3HTTPClientParserTests.test_contentLengthTooPositive  J     $GFD.$$OQUV 12!!<	
rA   c                    \        \        RR\        R4      R4      pVP                  \	        4       4       V P                  \        VP                  R4       R# )z
If the I{Content-Length} header has a negative value
L{HTTPClientParser.dataReceived} raises L{ValueError} to
indicate that the response is invalid and the transport is now unusable.
r   r   Ns'   HTTP/1.1 200 OK
Content-Length: -1

rM  r   s   & rB   test_contentLengthNegative0HTTPClientParserTests.test_contentLengthNegative  r^  rA   c                T   . p\        \        RR\        R4      VP                  4      pVP	                  \        4       4       VP                  R4       VP                  R4       VP                  R4       V P                  VP                  \        4       V P                  VR.4       R# )za
If extra bytes are received past the end of a response, they are passed
to the finish callback.
r   r   Nr   rH     
Here is another thing!   Here is another thing!
r    r*   rh   r   r   r   r   rM   r   r   rS   r  r   s   &  rB   test_extraBytesPassedBack/HTTPClientParserTests.test_extraBytesPassedBack  s    
 #FD.$7
 	 124567;<.$=#>?rA   c                T   . p\        \        RR\        R4      VP                  4      pVP	                  \        4       4       VP                  R4       VP                  R4       VP                  R4       V P                  VP                  \        4       V P                  VR.4       R# )z
If extra bytes are received past the end of the headers of a response
to a HEAD request, they are passed to the finish callback.
r  r   Nr   s   Content-Length: 12
rc  rd  re  rf  s   &  rB   test_extraBytesPassedBackHEAD3HTTPClientParserTests.test_extraBytesPassedBackHEAD  s    
 #GT>48(//
 	 124578;<.$=#>?rA   c                z   . p\        \        RR\        R4      VP                  4      pVP	                  \        4       4       VP                  R4       . pVP                  VP                  n        VP                  R4       VP                  R4       V P                  V. 4       V P                  VP                  P                  \        4       VP                  R4       V P                  VR.4       VP                  R	4       V P                  VRR
.4       VP                  R4       V P                  VR.4       R# )z
If the response headers indicate the response body is encoded with the
I{chunked} transfer encoding, the body is decoded according to that
transfer encoding before being passed to L{Response._bodyDataReceived}.
r   r   Nr   s   Transfer-Encoding: chunked
r   s   3
a   as   bc
s   bcs
   0

extras   extra)r    r*   rh   r   r   r   r   r   r  rM   r-  r  r   rI  s   &   rB   test_chunkedResponseBody.HTTPClientParserTests.test_chunkedResponseBody  s    #FD.$7
 	 1245.2kk+?@g& 	r" 	X..55~F 	i(v&i(e}-
 	/0H:.rA   c                   . p\        \        RR\        R4      VP                  4      p\	        4       pVP                  V4       VP                  R4       . pVP                  VP                  n        VP                  R4       VP                  R4       VP                  R4       V P                  VRR.4       VP                  \        R4      4       V P                  VR	.4       R# )
z
If a response does not include a I{Transfer-Encoding} or a
I{Content-Length}, the end of response body is indicated by the
connection being closed.
r   r   Nr   r   r   r   zsimulated end of connectionrA   )r    r*   rh   r   r   r   r   r   r  rM   connectionLostr	   rD  s   &    rB   test_unknownContentLength/HTTPClientParserTests.test_unknownContentLength)  s     #FD.$7
 $%		*45.2kk+g&f%f%/0/L MNC5)rA   c                V   . p\        \        RR\        R4      VP                  4      p\	        4       pVP                  V4       VP                  R4       . pVP                  VP                  n        VP                  R4       V P                  VR.4       V P                  VR.4       R# )z
According to RFC 2616, section 4.4, point 3, if I{Content-Length} and
I{Transfer-Encoding: chunked} are present, I{Content-Length} MUST be
ignored
r   r   Nr   s@   Content-Length: 102
Transfer-Encoding: chunked

3
abc
0

   abcrA   )
r    r*   rh   r   r   r   r   r   r  rM   rD  s   &    rB   %test_contentLengthAndTransferEncoding;HTTPClientParserTests.test_contentLengthAndTransferEncodingA  s     #FD.$7
 $%		*45.2kk+	
 	x(C5)rA   c                    \        4       p\        \        RR\        R4      R4      pVP	                  V4       VP
                  pVP                  \        \        4       4      4       \        W\        .4      # )z
If L{HTTPClientParser.connectionLost} is called before the headers are
finished, the C{_responseDeferred} is fired with the L{Failure} passed
to C{connectionLost}.
r   r   N)
r   r    r*   rh   r   _responseDeferredrq  r   r8   r^   )rS   rj   r   responseDeferreds   &   rB   test_connectionLostBeforeBody3HTTPClientParserTests.test_connectionLostBeforeBody_  sf     $%	#GFD.$$OQUV	*#55(:(< =>#D=O<PQQrA   c                (   \         P                  ! V \        4      p\        4       p\	        \        RR\        R4      R4      pVP                  V4       . pVP                  P                  VP                  4       VP                  R4       V^ ,          pRR lpWTn        VP                  R4       V P                  ^\        V4      4       V^ ,          pVR,          pV P!                  VP"                  \$        4       V P'                  \$        4       R# )z
If one of the L{Response} methods called by
L{HTTPClientParser.connectionLost} raises an exception, the exception
is logged and not re-raised.
r   r   N&   HTTP/1.1 200 OK
Content-Length: 1

c                     \        4       hrs   r8   )rO   s   &rB   fakeBodyDataFinishedPHTTPClientParserTests.test_connectionLostWithError.<locals>.fakeBodyDataFinished  s    $&&rA   log_failurers   )r   createWithCleanupr   r   r    r*   rh   r   ry  rW   r   r   r  rq  assertEqualsrN   assertIsInstancer   r8   flushLoggedErrors)rS   logObserverrj   r   r   r  eventr   s   &       rB   test_connectionLostWithError2HTTPClientParserTests.test_connectionLostWithErrorn  s     +<<TCUV#%	#GFD.$$OQUV	*""..x?UVA;	' &:"%!S-.A- agg'9:12rA   c                    \        \        RR\        R4      R 4      pVP                  pVP	                  \        4       4       VP                  \        4       4       V P                  V\        4      # )zq
If no response at all was received and the connection is lost, the
resulting error is L{ResponseNeverReceived}.
r  r   Nc                     R # rs   r9   igns   &rB   r  <HTTPClientParserTests.test_noResponseAtAll.<locals>.<lambda>  r)  rA   )
r    r*   rh   ry  r   r   rq  r
   rV   r0   rS   r   rZ   s   &  rB   test_noResponseAtAll*HTTPClientParserTests.test_noResponseAtAll  sb    
 $GT>48:J
 && 12 01!!!%:;;rA   c                B   \        \        RR\        R4      R 4      pVP                  pVP	                  \        4       4       VP                  R4       VP                  \        4       4       V P                  V\        4      P                  V P                  \        4      # )z
If a partial response was received and the connection is lost, the
resulting error is L{ResponseFailed}, but not
L{ResponseNeverReceived}.
r  r   Nc                     R # rs   r9   r  s   &rB   r  BHTTPClientParserTests.test_someResponseButNotAll.<locals>.<lambda>  r)  rA      2)r    r*   rh   ry  r   r   r   rq  r
   rV   r/   rW   r  r  s   &  rB   test_someResponseButNotAll0HTTPClientParserTests.test_someResponseButNotAll  s     $GT>48:J
 && 12d# 01!!!^4@@!!>
 	
rA   c                :   Rp\        \        RR\        R4      R 4      pVP                  \	        4       4       VP                  V4       V P                  \        VRR4      RJ 4       V P                  VP                  \        4       V P                  \        \        VP                  P                  4       4      4      ^ 4       V P                  \        \        VP                  P                  4       4      4      ^ 4       V P                  VP                   4       R# )za
If a response in the 1XX range is received it just gets swallowed and
the parser resets itself.
   HTTP/1.1 103 Early Hints
Server: socketserver/1.0.0
Link: </other/styles.css>; rel=preload; as=style
Link: </other/action.js>; rel=preload; as=script

r   r   Nc                     R # rs   r9   r  s   &rB   r  CHTTPClientParserTests.test_1XXResponseIsSwallowed.<locals>.<lambda>      TrA   r   )r    r*   rh   r   r   r   r   getattrrM   r   r   rN   r   r   r   r,  _everReceivedData)rS   sample103Responser   s   &  rB   test_1XXResponseIsSwallowed1HTTPClientParserTests.test_1XXResponseIsSwallowed  s     	 $FD.$79I
 	 12/0 	*d;tCD0T("2"2"C"C"EFGKT("6"6"G"G"IJKQO223rA   c                   RpRp\        \        RR\        R4      R 4      pVP                  \	        4       4       VP                  W,           4       V P                  VP                  P                  ^4       V P                  VP                  P                  \        / 4      4       V P                  VP                  \        RR./4      4       V P                  VP                  P                  ^{4       R# )	zy
When a 1XX response is swallowed, the final response that follows it is
the only one that gets sent to the application.
r  (   HTTP/1.1 200 OK
Content-Length: 123

r   r   Nc                     R # rs   r9   r  s   &rB   r  UHTTPClientParserTests.test_1XXFollowedByFinalResponseOnlyEmitsFinal.<locals>.<lambda>  r  rA   r   r9  r    r*   rh   r   r   r   rM   r   r   r   r2   r,  r  rS   r  following200Responser   s   &   rB   -test_1XXFollowedByFinalResponseOnlyEmitsFinalCHTTPClientParserTests.test_1XXFollowedByFinalResponseOnlyEmitsFinal  s     	  Y#FD.$79I
 	 12/FG**//5**22GBK@--w8IF87T/UV**1137rA   c                   RpRp\        \        RR\        R4      R 4      pVP                  \	        4       4       VP                  VV,           V,           V,           4       V P                  VP                  P                  ^4       V P                  VP                  P                  \        / 4      4       V P                  VP                  \        RR./4      4       V P                  VP                  P                  ^{4       R# )	zX
It is acceptable for multiple 1XX responses to come through, all of
which get ignored.
r  r  r   r   Nc                     R # rs   r9   r  s   &rB   r  KHTTPClientParserTests.test_multiple1XXResponsesAreIgnored.<locals>.<lambda>  r  rA   r   r9  r  r  s   &   rB   #test_multiple1XXResponsesAreIgnored9HTTPClientParserTests.test_multiple1XXResponsesAreIgnored  s     	  Y#FD.$79I
 	 12   ##	
 	**//5**22GBK@--w8IF87T/UV**1137rA   c                z   \         P                  ! V \        4      pRp\        \	        RR\
        R4      R 4      pVP                  \        4       4       VP                  V4       V P                  ^\        V4      4       V^ ,          pV P                  VR,          R4       V P                  VR,          ^g4       R# )	z6
When a 1XX response is ignored, Twisted emits a log.
r  r   r   Nc                     R # rs   r9   r  s   &rB   r  HHTTPClientParserTests.test_ignored1XXResponseCausesLog.<locals>.<lambda>
  r  rA   
log_formatz#Ignoring unexpected {code} responser   )r   r  r   r    r*   rh   r   r   r   r  rN   )rS   r  r  r   r  s   &    rB    test_ignored1XXResponseCausesLog6HTTPClientParserTests.test_ignored1XXResponseCausesLog  s     +<<TCUV 	 $FD.$79I
 	 12/0!S-.A%-/TU%--rA   r9   N))r;   r<   r=   r>   r?   r   r   r   r  r  r  r  r  r"  r.  r3  r;  r@  rE  rJ  rO  rS  rV  rY  r\  r`  rg  rj  rn  rr  rv  r{  r  r  r  r  r  r  r  r@   r   r   s   @rB   r   r   j  s     
P#,:8)&"H
=44G G&8(6$*>62
$/$
/ 

@"@"#/J*0*<R3:<
$44828<. .rA   r   c                   <   a  ] tR tRt o RtRtRtRtR tR t	Rt
V tR# )	SlowRequesti  ah  
L{SlowRequest} is a fake implementation of L{Request} which is easily
controlled externally (for example, by code in a test method).

@ivar stopped: A flag indicating whether C{stopWriting} has been called.

@ivar finished: After C{writeTo} is called, a L{Deferred} which was
    returned by that method.  L{SlowRequest} will never fire this
    L{Deferred}.
r   Fc                8    \        4       V n        V P                  # rs   )r   r  rS   rj   s   &&rB   writeToSlowRequest.writeTo%  s     
}}rA   c                    R V n         R# TNstoppedrt   s   &rB   stopWritingSlowRequest.stopWriting)  	    rA   )r  r  N)r;   r<   r=   r>   r?   methodr  
persistentr  r  r@   r   r   s   @rB   r  r    s*     	 FGJ rA   r  c                   .   a  ] tR tRt o RtRtR tRtV tR# )SimpleRequesti-  z
L{SimpleRequest} is a fake implementation of L{Request} which writes a
short, fixed string to the transport passed to its C{writeTo} method and
returns a succeeded L{Deferred}.  This vaguely emulates the behavior of a
L{Request} with no body producer.
Fc                :    VP                  R 4       \        R4      # )
   SOME BYTESN)writer   r  s   &&rB   r  SimpleRequest.writeTo7  s    &t}rA   r9   N)	r;   r<   r=   r>   r?   r  r  r@   r   r   s   @rB   r  r  -  s      J rA   r  c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R(R
 l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	# ))HTTP11ClientProtocolTestsi<  zQ
Tests for the HTTP 1.1 client protocol implementation,
L{HTTP11ClientProtocol}.
c                    \        4       V n        \        4       V n        V P                  P	                  V P                  4       R# )zB
Create an L{HTTP11ClientProtocol} connected to a fake transport.
N)r   rj   r(   r   r   rt   s   &rB   setUpHTTP11ClientProtocolTests.setUpB  s.     )*,.$$T^^4rA   c                    V P                   P                  \        4       4       V P                  V P                  P                  4       R4       R# )zn
L{HTTP11ClientProtocol.request} accepts a L{Request} and calls its
C{writeTo} method with its own transport.
r  N)r   r   r  rM   rj   r   rt   s   &rB   test_request&HTTP11ClientProtocolTests.test_requestJ  s5    
 	mo.--/?rA   c                   a  S P                   P                  \        4       4       V 3R lpS P                  S P                   P                  \	        4       4      \
        4      pVP                  V4       V# )z
The second time L{HTTP11ClientProtocol.request} is called, it returns a
L{Deferred} which immediately fires with a L{Failure} wrapping a
L{RequestNotSent} exception.
c                 \   < SP                  SP                  P                  4       R 4       R# rA   NrM   rj   r   ignoredrS   s   &rB   	cbNotSent?HTTP11ClientProtocolTests.test_secondRequest.<locals>.cbNotSentZ       T^^113S9rA   )r   r   r  rV   r  r$   rW   rS   r  rZ   s   f  rB   test_secondRequest,HTTP11ClientProtocolTests.test_secondRequestR  sT     	km,	: t}}44]_E~V	i rA   c                   a  S P                   P                  \        \        R4      4      4       V 3R lpS P	                  S P                   P                  \        4       4      \        4      pVP                  V4       V# )z
L{HTTP11ClientProtocol.request} returns a L{Deferred} which immediately
fires with a L{Failure} wrapping a L{RequestNotSent} if called after
the protocol has been disconnected.
zsad transportc                 \   < SP                  SP                  P                  4       R 4       R# r  r  r  s   &rB   r  LHTTP11ClientProtocolTests.test_requestAfterConnectionLost.<locals>.cbNotSenti  r  rA   )	r   rq  r   r	   rV   r   r  r$   rW   r  s   f  rB   test_requestAfterConnectionLost9HTTP11ClientProtocolTests.test_requestAfterConnectionLosta  s\     	$$W^O-L%MN	: t}}44]_E~V	i rA   c                   a   ! R R4      pS P                   P                  V! 4       4      pV 3R lp\        S V\        .4      pVP	                  V4       V# )z
If the L{Deferred} returned by L{Request.writeTo} fires with a
L{Failure}, L{HTTP11ClientProtocol.request} disconnects its transport
and returns a L{Deferred} which fires with a L{Failure} of
L{RequestGenerationFailed} wrapping the underlying failure.
c                   *   a  ] tR tRt o RtR tRtV tR# )CHTTP11ClientProtocolTests.test_failedWriteTo.<locals>.BrokenRequestix  Fc                (    \        \        4       4      # rs   )r   r8   r  s   &&rB   r  KHTTP11ClientProtocolTests.test_failedWriteTo.<locals>.BrokenRequest.writeTo{  s    .011rA   r9   Nr;   r<   r=   r>   r  r  r@   r   r   s   @rB   BrokenRequestr  x  s     J2 2rA   r  c                    < SP                  SP                  P                  4       SP                  P	                  \        \        R 4      4      4       R# )zyou asked for itN)r   rj   disconnectingr   rq  r   r	   r  s   &rB   rT   >HTTP11ClientProtocolTests.test_failedWriteTo.<locals>.cbFailed  s8    OODNN889 MM((@R1S)TUrA   )r   r   r`   r8   rW   )rS   r  rZ   rT   s   f   rB   test_failedWriteTo,HTTP11ClientProtocolTests.test_failedWriteTop  sP    	2 	2 MM!!-/2	V *$4F3GH	hrA   c                x     ! R R4      pV P                   P                  V! 4       4      p\        W\        .4      # )z
If L{Request.writeTo} raises an exception,
L{HTTP11ClientProtocol.request} returns a L{Deferred} which fires with
a L{Failure} of L{RequestGenerationFailed} wrapping that exception.
c                   *   a  ] tR tRt o RtR tRtV tR# )MHTTP11ClientProtocolTests.test_synchronousWriteToError.<locals>.BrokenRequesti  Fc                    \        4       hrs   r  r  s   &&rB   r  UHTTP11ClientProtocolTests.test_synchronousWriteToError.<locals>.BrokenRequest.writeTo  s    (**rA   r9   Nr  r   s   @rB   r  r    s     J+ +rA   r  )r   r   r`   r8   )rS   r  rZ   s   &  rB   test_synchronousWriteToError6HTTP11ClientProtocolTests.test_synchronousWriteToError  s5    	+ 	+ MM!!-/2,T7I6JKKrA   Nc                J   \        4       pV P                  P                  V4      p\        W\        .4      pV P                  VP                  4       V P                  P                  \        \	        4       4      4       V P                  VP                  4       VR8X  d   VP                  P                  R4       V# VR8X  d_   VP                  P                  \        \        4       4      4       V P                  \        4      pV P                  \!        V4      ^4       V#  V# )a
  
If L{HTTP11ClientProtocol}'s transport is disconnected before the
L{Deferred} returned by L{Request.writeTo} fires, the L{Deferred}
returned by L{HTTP11ClientProtocol.request} fires with a L{Failure} of
L{RequestTransmissionFailed} wrapping the underlying failure.
callbackNerrback)r  r   r   rb   r8   r   r  rq  r   r   r  r  r  rD   r  rM   rN   )rS   moder   rZ   errorss   &&   rB   *test_connectionLostDuringRequestGenerationDHTTP11ClientProtocolTests.test_connectionLostDuringRequestGeneration  s     -MM!!'*+D6H5IJ 	)$$W-?-A%BC 	(:%%d+  Y$$W-F-H%IJ++,EFFS[!,  rA   c                $    V P                  R4      # )z
If the request passed to L{HTTP11ClientProtocol} finishes generation
successfully after the L{HTTP11ClientProtocol}'s connection has been
lost, nothing happens.
r  r  rt   s   &rB   +test_connectionLostBeforeGenerationFinishedEHTTP11ClientProtocolTests.test_connectionLostBeforeGenerationFinished  s     >>zJJrA   c                $    V P                  R4      # )z
If the request passed to L{HTTP11ClientProtocol} finished generation
with an error after the L{HTTP11ClientProtocol}'s connection has been
lost, nothing happens.
r  r  rt   s   &rB   )test_connectionLostBeforeGenerationFailedCHTTP11ClientProtocolTests.test_connectionLostBeforeGenerationFailed  s     >>yIIrA   c                   a a \         P                  ! S \        4      oVV 3R lpS P                  R4      P	                  V4      # )z
If the request passed to L{HTTP11ClientProtocol} finished generation
with an error after the L{HTTP11ClientProtocol}'s connection has been
lost, an error is logged that gives a non-confusing hint to user on what
went wrong.
c                    < SP                  ^\        S4      4       S^ ,          pSP                  RV4       SP                  VR,          R4       SP                  VR,          R4       R# )rg   r  r  zJError writing request, but not in valid state to finalize request: {state}r   CONNECTION_LOSTN)r  rN   assertInrM   )ignorer  r  rS   s   & rB   checknHTTP11ClientProtocolTests.test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse.<locals>.check  sa    a[!12NEMM-/l#/
 U7^->?rA   r  )r   r  r   r  rW   )rS   r  r  s   f @rB   Etest_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse_HTTP11ClientProtocolTests.test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse  sA     +<<TCUV		@ >>yIUU
 	
rA   c                   a  S P                   P                  \        RR\        R4      4      pV 3R lpVP	                  V4       S P                   P                  R4       V# )z
When a response is delivered to L{HTTP11ClientProtocol}, the
L{Deferred} previously returned by the C{request} method is called back
with a L{Response} instance and the connection is closed.
r   r   Nc                   < SP                  V P                  ^4       SP                  V P                  \        4       4       SP	                  SP
                  P                  4       SP                  SP                  P                  R4       R# )   	QUIESCENTN)	rM   r   r   r2   r   rj   r  r   r   )r   rS   s   &rB   	cbRequestIHTTP11ClientProtocolTests.test_receiveSimplestResponse.<locals>.cbRequest  s_    X]]C0X--wy9OODNN889T]]00+>rA   s9   HTTP/1.1 200 OK
Content-Length: 0
Connection: close

r   r   r*   rh   rW   r   rS   rZ   r  s   f  rB   test_receiveSimplestResponse6HTTP11ClientProtocolTests.test_receiveSimplestResponse  sU     MM!!'&$"MN	? 	
i ""	
 rA   c                   a  S P                   P                  \        RR\        R4      4      pV 3R lpVP	                  V4       S P                   P                  R4       V# )z
The headers included in a response delivered to L{HTTP11ClientProtocol}
are included on the L{Response} instance passed to the callback
returned by the C{request} method.
r   r   Nc                 ^   < \        R RR./4      pSP                  V P                  V4       R# )r*  r   r   N)r2   rM   r   )r   r   rS   s   & rB   r  HHTTP11ClientProtocolTests.test_receiveResponseHeaders.<locals>.cbRequest  s-    66*:;<HX--x8rA   s+   HTTP/1.1 200 OK
X-Foo: bar
X-Foo: baz

r  r  s   f  rB   test_receiveResponseHeaders5HTTP11ClientProtocolTests.test_receiveResponseHeaders  sS     MM!!'&$"MN	9 	
i ""N	
 rA   c                0  a aaaa . o\        4       o\        SP                  4      oSP                  S4       \	        4       oSP                  S4      pSP                  R4       VVV V3R lpVP                  V4       VV 3R lpVP                  V4       V# )a+  
If response bytes are delivered to L{HTTP11ClientProtocol} before the
L{Deferred} returned by L{Request.writeTo} fires, those response bytes
are parsed as part of the response.

The connection is also closed, because we're in a confusing state, and
therefore the C{quiescentCallback} isn't called.
s8   HTTP/1.1 200 OK
X-Foo: bar
Content-Length: 6

foobarc                   <a a \        4       o\        4       ;pSn        S P                  S4       SP	                  SP
                  R 4       SP                  SP                  4       SP	                  S. 4       VP                  VV 3R l4      # )%TRANSMITTING_AFTER_RECEIVING_RESPONSEc                     < SSP                   3# rs   r   r  pr   s   &rB   r  oHTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone.<locals>.cbResponse.<locals>.<lambda>*      1668JrA   )	r   r   closedDeferreddeliverBodyrM   r   r   r  rW   )r   whenFinishedr%  r   quiescentResultrS   rj   s   f @rB   
cbResponse]HTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone.<locals>.cbResponse#  sq    $&A.6j8L1+  #X^^-TUOOI334_b1++,JKKrA   c                 b  < V w  rSP                  VP                  R4       SP                  VP                  ^4       SP                  VP                  R4       SP                  VP                  \        RR./4      4       SP                  VR4       SP                  P                  R4       R# )rf   rd   r*  r      foobarNre   )rM   r   r   r   r   r2   r  r  )resultr   r  r   rS   s   &  rB   cbAllResponse`HTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone.<locals>.cbAllResponse.  s    #NHX--?X]]C0X__e4X--w6(7K/LMT9- %%d+rA   )r   r(   r   r   r  r   r   rW   )rS   rZ   r,  r1  r   r+  r   rj   s   f   @@@@rB   /test_receiveResponseBeforeRequestGenerationDoneIHTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone  s     #%	'(>(>?	*-W%	
	L 	L 	
j!
	, 	
m$rA   c                (   \        4       p\        4       pW!n        VP                  V4       R\        P
                  ,          pVP                  \        RR\        R4      4      pVP                  RV,           R,           4       \        W\        .4      # )za
The connection is closed when the server respond with a header which
is above the maximum line.
rm  r   r   Ns   HTTP/1.1 200 OK
X-Foo: s   
X-Ignored: ignored

)r   r(   r   r   r   
MAX_LENGTHr   r*   rh   r   r^   r	   )rS   rj   r   longLinerZ   s   &    rB   "test_receiveResponseHeadersTooLong<HTTP11ClientProtocolTests.test_receiveResponseHeadersTooLong=  s    
 56	')%	*,111WVT>4HI!"%	
 $Dn-=>>rA   c                   a a \        4       oS P                  P                  S4      pS P                  P                  R4       R pVP	                  V4       VV 3R lpVP	                  V4       V# )z
If response bytes are delivered to L{HTTP11ClientProtocol} before the
request completes, calling C{connectionLost} on the protocol will
result in protocol being moved to C{'CONNECTION_LOST'} state.
s8   HTTP/1.1 400 BAD REQUEST
Content-Length: 9

tisk tiskc                    a a \        4       o\        4       ;pSn        S P                  S4       VP	                  VV 3R  l4      # )c                     < SSP                   3# rs   r#  r$  s   &rB   r  ڄHTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbResponse.<locals>.<lambda>j  r'  rA   )r   r   r(  r)  rW   )r   r*  r%  s   f @rB   r,  rHTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbResponsef  s:    $&A.6j8L1+  #++,JKKrA   c                    < SP                   P                  R 4       SP                  P                  \	        \        4       4      4       SP                  SP                  P                  R4       R # )Nr	  )r  r  r   rq  r   r8   rM   r   )r  r   rS   s   &rB   r1  uHTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbAllResponsen  sM    %%d+MM((1C1E)FGT]]113DErA   )r  r   r   r   rW   )rS   rZ   r,  r1  r   s   f   @rB   Dtest_connectionLostAfterReceivingResponseBeforeRequestGenerationDone^HTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDoneW  sd     -MM!!'*""	
	L 	
j!	F 	
m$rA   c                0  a a \        4       o\        4       ;pSn        S P                  P	                  \        RR\        R4      4      pS P                  P                  R4       . pVP                  VP                  4       S P                  V. 4       S P                  P                  R4       V^ ,          pVP                  S4       S P                  P                  R4       S P                  P                  R4       VV 3R lpVP                  V4       V# )	z
The C{deliverBody} method of the response object with which the
L{Deferred} returned by L{HTTP11ClientProtocol.request} fires can be
used to get the body of the response.
r   r   Ns%   HTTP/1.1 200 OK
Content-Length: 6
r   r   r   c                 ~   < SP                  SP                  R 4       SP                  P                  \        4       R# )r/  N)rM   r   closedReasonrL   r.   )r  r   rS   s   &rB   r1  IHTTP11ClientProtocolTests.test_receiveResponseBody.<locals>.cbAllResponse  s+    X]]I6!!&&|4rA   )r   r   r(  r   r   r*   rh   r   rW   r   rM   r)  )rS   r*  requestDeferredr0  r   r1  r   s   f     @rB   test_receiveResponseBody2HTTP11ClientProtocolTests.test_receiveResponseBodyw  s     ()19;x.--//FD.$7
 	""A	
 ##FMM2$ 	""5)!9X&""6*""6*	5 	  /rA   c                P   V P                   P                  \        RR\        R4      4      pV P                   P	                  R4       . pVP                  VP                  4       V^ ,          p\        4       pVP                  V4       V P                   P	                  R4       V P                   P	                  R4       V P                  VP                  R4       V P                   P                  \        \        R4      4      4       VP                  P                  \         4       R# )	z
If the length of the response body is unknown, the protocol passed to
the response's C{deliverBody} method has its C{connectionLost}
method called with a L{Failure} wrapping a L{PotentialDataLoss}
exception.
r   r   Ns   HTTP/1.1 200 OK

r   r   r/  z low-level transport disconnected)r   r   r*   rh   r   rW   r   r   r)  rM   r   rq  r   r	   rE  rL   r)   rS   rG  r0  r   r   s   &    rB   Etest_responseBodyFinishedWhenConnectionLostWhenContentLengthIsUnknown_HTTP11ClientProtocolTests.test_responseBodyFinishedWhenConnectionLostWhenContentLengthIsUnknown  s     --//FD.$7
 	""#AB##FMM2!9')X&""6*""6*	2$$N#EFG	
 	""#45rA   c                `   V P                   P                  \        RR\        R4      4      pV P                   P	                  R4       . pVP                  VP                  4       V^ ,          p\        4       pVP                  V4       V P                   P	                  R4       V P                   P	                  R4       V P                  VP                  R4       V P                   P                  \        \        4       4      4       \        V \        VP                   4      \        \"        .4      # )z
If the final chunk has not been received when the connection is lost
(for any reason), the protocol passed to C{deliverBody} has its
C{connectionLost} method called with a L{Failure} wrapping the
exception for that reason.
r   r   Ns/   HTTP/1.1 200 OK
Transfer-Encoding: chunked

   3
foo
s   3
bar
r/  )r   r   r*   rh   r   rW   r   r   r)  rM   r   rq  r   r8   r^   r   rE  r1   rK  s   &    rB   4test_chunkedResponseBodyUnfinishedWhenConnectionLostNHTTP11ClientProtocolTests.test_chunkedResponseBodyUnfinishedWhenConnectionLost  s     --//FD.$7
 	""L	
 ##FMM2!9')X&""?3""?3	2$$W-?-A%BC#$x,,-0BI/N
 	
rA   c                   a  S P                   P                  \        RR\        R4      4      pS P                   P	                  R4       \        S V\        .4      pV 3R lpVP                  V4       V# )z
If the parser L{HTTP11ClientProtocol} delivers bytes to in
C{dataReceived} raises an exception, the exception is wrapped in a
L{Failure} and passed to the parser's C{connectionLost} and then the
L{HTTP11ClientProtocol}'s transport is disconnected.
r   r   Ns   unparseable garbage goes here
c                   < SP                  SP                  P                  4       SP                  V P                  ^ ,          P
                  P                  R4       SP                  P                  \        \        R4      4      4       R# )    s   unparseable garbage goes herez
it is doneN)r   rj   r  rM   rK   r   r   r   rq  r   r	   )r   rS   s   &rB   rT   LHTTP11ClientProtocolTests.test_parserDataReceivedException.<locals>.cbFailed  s_    OODNN889A$$))+K MM((1M)NOrA   )r   r   r*   rh   r   r^   r#   rW   )rS   rG  rZ   rT   s   f   rB    test_parserDataReceivedException:HTTP11ClientProtocolTests.test_parserDataReceivedException  se     --//FD.$7
 	""#GH E
	P 	
hrA   c                   V P                   P                  \        RR\        R4      4      pV P                   P                  P
                  pV P                  VP                  V P
                  4       V P                   P                  \        \        R4      4      4       V P                  VP                  R4       \        W\        .4      # )z
When the HTTP response parser is disconnected, the
L{TransportProxyProducer} which was connected to it as a transport is
stopped.
r   r   Nzconnection done)r   r   r*   rh   _parserrj   r-  	_producer_disconnectParserr   r	   r^   )rS   rG  rj   s   &  rB   test_proxyStopped+HTTP11ClientProtocolTests.test_proxyStopped  s     --//FD.$7
 MM))33	Y00$..A''?P0Q(RSY00$7#DN;KLLrA   c                   \        4       p\        4       pVP                  V4       . p. pVP                  4       P	                  VP
                  4       VP                  4       P	                  VP
                  4       V P                  W43. . 34       V P                  VP                  4       VP                  \        \        4       4      4       V P                  VR.4       V P                  VR.4       R# )z
L{HTTP11ClientProtocol.abort} will tell the transport to close its
connection when it is invoked, and returns a C{Deferred} that fires
when the connection is lost.
N)r   r(   r   abortrW   r   rM   r   r  rq  r   r	   )rS   rj   r   r1r2s   &    rB   test_abortClosesConnection4HTTP11ClientProtocolTests.test_abortClosesConnection  s     $%	')	*$$RYY/$$RYY/"B8,	//0 	(8 9:dV$dV$rA   c                H   \        4       p\        4       pVP                  V4       VP                  \	        \        4       4      4       . pVP                  4       P                  VP                  4       V P                  VR.4       V P                  VP                  R4       R# )zq
L{HTTP11ClientProtocol.abort} called after the connection is lost
returns a C{Deferred} that fires immediately.
Nr	  )r   r(   r   rq  r   r	   r_  rW   r   rM   r   rS   rj   r   r0  s   &   rB   test_abortAfterConnectionLost7HTTP11ClientProtocolTests.test_abortAfterConnectionLost  s}    
 $%	')	*(8 9:$$V]]3$(*;<rA   c                J   \        4       p\        4       pVP                  V4       VP                  \	        RR\
        R4      4      pVP                  4        V P                  VP                  4       VP                  \        \        4       4      4       \        W\        .4      # )z
The Deferred returned by L{HTTP11ClientProtocol.request} will fire
with a L{ResponseFailed} failure containing a L{ConnectionAborted}
exception, if the connection was aborted before all response headers
have been received.
r   r   N)r   r(   r   r   r*   rh   r_  r   r  rq  r   r	   r^   r   re  s   &   rB   test_abortBeforeResponseBody6HTTP11ClientProtocolTests.test_abortBeforeResponseBody,  s     $%	')	*!!'&$"MN	//0(8 9:#D3D2EFFrA   c                  a aaaa \        RR7      o\        4       oSP                  S4       SP                  \	        RR\
        R4      4      pSP                  R4       \        4       o ! VV3R lR\        4      oVVV V3R	 lpV 3R
 lpVP                  V4       \        S S\        \        .4      pVP                  V4      # )a#  
When the connection is aborted after the response headers have
been received and the L{Response} has been made available to
application code, the response body protocol's C{connectionLost}
method will be invoked with a L{ResponseFailed} failure containing a
L{ConnectionAborted} exception.
T)lenientr   r   Nr~  c                   >   <a  ] tR tRt o RtV3R ltV3R ltRtV tR# )QHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.BodyDestinationiP  zH
A body response protocol which immediately aborts the HTTP
connection.
c                (   < SP                  4        R# )z
Abort the HTTP connection.
N)r_  r   s   &rB   connectionMade`HTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.BodyDestination.connectionMadeV  s      rA   c                *   < SP                  V4       R# )z`
Make the reason for the losing of the connection available to
the unit test via C{testResult}.
N)r  )rS   rP   
testResults   &&rB   rq  `HTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.BodyDestination.connectionLost\  s    
 ""6*rA   r9   N)	r;   r<   r=   r>   r?   rp  rq  r@   r   )r   r   rs  s   @rB   BodyDestinationrn  P  s     
!+ +rA   ru  c                   < V P                  S! 4       4       SP                  SP                  4       SP                  \	        \        4       4      4       R# )z
Connect the L{BodyDestination} response body protocol to the
response, and then simulate connection loss after ensuring that
the HTTP connection has been aborted.
N)r)  r   r  rq  r   r	   )r   ru  r   rS   rj   s   &rB   r)  MHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.deliverBodyc  s>       !23OOI334##GN,<$=>rA   c                 H   < SP                  V P                  \        4       R # rs   )r  r   r-   )errorrS   s   &rB   
checkErrorLHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.checkErrorm  s    !!%..(;rA   )r   r(   r   r   r*   rh   r   r   r   rW   r^   r   r1   )	rS   r0  r)  rz  rX   ru  r   rs  rj   s	   f    @@@@rB   test_abortAfterResponseHeaders8HTTP11ClientProtocolTests.test_abortAfterResponseHeaders<  s     $D1	')	*!!'&$"MNUVZ
	+ 	+h 	+&	? 	?	< 	;''*0)<
 ##J//rA   c           
     v  a aa . oVVV 3R lp\        4       p\        V4      oSP                  V4       SP                  \	        RR\
        RRR7      4      pSP                  R4       S P                  S. 4       . pVP                  VP                  4       V^ ,          p\        4       p\        4       Vn        VP                  P                  V3R l4       VP                  V4       SP                  R	4       VP                  P                  \         4       S P                  SSR
.4       S P                  SP"                  R4       S P                  SP$                  R4       S P                  SP&                  R4       S P                  SP(                  R4       S P                  SP*                  R4       R# )a  
If after a response is done the {HTTP11ClientProtocol} stays open and
returns to QUIESCENT state, all per-request state is reset and the
C{quiescentCallback} is called with the protocol instance.

This is useful for implementing a persistent connection pool.

The C{quiescentCallback} is called *before* the response-receiving
protocol's C{connectionLost}, so that new requests triggered by end of
first request can re-use a persistent connection.
c                    < SP                  V S4       SP                  V P                  R 4       SP                  V 4       R# r  NrM   r   r   r%  r   r+  rS   s   &rB   r  HHTTP11ClientProtocolTests.test_quiescentCallbackCalled.<locals>.callback  5    Q)QWWk2""1%rA   r   r   NTr  s&   HTTP/1.1 200 OK
Content-length: 3

c                 &   < SP                  R 4      # )response doner  )r  r+  s   &rB   r  HHTTP11ClientProtocolTests.test_quiescentCallbackCalled.<locals>.<lambda>  s    ..?rA   ru  r  )r   r(   r   r   r*   rh   r   rM   rW   r   r   r   r(  r)  rE  rL   r.   rY  _finishedRequest_currentRequest_transportProxyry  )	rS   r  rj   rG  r0  r   bodyProtocolr   r+  s	   f      @@rB   test_quiescentCallbackCalled6HTTP11ClientProtocolTests.test_quiescentCallbackCalledv  sx    	&
 $%	'1	*"**FD.$4H
 	UV 	"-##FMM2!9 ,-&.j###//?	
 	\*f%!!&&|4 	8_*EF 	))4022D91148114833T:rA   c           
       a aa . oVVV 3R lp\        4       p\        V4      oSP                  V4       SP                  \	        RR\
        RRR7      4      pSP                  R4       S P                  V4      pS P                  VP                  R4       S P                  \        S4      ^4       S P                  VP                  R	4       R# )
a  
The C{quiescentCallback} passed to L{HTTP11ClientProtocol} will only be
invoked once that protocol is in a state similar to its initial state.
One of the aspects of this initial state is the producer-state of its
transport; an L{HTTP11ClientProtocol} begins with a transport that is
producing, i.e. not C{pauseProducing}'d.

Therefore, when C{quiescentCallback} is invoked the protocol will still
be producing.
c                    < SP                  V S4       SP                  V P                  R 4       SP                  V 4       R# r  r  r  s   &rB   r  ]HTTP11ClientProtocolTests.test_transportProducingWhenQuiescentAfterFullBody.<locals>.callback  r  rA   r   r   NTr  s)   HTTP/1.1 200 OK
Content-length: 3

BBBDEFERRED_CLOSEr  )r   r(   r   r   r*   rh   r   successResultOfrM   r   rN   r  )rS   r  rj   rG  r   r   r+  s   f    @@rB   1test_transportProducingWhenQuiescentAfterFullBodyKHTTP11ClientProtocolTests.test_transportProducingWhenQuiescentAfterFullBody  s     	&
 $%	'1	*"**FD.$4H
 		
 ''8 	*:;
 	_-q1
 	00+>rA   c           
       a aa . oVVV 3R lp\        4       p\        V4      oSP                  V4       SP                  \	        RR\
        RRR7      4      pVP                  SP                  4       SP                  R4       S P                  \        S4      ^4       S P                  S^ ,          S4       S P                  S^,          \        4       R# )zp
The quiescentCallback is called before the request C{Deferred} fires,
in cases where the response has no body.
c                    < SP                  V S4       SP                  V P                  R 4       SP                  V 4       R# r  r  r  s   &rB   r  UHTTP11ClientProtocolTests.test_quiescentCallbackCalledEmptyResponse.<locals>.callback  r  rA   r   r   NTr  &   HTTP/1.1 200 OK
Content-length: 0

)r   r(   r   r   r*   rh   rW   r   r   rM   rN   r-  r  r-   )rS   r  rj   rG  r   r+  s   f   @@rB   )test_quiescentCallbackCalledEmptyResponseCHTTP11ClientProtocolTests.test_quiescentCallbackCalledEmptyResponse  s    
 	&
 $%	'1	*"**FD.$4H
 	##O$:$:;UV_-q1_Q/:oa0(;rA   c           
        . p\        4       p\        VP                  4      pVP                  V4       VP	                  \        RR\        RRR7      4      pVP                  R4       . pVP                  VP                  4       V^ ,          p\        4       pVP                  V4       VP                  P                  \        4       V P                  V. 4       V P                  VP                   4       R# )z
If after a response is done the {HTTP11ClientProtocol} returns a
C{Connection: close} header in the response, the C{quiescentCallback}
is not called and the connection is lost.
r   r   NTr  s9   HTTP/1.1 200 OK
Content-length: 0
Connection: close

r   r(   r   r   r   r*   rh   r   rW   r   r)  rE  rL   r.   rM   r   r  rS   r+  rj   r   rG  r0  r   r  s   &       rB   test_quiescentCallbackNotCalled9HTTP11ClientProtocolTests.test_quiescentCallbackNotCalled  s     #%	'(>(>?	*"**FD.$4H
 		
 ##FMM2!9+-\*!!&&|4"-	//0rA   c           
        . p\        4       p\        VP                  4      pVP                  V4       VP	                  \        RR\        RRR7      4      pVP                  R4       . pVP                  VP                  4       V^ ,          p\        4       pVP                  V4       VP                  P                  \        4       V P                  V. 4       V P                  VP                   4       R# )z
If the request was non-persistent (i.e. sent C{Connection: close}),
the C{quiescentCallback} is not called and the connection is lost.
r   r   NFr  r  r  r  s   &       rB   1test_quiescentCallbackNotCalledNonPersistentQueryKHTTP11ClientProtocolTests.test_quiescentCallbackNotCalledNonPersistentQuery  s    
 #%	'(>(>?	*"**FD.$5I
 	UV##FMM2!9+-\*!!&&|4"-	//0rA   c           
        R p\         P                  ! V \        4      p\        4       p\	        V4      pVP                  V4       VP                  \        RR\        RRR7      4      pVP                  R4       . pVP                  VP                  4       V^ ,          p\        4       pVP                  V4       VP                  P                  \         4       V P#                  ^\%        V4      4       V^ ,          p	V	R,          p
V P'                  V
P(                  \*        4       V P-                  \*        4       V P/                  VP0                  4       R# )	z`
If C{quiescentCallback} throws an exception, the error is logged and
protocol is disconnected.
c                     \        4       hrs   )ZeroDivisionError)r%  s   &rB   r  HHTTP11ClientProtocolTests.test_quiescentCallbackThrows.<locals>.callback5  s    #%%rA   r   r   NTr  r  r  )r   r  r   r   r(   r   r   r*   rh   r   rW   r   r   r)  rE  rL   r.   r  rN   r  r   r  r  r   r  )rS   r  r  rj   r   rG  r0  r   r  r  r   s   &          rB   test_quiescentCallbackThrows6HTTP11ClientProtocolTests.test_quiescentCallbackThrows/  s   	& +<<TCUV#%	'1	*"**FD.$4H
 	UV##FMM2!9+-\*!!&&|4!S-.A- agg'8901	//0rA   c                   \        4       p\        4       pVP                  V4       VP                  \	        RR\
        R4      4      pVP                  4        V P                  VP                  4       \        W\        \        .4      # )z
The L{Deferred} returned by L{HTTP11ClientProtocol.request} will fire
with a L{ResponseNeverReceived} failure containing a L{CancelledError}
exception if the request was cancelled before any response headers were
received.
r   r   N)r   r(   r   r   r*   rh   cancelr   disconnectedr[   r0   r   re  s   &   rB   test_cancelBeforeResponse3HTTP11ClientProtocolTests.test_cancelBeforeResponseR  sp     $%	')	*!!'&$"MN	../*/.1A
 	
rA   c                (   \        4       p\        4       pVP                  V4       VP                  \	        RR\
        R4      4      pVP                  R4       VP                  4        V P                  VP                  4       \        W\        .4      # )z
The L{Deferred} returned by L{HTTP11ClientProtocol.request} will fire
with a L{ResponseFailed} failure containing a L{CancelledError}
exception if the request was cancelled before all response headers were
received.
r   r   Nr   )r   r(   r   r   r*   rh   r   r  r   r  r^   r   re  s   &   rB   test_cancelDuringResponse3HTTP11ClientProtocolTests.test_cancelDuringResponsec  sw     $%	')	*!!'&$"MN45	../#D>2BCCrA   c                  aaa \        4       p\        4       pVP                  V4       \        V4      oRR/oV3R loVV3R lpVSn        VP                  \        RR\        S4      4      pSP                  P                  R4       VP                  4        V P                  VP                  4       V P                  SR,          4       \        W\        .4      # )z
The L{Deferred} returned by L{HTTP11ClientProtocol.request} will fire
with a L{RequestGenerationFailed} failure containing a
L{CancelledError} exception if the request was cancelled before a
C{bodyProducer} has finished producing.
	cancelledFc                    < R SR&   R# )Tr  Nr9   )r  nonLocals   &rB   r  JHTTP11ClientProtocolTests.assertCancelDuringBodyProduction.<locals>.cancel  s    $(H[!rA   c                 J   < V Sn         \        S4      Sn        SP                  # rs   consumerr   r  )r  r  producers   &rB   startProducingRHTTP11ClientProtocolTests.assertCancelDuringBodyProduction.<locals>.startProducing  s$     (H ( 0H$$$rA      POST   /bars   xxxxx)r   r(   r   StringProducerr  r   r*   rh   r  r  r  r   r  r`   r   )	rS   producerLengthrj   r   r  r0  r  r  r  s	   &&    @@@rB    assertCancelDuringBodyProduction:HTTP11ClientProtocolTests.assertCancelDuringBodyProductions  s     $%	')	*!.1'	)	%
 #1!!''7NH"UV)	../-.,TN;KLLrA   c                $    V P                  ^
4      # )a   
The L{Deferred} returned by L{HTTP11ClientProtocol.request} will fire
with a L{RequestGenerationFailed} failure containing a
L{CancelledError} exception if the request was cancelled before a
C{bodyProducer} with an explicit length has finished producing.
)r  rt   s   &rB   test_cancelDuringBodyProduction9HTTP11ClientProtocolTests.test_cancelDuringBodyProduction  s     44R88rA   c                ,    V P                  \        4      # )z
The L{Deferred} returned by L{HTTP11ClientProtocol.request} will fire
with a L{RequestGenerationFailed} failure containing a
L{CancelledError} exception if the request was cancelled before a
C{bodyProducer} with C{UNKNOWN_LENGTH} has finished producing.
)r  r   rt   s   &rB   &test_cancelDuringChunkedBodyProduction@HTTP11ClientProtocolTests.test_cancelDuringChunkedBodyProduction  s     44^DDrA   )r   rj   rs   )*r;   r<   r=   r>   r?   r  r  r  r  r  r  r  r  r  r  r  r  r3  r8  rA  rH  rL  rP  rV  r\  rb  rf  ri  r|  r  r  r  r  r  r  r  r  r  r  r  r@   r   r   s   @rB   r  r  <  s     
5@4L @KJ
0.$0d?4@'R6:
@8M%*=G 80t7;r,?\<41>12!1F
"D M>9E ErA   r  c                   F   a  ] tR tRt o RtRtR tR tR tR t	R t
R	tV tR
# )r  i  a  
L{StringProducer} is a dummy body producer.

@ivar stopped: A flag which indicates whether or not C{stopProducing} has
    been called.
@ivar consumer: After C{startProducing} is called, the value of the
    C{consumer} argument to that method.
@ivar finished: After C{startProducing} is called, a L{Deferred} which was
    returned by that method.  L{StringProducer} will never fire this
    L{Deferred}.
Fc                    Wn         R # rs   )r  )rS   r  s   &&rB   __init__StringProducer.__init__  s    rA   c                D    Wn         \        4       V n        V P                  # rs   r  )rS   r  s   &&rB   r  StringProducer.startProducing  s      
}}rA   c                    R V n         R# r  r  rt   s   &rB   stopProducingStringProducer.stopProducing  r  rA   c                    R # rs   r9   rt   s   &rB   pauseProducingStringProducer.pauseProducing      rA   c                    R # rs   r9   rt   s   &rB   resumeProducingStringProducer.resumeProducing  r  rA   )r  r  r  r  N)r;   r<   r=   r>   r?   r  r  r  r  r  r  r@   r   r   s   @rB   r  r    s/     
 G
 rA   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R ltR tR tR tR tR tRtV tR# )RequestTestsi  z
Tests for L{Request}.
c                $    \        4       V n        R # rs   )r   rj   rt   s   &rB   r  RequestTests.setUp  s    (*rA   c                    \        RR\        R4      P                  V P                  4       V P	                  V P                  P                  4       R4       R# )zS
L{Request.writeTo} formats the request data and writes it to the given
transport.
r   r   Ns8   GET / HTTP/1.1
Connection: close
Host: example.com

r*   rh   r  rj   rM   r   rt   s   &rB   test_sendSimplestRequest%RequestTests.test_sendSimplestRequest  sD    
 	nd3;;DNNKNN  "	
rA   c                    \        RR\        RRR7      pVP                  V P                  4       V P	                  V P                  P                  4       R4       R# )z?
A pesistent request does not send 'Connection: close' header.
r   r   NTr  s%   GET / HTTP/1.1
Host: example.com

r  )rS   reqs   & rB   "test_sendSimplestPersistentRequest/RequestTests.test_sendSimplestPersistentRequest  sG     fdNDTJDNN#NN  "B	
rA   c                   \        RRR.RR./4      p\        RRVR4      P                  V P                  4       V P                  P	                  4       P                  R	4      pV P                  V^ ,          R
4       V P                  VRR RR.4       V^  VRR1 VP                  4        V P                  V. RO4       R# )zN
L{Request.writeTo} formats header data and writes it to the given
transport.
r*  r   r   rE   rF   r      /fooNr      GET /foo HTTP/1.1rA   )   Connection: closes   Host: example.comr   r   )r2   r*   r  rj   r   splitrM   sort)rS   r   liness   &  rB   test_sendRequestHeaders$RequestTests.test_sendRequestHeaders  s    
 8ff%5w@PQR$/77G$$&,,W5q#78rsc3Z0!HeBCj

V	
rA   c                   \          F  p\        RV.RR./4      p\        4       p\        RRVR4      P	                  V4       VP                  4       P                  R4      pV P                  V^ ,          R4       V P                  VRR R	R	.4       V^  VRR1 VP                  R
4       VP                  R4       V P                  VR\        ,           .4       K  	  R# )zM
Linear whitespace in request header values is replaced with a
single space.
r*  rE   s   example.invalidr   r  Nr   r  rA   r  s   Host: example.invalids   X-Foo: r  )
r5   r2   r   r*   r  r   r  rM   remover6   )rS   	componentr   rj   r  s   &    rB   -test_sanitizeLinearWhitespaceInRequestHeaders:RequestTests.test_sanitizeLinearWhitespaceInRequestHeaders  s    
 9Ix)g@R?STUG')IFGWd3;;IFOO%++G4EU1X';<U23Z#s4a%*LL-.LL12UZ.%@$AB 9rA   c                   \        \        4      p\        RR\        V4      pVP	                  V P
                  4       V P                  VP                  R4       V P                  V P
                  P                  V4       V P                  V P
                  P                  4       V P                  V P
                  P                  4       R4       V P
                  P                  4        VP                  P                  R4       VP                  P                  R4       VP                   P#                  R4       V P                  V P
                  P                  R4       V P                  V P
                  P                  4       R4       R# )z
L{Request.writeTo} uses chunked encoding to write data from the request
body producer to the given transport.  It registers the request body
producer with the transport.
r  r  NsX   POST /bar HTTP/1.1
Connection: close
Transfer-Encoding: chunked
Host: example.com

s!   3
xxx
f
yyyyyyyyyyyyyyy
0

s   xxxs   yyyyyyyyyyyyyyy)r  r   r*   rh   r  rj   assertNotIdenticalr  r-  r  r   	streamingrM   r   clearr  r  r  rS   r  r   s   &  rB   test_sendChunkedRequestBody(RequestTests.test_sendChunkedRequestBody  s     ".1'7NHE' 1 148T^^44h?001NN  "	
 	)	*""4(T^^44d;NN  "P	
rA   c                T  a  \        \        4      p\        RR\        V4      pVP	                  S P
                  4      pS P
                  P                  4        VP                  P                  \        4       4       V 3R lpS P                  V\        4      pVP                  V4       V# )ab  
If L{Request} is created with a C{bodyProducer} without a known length
and the L{Deferred} returned from its C{startProducing} method fires
with a L{Failure}, the L{Deferred} returned by L{Request.writeTo} fires
with that L{Failure} and the body producer is unregistered from the
transport.  The final zero-length chunk is not written to the
transport.
r  r  c                    < SP                  SP                  P                  4       R 4       SP                  SP                  P                  R4       R# r  )rM   rj   r   r-  r  r  s   &rB   rT   CRequestTests.test_sendChunkedRequestBodyWithError.<locals>.cbFailed<  s:    T^^113S9  !8!8$?rA   )r  r   r*   rh   r  rj   r  r  r  r8   rV   rW   )rS   r  r   writeDeferredrT   rZ   s   f     rB   $test_sendChunkedRequestBodyWithError1RequestTests.test_sendChunkedRequestBodyWithError-  s     ".1'7NHE7!!"4"67	@ }.@A	hrA   c                   \        ^4      p\        RR\        V4      pVP                  V P                  4       V P                  VP                  R4       V P                  V P                  P                  V4       V P                  V P                  P                  4       V P                  V P                  P                  4       R4       V P                  P                  4        VP                  P                  R4       VP                  P!                  R4       V P                  V P                  P                  R4       V P                  V P                  P                  4       R4       R# )z
If L{Request} is created with a C{bodyProducer} with a known length,
that length is sent as the value for the I{Content-Length} header and
chunked encoding is not used.
r  r  NsO   POST /bar HTTP/1.1
Connection: close
Content-Length: 3
Host: example.com

ru  )r  r*   rh   r  rj   r  r  r-  r  r   r  rM   r   r  r  r  r  r  s   &  rB   test_sendRequestBodyWithLength+RequestTests.test_sendRequestBodyWithLengthD  s    "!$'7NHE' 1 148T^^44h?001NN  "	
 	'""4(T^^44d;--/8rA   c                    \        VR\        R4      pVP                  V P                  4       V P	                  V P                  P                  4       VR,           4       R# )z
Verify that the message generated by a L{Request} initialized with
the given method and C{None} as the C{bodyProducer} includes
I{Content-Length: 0} in the header.

@param method: The HTTP method issue in the request.
@type method: L{bytes}
r  NsK    /foo HTTP/1.1
Connection: close
Content-Length: 0
Host: example.com

r  )rS   r  r   s   && rB   _sendRequestEmptyBodyWithLength,RequestTests._sendRequestEmptyBodyWithLengtha  sO     &'>4@'NN  "  	
rA   c                (    V P                  R4       R# )z
If I{PUT} L{Request} is created without a C{bodyProducer},
I{Content-Length: 0} is included in the header and chunked
encoding is not used.
s   PUTNr  rt   s   &rB   test_sendPUTRequestEmptyBody)RequestTests.test_sendPUTRequestEmptyBodyv  s     	,,V4rA   c                (    V P                  R4       R# )z
If I{POST} L{Request} is created without a C{bodyProducer},
I{Content-Length: 0} is included in the header and chunked
encoding is not used.
r  Nr  rt   s   &rB   test_sendPOSTRequestEmptyBody*RequestTests.test_sendPOSTRequestEmptyBody~  s     	,,W5rA   c                V   \        ^4      p\        RR\        V4      pVP                  V P                  4      pVP
                  P                  R4       VP                  P                  R4       V P                  V P                  P                  R4       V P                  V\        4      # )z
If L{Request} is created with a C{bodyProducer} with a known length and
the producer does not produce that many bytes, the L{Deferred} returned
by L{Request.writeTo} fires with a L{Failure} wrapping a
L{WrongBodyLength} exception.
r  r     abN)r  r*   rh   r  rj   r  r  r  r  r-  r  rV   r&   rS   r  r   r  s   &   rB   #test_sendRequestBodyWithTooFewBytes0RequestTests.test_sendRequestBodyWithTooFewBytes  s     "!$'7NHE7&""4(T^^44d;!!-AArA   c                  a aa \        ^4      o\        RR\        S4      pVP                  S P                  4      pSP
                  P                  R4       S P                  SP                  4       SP
                  P                  R4       S P                  SP                  4       S P                  S P                  P                  R4       VVV 3R lpS P                  V\        4      pVP                  V4       V# )a  
Verify that when too many bytes have been written by a body producer
and then the body producer's C{startProducing} L{Deferred} fires that
the producer is unregistered from the transport and that the
L{Deferred} returned from L{Request.writeTo} is fired with a L{Failure}
wrapping a L{WrongBodyLength}.

@param finisher: A callable which will be invoked with the body
    producer after too many bytes have been written to the transport.
    It should fire the startProducing Deferred somehow.
r  r  r     cdNc                 J  < SP                  SP                  P                  4       R 4       SP                  P                  4        SP	                  \
        SP                  P                  R4       S! S4       SP                  SP                  P                  4       R4       R# )sQ   POST /bar HTTP/1.1
Connection: close
Content-Length: 3
Host: example.com

abs   efrA   N)rM   rj   r   r  r   r   r  r  )r   finisherr  rS   s   &rB   rT   CRequestTests._sendRequestBodyWithTooManyBytesTest.<locals>.cbFailed  s     $$& NN  " k8+<+<+B+BEJ
 X T^^113S9rA   )r  r*   rh   r  rj   r  r  r   r  r   r-  r  rV   r&   rW   )rS   r  r   r  rT   rZ   r  s   ff    @rB   $_sendRequestBodyWithTooManyBytesTest1RequestTests._sendRequestBodyWithTooManyBytesTest  s     "!$'7NHE7& 	))*& 	(() 	T^^44d;	:: }o>	hrA   c                *    R pV P                  V4      # )
If L{Request} is created with a C{bodyProducer} with a known length and
the producer tries to produce more than than many bytes, the
L{Deferred} returned by L{Request.writeTo} fires with a L{Failure}
wrapping a L{WrongBodyLength} exception.
c                 <    V P                   P                  R 4       R # rs   r  r  r  s   &rB   r  CRequestTests.test_sendRequestBodyWithTooManyBytes.<locals>.finisher      &&t,rA   )r  rS   r  s   & rB   $test_sendRequestBodyWithTooManyBytes1RequestTests.test_sendRequestBodyWithTooManyBytes  s    	- 88BBrA   c                l   a a \         P                  ! S \        4      oVV 3R lpS P                  V4      # )r  c                 6  < V P                   P                  \        4       4       S^ ,          pSP                  RV4       VR,          pSP	                  VP
                  \        4       SP                  \        4      pSP                  \        V4      ^4       R# )rT  r  N)	r  r  r8   r
  r  r   r  rM   rN   )r  r  r   r  r  rS   s   &   rB   r  HRequestTests.test_sendRequestBodyErrorWithTooManyBytes.<locals>.finisher  sv    %%&8&:;NEMM-/m$A!!!''+=>++,>?FS[!,rA   )r   r  r   r  )rS   r  r  s   f @rB   )test_sendRequestBodyErrorWithTooManyBytes6RequestTests.test_sendRequestBodyErrorWithTooManyBytes  s0     +<<TCUV	- 88BBrA   c                Z   \         P                  ! V \        4      p\        ^4      p\	        RR\
        V4      pVP                  V P                  4       VP                  P                  pVP                  P                  R4       VP                  P                  R4       VP                  \        4       4       V^ ,          pV P                  RV4       VR,          pV P!                  VP"                  \        4       V P%                  \'        V P)                  \        4      4      ^4       R# )aZ  
Though there should be no way for the internal C{finishedConsuming}
L{Deferred} in L{Request._writeToBodyProducerContentLength} to fire a
L{Failure} after the C{finishedProducing} L{Deferred} has fired, in
case this does happen, the error should be logged with a message about
how there's probably a bug in L{Request}.

This is a whitebox test.
r  r  ru  Nr  )r   r  r   r  r*   rh   r  rj   r  	_finishedr  r  r  r  r8   r
  r  r   rM   rN   r  )rS   r  r  r   finishedConsumingr  r   s   &      rB   *test_sendRequestBodyErrorWithConsumerError7RequestTests.test_sendRequestBodyErrorWithConsumerError  s     +<<TCUV!!$'7NHE'$--77'""4(!!"4"67AmU+- agg'9:T334FGH!LrA   c                   \        ^4      p\        RR\        V4      pVP                  V P                  4      pVP
                  P                  R4       V! V4       V P                  V P                  P                  R4       V P                  P                  4        V P                  \        VP
                  P                  R4       V P                  V P                  P                  4       R4       V# )z
Verify that if the body producer fires its Deferred and then keeps
writing to the consumer that the extra writes are ignored and the
L{Deferred} returned by L{Request.writeTo} fires with a L{Failure}
wrapping the most appropriate exception type.
r  r  r  Nr  rA   )r  r*   rh   r  rj   r  r  r-  r  r  r   r   rM   r   )rS   r  r  r   r  s   &&   rB   -_sendRequestBodyFinishedEarlyThenTooManyBytes:RequestTests._sendRequestBodyFinishedEarlyThenTooManyBytes	  s     "!$'7NHE7&T^^44d;+x'8'8'>'>F--/5rA   c                R    R pV P                  V P                  V4      \        4      # )a  
If the request body producer indicates it is done by firing the
L{Deferred} returned from its C{startProducing} method but then goes on
to write too many bytes, the L{Deferred} returned by {Request.writeTo}
fires with a L{Failure} wrapping L{WrongBodyLength}.
c                 <    V P                   P                  R 4       R # rs   r  r  s   &rB   r  PRequestTests.test_sendRequestBodyFinishedEarlyThenTooManyBytes.<locals>.finisher-	  r   rA   )rV   r/  r&   r!  s   & rB   1test_sendRequestBodyFinishedEarlyThenTooManyBytes>RequestTests.test_sendRequestBodyFinishedEarlyThenTooManyBytes%	  s-    	- !!>>xH
 	
rA   c                R    R pV P                  V P                  V4      \        4      # )a  
If the request body producer indicates an error by firing the
L{Deferred} returned from its C{startProducing} method but then goes on
to write too many bytes, the L{Deferred} returned by {Request.writeTo}
fires with that L{Failure} and L{WrongBodyLength} is logged.
c                 L    V P                   P                  \        4       4       R # rs   )r  r  r8   r  s   &rB   r  ORequestTests.test_sendRequestBodyErroredEarlyThenTooManyBytes.<locals>.finisher=	  s    %%&8&:;rA   )rV   r/  r8   r!  s   & rB   0test_sendRequestBodyErroredEarlyThenTooManyBytes=RequestTests.test_sendRequestBodyErroredEarlyThenTooManyBytes5	  s-    	< !!>>xH
 	
rA   Nc                   \        \        4      p\        RR\        V4      pVP	                  V P
                  4      pVP                  P                  V4       V P
                  P                  4        V P                  \        VP                  P                  R4       V P                  V P
                  P                  4       R4       V# )z
If the request body producer with an unknown length tries to write
after firing the L{Deferred} returned by its C{startProducing} method,
the C{write} call raises an exception and does not write anything to
the underlying transport.
r  r  r   rA   )r  r   r*   rh   r  rj   r  r  r  r   r   r  r  rM   r   )rS   _withr  r   r  s   &&   rB   0test_sendChunkedRequestBodyFinishedThenWriteMore=RequestTests.test_sendChunkedRequestBodyFinishedThenWriteMoreE	  s     ".1'7NHE7""5)+x'8'8'>'>G--/5rA   c                r    V P                  \        \        4       4      4      pV P                  V\        4      # )z
If the request body producer with an unknown length tries to write
after firing the L{Deferred} returned by its C{startProducing} method
with a L{Failure}, the C{write} call raises an exception and does not
write anything to the underlying transport.
)r=  r   r8   rV   )rS   rZ   s   & rB   9test_sendChunkedRequestBodyFinishedWithErrorThenWriteMoreFRequestTests.test_sendChunkedRequestBodyFinishedWithErrorThenWriteMoreV	  s6     AA&()
 !!!%788rA   c                   \        ^4      p\        RR\        V4      pVP                  V P                  4      pV P                  V P                  P                  V4       V P                  V P                  P                  4       VP                  P                  R4       V P                  V P                  P                  4       R4       V P                  V P                  P                  4       VP                  P!                  \#        \%        4       4      4       V P                  V P                  P                  4       V P                  V P                  P                  R4       V P'                  V\$        4      # )z
If the L{Deferred} returned from the C{startProducing} method of the
L{IBodyProducer} passed to L{Request} fires with a L{Failure}, the
L{Deferred} returned from L{Request.writeTo} fails with that
L{Failure}.
r  r  r  sQ   POST /bar HTTP/1.1
Connection: close
Content-Length: 5
Host: example.com

abN)r  r*   rh   r  rj   r-  r  r   r  r  r  rM   r   r   r  r  r  r   r8   rV   r  s   &   rB   test_sendRequestBodyWithError*RequestTests.test_sendRequestBodyWithErrorb	  s    "!$'7NHE7 	T^^44h?001&NN  "	
 	556!!'*<*>"?@ 	556 	T^^44d;!!-1CDDrA   c           	        \        RR\        / 4      R4      pV P                  \        VP                  V P
                  4       V P                  V P
                  P                  4       R4       \        RR\        RRR./4      R4      pV P                  \        VP                  V P
                  4       V P                  V P
                  P                  4       R4       R# )z
L{Request.writeTo} raises L{BadHeaders} if there is not exactly one
I{Host} header and writes nothing to the given transport.
r   r   NrA   s   HostrF   s   example.org)r*   r2   r   r   r  rj   rM   r   )rS   r   s   & rB   test_hostHeaderRequired$RequestTests.test_hostHeaderRequired	  s    
 &$T:*goot~~F--/5D'7^^,L"MNPT
 	*goot~~F--/5rA   c                   \        ^4      p\        RR\        V4      pVP                  V P                  4       V P                  VP                  4       VP                  4        V P                  VP                  4       R# )zK
L{Request.stopWriting} calls its body producer's C{stopProducing}
method.
r   r   N)	r  r*   rh   r  rj   r   r  r  r   r  s   &  rB   test_stopWritingRequestTests.test_stopWriting	  s`    
 "!$&$A'))*(()rA   c                   \         P                  ! V \        4      p\        ^4      pR pW2n        \        RR\        V4      pVP                  V P                  4       VP                  4        V P                  \        V P                  \        4      4      ^4       V P                  ^\        V4      4       V^ ,          pV P                  RV4       VR,          pV P!                  VP"                  \        4       R# )z~
If the body producer's C{stopProducing} method raises an exception,
L{Request.stopWriting} logs it and does not re-raise it.
c                      \        R 4      hzstopProducing is bustedr  r9   rA   rB   brokenStopProducingBRequestTests.test_brokenStopProducing.<locals>.brokenStopProducing	  s    $%>??rA   r   r   r  N)r   r  r   r  r  r*   rh   r  rj   r  rM   rN   r  r8   r  r
  r  r   )rS   r  r  rN  r   r  r   s   &      rB   test_brokenStopProducing%RequestTests.test_brokenStopProducing	  s    
 +<<TCUV!!$	@ "5&$A'T334FGH!L!S-.AmU+- agg'9:rA   ri   rs   ) r;   r<   r=   r>   r?   r  r  r  r  r  r  r  r  r  r	  r  r  r  r"  r'  r,  r/  r4  r9  r=  r@  rC  rF  rI  rP  r@   r   r   s   @rB   r  r    s     +
	

"C"
B.9:
*56B?BCC(M6&
 
 "
9%EN6
*; ;rA   r  c                   X   a  ] tR tRt o RtR tR tR tRR ltR t	R t
R	 tR
 tRtV tR# )LengthEnforcingConsumerTestsi	  z'
Tests for L{LengthEnforcingConsumer}.
c                    \        4       V n        \        ^
4      V n        \	        4       V n        \        V P                  V P
                  V P                  4      V n        R# )
   N)r   r0  r  r  r   rj   r"   enforcerrt   s   &rB   r  "LengthEnforcingConsumerTests.setUp	  s@    j&r*(*/MM4>>4;;
rA   c                N   V P                   P                  R4       V P                  V P                  P	                  4       R4       V P                  P                  4        V P                   P                  R4       V P                  V P                  P	                  4       R4       R# )z
L{LengthEnforcingConsumer.write} calls the wrapped consumer's C{write}
method with the bytes it is passed as long as there are fewer of them
than the C{length} attribute indicates remain to be received.
ru  s   defN)rV  r  rM   rj   r   r  rt   s   &rB   
test_write'LengthEnforcingConsumerTests.test_write	  sr     	F#--/8F#--/8rA   c                    V P                   P                  R4       V P                  \        V P                   P                  4       R# )z
L{LengthEnforcingConsumer._noMoreWritesExpected} raises
L{WrongBodyLength} if it is called before the indicated number of bytes
have been written.
Ns	   xxxxxxxxx)rV  r  r   r&   _noMoreWritesExpectedrt   s   &rB   test_finishedEarly/LengthEnforcingConsumerTests.test_finishedEarly	  s0     	H%/4==+N+NOrA   c                   V P                   P                  R4       V P                  V P                  P                  4       V P                   P                  R4       V P                  V P                  P                  4       V'       d   V P                   P                  4        V P                  V P                  \        4      # )a  
If it is called with a total number of bytes exceeding the indicated
limit passed to L{LengthEnforcingConsumer.__init__},
L{LengthEnforcingConsumer.write} fires the L{Deferred} with a
L{Failure} wrapping a L{WrongBodyLength} and also calls the
C{stopProducing} method of the producer.
   x
   xxxxxxxxxx)
rV  r  r   r  r  r   r\  rV   r0  r&   )rS   _unregisterAfters   &&rB   test_writeTooMany.LengthEnforcingConsumerTests.test_writeTooMany	  s     	I&../D!--.MM//1!!$++??rA   c                Z   V P                   P                  R4       V P                   P                  4        V P                  V P                  P
                  4       V P                  \        V P                   P                  R4       V P                  V P                  P
                  4       R# )z
If L{LengthEnforcingConsumer.write} is called after
L{LengthEnforcingConsumer._noMoreWritesExpected}, it calls the
producer's C{stopProducing} method and raises L{ExcessWrite}.
r`  Nra  )	rV  r  r\  r   r  r  r   r   r   rt   s   &rB   test_writeAfterNoMoreExpected:LengthEnforcingConsumerTests.test_writeAfterNoMoreExpected	  sp     	I&++-../+t}}':':DA--.rA   c                $    V P                  R4      # )z
L{LengthEnforcingConsumer._noMoreWritesExpected} does nothing (in
particular, it does not raise any exception) if called after too many
bytes have been passed to C{write}.
T)rc  rt   s   &rB   test_finishedLate.LengthEnforcingConsumerTests.test_finishedLate	  s     %%d++rA   c                    V P                   P                  R4       V P                  V P                   P                  4       R4       R# )z
If L{LengthEnforcingConsumer._noMoreWritesExpected} is called after
the correct number of bytes have been written it returns L{None}.
Nra  )rV  r  r-  r\  rt   s   &rB   test_finished*LengthEnforcingConsumerTests.test_finished
  s3    
 	I&T]]@@BDIrA   c                   a  V 3R lpVS P                   n        V 3R lpS P                  4       pVP                  V4       V# )a  
If L{LengthEnforcingConsumer.write} calls the producer's
C{stopProducing} because too many bytes were written and the
C{stopProducing} method raises an exception, the exception is logged
and the L{LengthEnforcingConsumer} still errbacks the finished
L{Deferred}.
c                  X   < \         P                  S P                  4       \        R 4      hrM  )r  r  r  r8   rt   s   rB   rN  RLengthEnforcingConsumerTests.test_stopProducingRaises.<locals>.brokenStopProducing
  s!    ((7$%>??rA   c                 d   < SP                  \        SP                  \        4      4      ^4       R# )rg   N)rM   rN   r  r8   r  s   &rB   
cbFinishedILengthEnforcingConsumerTests.test_stopProducingRaises.<locals>.cbFinished
  s$    S!7!78J!KLaPrA   )r  r  rc  rW   )rS   rN  rr  rZ   s   f   rB   test_stopProducingRaises5LengthEnforcingConsumerTests.test_stopProducingRaises

  s>    	@ ':#	Q ""$	j!rA   )rV  r  r0  rj   N)F)r;   r<   r=   r>   r?   r  rY  r]  rc  rf  ri  rl  rt  r@   r   r   s   @rB   rS  rS  	  s:     

9P@ 
/,J rA   rS  c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )RequestBodyConsumerTestsi!
  z
Tests for L{ChunkedEncoder} which sits between an L{ITransport} and a
request/response body producer and chunked encodes everything written to
it.
c           	     f    V P                  \        \        \        \	        4       4      4      4       R# )z3
L{ChunkedEncoder} instances provide L{IConsumer}.
N)r   r   r   r   r   rt   s   &rB   test_interface'RequestBodyConsumerTests.test_interface(
  s     	Y?P0QRSrA   c                   \        4       p\        V4      pVP                  R4       V P                  VP	                  4       R4       VP                  4        VP                  R4       V P                  VP	                  4       R4       R# )ze
L{ChunkedEncoder.write} writes to the transport the chunked encoded
form of the bytes passed to it.
r   rO  Ns   xxxxxxxxxxxxxxxxs   10
xxxxxxxxxxxxxxxx
)r   r   r  rM   r   r  )rS   rj   encoders   &  rB   rY  #RequestBodyConsumerTests.test_write.
  sg    
 $%	 +f*O<i *,KLrA   c                n   \        4       p\        4       p\        V4      pVP                  VR4       V P	                  VP
                  V4       V P                  VP                  4       VP                  4        V P	                  VP
                  R4       V P                  VP                  4       R4       R# )z
L{ChunkedEncoder.registerProducer} registers the given streaming
producer with its transport and L{ChunkedEncoder.unregisterProducer}
writes a zero-length chunk to its transport and unregisters the
transport's producer.
TNs   0

)r   r   r   registerProducerr-  r  r   r  unregisterProducerrM   r   )rS   rj   r  r|  s   &   rB   test_producerRegistration2RequestBodyConsumerTests.test_producerRegistration;
  s     $%	8 +  40Y//:	++,""$Y//6*L9rA   r9   N)
r;   r<   r=   r>   r?   ry  rY  r  r@   r   r   s   @rB   rw  rw  !
  s      TM: :rA   rw  c                   N   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V tR# )TransportProxyProducerTestsiM
  zb
Tests for L{TransportProxyProducer} which proxies the L{IPushProducer}
interface of a transport.
c                V    V P                  \        \        \        R4      4      4       R# )z?
L{TransportProxyProducer} instances provide L{IPushProducer}.
N)r   r   r   r%   rt   s   &rB   ry  *TransportProxyProducerTests.test_interfaceS
  s     	]4J44PQRrA   c                    \        4       p\        V4      pV P                  VP                  V4       VP	                  4        V P                  VP                  R4       R# )zf
L{TransportProxyProducer.stopProxying} drops the reference to the
wrapped L{IPushProducer} provider.
N)r   r%   r-  rZ  stopProxyingrS   rj   proxys   &  rB   %test_stopProxyingUnreferencesProducerATransportProxyProducerTests.test_stopProxyingUnreferencesProducerY
  sJ    
 $%	&y1U__i8U__d3rA   c                x   \        4       pVP                  4        \        V4      pV P                  VP                  R4       VP                  4        V P                  VP                  R4       VP                  4        VP                  4        VP                  4        V P                  VP                  R4       R# )z
L{TransportProxyProducer.resumeProducing} calls the wrapped
transport's C{resumeProducing} method unless told to stop proxying.
rC  r  N)r   r  r%   rM   r  r  r  r  s   &  rB   test_resumeProducing0TransportProxyProducerTests.test_resumeProducingd
  s    
 $%	  "&y100(;00+>  " 	00(;rA   c                X   \        4       p\        V4      pV P                  VP                  R4       VP	                  4        V P                  VP                  R4       VP                  4        VP                  4        VP	                  4        V P                  VP                  R4       R# )z
L{TransportProxyProducer.pauseProducing} calls the wrapped transport's
C{pauseProducing} method unless told to stop proxying.
r  rC  N)r   r%   rM   r  r  r  r  r  s   &  rB   test_pauseProducing/TransportProxyProducerTests.test_pauseProducingz
  s    
 $%	&y100+>00(;!!# 	00+>rA   c                b   \        4       p\        V4      pV P                  VP                  R4       VP	                  4        V P                  VP                  R4       \        4       p\        V4      pVP                  4        VP	                  4        V P                  VP                  R4       R# )z}
L{TransportProxyProducer.stopProducing} calls the wrapped transport's
C{stopProducing} method unless told to stop proxying.
r  r  N)r   r%   rM   r  r  r  r  s   &  rB   test_stopProducing.TransportProxyProducerTests.test_stopProducing
  s    
 $%	&y100+>00)<#%	&y100+>rA   c                n   \        4       p\        4       pVP                  V4       W!n        \	        V4      pV P                  VP                  4       V P                  VP                  R4       VP                  4        V P                  VP                  R4       V P                  VP                  4       R# )z[
L{TransportProxyProducer.loseConnection} calls the wrapped transport's
C{loseConnection}.
r  N)r   r   r   r   r%   r   	connectedrM   r  loseConnectionr   rS   rj   r   r  s   &   rB    test_loseConnectionWhileProxying<TransportProxyProducerTests.test_loseConnectionWhileProxying
  s    
 56	')	*%&y1	++,00+> 	00+>,,-rA   c                   \        4       p\        4       pVP                  V4       W!n        \	        V4      pVP                  4        V P                  VP                  4       VP                  4        V P                  VP                  4       R# )zU
L{TransportProxyProducer.loseConnection} does nothing when the
proxy is not active.
N)	r   r   r   r   r%   r  r   r  r  r  s   &   rB   test_loseConnectionNotProxying:TransportProxyProducerTests.test_loseConnectionNotProxying
  sp    
 56	')	*%&y1	++, 		++,rA   r9   N)r;   r<   r=   r>   r?   ry  r  r  r  r  r  r  r@   r   r   s   @rB   r  r  M
  s3     
S	4<,?*?(.*- -rA   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V tR# )ResponseTestsi
  z
Tests for L{Response}.
c                j    \        \        4       4      pV P                  \        \        V4      4       R# )z-
L{Response} instances provide L{IResponse}.
N)rk   r   r   r   r4   rS   r   s   & rB   test_verifyInterface"ResponseTests.test_verifyInterface
  s$     )):;Y9:rA   c                B  a . o\        4       p ! V3R lR\        4      pV! 4       p\        V4      pVP                  V4       Sw  pVP	                  4        V P                  VP                  R4       VP                  4        V P                  VP                  R4       R# )z
The L{IProtocol} provider passed to L{Response.deliverBody} has its
C{makeConnection} method called with an L{IPushProducer} provider
hooked up to the response as an argument.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )7ResponseTests.test_makeConnection.<locals>.SomeProtocoli
  c                *   < SP                  V4       R # rs   r  )rS   r  	producerss   &&rB   r   FResponseTests.test_makeConnection.<locals>.SomeProtocol.makeConnection
  s      *rA   r9   Nr;   r<   r=   r>   r   r@   r   )r   r  s   @rB   SomeProtocolr  
  s     + +rA   r  rC  r  N)r   r   rk   r)  r  rM   r  r  )rS   rj   r  r  r   theProducerr  s   &     @rB   test_makeConnection!ResponseTests.test_makeConnection
  s     	#%		+8 	+  >(3X&!""$00(;##%00+>rA   c                   a . o ! V3R lR\         4      pV! 4       p\        \        4       4      pVP                  V4       VP	                  R4       V P                  SR.4       R# )z
The L{IProtocol} provider passed to L{Response.deliverBody} has its
C{dataReceived} method called with bytes received as part of the
response body.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )5ResponseTests.test_dataReceived.<locals>.ListConsumeri
  c                *   < SP                  V4       R # rs   r  rS   r   r   s   &&rB   r   BResponseTests.test_dataReceived.<locals>.ListConsumer.dataReceived
      T"rA   r9   Nr;   r<   r=   r>   r   r@   r   r   r   s   @rB   ListConsumerr  
       # #rA   r  r   N)r   rk   r   r)  r  rM   )rS   r  r  r   r   s   &   @rB   test_dataReceivedResponseTests.test_dataReceived
  sZ     	#8 	#  >():;X&""6*)rA   c                L  a . o ! V3R lR\         4      pV! 4       p\        \        4       4      pVP                  V4       VP	                  4        S^ ,          P                  \        4       V P                  \        S4      ^4       V P                  VP                  R4       R# )z
The L{IProtocol} provider passed to L{Response.deliverBody} has its
C{connectionLost} method called with a L{Failure} wrapping
L{ResponseDone} when the response's C{_bodyDataFinished} method is
called.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )7ResponseTests.test_connectionLost.<locals>.ListConsumeri	  c                *   < SP                  V4       R # rs   r  )rS   rP   losts   &&rB   rq  FResponseTests.test_connectionLost.<locals>.ListConsumer.connectionLost
  s    F#rA   r9   N)r;   r<   r=   r>   rq  r@   r   )r   r  s   @rB   r  r  	  s     $ $rA   r  N)r   rk   r   r)  r  rL   r.   rM   rN   r-  _bodyProtocol)rS   r  r  r   r  s   &   @rB   test_connectionLost!ResponseTests.test_connectionLost   s     	$8 	$  >():;X&""$Q\"TA& 	X33T:rA   c                L  a . o ! V3R lR\         4      pV! 4       p\        \        4       4      pVP                  R4       VP                  R4       VP	                  V4       VP                  R4       V P                  S. RO4       V P                  VP                  R4       R# )z
If data is delivered to the L{Response} before a protocol is registered
with C{deliverBody}, that data is buffered until the protocol is
registered and then is delivered.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )8ResponseTests.test_bufferEarlyData.<locals>.ListConsumeri!  c                *   < SP                  V4       R # rs   r  r  s   &&rB   r   EResponseTests.test_bufferEarlyData.<locals>.ListConsumer.dataReceived"  r  rA   r9   Nr  r  s   @rB   r  r  !  r  rA   r  r   r   r   N)r   r   r   )r   rk   r   r  r)  rM   r-  _bodyBuffer)rS   r  r   r   r   s   &   @rB   test_bufferEarlyData"ResponseTests.test_bufferEarlyData  s     	#8 	#  >():;""6*""6*X&""6* 89 	X1148rA   c                    \        \        4       4      pVP                  \        4       4       V P	                  \
        VP                  \        4       4       R# )zJ
L{Response.deliverBody} raises L{RuntimeError} if called more than
once.
N)rk   r   r)  r   r   r   r  s   & rB    test_multipleStartProducingFails.ResponseTests.test_multipleStartProducingFails0  s;    
 )):;XZ(,(<(<hjIrA   c                    \        \        4       4      pVP                  \        4       4       VP	                  4        V P                  \        VP                  \        4       4       R# )z_
L{Response.deliverBody} raises L{RuntimeError} if called after
L{Response._bodyDataFinished}.
N)rk   r   r)  r   r  r   r   r  s   & rB   %test_startProducingAfterFinishedFails3ResponseTests.test_startProducingAfterFinishedFails9  sG    
 )):;XZ(""$,(<(<hjIrA   c                    \        \        4       4      pVP                  4        V P                  \        VP
                  R4       R# )z
L{Response._bodyDataReceived} raises L{RuntimeError} if called after
L{Response._bodyDataFinished} but before L{Response.deliverBody}.
r   N)rk   r   r  r   r   r  r  s   & rB   'test_bodyDataReceivedAfterFinishedFails5ResponseTests.test_bodyDataReceivedAfterFinishedFailsC  s5    
 )):;""$,(B(BFKrA   c                    \        \        4       4      pVP                  4        VP                  \	        4       4       V P                  \        VP                  R4       R# )z
L{Response._bodyDataReceived} raises L{RuntimeError} if called after
L{Response._bodyDataFinished} and after L{Response.deliverBody}.
r   N)rk   r   r  r)  r   r   r   r  r  s   & rB   'test_bodyDataReceivedAfterDeliveryFails5ResponseTests.test_bodyDataReceivedAfterDeliveryFailsL  sE    
 )):;""$XZ(,(B(BFKrA   c                    \        \        4       4      pVP                  4        V P                  \        VP                  4       R# )zP
L{Response._bodyDataFinished} raises L{RuntimeError} if called more
than once.
N)rk   r   r  r   r   r  s   & rB   'test_bodyDataFinishedAfterFinishedFails5ResponseTests.test_bodyDataFinishedAfterFinishedFailsV  s3    
 )):;""$,(B(BCrA   c                    \        \        4       4      pVP                  4        VP                  \	        4       4       V P                  \        VP                  4       R# )zc
L{Response._bodyDataFinished} raises L{RuntimeError} if called after
the body has been delivered.
N)rk   r   r  r)  r   r   r   r  s   & rB   'test_bodyDataFinishedAfterDeliveryFails5ResponseTests.test_bodyDataFinishedAfterDeliveryFails_  sC    
 )):;""$XZ(,(B(BCrA   c                @  a . o ! V3R lR\         4      p\        4       pVP                  4        V! 4       p\        V4      pV P	                  VP
                  R4       VP                  V4       V P	                  SR.4       V P	                  VP
                  R4       R# )z~
L{Response.deliverBody} resumes the HTTP connection's transport
after passing it to the consumer's C{makeConnection} method.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )9ResponseTests.test_transportResumed.<locals>.ListConsumerip  c                >   < SP                  VP                  4       R # rs   )r   r  )rS   rj   transportStates   &&rB   r   HResponseTests.test_transportResumed.<locals>.ListConsumer.makeConnectionq  s    %%i&=&=>rA   r9   Nr  )r   r  s   @rB   r  r  p  s     ? ?rA   r  rC  r  N)r   r   r  rk   rM   r  r)  )rS   r  rj   r   r   r  s   &    @rB   test_transportResumed#ResponseTests.test_transportResumedi  s    
 	?8 	? $%	  ">(300(;X&(400+>rA   c                @   \        4       p\        V4      pVP                  R4       VP                  R4       VP                  4        \	        4       pVP                  V4       V P                  VP                  R4       VP                  P                  \        4       R# )z
If the entire body is delivered to the L{Response} before the
response's C{deliverBody} method is called, the protocol passed to
C{deliverBody} is immediately given the body data and then
disconnected.
r   r   r/  N)r   rk   r  r  r   r)  rM   r   rE  rL   r.   rS   rj   r   r   s   &   rB   )test_bodyDataFinishedBeforeStartProducing7ResponseTests.test_bodyDataFinishedBeforeStartProducing}  s|     $%	(3""6*""6*""$')X&	2""<0rA   c                    \        4       p\        V4      p\        4       pVP                  V4       V P	                  VP
                  R4       VP                  \        \        4       4      4       VP                  P                  \        4       R# )z
The L{Failure} passed to L{Response._bodyDataFinished} when the response
is in the I{connected} state is passed to the C{connectionLost} method
of the L{IProtocol} provider passed to the L{Response}'s
C{deliverBody} method.
	CONNECTEDN)r   rk   r   r)  rM   r   r  r   r8   rE  rL   r  s   &   rB   #test_finishedWithErrorWhenConnected1ResponseTests.test_finishedWithErrorWhenConnected  sn     $%	(3')X& 	+6""7+=+?#@A""#56rA   c                    \        4       p\        V4      pV P                  VP                  R4       VP	                  \        \        4       4      4       \        4       pVP                  V4       VP                  P                  \        4       R# )z
The L{Failure} passed to L{Response._bodyDataFinished} when the response
is in the I{initial} state is passed to the C{connectionLost} method of
the L{IProtocol} provider passed to the L{Response}'s C{deliverBody}
method.
INITIALN)r   rk   rM   r   r  r   r8   r   r)  rE  rL   r  s   &   rB   !test_finishedWithErrorWhenInitial/ResponseTests.test_finishedWithErrorWhenInitial  sn     $%	(3 	)4""7+=+?#@A')X&""#56rA   r9   N)r;   r<   r=   r>   r?   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r@   r   r   s   @rB   r  r  
  s`     ;?,*&;29.JJLLDD?(1$7&7 7rA   r  N)_r?   typingr   zope.interfacer   zope.interface.verifyr   twisted.internet.deferr   r   r   r   twisted.internet.errorr	   r
   twisted.internet.interfacesr   r   twisted.internet.protocolr   twisted.internet.testingr   r   r   r   twisted.loggerr   twisted.protocols.basicr   twisted.python.failurer   twisted.trial.unittestr   twisted.web._newclientr   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   twisted.web.clientr(   r)   r*   r+   r,   r-   r.   r/   r0   twisted.web.httpr1   twisted.web.http_headersr2   twisted.web.iwebr3   r4   twisted.web.test.requesthelperr5   r6   	Exceptionr8   rD   rh   r[   r^   r`   rb   rk   rm   r   r   r   r   r  r  r  r  r  rS  rw  r  r  r9   rA   rB   <module>r     s    & . J J A @ .  . 0 * +    (
 
 
 ' , 5 	  'N#345%PTL6( 6BSM SMl+;X .> h
.H h
.V 0 fE fER ]     Fp;8 p;fb8 bJ):x ):X{-( {-|h7H h7rA   