Ë
    oj4« ã                   ó  — d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZ ddlmZmZ ddlmZ dd	lmZmZmZmZ dd
lmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZCmDZD ddlEmFZFmGZG  G d„ deH«      ZI G d„ deH«      ZJ eAddgi«      ZKd„ ZLd„ ZMd„ ZNd„ ZOd„ ZP G d„ d e «      ZQ G d!„ d"«      ZR G d#„ d$eRe «      ZS G d%„ d&eRe «      ZT G d'„ d(e «      ZU G d)„ d*«      ZV G d+„ d,«      ZW G d-„ d.e «      ZX eeC«       G d/„ d0«      «       ZY G d1„ d2e «      ZZ G d3„ d4e «      Z[ G d5„ d6e «      Z\ G d7„ d8e «      Z] G d9„ d:e «      Z^y;)<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                   ó   — e Zd ZdZy)ÚArbitraryExceptionze
    A unique, arbitrary exception type which L{twisted.web._newclient} knows
    nothing about.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úA/usr/lib/python3/dist-packages/twisted/web/test/test_newclient.pyr9   r9   C   s   „ òr@   r9   c                   ó   — e Zd ZdZy)ÚAnotherArbitraryExceptionzI
    Similar to L{ArbitraryException} but with a different identity.
    Nr:   r?   r@   rA   rC   rC   J   s   „ òr@   rC   ó   hostó   example.comc                 ó\   ‡ ‡— ˆˆ fd„}‰ j                  ||«      }|j                  |«       |S )a•  
    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           	      óæ   •— t        | j                  ‰«      D ]  \  }}|j                  |«       Œ ‰j                  t	        | j                  «      t	        ‰«      d| j                  › d‰› d�«       | S )Nzlen(z	) != len(ú))ÚzipÚreasonsÚtrapÚassertEqualÚlen)ÚerrÚreasonÚtypeÚreasonTypesÚselfs      €€rA   ÚcbFailedz-assertWrapperExceptionTypes.<locals>.cbFailedn   sl   ø€ Ü §¡¨[Ó9ò 	‰LˆF�DØ�K‰K˜Õð	à×ÑÜ�—‘ÓÜ�ÓØ�3—;‘;�-˜y¨¨°QÐ7ô	
ð
 ˆ
r@   )ÚassertFailureÚaddCallback)rR   ÚdeferredÚmainTyperQ   rS   Úds   `  `  rA   ÚassertWrapperExceptionTypesrY   U   s-   ù€ õ2ð 	×Ñ˜8 XÓ.€AØ‡M�M�(ÔØ€Hr@   c                 ó&   — t        | |t        |«      S )zo
    A simple helper to invoke L{assertWrapperExceptionTypes} with a C{mainType}
    of L{ResponseFailed}.
    )rY   r0   ©rR   rV   rQ   s      rA   ÚassertResponseFailedr\   }   s   € ô
 ' t¨X´~À{ÓSÐSr@   c                 ó&   — t        | |t        |«      S )zx
    A simple helper to invoke L{assertWrapperExceptionTypes} with a C{mainType}
    of L{RequestGenerationFailed}.
    )rY   r,   r[   s      rA   ÚassertRequestGenerationFailedr^   …   s   € ô
 'ØˆhÔ/°óð r@   c                 ó&   — t        | |t        |«      S )zz
    A simple helper to invoke L{assertWrapperExceptionTypes} with a C{mainType}
    of L{RequestTransmissionFailed}.
    )rY   r-   r[   s      rA   ÚassertRequestTransmissionFailedr`   �   s   € ô
 'ØˆhÔ1°;óð r@   c                 ó(   — t        dddt        | «      S )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.
    ©s   HTTPé   rc   éÈ   ó   OK)r.   Ú_boringHeaders)Ú	transports    rA   ÚjustTransportResponserh   ™   s   € ô �O S¨%´ÀÓKÐKr@   c                   ó   — e Zd ZdZd„ Zy)ÚMakeStatefulDispatcherTestsz.
    Tests for L{makeStatefulDispatcher}.
    c                 ó  —  G d„ d«      } |«       }| j                  |j                  «       d«       d|_        | j                  |j                  «       d«       d|_        | j                  t        |j                  «       y)z‹
        A method defined with L{makeStatefulDispatcher} invokes a second
        method based on the current state of the object.
        c                   ó4   — e Zd ZdZd„ Z ede«      Zd„ Zd„ Zy)úCMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.FooÚAc                  ó   — y ©Nr?   ©rR   s    rA   ÚbarzGMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo.bar±   s   € Ør@   Úquuxc                  ó   — y)NÚar?   rq   s    rA   Ú_quux_AzKMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo._quux_A¶   ó   € Ør@   c                  ó   — y)NÚbr?   rq   s    rA   Ú_quux_BzKMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo._quux_B¹   rw   r@   N)r;   r<   r=   Ú_staterr   r(   rv   rz   r?   r@   rA   ÚFoorm   ®   s$   „ ØˆFòñ )¨°Ó5ˆCòór@   r|   ru   ÚBry   ÚCN)rL   rr   r{   ÚassertRaisesÚRuntimeError)rR   r|   Ústatefuls      rA   Útest_functionCalledByStatez6MakeStatefulDispatcherTests.test_functionCalledByState¨   sc   € ÷	ñ 	ñ “5ˆØ×Ñ˜Ÿ™›¨Ô-ØˆŒØ×Ñ˜Ÿ™›¨Ô-ØˆŒØ×Ñœ,¨¯©Õ5r@   N)r;   r<   r=   r>   r‚   r?   r@   rA   rj   rj   £   s   „ ñó6r@   rj   c                   ób   — e Zd ZU dZdZee   ed<   d„ Zd„ Z	d„ Z
d„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zy)Ú_HTTPParserTestszt
    Base test class for L{HTTPParser} which is responsible for the bulk of
    the task of parsing HTTP bytes.
    NÚsepc                 óR  — g }t        «       }|j                  |_        |j                  t	        «       «       | j                  |j                  t        «       |j                  d| j                  z   «       | j                  |dg«       | j                  |j                  t        «       y)zj
        L{HTTPParser} calls its C{statusReceived} method when it receives a
        status line.
        ó   HTTP/1.1 200 OKN)r"   ÚappendÚstatusReceivedÚmakeConnectionr   rL   Ústater   ÚdataReceivedr…   r   )rR   ÚstatusÚprotocols      rA   Útest_statusCallbackz$_HTTPParserTests.test_statusCallbackÌ   s�   € ð
 ˆÜ“<ˆØ"(§-¡-ˆÔØ×Ñ¤Ó 1Ô2Ø×Ñ˜Ÿ™¬Ô0Ø×ÑÐ0°4·8±8Ñ;Ô<Ø×Ñ˜Ð"4Ð!5Ô6Ø×Ñ˜Ÿ™¬Õ0r@   c                 ó²   — i }t        «       }|j                  |_        |j                  t	        «       «       |j                  d| j                  z   «       ||fS )Nr‡   )r"   Ú__setitem__ÚheaderReceivedrŠ   r   rŒ   r…   ©rR   ÚheaderrŽ   s      rA   Ú_headerTestSetupz!_HTTPParserTests._headerTestSetupÚ   sP   € ØˆÜ“<ˆØ"(×"4Ñ"4ˆÔØ×Ñ¤Ó 1Ô2Ø×ÑÐ0°4·8±8Ñ;Ô<Ø�xÐÐr@   c                 ó  — | j                  «       \  }}|j                  d| j                  z   «       |j                  | j                  «       | j                  |ddi«       | j                  |j                  t
        «       y)ze
        L{HTTPParser} calls its C{headerReceived} method when it receives a
        header.
        s	   X-Foo:baró   X-Fooó   barN©r•   rŒ   r…   rL   r‹   r   r“   s      rA   Útest_headerCallbackz$_HTTPParserTests.test_headerCallbackâ   sk   € ð
  ×0Ñ0Ó2Ñˆ�Ø×Ñ˜l¨T¯X©XÑ5Ô6ð 	×Ñ˜dŸh™hÔ'Ø×Ñ˜ (¨FÐ!3Ô4Ø×Ñ˜Ÿ™¬Õ.r@   c                 ó|  — | j                  «       \  }}|j                  d| j                  z   «       |j                  d| j                  z   «       |j                  d| j                  z   «       |j                  | j                  «       | j                  |ddi«       | j                  |j                  t
        «       y)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      rA   Útest_continuedHeaderCallbackz-_HTTPParserTests.test_continuedHeaderCallbackï   s˜   € ð
  ×0Ñ0Ó2Ñˆ�Ø×Ñ˜m¨d¯h©hÑ6Ô7Ø×Ñ˜g¨¯©Ñ0Ô1Ø×Ñ˜i¨$¯(©(Ñ2Ô3Ø×Ñ˜dŸh™hÔ'Ø×Ñ˜ (Ð,<Ð!=Ô>Ø×Ñ˜Ÿ™¬Õ.r@   c                 ó  — | j                  «       \  }}| j                  j                  g d¢«      }|j                  d|z   «       |j                  d|z   «       |j                  | j                  «       | j	                  |dddœ«       y)zŒ
        Leading and trailing linear whitespace is stripped from the header
        value passed to the C{headerReceived} callback.
        )s    	 s    bar 	s    	r@   s   X-Bar:s   X-Foo:r˜   )r—   s   X-BarN)r•   r…   ÚjoinrŒ   rL   )rR   r”   rŽ   Úvalues       rA   Útest_fieldContentWhitespacez,_HTTPParserTests.test_fieldContentWhitespaceü   sw   € ð
  ×0Ñ0Ó2Ñˆ�Ø—‘—‘Ò@ÓAˆØ×Ñ˜i¨%Ñ/Ô0Ø×Ñ˜i¨%Ñ/Ô0Ø×Ñ˜dŸh™hÔ'Ø×Ñ˜¨F¸fÑ!EÕFr@   c                 óð   ‡‡— g Š| j                  «       \  }Šˆˆfd„}|‰_        ‰j                  | j                  «       | j	                  ‰t
        g«       | j	                  ‰j                  t        «       y)zg
        After the last header is received, L{HTTPParser} calls
        C{allHeadersReceived}.
        c                  óR   •— ‰ j                  ‰j                  «       t        ‰_        y rp   )rˆ   r‹   r   )ÚcalledrŽ   s   €€rA   ÚallHeadersReceivedzD_HTTPParserTests.test_allHeadersCallback.<locals>.allHeadersReceived  s   ø€ Ø�M‰M˜(Ÿ.™.Ô)Ü#ˆH�Nr@   N)r•   r¥   rŒ   r…   rL   r   r‹   r   )rR   r”   r¥   r¤   rŽ   s      @@rA   Útest_allHeadersCallbackz(_HTTPParserTests.test_allHeadersCallback  sd   ù€ ð
 ˆØ×0Ñ0Ó2Ñˆ�õ	$ð '9ˆÔ#Ø×Ñ˜dŸh™hÔ'Ø×Ñ˜¤& Ô*Ø×Ñ˜Ÿ™¬Õ0r@   c                 óÄ   — | j                  «       \  }}|j                  | j                  «       | j                  |i «       | j                  |j                  t
        «       y)zp
        If there are no headers in the message, L{HTTPParser} does not call
        C{headerReceived}.
        Nr™   r“   s      rA   Útest_noHeaderCallbackz&_HTTPParserTests.test_noHeaderCallback  sM   € ð
  ×0Ñ0Ó2Ñˆ�Ø×Ñ˜dŸh™hÔ'Ø×Ñ˜ Ô$Ø×Ñ˜Ÿ™¬Õ.r@   c                 ó¨  — t        «       }|j                  t        «       «       |j                  d| j                  z   «       |j                  d| j                  z   «       |j                  d| j                  z   «       |j                  | j                  «       dddgfg}| j                  |t        |j                  j                  «       «      «       y)zc
        All headers received by L{HTTPParser} are added to
        L{HTTPParser.headers}.
        r‡   rœ   ó
   X-Foo: bazr—   r˜   ó   bazN)	r"   rŠ   r   rŒ   r…   rL   ÚlistÚheadersÚgetAllRawHeaders)rR   rŽ   Úexpecteds      rA   Útest_headersSavedOnResponsez,_HTTPParserTests.test_headersSavedOnResponse#  sª   € ô
 “<ˆØ×Ñ¤Ó 1Ô2Ø×ÑÐ0°4·8±8Ñ;Ô<Ø×Ñ˜m¨d¯h©hÑ6Ô7Ø×Ñ˜m¨d¯h©hÑ6Ô7Ø×Ñ˜dŸh™hÔ'Ø ¨Ð/Ð0Ð1ˆØ×Ñ˜¤4¨×(8Ñ(8×(IÑ(IÓ(KÓ#LÕMr@   c                 óº   — t        «       }g d¢}|D ]'  }| j                  |j                  |«      d|›d�«       Œ) | j                  |j                  d«      d«       y)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.
        )ó   content-lengthó
   connections
   keep-alives   tes   trailerss   transfer-encodings   upgrades   proxy-connectionz
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)r"   Ú
assertTrueÚisConnectionControlHeaderÚassertFalse)rR   rŽ   ÚconnHeaderNamesr”   s       rA   Útest_connectionControlHeadersz._HTTPParserTests.test_connectionControlHeaders1  sh   € ô “<ˆò	
ˆð &ò 	ˆFØ�O‰OØ×2Ñ2°6Ô:â"ð%õð	ð 	×ÑØ×.Ñ.¨wÓ7ð4õ	
r@   c                 óÎ   — t        «       }|j                  t        «       «       |j                  t	        «       «       | j                  t        |j                  t	        «       «       y)zi
        L{HTTPParser.switchToBodyMode} raises L{RuntimeError} if called more
        than once.
        N)r"   rŠ   r   ÚswitchToBodyModeÚobjectr   r€   ©rR   rŽ   s     rA   Útest_switchToBodyModez&_HTTPParserTests.test_switchToBodyModeO  sF   € ô
 “<ˆØ×Ñ¤Ó 1Ô2Ø×!Ñ!¤&£(Ô+Ø×Ñœ,¨×(AÑ(AÄ6Ã8ÕLr@   )r;   r<   r=   r>   r…   r   ÚbytesÚ__annotations__r�   r•   rš   r�   r¡   r¦   r¨   r°   r¸   r½   r?   r@   rA   r„   r„   Ä   sL   … ñð
  €Cˆ�%‰Óò1ò ò/ò/ò
Gò1ò"/òNò
ó<Mr@   r„   c                   ó   — e Zd ZdZdZy)Ú$HTTPParserRFCComplaintDelimeterTestsz<
    L{_HTTPParserTests} using standard CR LF newlines.
    ó   
N©r;   r<   r=   r>   r…   r?   r@   rA   rÁ   rÁ   Z  s   „ ñð �Cr@   rÁ   c                   ó   — e Zd ZdZdZy)Ú'HTTPParserNonRFCComplaintDelimeterTestsz5
    L{_HTTPParserTests} using bare LF newlines.
    ó   
NrÃ   r?   r@   rA   rÅ   rÅ   b  s   „ ñð �Cr@   rÅ   c                   ó¾   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z y) ÚHTTPClientParserTestszd
    Tests for L{HTTPClientParser} which is responsible for parsing HTTP
    response messages.
    c                 ó^   — t        dd«      }| j                  |j                  d«      d«       y)zj
        L{HTTPClientParser.parseVersion} parses a status line into its three
        components.
        Ns	   CANDY/7.2)s   CANDYé   é   )r!   rL   ÚparseVersionr¼   s     rA   Útest_parseVersionz'HTTPClientParserTests.test_parseVersionp  s,   € ô
 $ D¨$Ó/ˆØ×Ñ˜×.Ñ.¨|Ó<Ð>NÕOr@   c                 ó´   ‡ ‡‡— t        dd«      }t        Š|j                  Šˆˆˆ fd„} |d«        |d«        |d«        |d«        |d«        |d«       y)	zr
        L{HTTPClientParser.parseVersion} raises L{ValueError} when passed an
        unparsable version.
        Nc                 ód   •— ‰j                  ‰‰| «      }‰j                  |j                  | «       y rp   )r   rL   Údata)ÚsÚexcÚeÚfrR   s     €€€rA   ÚcheckParsingz@HTTPClientParserTests.test_parseBadVersion.<locals>.checkParsing�  s+   ø€ Ø×#Ñ# A q¨!Ó,ˆCØ×Ñ˜SŸX™X qÕ)r@   ó   foos   foo/bar/bazs   foo/s   foo/..s   foo/a.bs	   foo/-1.-1)r!   r   rÌ   )rR   rŽ   rÕ   rÓ   rÔ   s   `  @@rA   Útest_parseBadVersionz*HTTPClientParserTests.test_parseBadVersionx  sX   ú€ ô
 $ D¨$Ó/ˆÜˆØ×!Ñ!ˆö	*ñ 	�VÔÙ�^Ô$á�WÔÙ�YÔá�ZÔ Ù�\Õ"r@   c                 óx  — t        ddt        d«      }t        |d«      }|j                  t	        «       «       |j                  d«       | j                  |j                  j                  d«       | j                  |j                  j                  d«       | j                  |j                  j                  d«       y)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
rb   rd   re   ©r+   rf   r!   rŠ   r   rŒ   rL   ÚresponseÚversionÚcodeÚphrase©rR   ÚrequestrŽ   s      rA   Útest_responseStatusParsingz0HTTPClientParserTests.test_responseStatusParsingŽ  s”   € ô
 ˜& $¬¸Ó=ˆÜ# G¨TÓ2ˆØ×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5Ø×Ñ˜×*Ñ*×2Ñ2°OÔDØ×Ñ˜×*Ñ*×/Ñ/°Ô5Ø×Ñ˜×*Ñ*×1Ñ1°5Õ9r@   c                 óx  — t        ddt        d«      }t        |d«      }|j                  t	        «       «       |j                  d«       | j                  |j                  j                  d«       | j                  |j                  j                  d«       | j                  |j                  j                  d«       y)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
rb   rd   r@   rÜ   rá   s      rA   Ú test_responseStatusWithoutPhrasez6HTTPClientParserTests.test_responseStatusWithoutPhrase›  s”   € ô ˜& $¬¸Ó=ˆÜ# G¨TÓ2ˆØ×Ñ¤Ó 1Ô2Ø×ÑÐ1Ô2Ø×Ñ˜×*Ñ*×2Ñ2°OÔDØ×Ñ˜×*Ñ*×/Ñ/°Ô5Ø×Ñ˜×*Ñ*×1Ñ1°3Õ7r@   c                 óL   ‡ ‡— t        dd«      Šˆˆ fd„} |d«        |d«       y)zŒ
        L{HTTPClientParser.statusReceived} raises L{ParseError} if it is called
        with a status line which cannot be parsed.
        Nc                 ó€   •— ‰j                  t        ‰j                  | «      }‰j                  |j                  | «       y rp   )r   r$   r‰   rL   rÐ   )rÑ   rÒ   rŽ   rR   s     €€rA   rÕ   zBHTTPClientParserTests.test_badResponseStatus.<locals>.checkParsing°  s1   ø€ Ø×#Ñ#¤J°×0GÑ0GÈÓKˆCØ×Ñ˜SŸX™X qÕ)r@   rÖ   s   HTTP/1.1 bar OK)r!   )rR   rÕ   rŽ   s   ` @rA   Útest_badResponseStatusz,HTTPClientParserTests.test_badResponseStatus©  s+   ù€ ô
 $ D¨$Ó/ˆõ	*ñ 	�VÔñ 	Ð'Õ(r@   c                 ór  ‡	— i }g }g }g Š	t        ||j                  «      }|j                  |_        t	        «       }|j                  |«       |j                  |«       |j                  |j                  _        ˆ	fd„|j                  _	        |j                  |«       | j                  |j                  d«       | j                  |j                  t        «       | j                  |g «       | j                  |dg«       | j                  ‰	dg«       | j                  |j                  j                  d«       |S )a0  
        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                  ó&   •— ‰ j                  d«      S ©NT©rˆ   )ÚbodyDataFinisheds   €rA   ú<lambda>z3HTTPClientParserTests._noBodyTest.<locals>.<lambda>Ö  s   ø€ Ð6F×6MÑ6MÈdÓ6S€ r@   Ú	producingr@   Tr   )r!   rˆ   r‘   r’   r   rŠ   rŒ   rÝ   Ú_bodyDataReceivedÚ_bodyDataFinishedrL   ÚproducerStater‹   r   Úlength)
rR   râ   r�   rÝ   r”   ÚfinishedÚbodyrŽ   rg   rí   s
            @rA   Ú_noBodyTestz!HTTPClientParserTests._noBodyTest¼  s  ø€ ð ˆØˆØˆØÐÜ# G¨X¯_©_Ó=ˆØ"(×"4Ñ"4ˆÔÜ#Ó%ˆ	Ø×Ñ 	Ô*ð 	×Ñ˜fÔ%Ø.2¯k©kˆ×ÑÔ+Û.Sˆ×ÑÔ+Ø×Ñ˜hÔ'Ø×Ñ˜×0Ñ0°+Ô>Ø×Ñ˜Ÿ™¬Ô.Ø×Ñ˜˜rÔ"Ø×Ñ˜ C 5Ô)Ø×ÑÐ)¨D¨6Ô2Ø×Ñ˜×*Ñ*×1Ñ1°1Ô5Øˆr@   c                 ó~   — t        ddt        d«      }d}d}| j                  |||«      }| j                  |ddi«       y)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+   rf   rö   rL   )rR   râ   r�   rÝ   r”   s        rA   Útest_headResponsez'HTTPClientParserTests.test_headResponseà  sH   € ô ˜' 4¬¸Ó>ˆØ'ˆØ4ˆØ×!Ñ! '¨6°8Ó<ˆØ×Ñ˜Ð"3°UÐ!;Õ<r@   c                 óV   — t        ddt        d«      }d}d}| j                  |||«       y)z€
        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+   rf   rö   ©rR   râ   r�   rÝ   s       rA   Útest_noContentResponsez,HTTPClientParserTests.test_noContentResponseì  s0   € ô
 ˜& $¬¸Ó=ˆØ/ˆØˆØ×Ñ˜ &¨(Õ3r@   c                 óV   — t        ddt        d«      }d}d}| j                  |||«       y)z‚
        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       rA   Útest_notModifiedResponsez.HTTPClientParserTests.test_notModifiedResponseö  s0   € ô
 ˜& $¬¸Ó=ˆØ1ˆØˆØ×Ñ˜ &¨(Õ3r@   c                 óØ  — t        t        ddt        d«      d„ «      }|j                  t	        «       «       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  t        i «      «       | j                  |j                  j                  t        dd	gi«      «       | j                  |j                  j                  t        «       y)
zq
        The response headers are added to the response object's C{headers}
        L{Headers} instance.
        rÙ   rÚ   Nc                  ó   — y rp   r?   ©Úrests    rA   rî   z<HTTPClientParserTests.test_responseHeaders.<locals>.<lambda>  ó   � r@   rÛ   s   X-Foo: bar
rÂ   ó   x-foor˜   ©r!   r+   rf   rŠ   r   rŒ   rL   ÚconnHeadersr3   rÝ   r­   ÚassertIdenticalró   r   r¼   s     rA   Útest_responseHeadersz*HTTPClientParserTests.test_responseHeaders   s¼   € ô
 $Ü�F˜D¤.°$Ó7Ñ9Jó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5Ø×ÑÐ/Ô0Ø×Ñ˜gÔ&Ø×Ñ˜×-Ñ-¬w°r«{Ô;Ø×Ñ˜×*Ñ*×2Ñ2´G¸XÈÀxÐ<PÓ4QÔRØ×Ñ˜X×.Ñ.×5Ñ5´~ÕFr@   c                 óú  — t        t        ddt        d«      d„ «      }|j                  t	        «       «       |j                  d«       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  t        i «      «       | j                  |j                  j                  t        d	d
gi«      «       | j                  |j                  j                  t        «       y)z‡
        The multi-line response headers are folded and added to the response
        object's C{headers} L{Headers} instance.
        rÙ   rÚ   Nc                  ó   — y rp   r?   r  s    rA   rî   zEHTTPClientParserTests.test_responseHeadersMultiline.<locals>.<lambda>  r  r@   rÛ   s   X-Multiline: a
s       b
rÂ   s   x-multilines   a    br  r¼   s     rA   Útest_responseHeadersMultilinez3HTTPClientParserTests.test_responseHeadersMultiline  sÏ   € ô
 $Ü�F˜D¤.°$Ó7Ñ9Jó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5Ø×ÑÐ3Ô4Ø×Ñ˜lÔ+Ø×Ñ˜gÔ&Ø×Ñ˜×-Ñ-¬w°r«{Ô;Ø×ÑØ×Ñ×%Ñ%¤w°ÀÀÐ/LÓ'Mô	
ð 	×Ñ˜X×.Ñ.×5Ñ5´~ÕFr@   c                 óö  — t        t        ddt        d«      d„ «      }|j                  t	        «       «       |j                  d«       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  j                  t        i «      «       | j                  |j                  t        d	gd
gdœ«      «       | j                  |j                  j                  d«       y)zv
        The connection control headers are added to the parser's C{connHeaders}
        L{Headers} instance.
        rÙ   rÚ   Nc                  ó   — y rp   r?   r  s    rA   rî   z>HTTPClientParserTests.test_connectionHeaders.<locals>.<lambda>)  r  r@   rÛ   ó   Content-Length: 123
s   Connection: close
rÂ   ó   123s   close)r²   r³   é{   ©r!   r+   rf   rŠ   r   rŒ   rL   rÝ   r­   r3   r  ró   r¼   s     rA   Útest_connectionHeadersz,HTTPClientParserTests.test_connectionHeaders#  sÓ   € ô
 $Ü�F˜D¤.°$Ó7Ñ9Jó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5Ø×ÑÐ8Ô9Ø×ÑÐ6Ô7Ø×Ñ˜gÔ&Ø×Ñ˜×*Ñ*×2Ñ2´G¸B³KÔ@Ø×ÑØ× Ñ Ü¨¨À(ÀÑLÓMô	
ð 	×Ñ˜×*Ñ*×1Ñ1°3Õ7r@   c                 óÐ  — t        t        ddt        d«      d„ «      }|j                  t	        «       «       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  j                  t        dd	gi«      «       | j                  |j                  t        i «      «       | j                  |j                  j                  d
«       y)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                  ó   — y rp   r?   r  s    rA   rî   zRHTTPClientParserTests.test_headResponseContentLengthEntityHeader.<locals>.<lambda>=  r  r@   rÛ   r  rÂ   r²   r  r   r  r¼   s     rA   Ú*test_headResponseContentLengthEntityHeaderz@HTTPClientParserTests.test_headResponseContentLengthEntityHeader7  sÂ   € ô
 $Ü�G˜T¤>°4Ó8Ñ:Kó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5Ø×ÑÐ8Ô9Ø×Ñ˜gÔ&Ø×ÑØ×Ñ×%Ñ%¤wÐ0AÀFÀ8Ð/LÓ'Mô	
ð 	×Ñ˜×-Ñ-¬w°r«{Ô;Ø×Ñ˜×*Ñ*×1Ñ1°1Õ5r@   c                 óÚ  — g }t        t        ddt        d«      |j                  «      }t	        «       }|j                  |«       |j                  d«       g }|j                  |j                  _        |j                  d«       |j                  d«       | j                  |j                  d«       | j                  |j                  t        «       |j                  d«       | j                  |dg«       | j                  |j                  t        «       |j                  d	«       | j                  |dd	g«       | j                  |j                  t        «       | j                  |d
g«       y)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Â   Úpauseds   xxxxxxs   yyyyr@   )r!   r+   rf   rˆ   r   rŠ   rŒ   rÝ   rð   rL   rò   r‹   r   r   ©rR   rô   rŽ   rg   rõ   s        rA   Útest_contentLengthz(HTTPClientParserTests.test_contentLengthI  s+  € ð ˆÜ#Ü�F˜D¤.°$Ó7¸¿¹ó
ˆô $Ó%ˆ	Ø×Ñ 	Ô*Ø×ÑÐ4Ô5ØˆØ.2¯k©kˆ×ÑÔ+Ø×ÑÐ7Ô8Ø×Ñ˜gÔ&ð 	×Ñ˜×0Ñ0°(Ô;à×Ñ˜Ÿ™¬Ô.Ø×Ñ˜hÔ'Ø×Ñ˜ ˜zÔ*Ø×Ñ˜Ÿ™¬Ô.Ø×Ñ˜hÔ'Ø×Ñ˜ ¨(Ð3Ô4Ø×Ñ˜Ÿ™¬Ô.Ø×Ñ˜ C 5Õ)r@   c                 óü  — g }t        t        ddt        d«      |j                  «      }|j	                  t        «       «       |j                  d«       g }|j                  |j                  _        |j                  d«       |j                  d«       | j                  |j                  t        «       | j                  |g «       | j                  |dg«       | j                  |j                  j                  d«       y)	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Â   r@   r   )r!   r+   rf   rˆ   rŠ   r   rŒ   rÝ   rð   rL   r‹   r   ró   ©rR   rô   rŽ   rõ   s       rA   Útest_zeroContentLengthz,HTTPClientParserTests.test_zeroContentLengthh  sÏ   € ð ˆÜ#Ü�F˜D¤.°$Ó7¸¿¹ó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5àˆØ.2¯k©kˆ×ÑÔ+à×ÑÐ6Ô7Ø×Ñ˜gÔ&à×Ñ˜Ÿ™¬Ô.Ø×Ñ˜˜rÔ"Ø×Ñ˜ C 5Ô)Ø×Ñ˜×*Ñ*×1Ñ1°1Õ5r@   c                 ó°   — t        t        ddt        d«      d«      }|j                  t	        «       «       | j                  t        |j                  d«       y)zÞ
        If a response includes multiple 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+   rf   rŠ   r   r   Ú
ValueErrorrŒ   r¼   s     rA   Ú!test_multipleContentLengthHeadersz7HTTPClientParserTests.test_multipleContentLengthHeaders�  sL   € ô $¤G¨F°D¼.È$Ó$OÐQUÓVˆà×Ñ¤Ó 1Ô2Ø×ÑÜØ×!Ñ!ðõ	
r@   c                 óR  — g }t        t        ddt        d«      |j                  «      }|j	                  t        «       «       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  t        «       | j                  |dg«       y)zy
        If extra bytes are received past the end of a response, they are passed
        to the finish callback.
        rÙ   rÚ   NrÛ   r  ó   
Here is another thing!ó   Here is another thing!©
r!   r+   rf   rˆ   rŠ   r   rŒ   rL   r‹   r   ©rR   rô   rŽ   s      rA   Útest_extraBytesPassedBackz/HTTPClientParserTests.test_extraBytesPassedBack“  s�   € ð
 ˆÜ#Ü�F˜D¤.°$Ó7¸¿¹ó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5Ø×ÑÐ6Ô7Ø×ÑÐ;Ô<Ø×Ñ˜Ÿ™¬Ô.Ø×Ñ˜Ð$=Ð#>Õ?r@   c                 óR  — g }t        t        ddt        d«      |j                  «      }|j	                  t        «       «       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  t        «       | j                  |dg«       y)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
r#  r$  r%  r&  s      rA   Útest_extraBytesPassedBackHEADz3HTTPClientParserTests.test_extraBytesPassedBackHEAD¤  s�   € ð
 ˆÜ#Ü�G˜T¤>°4Ó8¸(¿/¹/ó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5Ø×ÑÐ7Ô8Ø×ÑÐ;Ô<Ø×Ñ˜Ÿ™¬Ô.Ø×Ñ˜Ð$=Ð#>Õ?r@   c                 óx  — g }t        t        ddt        d«      |j                  «      }|j	                  t        «       «       |j                  d«       g }|j                  |j                  _        |j                  d«       |j                  d«       | j                  |g «       | j                  |j                  j                  t        «       |j                  d«       | j                  |dg«       |j                  d	«       | j                  |dd
g«       |j                  d«       | j                  |dg«       y)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+   rf   rˆ   rŠ   r   rŒ   rÝ   rð   rL   r  ró   r   r  s       rA   Útest_chunkedResponseBodyz.HTTPClientParserTests.test_chunkedResponseBodyµ  s  € ð ˆÜ#Ü�F˜D¤.°$Ó7¸¿¹ó
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ4Ô5àˆØ.2¯k©kˆ×ÑÔ+à×ÑÐ?Ô@Ø×Ñ˜gÔ&ð 	×Ñ˜˜rÔ"ð 	×Ñ˜X×.Ñ.×5Ñ5´~ÔFð 	×Ñ˜iÔ(Ø×Ñ˜ ˜vÔ&Ø×Ñ˜iÔ(Ø×Ñ˜  e˜}Ô-ð
 	×ÑÐ/Ô0Ø×Ñ˜ H :Õ.r@   c                 óÎ  — g }t        t        ddt        d«      |j                  «      }t	        «       }|j                  |«       |j                  d«       g }|j                  |j                  _        |j                  d«       |j                  d«       |j                  d«       | j                  |ddg«       |j                  t        d«      «       | j                  |d	g«       y)
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 connectionr@   )r!   r+   rf   rˆ   r   rŠ   rŒ   rÝ   rð   rL   ÚconnectionLostr
   r  s        rA   Útest_unknownContentLengthz/HTTPClientParserTests.test_unknownContentLengthÚ  sÊ   € ð ˆÜ#Ü�F˜D¤.°$Ó7¸¿¹ó
ˆô $Ó%ˆ	Ø×Ñ 	Ô*Ø×ÑÐ4Ô5àˆØ.2¯k©kˆ×ÑÔ+à×Ñ˜gÔ&Ø×Ñ˜fÔ%Ø×Ñ˜fÔ%Ø×Ñ˜ ¨Ð/Ô0Ø×Ñ¤Ð/LÓ MÔNØ×Ñ˜ C 5Õ)r@   c                 óT  — g }t        t        ddt        d«      |j                  «      }t	        «       }|j                  |«       |j                  d«       g }|j                  |j                  _        |j                  d«       | j                  |dg«       | j                  |dg«       y)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

ó   abcr@   )
r!   r+   rf   rˆ   r   rŠ   rŒ   rÝ   rð   rL   r  s        rA   Ú%test_contentLengthAndTransferEncodingz;HTTPClientParserTests.test_contentLengthAndTransferEncodingò  sž   € ð ˆÜ#Ü�F˜D¤.°$Ó7¸¿¹ó
ˆô $Ó%ˆ	Ø×Ñ 	Ô*Ø×ÑÐ4Ô5àˆØ.2¯k©kˆ×ÑÔ+à×Ñðô	
ð 	×Ñ˜ ˜xÔ(Ø×Ñ˜ C 5Õ)r@   c                 óð   — t        «       }t        t        ddt        d«      d«      }|j	                  |«       |j
                  }|j                  t        t        «       «      «       t        | |t        g«      S )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+   rf   rŠ   Ú_responseDeferredr.  r   r9   r\   )rR   rg   rŽ   ÚresponseDeferreds       rA   Útest_connectionLostBeforeBodyz3HTTPClientParserTests.test_connectionLostBeforeBody  si   € ô $Ó%ˆ	Ü#¤G¨F°D¼.È$Ó$OÐQUÓVˆØ×Ñ 	Ô*à#×5Ñ5ÐØ×Ñ¤Ô(:Ó(<Ó =Ô>ä# DÐ*:Ô=OÐ<PÓQÐQr@   c                 ó  — t        j                  | t        «      }t        «       }t	        t        ddt        d«      d«      }|j                  |«       g }|j                  j                  |j                  «       |j                  d«       |d   }d	d„}||_        |j                  d«       | j                  dt        |«      «       |d   }|d   }| j!                  |j"                  t$        «       | j'                  t$        «       y)
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

r   c                 ó   — t        «       ‚rp   ©r9   )rN   s    rA   ÚfakeBodyDataFinishedzPHTTPClientParserTests.test_connectionLostWithError.<locals>.fakeBodyDataFinished0  s   € Ü$Ó&Ð&r@   rc   Úlog_failurerp   )r   ÚcreateWithCleanupr   r   r!   r+   rf   rŠ   r4  rU   rˆ   rŒ   rñ   r.  ÚassertEqualsrM   ÚassertIsInstancer    r9   ÚflushLoggedErrors)rR   ÚlogObserverrg   rŽ   rÝ   r;  ÚeventrÔ   s           rA   Útest_connectionLostWithErrorz2HTTPClientParserTests.test_connectionLostWithError  sã   € ô +×<Ñ<¸TÔCUÓVˆÜ#Ó%ˆ	Ü#¤G¨F°D¼.È$Ó$OÐQUÓVˆØ×Ñ 	Ô*àˆØ×"Ñ"×.Ñ.¨x¯©Ô?Ø×ÑÐUÔVØ˜A‘;ˆó	'ð &:ˆÔ"à×Ñ Ô%Ø×Ñ˜!œS Ó-Ô.Ø˜A‘ˆØ�-Ñ ˆØ×Ñ˜aŸg™gÔ'9Ô:Ø×ÑÔ1Õ2r@   c                 óä   — t        t        ddt        d«      d„ «      }|j                  }|j	                  t        «       «       |j                  t        «       «       | j                  |t        «      S )z‰
        If no response at all was received and the connection is lost, the
        resulting error is L{ResponseNeverReceived}.
        rø   rÚ   Nc                  ó   — y rp   r?   ©Úigns    rA   rî   z<HTTPClientParserTests.test_noResponseAtAll.<locals>.<lambda>B  r  r@   )
r!   r+   rf   r4  rŠ   r   r.  r   rT   r1   ©rR   rŽ   rX   s      rA   Útest_noResponseAtAllz*HTTPClientParserTests.test_noResponseAtAll<  sb   € ô
 $Ü�G˜T¤>°4Ó8Ñ:Jó
ˆð ×&Ñ&ˆà×Ñ¤Ó 1Ô2Ø×Ñ¤Ó 0Ô1Ø×!Ñ! !Ô%:Ó;Ð;r@   c                 óB  — t        t        ddt        d«      d„ «      }|j                  }|j	                  t        «       «       |j                  d«       |j                  t        «       «       | j                  |t        «      j                  | j                  t        «      S )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                  ó   — y rp   r?   rF  s    rA   rî   zBHTTPClientParserTests.test_someResponseButNotAll.<locals>.<lambda>Q  r  r@   ó   2)r!   r+   rf   r4  rŠ   r   rŒ   r.  r   rT   r0   rU   r?  rH  s      rA   Útest_someResponseButNotAllz0HTTPClientParserTests.test_someResponseButNotAllJ  s‡   € ô $Ü�G˜T¤>°4Ó8Ñ:Jó
ˆð ×&Ñ&ˆà×Ñ¤Ó 1Ô2Ø×Ñ˜dÔ#Ø×Ñ¤Ó 0Ô1Ø×!Ñ! !¤^Ó4×@Ñ@Ø×!Ñ!¤>ó
ð 	
r@   c                 ó8  — d}t        t        ddt        d«      d„ «      }|j                  t	        «       «       |j                  |«       | j                  t        |dd«      du «       | j                  |j                  t        «       | j                  t        t        |j                  j                  «       «      «      d«       | j                  t        t        |j                  j                  «       «      «      d«       | j                  |j                   «       y)zy
        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                  ó   — y rp   r?   rF  s    rA   rî   zCHTTPClientParserTests.test_1XXResponseIsSwallowed.<locals>.<lambda>j  r  r@   rÝ   r   )r!   r+   rf   rŠ   r   rŒ   r´   ÚgetattrrL   r‹   r   rM   r¬   r­   r®   r  Ú_everReceivedData)rR   Úsample103ResponserŽ   s      rA   Útest_1XXResponseIsSwallowedz1HTTPClientParserTests.test_1XXResponseIsSwallowed\  sß   € ðð 	ô $Ü�F˜D¤.°$Ó7Ñ9Ió
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ/Ô0ð 	�‰œ ¨*°dÓ;¸tÐCÔDØ×Ñ˜Ÿ™¬Ô0Ø×ÑœœT (×"2Ñ"2×"CÑ"CÓ"EÓFÓGÈÔKØ×ÑœœT (×"6Ñ"6×"GÑ"GÓ"IÓJÓKÈQÔOØ�‰˜×2Ñ2Õ3r@   c                 óæ  — d}d}t        t        ddt        d«      d„ «      }|j                  t	        «       «       |j                  ||z   «       | j                  |j                  j                  d«       | j                  |j                  j                  t        i «      «       | j                  |j                  t        dd	gi«      «       | j                  |j                  j                  d
«       y)z‘
        When a 1XX response is swallowed, the final response that follows it is
        the only one that gets sent to the application.
        rO  ó(   HTTP/1.1 200 OK
Content-Length: 123

rÙ   rÚ   Nc                  ó   — y rp   r?   rF  s    rA   rî   zUHTTPClientParserTests.test_1XXFollowedByFinalResponseOnlyEmitsFinal.<locals>.<lambda>…  r  r@   rd   r²   r  r  ©r!   r+   rf   rŠ   r   rŒ   rL   rÝ   rß   r­   r3   r  ró   ©rR   rS  Úfollowing200ResponserŽ   s       rA   Ú-test_1XXFollowedByFinalResponseOnlyEmitsFinalzCHTTPClientParserTests.test_1XXFollowedByFinalResponseOnlyEmitsFinalv  sÓ   € ðð 	ð  YÐä#Ü�F˜D¤.°$Ó7Ñ9Ió
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ/Ð2FÑFÔGà×Ñ˜×*Ñ*×/Ñ/°Ô5Ø×Ñ˜×*Ñ*×2Ñ2´G¸B³KÔ@Ø×Ñ˜×-Ñ-¬wÐ8IÈFÈ8Ð7TÓ/UÔVØ×Ñ˜×*Ñ*×1Ñ1°3Õ7r@   c                 óò  — d}d}t        t        ddt        d«      d„ «      }|j                  t	        «       «       |j                  ||z   |z   |z   «       | j                  |j                  j                  d«       | j                  |j                  j                  t        i «      «       | j                  |j                  t        dd	gi«      «       | j                  |j                  j                  d
«       y)zp
        It is acceptable for multiple 1XX responses to come through, all of
        which get ignored.
        rO  rV  rÙ   rÚ   Nc                  ó   — y rp   r?   rF  s    rA   rî   zKHTTPClientParserTests.test_multiple1XXResponsesAreIgnored.<locals>.<lambda>ž  r  r@   rd   r²   r  r  rX  rY  s       rA   Ú#test_multiple1XXResponsesAreIgnoredz9HTTPClientParserTests.test_multiple1XXResponsesAreIgnored�  së   € ðð 	ð  YÐä#Ü�F˜D¤.°$Ó7Ñ9Ió
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑØØñ àñ ð #ñ#ô	
ð 	×Ñ˜×*Ñ*×/Ñ/°Ô5Ø×Ñ˜×*Ñ*×2Ñ2´G¸B³KÔ@Ø×Ñ˜×-Ñ-¬wÐ8IÈFÈ8Ð7TÓ/UÔVØ×Ñ˜×*Ñ*×1Ñ1°3Õ7r@   c                 ó^  — t        j                  | t        «      }d}t        t	        ddt
        d«      d„ «      }|j                  t        «       «       |j                  |«       | j                  dt        |«      «       |d   }| j                  |d   d	«       | j                  |d
   d«       y)zF
        When a 1XX response is ignored, Twisted emits a log.
        rO  rÙ   rÚ   Nc                  ó   — y rp   r?   rF  s    rA   rî   zHHTTPClientParserTests.test_ignored1XXResponseCausesLog.<locals>.<lambda>»  r  r@   rc   r   Ú
log_formatz#Ignoring unexpected {code} responserß   ég   )r   r=  r   r!   r+   rf   rŠ   r   rŒ   r>  rM   )rR   rA  rS  rŽ   rB  s        rA   Ú test_ignored1XXResponseCausesLogz6HTTPClientParserTests.test_ignored1XXResponseCausesLog­  s¨   € ô +×<Ñ<¸TÔCUÓVˆðð 	ô $Ü�F˜D¤.°$Ó7Ñ9Ió
ˆð 	×Ñ¤Ó 1Ô2Ø×ÑÐ/Ô0à×Ñ˜!œS Ó-Ô.Ø˜A‘ˆØ×Ñ˜% Ñ-Ð/TÔUØ×Ñ˜% ™-¨Õ-r@   N)!r;   r<   r=   r>   rÍ   r×   rã   rå   rè   rö   rù   rý   rÿ   r	  r  r  r  r  r  r!  r'  r)  r,  r/  r2  r6  rC  rI  rM  rT  r[  r^  rc  r?   r@   rA   rÈ   rÈ   j  s    „ ñò
Pò#ò,:ò8ò)ò&"òH
=ò4ò4òGò Gò&8ò(6ò$*ò>6ò2
ò$@ò"@ò"#/òJ*ò0*ò<Rò3ò:<ò
ò$4ò48ò28ó<.r@   rÈ   c                   ó(   — e Zd ZdZdZdZdZd„ Zd„ Zy)ÚSlowRequesta„  
    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   — t        «       | _        | j                  S rp   )r   rô   ©rR   rg   s     rA   ÚwriteTozSlowRequest.writeToÖ  s   € Ü ›
ˆŒØ�}‰}Ðr@   c                 ó   — d| _         y rë   ©Ústoppedrq   s    rA   ÚstopWritingzSlowRequest.stopWritingÚ  ó	   € Øˆ�r@   N)	r;   r<   r=   r>   Úmethodrk  Ú
persistentrh  rl  r?   r@   rA   re  re  Æ  s"   „ ñ	ð €FØ€GØ€Jòór@   re  c                   ó   — e Zd ZdZdZd„ Zy)ÚSimpleRequesta  
    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                 ó:   — |j                  d«       t        d «      S )Nó
   SOME BYTES)Úwriter	   rg  s     rA   rh  zSimpleRequest.writeToè  s   € Ø�‰˜Ô&Ü�t‹}Ðr@   N)r;   r<   r=   r>   ro  rh  r?   r@   rA   rq  rq  Þ  s   „ ñð €Jór@   rq  c                   óä   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d&d	„Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d „ Z!d!„ Z"d"„ Z#d#„ Z$d$„ Z%d%„ Z&y)'ÚHTTP11ClientProtocolTestsz]
    Tests for the HTTP 1.1 client protocol implementation,
    L{HTTP11ClientProtocol}.
    c                 óŠ   — t        «       | _        t        «       | _        | j                  j	                  | j                  «       y)zR
        Create an L{HTTP11ClientProtocol} connected to a fake transport.
        N)r   rg   r)   rŽ   rŠ   rq   s    rA   ÚsetUpzHTTP11ClientProtocolTests.setUpó  s.   € ô )Ó*ˆŒÜ,Ó.ˆŒØ�‰×$Ñ$ T§^¡^Õ4r@   c                 óž   — | j                   j                  t        «       «       | j                  | j                  j                  «       d«       y)z†
        L{HTTP11ClientProtocol.request} accepts a L{Request} and calls its
        C{writeTo} method with its own transport.
        rs  N)rŽ   râ   rq  rL   rg   r    rq   s    rA   Útest_requestz&HTTP11ClientProtocolTests.test_requestû  s5   € ð
 	�‰×Ñœm›oÔ.Ø×Ñ˜Ÿ™×-Ñ-Ó/°Õ?r@   c                 óè   ‡ — ‰ j                   j                  t        «       «       ˆ fd„}‰ j                  ‰ j                   j                  t	        «       «      t
        «      }|j                  |«       |S )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                 óZ   •— ‰j                  ‰j                  j                  «       d«       y ©Nr@   ©rL   rg   r    ©ÚignoredrR   s    €rA   Ú	cbNotSentz?HTTP11ClientProtocolTests.test_secondRequest.<locals>.cbNotSent  ó    ø€ Ø×Ñ˜TŸ^™^×1Ñ1Ó3°SÕ9r@   )rŽ   râ   re  rT   rq  r%   rU   ©rR   r�  rX   s   `  rA   Útest_secondRequestz,HTTP11ClientProtocolTests.test_secondRequest  sT   ø€ ð 	�‰×Ñœk›mÔ,ô	:ð ×Ñ˜tŸ}™}×4Ñ4´]³_ÓEÄ~ÓVˆØ	�‰�iÔ Øˆr@   c                 óü   ‡ — ‰ j                   j                  t        t        d«      «      «       ˆ fd„}‰ j	                  ‰ j                   j                  t        «       «      t        «      }|j                  |«       |S )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                 óZ   •— ‰j                  ‰j                  j                  «       d«       y r}  r~  r  s    €rA   r�  zLHTTP11ClientProtocolTests.test_requestAfterConnectionLost.<locals>.cbNotSent  r‚  r@   )	rŽ   r.  r   r
   rT   râ   rq  r%   rU   rƒ  s   `  rA   Útest_requestAfterConnectionLostz9HTTP11ClientProtocolTests.test_requestAfterConnectionLost  s\   ø€ ð 	�‰×$Ñ$¤W¬^¸OÓ-LÓ%MÔNô	:ð ×Ñ˜tŸ}™}×4Ñ4´]³_ÓEÄ~ÓVˆØ	�‰�iÔ Øˆr@   c                 ó¬   ‡ —  G d„ d«      }‰ j                   j                   |«       «      }ˆ fd„}t        ‰ |t        g«      }|j	                  |«       |S )a%  
        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                   ó   — e Zd ZdZd„ Zy)úCHTTP11ClientProtocolTests.test_failedWriteTo.<locals>.BrokenRequestFc                 ó(   — t        t        «       «      S rp   )r   r9   rg  s     rA   rh  zKHTTP11ClientProtocolTests.test_failedWriteTo.<locals>.BrokenRequest.writeTo,  s   € ÜÔ.Ó0Ó1Ð1r@   N©r;   r<   r=   ro  rh  r?   r@   rA   ÚBrokenRequestrŠ  )  s   „ ØˆJó2r@   r�  c                 óª   •— ‰j                  ‰j                  j                  «       ‰j                  j	                  t        t        d«      «      «       y )Nzyou asked for it)r´   rg   ÚdisconnectingrŽ   r.  r   r
   r  s    €rA   rS   z>HTTP11ClientProtocolTests.test_failedWriteTo.<locals>.cbFailed1  s8   ø€ Ø�O‰O˜DŸN™N×8Ñ8Ô9ð �M‰M×(Ñ(¬´Ð@RÓ1SÓ)TÕUr@   )rŽ   râ   r^   r9   rU   )rR   r�  rX   rS   s   `   rA   Útest_failedWriteToz,HTTP11ClientProtocolTests.test_failedWriteTo!  sP   ø€ ÷	2ñ 	2ð �M‰M×!Ñ!¡-£/Ó2ˆô	Vô *¨$°Ô4FÐ3GÓHˆØ	�‰�hÔØˆr@   c                 óz   —  G d„ d«      }| j                   j                   |«       «      }t        | |t        g«      S )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                   ó   — e Zd ZdZd„ Zy)úMHTTP11ClientProtocolTests.test_synchronousWriteToError.<locals>.BrokenRequestFc                 ó   — t        «       ‚rp   r:  rg  s     rA   rh  zUHTTP11ClientProtocolTests.test_synchronousWriteToError.<locals>.BrokenRequest.writeToE  s   € Ü(Ó*Ð*r@   NrŒ  r?   r@   rA   r�  r“  B  s   „ ØˆJó+r@   r�  )rŽ   râ   r^   r9   )rR   r�  rX   s      rA   Útest_synchronousWriteToErrorz6HTTP11ClientProtocolTests.test_synchronousWriteToError;  s7   € ÷	+ñ 	+ð �M‰M×!Ñ!¡-£/Ó2ˆÜ,¨T°1Ô7IÐ6JÓKÐKr@   Nc                 óD  — t        «       }| j                  j                  |«      }t        | |t        g«      }| j                  |j                  «       | j                  j                  t        t	        «       «      «       | j                  |j                  «       |dk(  r|j                  j                  d«       |S |dk(  r^|j                  j                  t        t        «       «      «       | j                  t        «      }| j                  t!        |«      d«       |S 	 |S )a2  
        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Úerrbackrc   )re  rŽ   râ   r`   r9   r¶   rk  r.  r   r´   rô   r—  r˜  rC   r@  rL   rM   )rR   Úmoderâ   rX   Úerrorss        rA   Ú*test_connectionLostDuringRequestGenerationzDHTTP11ClientProtocolTests.test_connectionLostDuringRequestGenerationK  sò   € ô “-ˆØ�M‰M×!Ñ! 'Ó*ˆÜ+¨D°!Ô6HÐ5IÓJˆð 	×Ñ˜Ÿ™Ô)à�‰×$Ñ$¤WÔ-?Ó-AÓ%BÔCð 	�‰˜Ÿ™Ô(à�:ÒØ×Ñ×%Ñ% dÔ+ð ˆð �YÒØ×Ñ×$Ñ$¤WÔ-FÓ-HÓ%IÔJØ×+Ñ+Ô,EÓFˆFØ×ÑœS ›[¨!Ô,ð ˆð Øˆr@   c                 ó$   — | j                  d«      S )zÂ
        If the request passed to L{HTTP11ClientProtocol} finishes generation
        successfully after the L{HTTP11ClientProtocol}'s connection has been
        lost, nothing happens.
        r—  ©r›  rq   s    rA   Ú+test_connectionLostBeforeGenerationFinishedzEHTTP11ClientProtocolTests.test_connectionLostBeforeGenerationFinishedk  s   € ð ×>Ñ>¸zÓJÐJr@   c                 ó$   — | j                  d«      S )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�  rq   s    rA   Ú)test_connectionLostBeforeGenerationFailedzCHTTP11ClientProtocolTests.test_connectionLostBeforeGenerationFaileds  s   € ð ×>Ñ>¸yÓIÐIr@   c                 ó†   ‡ ‡— t        j                  ‰ t        «      Šˆˆ fd„}‰ j                  d«      j	                  |«      S )a	  
        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                 ó¾   •— ‰j                  dt        ‰«      «       ‰d   }‰j                  d|«       ‰j                  |d   d«       ‰j                  |d   d«       y )Nrc   r   r<  ra  zJError writing request, but not in valid state to finalize request: {state}r‹   ÚCONNECTION_LOST)r>  rM   ÚassertInrL   )ÚignorerB  rA  rR   s     €€rA   ÚcheckznHTTP11ClientProtocolTests.test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse.<locals>.check„  sa   ø€ Ø×Ñ˜a¤ [Ó!1Ô2Ø ‘NˆEØ�M‰M˜-¨Ô/Ø×ÑØ�lÑ#ð/ôð
 ×Ñ˜U 7™^Ð->Õ?r@   r˜  )r   r=  r   r›  rU   )rR   r¦  rA  s   ` @rA   ÚEtest_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfusez_HTTP11ClientProtocolTests.test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse{  sA   ù€ ô +×<Ñ<¸TÔCUÓVˆõ		@ð ×>Ñ>¸yÓI×UÑUØó
ð 	
r@   c                 óÀ   ‡ — ‰ j                   j                  t        ddt        d«      «      }ˆ fd„}|j	                  |«       ‰ j                   j                  d«       |S )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                 ó  •— ‰j                  | j                  d«       ‰j                  | j                  t        «       «       ‰j	                  ‰j
                  j                  «       ‰j                  ‰j                  j                  d«       y )Nrd   Ú	QUIESCENT)	rL   rß   r­   r3   r´   rg   r�  rŽ   r‹   )rÝ   rR   s    €rA   Ú	cbRequestzIHTTP11ClientProtocolTests.test_receiveSimplestResponse.<locals>.cbRequest›  s_   ø€ Ø×Ñ˜XŸ]™]¨CÔ0Ø×Ñ˜X×-Ñ-¬w«yÔ9Ø�O‰O˜DŸN™N×8Ñ8Ô9Ø×Ñ˜TŸ]™]×0Ñ0°+Õ>r@   s9   HTTP/1.1 200 OK
Content-Length: 0
Connection: close

©rŽ   râ   r+   rf   rU   rŒ   ©rR   rX   r«  s   `  rA   Útest_receiveSimplestResponsez6HTTP11ClientProtocolTests.test_receiveSimplestResponse“  sU   ø€ ð �M‰M×!Ñ!¤'¨&°$¼ÈÓ"MÓNˆô	?ð 	
�‰�iÔ Ø�‰×"Ñ"ðô	
ð ˆr@   c                 óÀ   ‡ — ‰ j                   j                  t        ddt        d«      «      }ˆ fd„}|j	                  |«       ‰ j                   j                  d«       |S )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                 ó\   •— t        dddgi«      }‰j                  | j                  |«       y )Nr  r˜   r«   )r3   rL   r­   )rÝ   r¯   rR   s     €rA   r«  zHHTTP11ClientProtocolTests.test_receiveResponseHeaders.<locals>.cbRequest²  s-   ø€ Ü ¨6°6Ð*:Ð;Ó<ˆHØ×Ñ˜X×-Ñ-¨xÕ8r@   s+   HTTP/1.1 200 OK
X-Foo: bar
X-Foo: baz

r¬  r­  s   `  rA   Útest_receiveResponseHeadersz5HTTP11ClientProtocolTests.test_receiveResponseHeadersª  sS   ø€ ð �M‰M×!Ñ!¤'¨&°$¼ÈÓ"MÓNˆô	9ð 	
�‰�iÔ Ø�‰×"Ñ"ØNô	
ð ˆr@   c                 ó,  ‡ ‡‡‡‡— g Št        «       Št        ‰j                  «      Š‰j                  ‰«       t	        «       Š‰j                  ‰«      }‰j                  d«       ˆˆˆ ˆfd„}|j                  |«       ˆˆ fd„}|j                  |«       |S )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                 ó  •‡ ‡— t        «       Št        «       x}‰_        ‰ j                  ‰«       ‰j	                  ‰j
                  d«       ‰j                  ‰j                  «       ‰j	                  ‰g «       |j                  ˆˆ fd„«      S )NÚ%TRANSMITTING_AFTER_RECEIVING_RESPONSEc                 ó    •— ‰‰j                   fS rp   ©rÐ   ©rG  ÚprÝ   s    €€rA   rî   zoHTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone.<locals>.cbResponse.<locals>.<lambda>Û  ó   ø€ ¸À1Ç6Á6Ð8J€ r@   )	r   r   ÚclosedDeferredÚdeliverBodyrL   r‹   r´   r�  rU   )rÝ   ÚwhenFinishedr¸  rŽ   ÚquiescentResultrR   rg   s   ` @€€€€rA   Ú
cbResponsez]HTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone.<locals>.cbResponseÔ  sq   ú€ Ü$Ó&ˆAÜ.6«jÐ8ˆL˜1Ô+Ø× Ñ  Ô#Ø×Ñ˜XŸ^™^Ð-TÔUØ�O‰O˜I×3Ñ3Ô4Ø×Ñ˜_¨bÔ1Ø×+Ñ+Ô,JÓKÐKr@   c                 ób  •— | \  }}‰j                  |j                  d«       ‰j                  |j                  d«       ‰j                  |j                  d«       ‰j                  |j                  t        ddgi«      «       ‰j                  |d«       ‰j                  j                  d «       y )Nrb   rd   re   r  r˜   ó   foobar)rL   rÞ   rß   rà   r­   r3   rô   r—  )ÚresultrÝ   rõ   râ   rR   s      €€rA   ÚcbAllResponsez`HTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone.<locals>.cbAllResponseß  s’   ø€ Ø#‰NˆH�dØ×Ñ˜X×-Ñ-¨Ô?Ø×Ñ˜XŸ]™]¨CÔ0Ø×Ñ˜XŸ_™_¨eÔ4Ø×Ñ˜X×-Ñ-¬w¸À6À(Ð7KÓ/LÔMØ×Ñ˜T 9Ô-ð ×Ñ×%Ñ% dÕ+r@   )r   r)   rˆ   rŠ   re  râ   rŒ   rU   )rR   rX   r¾  rÂ  rŽ   r½  râ   rg   s   `   @@@@rA   Ú/test_receiveResponseBeforeRequestGenerationDonezIHTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone¼  s†   ü€ ð ˆÜ#Ó%ˆ	Ü'¨×(>Ñ(>Ó?ˆØ×Ñ 	Ô*ä“-ˆØ×Ñ˜WÓ%ˆØ×Ñðô	
÷	Lð 	
�‰�jÔ!õ
	,ð 	
�‰�mÔ$Øˆr@   c                 ó  — t        «       }t        «       }||_        |j                  |«       dt        j
                  z  }|j                  t        ddt        d«      «      }|j                  d|z   dz   «       t        | |t        g«      S )zy
        The connection is closed when the server respond with a header which
        is above the maximum line.
        r+  rÙ   rÚ   Ns   HTTP/1.1 200 OK
X-Foo: s   
X-Ignored: ignored

)r   r)   rŽ   rŠ   r   Ú
MAX_LENGTHrâ   r+   rf   rŒ   r\   r
   )rR   rg   rŽ   ÚlongLinerX   s        rA   Ú"test_receiveResponseHeadersTooLongz<HTTP11ClientProtocolTests.test_receiveResponseHeadersTooLongî  sŽ   € ô
 5Ó6ˆ	Ü'Ó)ˆØ%ˆ	ÔØ×Ñ 	Ô*àœ,×1Ñ1Ñ1ˆØ×ÑœW V¨T´>À4ÓHÓIˆà×ÑðØ!ñ"ð%ñô	
ô $ D¨!¬nÐ-=Ó>Ð>r@   c                 óà   ‡ ‡— t        «       Š‰ j                  j                  ‰«      }‰ j                  j                  d«       d„ }|j	                  |«       ˆˆ fd„}|j	                  |«       |S )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                 óˆ   ‡ ‡— t        «       Št        «       x}‰_        ‰ j                  ‰«       |j	                  ˆˆ fd„«      S )Nc                 ó    •— ‰‰j                   fS rp   r¶  r·  s    €€rA   rî   z„HTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbResponse.<locals>.<lambda>  r¹  r@   )r   r   rº  r»  rU   )rÝ   r¼  r¸  s   ` @rA   r¾  zrHTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbResponse  s:   ù€ Ü$Ó&ˆAÜ.6«jÐ8ˆL˜1Ô+Ø× Ñ  Ô#Ø×+Ñ+Ô,JÓKÐKr@   c                 óà   •— ‰j                   j                  d «       ‰j                  j                  t	        t        «       «      «       ‰j                  ‰j                  j                  d«       y )Nr£  )rô   r—  rŽ   r.  r   r9   rL   r{   )r¥  râ   rR   s    €€rA   rÂ  zuHTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbAllResponse  sM   ø€ Ø×Ñ×%Ñ% dÔ+à�M‰M×(Ñ(¬Ô1CÓ1EÓ)FÔGØ×Ñ˜TŸ]™]×1Ñ1Ð3DÕEr@   )re  rŽ   râ   rŒ   rU   )rR   rX   r¾  rÂ  râ   s   `   @rA   ÚDtest_connectionLostAfterReceivingResponseBeforeRequestGenerationDonez^HTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone  sd   ù€ ô “-ˆØ�M‰M×!Ñ! 'Ó*ˆØ�‰×"Ñ"ðô	
ò	Lð 	
�‰�jÔ!õ	Fð 	
�‰�mÔ$Øˆr@   c                 ó&  ‡ ‡— t        «       Št        «       x}‰_        ‰ j                  j	                  t        ddt        d«      «      }‰ j                  j                  d«       g }|j                  |j                  «       ‰ j                  |g «       ‰ j                  j                  d«       |d   }|j                  ‰«       ‰ j                  j                  d«       ‰ j                  j                  d«       ˆˆ fd	„}|j                  |«       |S )
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Ö   r˜   c                 ó|   •— ‰j                  ‰j                  d«       ‰j                  j                  t        «       y )NrÀ  )rL   rÐ   ÚclosedReasonrK   r/   )r€  rŽ   rR   s    €€rA   rÂ  zIHTTP11ClientProtocolTests.test_receiveResponseBody.<locals>.cbAllResponseJ  s+   ø€ Ø×Ñ˜XŸ]™]¨IÔ6Ø×!Ñ!×&Ñ&¤|Õ4r@   )r   r   rº  rŽ   râ   r+   rf   rŒ   rU   rˆ   rL   r»  )rR   r¼  ÚrequestDeferredrÁ  rÝ   rÂ  rŽ   s   `     @rA   Útest_receiveResponseBodyz2HTTP11ClientProtocolTests.test_receiveResponseBody(  sè   ù€ ô (Ó)ˆÜ19³Ð;ˆ�xÔ.ØŸ-™-×/Ñ/Ü�F˜D¤.°$Ó7ó
ˆð 	�‰×"Ñ"ØAô	
ð ˆØ×#Ñ# F§M¡MÔ2à×Ñ˜ Ô$ð 	�‰×"Ñ" 5Ô)Ø˜!‘9ˆà×Ñ˜XÔ&à�‰×"Ñ" 6Ô*Ø�‰×"Ñ" 6Ô*õ	5ð 	× Ñ  Ô/ØÐr@   c                 óF  — | j                   j                  t        ddt        d«      «      }| j                   j	                  d«       g }|j                  |j                  «       |d   }t        «       }|j                  |«       | j                   j	                  d«       | j                   j	                  d«       | j                  |j                  d«       | j                   j                  t        t        d	«      «      «       |j                  j                  t         «       y)
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˜   rÀ  z low-level transport disconnected)rŽ   râ   r+   rf   rŒ   rU   rˆ   r   r»  rL   rÐ   r.  r   r
   rÏ  rK   r*   ©rR   rÐ  rÁ  rÝ   rŽ   s        rA   ÚEtest_responseBodyFinishedWhenConnectionLostWhenContentLengthIsUnknownz_HTTP11ClientProtocolTests.test_responseBodyFinishedWhenConnectionLostWhenContentLengthIsUnknownQ  sà   € ð Ÿ-™-×/Ñ/Ü�F˜D¤.°$Ó7ó
ˆð 	�‰×"Ñ"Ð#AÔBàˆØ×#Ñ# F§M¡MÔ2Ø˜!‘9ˆä'Ó)ˆØ×Ñ˜XÔ&à�‰×"Ñ" 6Ô*Ø�‰×"Ñ" 6Ô*à×Ñ˜Ÿ™¨	Ô2Ø�‰×$Ñ$Ü”NÐ#EÓFÓGô	
ð 	×Ñ×"Ñ"Ô#4Õ5r@   c                 óX  — | j                   j                  t        ddt        d«      «      }| j                   j	                  d«       g }|j                  |j                  «       |d   }t        «       }|j                  |«       | j                   j	                  d«       | j                   j	                  d«       | j                  |j                  d«       | j                   j                  t        t        «       «      «       t        | t        |j                   «      t        t"        g«      S )	a  
        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

r   ó   3
foo
s   3
bar
rÀ  )rŽ   râ   r+   rf   rŒ   rU   rˆ   r   r»  rL   rÐ   r.  r   r9   r\   r   rÏ  r2   rÓ  s        rA   Ú4test_chunkedResponseBodyUnfinishedWhenConnectionLostzNHTTP11ClientProtocolTests.test_chunkedResponseBodyUnfinishedWhenConnectionLostn  sí   € ð Ÿ-™-×/Ñ/Ü�F˜D¤.°$Ó7ó
ˆð 	�‰×"Ñ"ØLô	
ð ˆØ×#Ñ# F§M¡MÔ2Ø˜!‘9ˆä'Ó)ˆØ×Ñ˜XÔ&à�‰×"Ñ" ?Ô3Ø�‰×"Ñ" ?Ô3à×Ñ˜Ÿ™¨	Ô2à�‰×$Ñ$¤WÔ-?Ó-AÓ%BÔCä#Ø”$�x×,Ñ,Ó-Ô0BÄIÐ/Nó
ð 	
r@   c                 óä   ‡ — ‰ j                   j                  t        ddt        d«      «      }‰ j                   j	                  d«       t        ‰ |t        g«      }ˆ fd„}|j                  |«       |S )a!  
        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                 ó  •— ‰j                  ‰j                  j                  «       ‰j                  | j                  d   j
                  j                  d«       ‰j                  j                  t        t        d«      «      «       y )Nr   s   unparseable garbage goes herez
it is done)r´   rg   r�  rL   rJ   r    rÐ   rŽ   r.  r   r
   )rÒ   rR   s    €rA   rS   zLHTTP11ClientProtocolTests.test_parserDataReceivedException.<locals>.cbFailed›  s_   ø€ Ø�O‰O˜DŸN™N×8Ñ8Ô9Ø×ÑØ—‘˜A‘×$Ñ$×)Ñ)Ð+Kôð �M‰M×(Ñ(¬´ÀÓ1MÓ)NÕOr@   )rŽ   râ   r+   rf   rŒ   r\   r$   rU   )rR   rÐ  rX   rS   s   `   rA   Ú test_parserDataReceivedExceptionz:HTTP11ClientProtocolTests.test_parserDataReceivedExceptionŽ  se   ø€ ð Ÿ-™-×/Ñ/Ü�F˜D¤.°$Ó7ó
ˆð 	�‰×"Ñ"Ð#GÔHÜ   ¼¸ÓEˆô
	Pð 	
�‰�hÔØˆr@   c                 óš  — | j                   j                  t        ddt        d«      «      }| j                   j                  j
                  }| j                  |j                  | j
                  «       | j                   j                  t        t        d«      «      «       | j                  |j                  d«       t        | |t        g«      S )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+   rf   Ú_parserrg   r  Ú	_producerÚ_disconnectParserr   r
   r\   )rR   rÐ  rg   s      rA   Útest_proxyStoppedz+HTTP11ClientProtocolTests.test_proxyStoppedª  sœ   € ð Ÿ-™-×/Ñ/Ü�F˜D¤.°$Ó7ó
ˆð —M‘M×)Ñ)×3Ñ3ˆ	Ø×Ñ˜Y×0Ñ0°$·.±.ÔAØ�‰×'Ñ'¬´Ð?PÓ0QÓ(RÔSØ×Ñ˜Y×0Ñ0°$Ô7Ü# D¨/¼NÐ;KÓLÐLr@   c                 óì  — t        «       }t        «       }|j                  |«       g }g }|j                  «       j	                  |j
                  «       |j                  «       j	                  |j
                  «       | j                  ||fg g f«       | j                  |j                  «       |j                  t        t        «       «      «       | j                  |dg«       | j                  |dg«       y)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Š   ÚabortrU   rˆ   rL   r´   r�  r.  r   r
   )rR   rg   rŽ   Úr1Úr2s        rA   Útest_abortClosesConnectionz4HTTP11ClientProtocolTests.test_abortClosesConnection¹  sÄ   € ô $Ó%ˆ	Ü'Ó)ˆØ×Ñ 	Ô*ØˆØˆØ�‰Ó×$Ñ$ R§Y¡YÔ/Ø�‰Ó×$Ñ$ R§Y¡YÔ/Ø×Ñ˜"˜b˜ B¨ 8Ô,Ø�‰˜	×/Ñ/Ô0ð 	×Ñ¤¬Ó(8Ó 9Ô:Ø×Ñ˜˜d˜VÔ$Ø×Ñ˜˜d˜VÕ$r@   c                 óF  — t        «       }t        «       }|j                  |«       |j                  t	        t        «       «      «       g }|j                  «       j                  |j                  «       | j                  |dg«       | j                  |j                  d«       y)z‰
        L{HTTP11ClientProtocol.abort} called after the connection is lost
        returns a C{Deferred} that fires immediately.
        Nr£  )r   r)   rŠ   r.  r   r
   rá  rU   rˆ   rL   r{   ©rR   rg   rŽ   rÁ  s       rA   Útest_abortAfterConnectionLostz7HTTP11ClientProtocolTests.test_abortAfterConnectionLostÎ  s}   € ô
 $Ó%ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ø×Ñ¤¬Ó(8Ó 9Ô:àˆØ�‰Ó×$Ñ$ V§]¡]Ô3Ø×Ñ˜ $ Ô(Ø×Ñ˜Ÿ™Ð*;Õ<r@   c                 óL  — t        «       }t        «       }|j                  |«       |j                  t	        ddt
        d«      «      }|j                  «        | j                  |j                  «       |j                  t        t        «       «      «       t        | |t        g«      S )a  
        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+   rf   rá  r´   r�  r.  r   r
   r\   r   ræ  s       rA   Útest_abortBeforeResponseBodyz6HTTP11ClientProtocolTests.test_abortBeforeResponseBodyÝ  s‚   € ô $Ó%ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ø×!Ñ!¤'¨&°$¼ÈÓ"MÓNˆØ�‰ÔØ�‰˜	×/Ñ/Ô0Ø×Ñ¤¬Ó(8Ó 9Ô:Ü# D¨&Ô3DÐ2EÓFÐFr@   c                 ó‚  ‡ ‡‡‡‡— t        d¬«      Št        «       Š‰j                  ‰«       ‰j                  t	        ddt
        d«      «      }‰j                  d«       t        «       Š G ˆˆfd„dt        «      Šˆˆˆ ˆfd	„}ˆ fd
„}|j                  |«       t        ‰ ‰t        t        g«      }|j                  |«      S )aS  
        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Ú   Nr8  c                   ó&   •— e Zd ZdZˆ fd„Zˆfd„Zy)úQHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.BodyDestinationzl
            A body response protocol which immediately aborts the HTTP
            connection.
            c                 ó&   •— ‰j                  «        y)z<
                Abort the HTTP connection.
                N)rá  r¼   s    €rA   ÚconnectionMadez`HTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.BodyDestination.connectionMade  s   ø€ ð —‘Õ r@   c                 ó(   •— ‰j                  |«       y)z�
                Make the reason for the losing of the connection available to
                the unit test via C{testResult}.
                N)r˜  )rR   rO   Ú
testResults     €rA   r.  z`HTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.BodyDestination.connectionLost  s   ø€ ð
 ×"Ñ" 6Õ*r@   N)r;   r<   r=   r>   rï  r.  )rŽ   rñ  s   €€rA   ÚBodyDestinationrí    s   ø„ ñô
!õ+r@   rò  c                 ó¬   •— | j                   ‰«       «       ‰j                  ‰j                  «       ‰j                  t	        t        «       «      «       y)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�  r.  r   r
   )rÝ   rò  rŽ   rR   rg   s    €€€€rA   r»  zMHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.deliverBody  s>   ø€ ð × Ñ ¡Ó!2Ô3Ø�O‰O˜I×3Ñ3Ô4Ø×#Ñ#¤G¬NÓ,<Ó$=Õ>r@   c                 óF   •— ‰j                  | j                  t        «       y rp   )r?  rÝ   r.   )ÚerrorrR   s    €rA   Ú
checkErrorzLHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.checkError  s   ø€ Ø×!Ñ! %§.¡.´(Õ;r@   )r   r)   rŠ   râ   r+   rf   rŒ   r   r   rU   r\   r   r2   )	rR   rÁ  r»  rö  rV   rò  rŽ   rñ  rg   s	   `    @@@@rA   Útest_abortAfterResponseHeadersz8HTTP11ClientProtocolTests.test_abortAfterResponseHeadersí  s¦   ü€ ô $¨DÔ1ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ø×!Ñ!¤'¨&°$¼ÈÓ"MÓNˆà×ÑÐUÔVä“Zˆ
÷	+œhô 	+÷&	?ô	<ð 	×Ñ˜;Ô'Ü'Ø�*Ô0´)Ð<ó
ˆð ×#Ñ# JÓ/Ð/r@   c           	      óh  ‡ ‡‡— g Šˆˆˆ fd„}t        «       }t        |«      Š‰j                  |«       ‰j                  t	        ddt
        dd¬«      «      }‰j                  d«       ‰ j                  ‰g «       g }|j                  |j                  «       |d   }t        «       }t        «       |_        |j                  j                  ˆfd	„«       |j                  |«       ‰j                  d
«       |j                  j                  t         «       ‰ j                  ‰‰dg«       ‰ j                  ‰j"                  d«       ‰ j                  ‰j$                  d«       ‰ j                  ‰j&                  d«       ‰ j                  ‰j(                  d«       ‰ j                  ‰j*                  d«       y)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                 ó„   •— ‰j                  | ‰«       ‰j                  | j                  d«       ‰j                  | «       y ©Nrª  ©rL   r‹   rˆ   ©r¸  rŽ   r½  rR   s    €€€rA   r—  zHHTTP11ClientProtocolTests.test_quiescentCallbackCalled.<locals>.callback5  ó5   ø€ Ø×Ñ˜Q Ô)Ø×Ñ˜QŸW™W kÔ2Ø×"Ñ" 1Õ%r@   rÙ   rÚ   NT©ro  s&   HTTP/1.1 200 OK
Content-length: 3

r   c                 ó&   •— ‰j                  d«      S )Núresponse donerì   )rG  r½  s    €rA   rî   zHHTTP11ClientProtocolTests.test_quiescentCallbackCalled.<locals>.<lambda>O  s   ø€ ˜×.Ñ.¨Ó?€ r@   r1  r   )r   r)   rŠ   râ   r+   rf   rŒ   rL   rU   rˆ   r   r   rº  r»  rÏ  rK   r/   rÜ  Ú_finishedRequestÚ_currentRequestÚ_transportProxyr4  )	rR   r—  rg   rÐ  rÁ  rÝ   ÚbodyProtocolrŽ   r½  s	   `      @@rA   Útest_quiescentCallbackCalledz6HTTP11ClientProtocolTests.test_quiescentCallbackCalled'  sx  ú€ ð ˆö	&ô
 $Ó%ˆ	Ü'¨Ó1ˆØ×Ñ 	Ô*à"×*Ñ*Ü�F˜D¤.°$À4ÔHó
ˆð 	×ÑÐUÔVð 	×Ñ˜¨"Ô-àˆØ×#Ñ# F§M¡MÔ2Ø˜!‘9ˆô ,Ó-ˆÜ&.£jˆÔ#Ø×#Ñ#×/Ñ/Û?ô	
ð 	×Ñ˜\Ô*Ø×Ñ˜fÔ%Ø×!Ñ!×&Ñ&¤|Ô4ð 	×Ñ˜¨8°_Ð*EÔFð 	×Ñ˜×)Ñ)¨4Ô0Ø×Ñ˜×2Ñ2°DÔ9Ø×Ñ˜×1Ñ1°4Ô8Ø×Ñ˜×1Ñ1°4Ô8Ø×Ñ˜×3Ñ3°TÕ:r@   c           	      ó˜  ‡ ‡‡— g Šˆˆˆ fd„}t        «       }t        |«      Š‰j                  |«       ‰j                  t	        ddt
        dd¬«      «      }‰j                  d«       ‰ j                  |«      }‰ j                  |j                  d«       ‰ j                  t        ‰«      d	«       ‰ j                  |j                  d
«       y)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                 ó„   •— ‰j                  | ‰«       ‰j                  | j                  d«       ‰j                  | «       y rú  rû  rü  s    €€€rA   r—  z]HTTP11ClientProtocolTests.test_transportProducingWhenQuiescentAfterFullBody.<locals>.callbackm  rý  r@   rÙ   rÚ   NTrþ  s)   HTTP/1.1 200 OK
Content-length: 3

BBBÚDEFERRED_CLOSErc   rï   )r   r)   rŠ   râ   r+   rf   rŒ   ÚsuccessResultOfrL   r{   rM   rò   )rR   r—  rg   rÐ  rÝ   rŽ   r½  s   `    @@rA   Ú1test_transportProducingWhenQuiescentAfterFullBodyzKHTTP11ClientProtocolTests.test_transportProducingWhenQuiescentAfterFullBody`  s¾   ú€ ð ˆö	&ô
 $Ó%ˆ	Ü'¨Ó1ˆØ×Ñ 	Ô*Ø"×*Ñ*Ü�F˜D¤.°$À4ÔHó
ˆð 	×Ñðô	
ð ×'Ñ'¨Ó8ˆð 	×Ñ˜Ÿ™Ð*:Ô;ð
 	×Ñœ˜_Ó-¨qÔ1ð
 	×Ñ˜×0Ñ0°+Õ>r@   c           	      ó˜  ‡ ‡‡— g Šˆˆˆ fd„}t        «       }t        |«      Š‰j                  |«       ‰j                  t	        ddt
        dd¬«      «      }|j                  ‰j                  «       ‰j                  d«       ‰ j                  t        ‰«      d«       ‰ j                  ‰d	   ‰«       ‰ j                  ‰d
   t        «       y)zˆ
        The quiescentCallback is called before the request C{Deferred} fires,
        in cases where the response has no body.
        c                 ó„   •— ‰j                  | ‰«       ‰j                  | j                  d«       ‰j                  | «       y rú  rû  rü  s    €€€rA   r—  zUHTTP11ClientProtocolTests.test_quiescentCallbackCalledEmptyResponse.<locals>.callback•  rý  r@   rÙ   rÚ   NTrþ  ó&   HTTP/1.1 200 OK
Content-length: 0

rË   r   rc   )r   r)   rŠ   râ   r+   rf   rU   rˆ   rŒ   rL   rM   r  r?  r.   )rR   r—  rg   rÐ  rŽ   r½  s   `   @@rA   Ú)test_quiescentCallbackCalledEmptyResponsezCHTTP11ClientProtocolTests.test_quiescentCallbackCalledEmptyResponseŽ  sµ   ú€ ð
 ˆö	&ô
 $Ó%ˆ	Ü'¨Ó1ˆØ×Ñ 	Ô*à"×*Ñ*Ü�F˜D¤.°$À4ÔHó
ˆð 	×#Ñ# O×$:Ñ$:Ô;Ø×ÑÐUÔVà×Ñœ˜_Ó-¨qÔ1Ø×Ñ˜_¨QÑ/°Ô:Ø×Ñ˜o¨aÑ0´(Õ;r@   c           	      óâ  — g }t        «       }t        |j                  «      }|j                  |«       |j	                  t        ddt        dd¬«      «      }|j                  d«       g }|j                  |j                  «       |d   }t        «       }|j                  |«       |j                  j                  t        «       | j                  |g «       | j                  |j                   «       y)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â   r+   rf   rŒ   rU   r   r»  rÏ  rK   r/   rL   r´   r�  ©rR   r½  rg   rŽ   rÐ  rÁ  rÝ   r  s           rA   Útest_quiescentCallbackNotCalledz9HTTP11ClientProtocolTests.test_quiescentCallbackNotCalled¨  sÒ   € ð ˆÜ#Ó%ˆ	Ü'¨×(>Ñ(>Ó?ˆØ×Ñ 	Ô*à"×*Ñ*Ü�F˜D¤.°$À4ÔHó
ˆð 	×Ñðô	
ð ˆØ×#Ñ# F§M¡MÔ2Ø˜!‘9ˆä+Ó-ˆØ×Ñ˜\Ô*Ø×!Ñ!×&Ñ&¤|Ô4Ø×Ñ˜¨"Ô-Ø�‰˜	×/Ñ/Õ0r@   c           	      óâ  — g }t        «       }t        |j                  «      }|j                  |«       |j	                  t        ddt        dd¬«      «      }|j                  d«       g }|j                  |j                  «       |d   }t        «       }|j                  |«       |j                  j                  t        «       | j                  |g «       | j                  |j                   «       y)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  r  s           rA   Ú1test_quiescentCallbackNotCalledNonPersistentQueryzKHTTP11ClientProtocolTests.test_quiescentCallbackNotCalledNonPersistentQueryÇ  sÌ   € ð
 ˆÜ#Ó%ˆ	Ü'¨×(>Ñ(>Ó?ˆØ×Ñ 	Ô*à"×*Ñ*Ü�F˜D¤.°$À5ÔIó
ˆð 	×ÑÐUÔVàˆØ×#Ñ# F§M¡MÔ2Ø˜!‘9ˆä+Ó-ˆØ×Ñ˜\Ô*Ø×!Ñ!×&Ñ&¤|Ô4Ø×Ñ˜¨"Ô-Ø�‰˜	×/Ñ/Õ0r@   c           	      ó”  — d„ }t        j                  | t        «      }t        «       }t	        |«      }|j                  |«       |j                  t        ddt        dd¬«      «      }|j                  d«       g }|j                  |j                  «       |d   }t        «       }|j                  |«       |j                  j                  t         «       | j#                  d	t%        |«      «       |d   }	|	d
   }
| j'                  |
j(                  t*        «       | j-                  t*        «       | j/                  |j0                  «       y)zx
        If C{quiescentCallback} throws an exception, the error is logged and
        protocol is disconnected.
        c                 ó   — t        «       ‚rp   )ÚZeroDivisionError)r¸  s    rA   r—  zHHTTP11ClientProtocolTests.test_quiescentCallbackThrows.<locals>.callbackæ  s   € Ü#Ó%Ð%r@   rÙ   rÚ   NTrþ  r  r   rc   r<  )r   r=  r   r   r)   rŠ   râ   r+   rf   rŒ   rU   rˆ   r   r»  rÏ  rK   r/   r>  rM   r?  r    r  r@  r´   r�  )rR   r—  rA  rg   rŽ   rÐ  rÁ  rÝ   r  rB  rÔ   s              rA   Útest_quiescentCallbackThrowsz6HTTP11ClientProtocolTests.test_quiescentCallbackThrowsà  s  € ò	&ô +×<Ñ<¸TÔCUÓVˆä#Ó%ˆ	Ü'¨Ó1ˆØ×Ñ 	Ô*à"×*Ñ*Ü�F˜D¤.°$À4ÔHó
ˆð 	×ÑÐUÔVàˆØ×#Ñ# F§M¡MÔ2Ø˜!‘9ˆÜ+Ó-ˆØ×Ñ˜\Ô*Ø×!Ñ!×&Ñ&¤|Ô4à×Ñ˜!œS Ó-Ô.Ø˜A‘ˆØ�-Ñ ˆØ×Ñ˜aŸg™gÔ'8Ô9à×ÑÔ0Ô1Ø�‰˜	×/Ñ/Õ0r@   c                 ó  — t        «       }t        «       }|j                  |«       |j                  t	        ddt
        d«      «      }|j                  «        | j                  |j                  «       t        | |t        t        g«      S )a  
        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+   rf   Úcancelr´   ÚdisconnectedrY   r1   r   ræ  s       rA   Útest_cancelBeforeResponsez3HTTP11ClientProtocolTests.test_cancelBeforeResponse  sr   € ô $Ó%ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ø×!Ñ!¤'¨&°$¼ÈÓ"MÓNˆØ�‰ŒØ�‰˜	×.Ñ.Ô/Ü*Ø�&Ô/´.Ð1Aó
ð 	
r@   c                 ó*  — t        «       }t        «       }|j                  |«       |j                  t	        ddt
        d«      «      }|j                  d«       |j                  «        | j                  |j                  «       t        | |t        g«      S )a  
        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+   rf   rŒ   r  r´   r  r\   r   ræ  s       rA   Útest_cancelDuringResponsez3HTTP11ClientProtocolTests.test_cancelDuringResponse  sy   € ô $Ó%ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ø×!Ñ!¤'¨&°$¼ÈÓ"MÓNˆØ×ÑÐ4Ô5Ø�‰ŒØ�‰˜	×.Ñ.Ô/Ü# D¨&´>Ð2BÓCÐCr@   c                 ó®  ‡‡‡— t        «       }t        «       }|j                  |«       t        |«      ŠddiŠˆfd„Šˆˆfd„}|‰_        |j                  t        ddt        ‰«      «      }‰j                  j                  d«       |j                  «        | j                  |j                  «       | j                  ‰d   «       t        | |t        g«      S )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} has finished producing.
        Ú	cancelledFc                 ó   •— d‰d<   y )NTr   r?   )rG  ÚnonLocals    €rA   r  zJHTTP11ClientProtocolTests.assertCancelDuringBodyProduction.<locals>.cancel2  s   ø€ Ø$(ˆH�[Ò!r@   c                 óJ   •— | ‰_         t        ‰«      ‰_        ‰j                  S rp   ©Úconsumerr   rô   )r%  r  Úproducers    €€rA   ÚstartProducingzRHTTP11ClientProtocolTests.assertCancelDuringBodyProduction.<locals>.startProducing5  s$   ø€ Ø (ˆHÔÜ (¨Ó 0ˆHÔØ×$Ñ$Ð$r@   ó   POSTó   /bars   xxxxx)r   r)   rŠ   ÚStringProducerr'  râ   r+   rf   r%  rt  r  r´   r  r^   r   )	rR   ÚproducerLengthrg   rŽ   r'  rÁ  r  r"  r&  s	         @@@rA   Ú assertCancelDuringBodyProductionz:HTTP11ClientProtocolTests.assertCancelDuringBodyProduction$  s¸   ú€ ô $Ó%ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ü! .Ó1ˆà Ð'ˆô	)õ	%ð
 #1ˆÔà×!Ñ!¤'¨'°7¼NÈHÓ"UÓVˆØ×Ñ×Ñ Ô)Ø�‰ŒØ�‰˜	×.Ñ.Ô/Ø�‰˜ Ñ-Ô.Ü,¨T°6¼NÐ;KÓLÐLr@   c                 ó$   — | j                  d«      S )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,  rq   s    rA   Útest_cancelDuringBodyProductionz9HTTP11ClientProtocolTests.test_cancelDuringBodyProductionC  s   € ð ×4Ñ4°RÓ8Ð8r@   c                 ó,   — | j                  t        «      S )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 C{UNKNOWN_LENGTH} has finished producing.
        )r,  r   rq   s    rA   Ú&test_cancelDuringChunkedBodyProductionz@HTTP11ClientProtocolTests.test_cancelDuringChunkedBodyProductionL  s   € ð ×4Ñ4´^ÓDÐDr@   rp   )'r;   r<   r=   r>   rx  rz  r„  r‡  r�  r•  r›  rž  r   r§  r®  r±  rÃ  rÇ  rÌ  rÑ  rÔ  r×  rÚ  rß  rä  rç  ré  r÷  r  r
  r  r  r  r  r  r  r,  r/  r1  r?   r@   rA   rv  rv  í  sÈ   „ ñò
5ò@òòòò4Ló ò@KòJò
ò0ò.ò$0òd?ò4ò@'òR6ò:
ò@ò8Mò%ò*=òGò 80òt7;òr,?ò\<ò41ò>1ò2!1òF
ò"Dò Mò>9óEr@   rv  c                   ó2   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	y)	r*  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                 ó   — || _         y rp   )ró   )rR   ró   s     rA   Ú__init__zStringProducer.__init__f  s	   € Øˆ�r@   c                 óF   — || _         t        «       | _        | j                  S rp   r$  )rR   r%  s     rA   r'  zStringProducer.startProducingi  s   € Ø ˆŒÜ ›
ˆŒØ�}‰}Ðr@   c                 ó   — d| _         y rë   rj  rq   s    rA   ÚstopProducingzStringProducer.stopProducingn  rm  r@   c                  ó   — y rp   r?   rq   s    rA   ÚpauseProducingzStringProducer.pauseProducingq  ó   € àr@   c                  ó   — y rp   r?   rq   s    rA   ÚresumeProducingzStringProducer.resumeProducingu  r:  r@   N)
r;   r<   r=   r>   rk  r4  r'  r7  r9  r<  r?   r@   rA   r*  r*  V  s'   „ ñ
ð €Gòòò
òór@   r*  c                   ó¨   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚRequestTestsz
    Tests for L{Request}.
    c                 ó"   — t        «       | _        y rp   )r   rg   rq   s    rA   rx  zRequestTests.setUp  s   € Ü(Ó*ˆ�r@   c                 ó®   — t        ddt        d«      j                  | j                  «       | j	                  | j                  j                  «       d«       y)zk
        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+   rf   rh  rg   rL   r    rq   s    rA   Útest_sendSimplestRequestz%RequestTests.test_sendSimplestRequest‚  sD   € ô
 	�˜œn¨dÓ3×;Ñ;¸D¿N¹NÔKØ×ÑØ�N‰N× Ñ Ó"ðõ	
r@   c                 ó¶   — t        ddt        dd¬«      }|j                  | j                  «       | j	                  | j                  j                  «       d«       y)zO
        A pesistent request does not send 'Connection: close' header.
        rÙ   rÚ   NTrþ  s%   GET / HTTP/1.1
Host: example.com

rA  )rR   Úreqs     rA   Ú"test_sendSimplestPersistentRequestz/RequestTests.test_sendSimplestPersistentRequest�  sG   € ô �f˜d¤N°DÀTÔJˆØ�‰�D—N‘NÔ#Ø×ÑØ�N‰N× Ñ Ó"ØBõ	
r@   c                 óv  — t        ddgdgdœ«      }t        dd|d«      j                  | j                  «       | j                  j	                  «       j                  d«      }| j                  |d	   d
«       | j                  |dd ddg«       |d	= |dd…= |j                  «        | j                  |g d¢«       y)zf
        L{Request.writeTo} formats header data and writes it to the given
        transport.
        r˜   r«   rE   )r  rD   rÙ   ó   /fooNrÂ   r   ó   GET /foo HTTP/1.1éþÿÿÿr@   )ó   Connection: closes   Host: example.comrœ   rª   )r3   r+   rh  rg   r    ÚsplitrL   Úsort)rR   r­   Úliness      rA   Útest_sendRequestHeadersz$RequestTests.test_sendRequestHeaders›  s°   € ô
  f¨fÐ%5ÀÐ@PÑQÓRˆÜ�˜ ¨$Ó/×7Ñ7¸¿¹ÔGØ—‘×$Ñ$Ó&×,Ñ,¨WÓ5ˆØ×Ñ˜˜q™Ð#7Ô8Ø×Ñ˜˜r˜s˜ c¨3 ZÔ0Ø�!ˆH�e˜B™C�jØ�
‰
ŒØ×ÑØÚVõ	
r@   c                 óÐ  — t         D ]Ý  }t        ||gddgi«      }t        «       }t        dd|d«      j	                  |«       |j                  «       j                  d«      }| j                  |d   d«       | j                  |d	d d
d
g«       |d= |d	d…= |j                  d«       |j                  d«       dj                  t        t        g«      }| j                  ||g«       Œß y)z_
        Linear whitespace in request headers is replaced with a single
        space.
        rD   s   example.invalidrÙ   rG  NrÂ   r   rH  rI  r@   rJ  s   Host: example.invalids   : )r6   r3   r   r+   rh  r    rK  rL   ÚremoverŸ   r7   )rR   Ú	componentr­   rg   rM  ÚsanitizedHeaderLines         rA   Ú-test_sanitizeLinearWhitespaceInRequestHeadersz:RequestTests.test_sanitizeLinearWhitespaceInRequestHeaders¬  sä   € ô
 9ò 	;ˆIÜ˜y¨9¨+°wÐASÐ@TÐUÓVˆGÜ'Ó)ˆIÜ�F˜G W¨dÓ3×;Ñ;¸IÔFØ—O‘OÓ%×+Ñ+¨GÓ4ˆEØ×Ñ˜U 1™XÐ';Ô<Ø×Ñ˜U 2 3˜Z¨#¨s¨Ô4Ø�a�˜% ¡˜*Ø�L‰LÐ-Ô.Ø�L‰LÐ1Ô2Ø"'§*¡*¬n¼nÐ-MÓ"NÐØ×Ñ˜UÐ%8Ð$9Õ:ñ	;r@   c                 ó  — t        t        «      }t        ddt        |«      }|j	                  | j
                  «       | j                  |j                  d«       | j                  | j
                  j                  |«       | j                  | j
                  j                  «       | j                  | j
                  j                  «       d«       | j
                  j                  «        |j                  j                  d«       |j                  j                  d«       |j                   j#                  d«       | j                  | j
                  j                  d«       | j                  | j
                  j                  «       d«       y)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   xxxs   yyyyyyyyyyyyyyys!   3
xxx
f
yyyyyyyyyyyyyyy
0

)r*  r   r+   rf   rh  rg   ÚassertNotIdenticalr%  r  r&  r´   Ú	streamingrL   r    Úclearrt  rô   r—  ©rR   r&  râ   s      rA   Útest_sendChunkedRequestBodyz(RequestTests.test_sendChunkedRequestBody¾  s   € ô "¤.Ó1ˆÜ˜' 7¬N¸HÓEˆØ�‰˜Ÿ™Ô'à×Ñ × 1Ñ 1°4Ô8Ø×Ñ˜TŸ^™^×4Ñ4°hÔ?Ø�‰˜Ÿ™×0Ñ0Ô1à×ÑØ�N‰N× Ñ Ó"ðô	
ð 	�‰×ÑÔà×Ñ×Ñ Ô)Ø×Ñ×Ñ 	Ô*Ø×Ñ×"Ñ" 4Ô(Ø×Ñ˜TŸ^™^×4Ñ4°dÔ;Ø×ÑØ�N‰N× Ñ Ó"ØPõ	
r@   c                 óR  ‡ — t        t        «      }t        ddt        |«      }|j	                  ‰ j
                  «      }‰ j
                  j                  «        |j                  j                  t        «       «       ˆ fd„}‰ j                  |t        «      }|j                  |«       |S )aš  
        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                 ó¦   •— ‰j                  ‰j                  j                  «       d«       ‰j                  ‰j                  j                  d «       y r}  )rL   rg   r    r  r&  r  s    €rA   rS   zCRequestTests.test_sendChunkedRequestBodyWithError.<locals>.cbFailedî  s:   ø€ Ø×Ñ˜TŸ^™^×1Ñ1Ó3°SÔ9Ø× Ñ  §¡×!8Ñ!8¸$Õ?r@   )r*  r   r+   rf   rh  rg   rW  rô   r˜  r9   rT   rU   )rR   r&  râ   ÚwriteDeferredrS   rX   s   `     rA   Ú$test_sendChunkedRequestBodyWithErrorz1RequestTests.test_sendChunkedRequestBodyWithErrorß  s…   ø€ ô "¤.Ó1ˆÜ˜' 7¬N¸HÓEˆØŸ™¨¯©Ó7ˆØ�‰×ÑÔØ×Ñ×!Ñ!Ô"4Ó"6Ô7ô	@ð ×Ñ˜}Ô.@ÓAˆØ	�‰�hÔØˆr@   c                 óÖ  — t        d«      }t        ddt        |«      }|j                  | j                  «       | j                  |j                  d«       | j                  | j                  j                  |«       | j                  | j                  j                  «       | j                  | j                  j                  «       d«       | j                  j                  «        |j                  j                  d«       |j                  j!                  d«       | j                  | j                  j                  d«       | j                  | j                  j                  «       d«       y)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

r1  )r*  r+   rf   rh  rg   rU  r%  r  r&  r´   rV  rL   r    rW  rt  rô   r—  rX  s      rA   Útest_sendRequestBodyWithLengthz+RequestTests.test_sendRequestBodyWithLengthö  s  € ô " !Ó$ˆÜ˜' 7¬N¸HÓEˆØ�‰˜Ÿ™Ô'à×Ñ × 1Ñ 1°4Ô8Ø×Ñ˜TŸ^™^×4Ñ4°hÔ?Ø�‰˜Ÿ™×0Ñ0Ô1à×ÑØ�N‰N× Ñ Ó"ðô	
ð 	�‰×ÑÔà×Ñ×Ñ Ô'Ø×Ñ×"Ñ" 4Ô(Ø×Ñ˜TŸ^™^×4Ñ4°dÔ;Ø×Ñ˜Ÿ™×-Ñ-Ó/°Õ8r@   c                 ó¸   — t        |dt        d«      }|j                  | j                  «       | j	                  | j                  j                  «       |dz   «       y)a"  
        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}
        rG  NsK    /foo HTTP/1.1
Connection: close
Content-Length: 0
Host: example.com

rA  )rR   rn  râ   s      rA   Ú_sendRequestEmptyBodyWithLengthz,RequestTests._sendRequestEmptyBodyWithLength  sO   € ô ˜& '¬>¸4Ó@ˆØ�‰˜Ÿ™Ô'à×ÑØ�N‰N× Ñ Ó"Øð ñ õ	
r@   c                 ó&   — | j                  d«       y)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©rb  rq   s    rA   Útest_sendPUTRequestEmptyBodyz)RequestTests.test_sendPUTRequestEmptyBody(  s   € ð 	×,Ñ,¨VÕ4r@   c                 ó&   — | j                  d«       y)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(  Nrd  rq   s    rA   Útest_sendPOSTRequestEmptyBodyz*RequestTests.test_sendPOSTRequestEmptyBody0  s   € ð 	×,Ñ,¨WÕ5r@   c                 óV  — t        d«      }t        ddt        |«      }|j                  | j                  «      }|j
                  j                  d«       |j                  j                  d«       | j                  | j                  j                  d«       | j                  |t        «      S )a  
        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(  r)  ó   abN)r*  r+   rf   rh  rg   r%  rt  rô   r—  r  r&  rT   r'   ©rR   r&  râ   r\  s       rA   Ú#test_sendRequestBodyWithTooFewBytesz0RequestTests.test_sendRequestBodyWithTooFewBytes8  s…   € ô " !Ó$ˆÜ˜' 7¬N¸HÓEˆØŸ™¨¯©Ó7ˆØ×Ñ×Ñ Ô&Ø×Ñ×"Ñ" 4Ô(Ø×Ñ˜TŸ^™^×4Ñ4°dÔ;Ø×!Ñ! -´ÓAÐAr@   c                 óü  ‡ ‡‡— t        d«      Št        ddt        ‰«      }|j                  ‰ j                  «      }‰j
                  j                  d«       ‰ j                  ‰j                  «       ‰j
                  j                  d«       ‰ j                  ‰j                  «       ‰ j                  ‰ j                  j                  d«       ˆˆˆ fd„}‰ j                  |t        «      }|j                  |«       |S )a7  
        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)  ri  ó   cdNc                 óH  •— ‰j                  ‰j                  j                  «       d«       ‰j                  j                  «        ‰j	                  t
        ‰j                  j                  d«        ‰‰«       ‰j                  ‰j                  j                  «       d«       y )NsQ   POST /bar HTTP/1.1
Connection: close
Content-Length: 3
Host: example.com

abs   efr@   )rL   rg   r    rW  r   r    r%  rt  )rÒ   Úfinisherr&  rR   s    €€€rA   rS   zCRequestTests._sendRequestBodyWithTooManyBytesTest.<locals>.cbFailedg  sƒ   ø€ ð ×ÑØ—‘×$Ñ$Ó&ðôð �N‰N× Ñ Ô"ð ×Ñœk¨8×+<Ñ+<×+BÑ+BÀEÔJñ
 �XÔð ×Ñ˜TŸ^™^×1Ñ1Ó3°SÕ9r@   )r*  r+   rf   rh  rg   r%  rt  r¶   rk  r´   r  r&  rT   r'   rU   )rR   ro  râ   r\  rS   rX   r&  s   ``    @rA   Ú$_sendRequestBodyWithTooManyBytesTestz1RequestTests._sendRequestBodyWithTooManyBytesTestG  sÉ   ú€ ô " !Ó$ˆÜ˜' 7¬N¸HÓEˆØŸ™¨¯©Ó7ˆà×Ñ×Ñ Ô&ð 	×Ñ˜×)Ñ)Ô*à×Ñ×Ñ Ô&ð 	�‰˜×(Ñ(Ô)ð 	×Ñ˜TŸ^™^×4Ñ4°dÔ;ö	:ð: ×Ñ˜}¬oÓ>ˆØ	�‰�hÔØˆr@   c                 ó*   — d„ }| j                  |«      S )á  
        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                 ó:   — | j                   j                  d «       y rp   ©rô   r—  ©r&  s    rA   ro  zCRequestTests.test_sendRequestBodyWithTooManyBytes.<locals>.finisher�  ó   € Ø×Ñ×&Ñ& tÕ,r@   )rp  ©rR   ro  s     rA   Ú$test_sendRequestBodyWithTooManyBytesz1RequestTests.test_sendRequestBodyWithTooManyBytesˆ  s   € ò	-ð ×8Ñ8¸ÓBÐBr@   c                 óh   ‡ ‡— t        j                  ‰ t        «      Šˆˆ fd„}‰ j                  |«      S )rr  c                 ó$  •— | j                   j                  t        «       «       ‰d   }‰j                  d|«       |d   }‰j	                  |j
                  t        «       ‰j                  t        «      }‰j                  t        |«      d«       y )Nr   r<  rc   )	rô   r˜  r9   r¤  r?  r    r@  rL   rM   )r&  rB  rÔ   rš  rA  rR   s       €€rA   ro  zHRequestTests.test_sendRequestBodyErrorWithTooManyBytes.<locals>.finisherž  sv   ø€ Ø×Ñ×%Ñ%Ô&8Ó&:Ô;Ø ‘NˆEØ�M‰M˜-¨Ô/Ø�mÑ$ˆAØ×!Ñ! !§'¡'Ô+=Ô>Ø×+Ñ+Ô,>Ó?ˆFØ×ÑœS ›[¨!Õ,r@   )r   r=  r   rp  )rR   ro  rA  s   ` @rA   Ú)test_sendRequestBodyErrorWithTooManyBytesz6RequestTests.test_sendRequestBodyErrorWithTooManyBytes•  s0   ù€ ô +×<Ñ<¸TÔCUÓVˆõ	-ð ×8Ñ8¸ÓBÐBr@   c                 óF  — t        j                  | t        «      }t        d«      }t	        ddt
        |«      }|j                  | j                  «       |j                  j                  }|j                  j                  d«       |j                  j                  d«       |j                  t        «       «       |d   }| j                  d|«       |d   }| j!                  |j"                  t        «       | j%                  t'        | j)                  t        «      «      d«       y)	a’  
        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(  r)  r1  Nr   r<  rc   )r   r=  r   r*  r+   rf   rh  rg   r%  Ú	_finishedrt  rô   r—  r˜  r9   r¤  r?  r    rL   rM   r@  )rR   rA  r&  râ   ÚfinishedConsumingrB  rÔ   s          rA   Ú*test_sendRequestBodyErrorWithConsumerErrorz7RequestTests.test_sendRequestBodyErrorWithConsumerError©  sä   € ô +×<Ñ<¸TÔCUÓVˆÜ! !Ó$ˆÜ˜' 7¬N¸HÓEˆØ�‰˜Ÿ™Ô'à$×-Ñ-×7Ñ7Ðà×Ñ×Ñ Ô'Ø×Ñ×"Ñ" 4Ô(à×!Ñ!Ô"4Ó"6Ô7Ø˜A‘ˆØ�‰�m UÔ+Ø�-Ñ ˆØ×Ñ˜aŸg™gÔ'9Ô:Ø×Ñœ˜T×3Ñ3Ô4FÓGÓHÈ!ÕLr@   c                 óæ  — t        d«      }t        ddt        |«      }|j                  | j                  «      }|j
                  j                  d«        ||«       | j                  | j                  j                  d«       | j                  j                  «        | j                  t        |j
                  j                  d«       | j                  | j                  j                  «       d«       |S )a  
        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)  ri  Nrm  r@   )r*  r+   rf   rh  rg   r%  rt  r  r&  rW  r   r    rL   r    )rR   ro  r&  râ   r\  s        rA   Ú-_sendRequestBodyFinishedEarlyThenTooManyBytesz:RequestTests._sendRequestBodyFinishedEarlyThenTooManyBytesÄ  s·   € ô " !Ó$ˆÜ˜' 7¬N¸HÓEˆØŸ™¨¯©Ó7ˆà×Ñ×Ñ Ô&Ù�ÔØ×Ñ˜TŸ^™^×4Ñ4°dÔ;Ø�‰×ÑÔØ×Ñœ+ x×'8Ñ'8×'>Ñ'>ÀÔFØ×Ñ˜Ÿ™×-Ñ-Ó/°Ô5ØÐr@   c                 óR   — d„ }| j                  | j                  |«      t        «      S )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                 ó:   — | j                   j                  d «       y rp   rt  ru  s    rA   ro  zPRequestTests.test_sendRequestBodyFinishedEarlyThenTooManyBytes.<locals>.finisherß  rv  r@   )rT   r�  r'   rw  s     rA   Ú1test_sendRequestBodyFinishedEarlyThenTooManyBytesz>RequestTests.test_sendRequestBodyFinishedEarlyThenTooManyBytes×  s-   € ò	-ð ×!Ñ!Ø×>Ñ>¸xÓHÜó
ð 	
r@   c                 óR   — d„ }| j                  | j                  |«      t        «      S )a3  
        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                 óJ   — | j                   j                  t        «       «       y rp   )rô   r˜  r9   ru  s    rA   ro  zORequestTests.test_sendRequestBodyErroredEarlyThenTooManyBytes.<locals>.finisherï  s   € Ø×Ñ×%Ñ%Ô&8Ó&:Õ;r@   )rT   r�  r9   rw  s     rA   Ú0test_sendRequestBodyErroredEarlyThenTooManyBytesz=RequestTests.test_sendRequestBodyErroredEarlyThenTooManyBytesç  s-   € ò	<ð ×!Ñ!Ø×>Ñ>¸xÓHÜó
ð 	
r@   Nc                 ó’  — t        t        «      }t        ddt        |«      }|j	                  | j
                  «      }|j                  j                  |«       | j
                  j                  «        | j                  t        |j                  j                  d«       | j                  | j
                  j                  «       d«       |S )a  
        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Ö   r@   )r*  r   r+   rf   rh  rg   rô   r—  rW  r   r    r%  rt  rL   r    )rR   Ú_withr&  râ   r\  s        rA   Ú0test_sendChunkedRequestBodyFinishedThenWriteMorez=RequestTests.test_sendChunkedRequestBodyFinishedThenWriteMore÷  s•   € ô "¤.Ó1ˆÜ˜' 7¬N¸HÓEˆØŸ™¨¯©Ó7ˆØ×Ñ×"Ñ" 5Ô)Ø�‰×ÑÔà×Ñœ+ x×'8Ñ'8×'>Ñ'>ÀÔGØ×Ñ˜Ÿ™×-Ñ-Ó/°Ô5ØÐr@   c                 ór   — | j                  t        t        «       «      «      }| j                  |t        «      S )a$  
        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   r9   rT   )rR   rX   s     rA   Ú9test_sendChunkedRequestBodyFinishedWithErrorThenWriteMorezFRequestTests.test_sendChunkedRequestBodyFinishedWithErrorThenWriteMore	  s6   € ð ×AÑAÜÔ&Ó(Ó)ó
ˆð ×!Ñ! !Ô%7Ó8Ð8r@   c                 óö  — t        d«      }t        ddt        |«      }|j                  | j                  «      }| j                  | j                  j                  |«       | j                  | j                  j                  «       |j                  j                  d«       | j                  | j                  j                  «       d«       | j                  | j                  j                  «       |j                  j!                  t#        t%        «       «      «       | j                  | j                  j                  «       | j                  | j                  j                  d«       | j'                  |t$        «      S )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)  ri  sQ   POST /bar HTTP/1.1
Connection: close
Content-Length: 5
Host: example.com

abN)r*  r+   rf   rh  rg   r  r&  r´   rV  r%  rt  rL   r    r¶   r�  rô   r˜  r   r9   rT   rj  s       rA   Útest_sendRequestBodyWithErrorz*RequestTests.test_sendRequestBodyWithError	  s  € ô " !Ó$ˆÜ˜' 7¬N¸HÓEˆØŸ™¨¯©Ó7ˆð 	×Ñ˜TŸ^™^×4Ñ4°hÔ?Ø�‰˜Ÿ™×0Ñ0Ô1à×Ñ×Ñ Ô&Ø×ÑØ�N‰N× Ñ Ó"ðô	
ð 	×Ñ˜Ÿ™×5Ñ5Ô6Ø×Ñ×!Ñ!¤'Ô*<Ó*>Ó"?Ô@ð 	×Ñ˜Ÿ™×5Ñ5Ô6ð 	×Ñ˜TŸ^™^×4Ñ4°dÔ;à×!Ñ! -Ô1CÓDÐDr@   c           	      ó¼  — t        ddt        i «      d«      }| j                  t        |j                  | j
                  «       | j                  | j
                  j                  «       d«       t        ddt        dddgi«      d«      }| j                  t        |j                  | j
                  «       | j                  | j
                  j                  «       d«       y)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Ú   Nr@   s   HostrE   s   example.org)r+   r3   r   r   rh  rg   rL   r    )rR   râ   s     rA   Útest_hostHeaderRequiredz$RequestTests.test_hostHeaderRequired;	  s«   € ô
 ˜& $¬°«°TÓ:ˆØ×Ñœ* g§o¡o°t·~±~ÔFØ×Ñ˜Ÿ™×-Ñ-Ó/°Ô5äØ�Dœ' 7¨^¸^Ð,LÐ"MÓNÐPTó
ˆð 	×Ñœ* g§o¡o°t·~±~ÔFØ×Ñ˜Ÿ™×-Ñ-Ó/°Õ5r@   c                 ó   — t        d«      }t        ddt        |«      }|j                  | j                  «       | j                  |j                  «       |j                  «        | j                  |j                  «       y)zc
        L{Request.stopWriting} calls its body producer's C{stopProducing}
        method.
        r_  rÙ   rÚ   N)	r*  r+   rf   rh  rg   r¶   rk  rl  r´   rX  s      rA   Útest_stopWritingzRequestTests.test_stopWritingJ	  s`   € ô
 " !Ó$ˆÜ˜& $¬¸ÓAˆØ�‰˜Ÿ™Ô'Ø×Ñ˜×)Ñ)Ô*Ø×ÑÔØ�‰˜×(Ñ(Õ)r@   c                 óæ  — t        j                  | t        «      }t        d«      }d„ }||_        t        ddt        |«      }|j                  | j                  «       |j                  «        | j                  t        | j                  t        «      «      d«       | j                  dt        |«      «       |d   }| j                  d|«       |d   }| j!                  |j"                  t        «       y)	z–
        If the body producer's C{stopProducing} method raises an exception,
        L{Request.stopWriting} logs it and does not re-raise it.
        r_  c                  ó   — t        d«      ‚©NzstopProducing is bustedr:  r?   r@   rA   ÚbrokenStopProducingzBRequestTests.test_brokenStopProducing.<locals>.brokenStopProducing^	  s   € Ü$Ð%>Ó?Ð?r@   rÙ   rÚ   rc   r   r<  N)r   r=  r   r*  r7  r+   rf   rh  rg   rl  rL   rM   r@  r9   r>  r¤  r?  r    )rR   rA  r&  r—  râ   rB  rÔ   s          rA   Útest_brokenStopProducingz%RequestTests.test_brokenStopProducingV	  sÉ   € ô
 +×<Ñ<¸TÔCUÓVˆÜ! !Ó$ˆò	@ð "5ˆÔä˜& $¬¸ÓAˆØ�‰˜Ÿ™Ô'Ø×ÑÔØ×Ñœ˜T×3Ñ3Ô4FÓGÓHÈ!ÔLØ×Ñ˜!œS Ó-Ô.Ø˜A‘ˆØ�‰�m UÔ+Ø�-Ñ ˆØ×Ñ˜aŸg™gÔ'9Õ:r@   rp   )r;   r<   r=   r>   rx  rB  rE  rN  rS  rY  r]  r`  rb  re  rg  rk  rp  rx  r{  r  r�  r„  r‡  rŠ  rŒ  r�  r‘  r“  r˜  r?   r@   rA   r>  r>  z  sŒ   „ ñò+ò
ò	
ò
ò";ò$
òBò.9ò:
ò*5ò6òBò?òBCòCò(Mò6ò&
ò 
ó ò"
9ò%EòN6ò
*ó;r@   r>  c                   óB   — e Zd ZdZd„ Zd„ Zd„ Zdd„Zd„ Zd„ Z	d„ Z
d	„ Zy
)ÚLengthEnforcingConsumerTestsz/
    Tests for L{LengthEnforcingConsumer}.
    c                 óÀ   — t        «       | _        t        d«      | _        t	        «       | _        t        | j                  | j
                  | j                  «      | _        y )Nr.  )r   rÁ  r*  r&  r   rg   r#   Úenforcerrq   s    rA   rx  z"LengthEnforcingConsumerTests.setUps	  s@   € Ü“jˆŒÜ& rÓ*ˆŒÜ(Ó*ˆŒÜ/Ø�M‰M˜4Ÿ>™>¨4¯;©;ó
ˆ�r@   c                 óL  — | j                   j                  d«       | j                  | j                  j	                  «       d«       | j                  j                  «        | j                   j                  d«       | j                  | j                  j	                  «       d«       y)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.
        r1  s   defN)rœ  rt  rL   rg   r    rW  rq   s    rA   Ú
test_writez'LengthEnforcingConsumerTests.test_write{	  sr   € ð 	�‰×Ñ˜FÔ#Ø×Ñ˜Ÿ™×-Ñ-Ó/°Ô8Ø�‰×ÑÔØ�‰×Ñ˜FÔ#Ø×Ñ˜Ÿ™×-Ñ-Ó/°Õ8r@   c                 óŽ   — | j                   j                  d«       | j                  t        | j                   j                  «       y)z´
        L{LengthEnforcingConsumer._noMoreWritesExpected} raises
        L{WrongBodyLength} if it is called before the indicated number of bytes
        have been written.
        s	   xxxxxxxxxN)rœ  rt  r   r'   Ú_noMoreWritesExpectedrq   s    rA   Útest_finishedEarlyz/LengthEnforcingConsumerTests.test_finishedEarly‡	  s0   € ð 	�‰×Ñ˜HÔ%Ø×Ñœ/¨4¯=©=×+NÑ+NÕOr@   c                 óz  — | j                   j                  d«       | j                  | j                  j                  «       | j                   j                  d«       | j                  | j                  j                  «       |r| j                   j                  «        | j                  | j                  t        «      S )aN  
        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.
        ó
   xxxxxxxxxxó   x)
rœ  rt  r¶   r&  rk  r´   r   rT   rÁ  r'   )rR   Ú_unregisterAfters     rA   Útest_writeTooManyz.LengthEnforcingConsumerTests.test_writeTooMany�	  s€   € ð 	�‰×Ñ˜IÔ&Ø×Ñ˜Ÿ™×.Ñ.Ô/Ø�‰×Ñ˜DÔ!Ø�‰˜Ÿ™×-Ñ-Ô.ÙØ�M‰M×/Ñ/Ô1Ø×!Ñ! $§+¡+¬Ó?Ð?r@   c                 óX  — | j                   j                  d«       | j                   j                  «        | j                  | j                  j
                  «       | j                  t        | j                   j                  d«       | j                  | j                  j
                  «       y)zÒ
        If L{LengthEnforcingConsumer.write} is called after
        L{LengthEnforcingConsumer._noMoreWritesExpected}, it calls the
        producer's C{stopProducing} method and raises L{ExcessWrite}.
        r£  r¤  N)	rœ  rt  r   r¶   r&  rk  r   r    r´   rq   s    rA   Útest_writeAfterNoMoreExpectedz:LengthEnforcingConsumerTests.test_writeAfterNoMoreExpected 	  sp   € ð 	�‰×Ñ˜IÔ&Ø�‰×+Ñ+Ô-Ø×Ñ˜Ÿ™×.Ñ.Ô/Ø×Ñœ+ t§}¡}×':Ñ':¸DÔAØ�‰˜Ÿ™×-Ñ-Õ.r@   c                 ó$   — | j                  d«      S )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)r¦  rq   s    rA   Útest_finishedLatez.LengthEnforcingConsumerTests.test_finishedLate¬	  s   € ð ×%Ñ% dÓ+Ð+r@   c                 óŽ   — | j                   j                  d«       | j                  | j                   j                  «       d«       y)zŸ
        If L{LengthEnforcingConsumer._noMoreWritesExpected} is called after
        the correct number of bytes have been written it returns L{None}.
        r£  N)rœ  rt  r  r   rq   s    rA   Útest_finishedz*LengthEnforcingConsumerTests.test_finished´	  s3   € ð
 	�‰×Ñ˜IÔ&Ø×Ñ˜TŸ]™]×@Ñ@ÓBÀDÕIr@   c                 ó€   ‡ — ˆ fd„}|‰ j                   _        ˆ fd„}‰ j                  «       }|j                  |«       |S )a8  
        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   •— t         j                  ‰ j                  «       t        d«      ‚r–  )r*  r7  r&  r9   rq   s   €rA   r—  zRLengthEnforcingConsumerTests.test_stopProducingRaises.<locals>.brokenStopProducingÅ	  s!   ø€ Ü×(Ñ(¨¯©Ô7Ü$Ð%>Ó?Ð?r@   c                 ób   •— ‰j                  t        ‰j                  t        «      «      d«       y )Nrc   )rL   rM   r@  r9   r  s    €rA   Ú
cbFinishedzILengthEnforcingConsumerTests.test_stopProducingRaises.<locals>.cbFinishedË	  s$   ø€ Ø×ÑœS ×!7Ñ!7Ô8JÓ!KÓLÈaÕPr@   )r&  r7  r¦  rU   )rR   r—  r°  rX   s   `   rA   Útest_stopProducingRaisesz5LengthEnforcingConsumerTests.test_stopProducingRaises¼	  s>   ø€ ô	@ð ':ˆ�‰Ô#ô	Qð ×"Ñ"Ó$ˆØ	�‰�jÔ!Øˆr@   N)F)r;   r<   r=   r>   rx  rž  r¡  r¦  r¨  rª  r¬  r±  r?   r@   rA   rš  rš  n	  s2   „ ñò
ò
9òPó@ò 
/ò,òJór@   rš  c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚRequestBodyConsumerTestsz¤
    Tests for L{ChunkedEncoder} which sits between an L{ITransport} and a
    request/response body producer and chunked encodes everything written to
    it.
    c           	      ód   — | j                  t        t        t        t	        «       «      «      «       y)zC
        L{ChunkedEncoder} instances provide L{IConsumer}.
        N)r´   r   r   r   r   rq   s    rA   Útest_interfacez'RequestBodyConsumerTests.test_interfaceÚ	  s   € ð 	�‰œ¤Y´¼Ó?PÓ0QÓRÕSr@   c                 ó  — t        «       }t        |«      }|j                  d«       | j                  |j	                  «       d«       |j                  «        |j                  d«       | j                  |j	                  «       d«       y)z}
        L{ChunkedEncoder.write} writes to the transport the chunked encoded
        form of the bytes passed to it.
        rÖ   rÖ  s   xxxxxxxxxxxxxxxxs   10
xxxxxxxxxxxxxxxx
N)r   r   rt  rL   r    rW  )rR   rg   Úencoders      rA   rž  z#RequestBodyConsumerTests.test_writeà	  sg   € ô
 $Ó%ˆ	Ü  Ó+ˆØ�‰�fÔØ×Ñ˜Ÿ™Ó*¨OÔ<Ø�‰ÔØ�‰�iÔ Ø×Ñ˜Ÿ™Ó*Ð,KÕLr@   c                 ól  — t        «       }t        «       }t        |«      }|j                  |d«       | j	                  |j
                  |«       | j                  |j                  «       |j                  «        | j	                  |j
                  d«       | j                  |j                  «       d«       y)a  
        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´   rV  ÚunregisterProducerrL   r    )rR   rg   r&  r·  s       rA   Útest_producerRegistrationz2RequestBodyConsumerTests.test_producerRegistrationí	  sŽ   € ô $Ó%ˆ	Ü“8ˆÜ  Ó+ˆØ× Ñ  ¨4Ô0Ø×Ñ˜Y×/Ñ/°Ô:Ø�‰˜	×+Ñ+Ô,Ø×"Ñ"Ô$Ø×Ñ˜Y×/Ñ/°Ô6Ø×Ñ˜Ÿ™Ó*¨LÕ9r@   N)r;   r<   r=   r>   rµ  rž  r»  r?   r@   rA   r³  r³  Ó	  s   „ ñòTòMó:r@   r³  c                   ó:   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)
ÚTransportProxyProducerTestszn
    Tests for L{TransportProxyProducer} which proxies the L{IPushProducer}
    interface of a transport.
    c                 óT   — | j                  t        t        t        d«      «      «       y)zO
        L{TransportProxyProducer} instances provide L{IPushProducer}.
        N)r´   r   r   r&   rq   s    rA   rµ  z*TransportProxyProducerTests.test_interface
  s   € ð 	�‰œ¤]Ô4JÈ4Ó4PÓQÕRr@   c                 ó¾   — t        «       }t        |«      }| j                  |j                  |«       |j	                  «        | j                  |j                  d«       y)z~
        L{TransportProxyProducer.stopProxying} drops the reference to the
        wrapped L{IPushProducer} provider.
        N)r   r&   r  rÝ  ÚstopProxying©rR   rg   Úproxys      rA   Ú%test_stopProxyingUnreferencesProducerzATransportProxyProducerTests.test_stopProxyingUnreferencesProducer
  sJ   € ô
 $Ó%ˆ	Ü& yÓ1ˆØ×Ñ˜UŸ_™_¨iÔ8Ø×ÑÔØ×Ñ˜UŸ_™_¨dÕ3r@   c                 óv  — t        «       }|j                  «        t        |«      }| j                  |j                  d«       |j                  «        | j                  |j                  d«       |j                  «        |j                  «        |j                  «        | j                  |j                  d«       y)z™
        L{TransportProxyProducer.resumeProducing} calls the wrapped
        transport's C{resumeProducing} method unless told to stop proxying.
        r  rï   N)r   r9  r&   rL   rò   r<  rÀ  rÁ  s      rA   Útest_resumeProducingz0TransportProxyProducerTests.test_resumeProducing
  s–   € ô
 $Ó%ˆ	Ø× Ñ Ô"ä& yÓ1ˆà×Ñ˜×0Ñ0°(Ô;Ø×ÑÔà×Ñ˜×0Ñ0°+Ô>à× Ñ Ô"Ø×ÑÔð 	×ÑÔØ×Ñ˜×0Ñ0°(Õ;r@   c                 óV  — t        «       }t        |«      }| j                  |j                  d«       |j	                  «        | j                  |j                  d«       |j                  «        |j                  «        |j	                  «        | j                  |j                  d«       y)z—
        L{TransportProxyProducer.pauseProducing} calls the wrapped transport's
        C{pauseProducing} method unless told to stop proxying.
        rï   r  N)r   r&   rL   rò   r9  r<  rÀ  rÁ  s      rA   Útest_pauseProducingz/TransportProxyProducerTests.test_pauseProducing,
  sŠ   € ô
 $Ó%ˆ	ä& yÓ1ˆà×Ñ˜×0Ñ0°+Ô>Ø×ÑÔà×Ñ˜×0Ñ0°(Ô;à×!Ñ!Ô#Ø×ÑÔð 	×ÑÔØ×Ñ˜×0Ñ0°+Õ>r@   c                 ó`  — t        «       }t        |«      }| j                  |j                  d«       |j	                  «        | j                  |j                  d«       t        «       }t        |«      }|j                  «        |j	                  «        | j                  |j                  d«       y)z•
        L{TransportProxyProducer.stopProducing} calls the wrapped transport's
        C{stopProducing} method unless told to stop proxying.
        rï   rk  N)r   r&   rL   rò   r7  rÀ  rÁ  s      rA   Útest_stopProducingz.TransportProxyProducerTests.test_stopProducingA
  sŽ   € ô
 $Ó%ˆ	Ü& yÓ1ˆà×Ñ˜×0Ñ0°+Ô>Ø×ÑÔà×Ñ˜×0Ñ0°)Ô<ä#Ó%ˆ	Ü& yÓ1ˆØ×ÑÔØ×ÑÔà×Ñ˜×0Ñ0°+Õ>r@   c                 ón  — t        «       }t        «       }|j                  |«       ||_        t	        |«      }| j                  |j                  «       | j                  |j                  d«       |j                  «        | j                  |j                  d«       | j                  |j                  «       y)zs
        L{TransportProxyProducer.loseConnection} calls the wrapped transport's
        C{loseConnection}.
        rï   N)r   r   rŠ   rŽ   r&   r´   Ú	connectedrL   rò   ÚloseConnectionr¶   ©rR   rg   rŽ   rÂ  s       rA   Ú test_loseConnectionWhileProxyingz<TransportProxyProducerTests.test_loseConnectionWhileProxyingU
  s”   € ô
 5Ó6ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ø%ˆ	ÔÜ& yÓ1ˆà�‰˜	×+Ñ+Ô,Ø×Ñ˜×0Ñ0°+Ô>à×ÑÔð 	×Ñ˜×0Ñ0°+Ô>Ø×Ñ˜×,Ñ,Õ-r@   c                 ó  — t        «       }t        «       }|j                  |«       ||_        t	        |«      }|j                  «        | j                  |j                  «       |j                  «        | j                  |j                  «       y)zm
        L{TransportProxyProducer.loseConnection} does nothing when the
        proxy is not active.
        N)	r   r   rŠ   rŽ   r&   rÀ  r´   rË  rÌ  rÍ  s       rA   Útest_loseConnectionNotProxyingz:TransportProxyProducerTests.test_loseConnectionNotProxyingj
  sr   € ô
 5Ó6ˆ	Ü'Ó)ˆØ×Ñ 	Ô*Ø%ˆ	ÔÜ& yÓ1ˆØ×ÑÔØ�‰˜	×+Ñ+Ô,à×ÑÔð 	�‰˜	×+Ñ+Õ,r@   N)r;   r<   r=   r>   rµ  rÃ  rÅ  rÇ  rÉ  rÎ  rÐ  r?   r@   rA   r½  r½  ÿ	  s+   „ ñò
Sò	4ò<ò,?ò*?ò(.ó*-r@   r½  c                   ój   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚResponseTestsz 
    Tests for L{Response}.
    c                 óh   — t        t        «       «      }| j                  t        t        |«      «       y)z=
        L{Response} instances provide L{IResponse}.
        N)rh   r   r´   r   r5   ©rR   rÝ   s     rA   Útest_verifyInterfacez"ResponseTests.test_verifyInterface‚
  s$   € ô )¬Ó):Ó;ˆØ�‰œ¤Y°Ó9Õ:r@   c                 ó>  ‡— g Št        «       } G ˆfd„dt        «      } |«       }t        |«      }|j                  |«       ‰\  }|j	                  «        | j                  |j                  d«       |j                  «        | j                  |j                  d«       y)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                   ó   •— e Zd Zˆ fd„Zy)ú7ResponseTests.test_makeConnection.<locals>.SomeProtocolc                 ó(   •— ‰j                  |«       y rp   rì   )rR   r&  Ú	producerss     €rA   rŠ   zFResponseTests.test_makeConnection.<locals>.SomeProtocol.makeConnection“
  s   ø€ Ø× Ñ  Õ*r@   N©r;   r<   r=   rŠ   )rÚ  s   €rA   ÚSomeProtocolrØ  ’
  s   ø„ õ+r@   rÜ  r  rï   N)r   r   rh   r»  r9  rL   rò   r<  )rR   rg   rÜ  r%  rÝ   ÚtheProducerrÚ  s         @rA   Útest_makeConnectionz!ResponseTests.test_makeConnection‰
  sŠ   ø€ ð ˆ	Ü#Ó%ˆ	ö	+œ8ô 	+ñ  “>ˆÜ(¨Ó3ˆØ×Ñ˜XÔ&Ø!‰ˆØ×"Ñ"Ô$Ø×Ñ˜×0Ñ0°(Ô;Ø×#Ñ#Ô%Ø×Ñ˜×0Ñ0°+Õ>r@   c                 óÊ   ‡— g Š G ˆfd„dt         «      } |«       }t        t        «       «      }|j                  |«       |j	                  d«       | j                  ‰dg«       y)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                   ó   •— e Zd Zˆ fd„Zy)ú5ResponseTests.test_dataReceived.<locals>.ListConsumerc                 ó(   •— ‰j                  |«       y rp   rì   ©rR   rÐ   r¾   s     €rA   rŒ   zBResponseTests.test_dataReceived.<locals>.ListConsumer.dataReceived¨
  ó   ø€ Ø—‘˜TÕ"r@   N©r;   r<   r=   rŒ   ©r¾   s   €rA   ÚListConsumerrá  §
  ó   ø„ õ#r@   rç  rÖ   N)r   rh   r   r»  rð   rL   )rR   rç  r%  rÝ   r¾   s       @rA   Útest_dataReceivedzResponseTests.test_dataReceivedŸ
  sZ   ø€ ð ˆö	#œ8ô 	#ñ  “>ˆÜ(¬Ó):Ó;ˆØ×Ñ˜XÔ&à×"Ñ" 6Ô*Ø×Ñ˜  Õ)r@   c                 ó@  ‡— g Š G ˆfd„dt         «      } |«       }t        t        «       «      }|j                  |«       |j	                  «        ‰d   j                  t        «       | j                  t        ‰«      d«       | j                  |j                  d«       y)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                   ó   •— e Zd Zˆ fd„Zy)ú7ResponseTests.test_connectionLost.<locals>.ListConsumerc                 ó(   •— ‰j                  |«       y rp   rì   )rR   rO   Úlosts     €rA   r.  zFResponseTests.test_connectionLost.<locals>.ListConsumer.connectionLost¼
  s   ø€ Ø—‘˜FÕ#r@   N)r;   r<   r=   r.  )rî  s   €rA   rç  rì  »
  s   ø„ õ$r@   rç  r   rc   N)r   rh   r   r»  rñ   rK   r/   rL   rM   r  Ú_bodyProtocol)rR   rç  r%  rÝ   rî  s       @rA   Útest_connectionLostz!ResponseTests.test_connectionLost²
  s‚   ø€ ð ˆö	$œ8ô 	$ñ  “>ˆÜ(¬Ó):Ó;ˆØ×Ñ˜XÔ&à×"Ñ"Ô$ØˆQ‰�‰”\Ô"Ø×Ñœ˜T› AÔ&ð 	×Ñ˜X×3Ñ3°TÕ:r@   c                 óH  ‡— g Š G ˆfd„dt         «      } |«       }t        t        «       «      }|j                  d«       |j                  d«       |j	                  |«       |j                  d«       | j                  ‰g d¢«       | j                  |j                  d«       y)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                   ó   •— e Zd Zˆ fd„Zy)ú8ResponseTests.test_bufferEarlyData.<locals>.ListConsumerc                 ó(   •— ‰j                  |«       y rp   rì   rã  s     €rA   rŒ   zEResponseTests.test_bufferEarlyData.<locals>.ListConsumer.dataReceivedÔ
  rä  r@   Nrå  ræ  s   €rA   rç  ró  Ó
  rè  r@   rç  rÖ   r˜   r«   )rÖ   r˜   r«   N)r   rh   r   rð   r»  rL   r  Ú_bodyBuffer)rR   rç  rŽ   rÝ   r¾   s       @rA   Útest_bufferEarlyDataz"ResponseTests.test_bufferEarlyDataË
  s�   ø€ ð ˆö	#œ8ô 	#ñ  “>ˆÜ(¬Ó):Ó;ˆØ×"Ñ" 6Ô*Ø×"Ñ" 6Ô*Ø×Ñ˜XÔ&Ø×"Ñ" 6Ô*Ø×Ñ˜Ò 8Ô9ð 	×Ñ˜X×1Ñ1°4Õ8r@   c                 ó®   — t        t        «       «      }|j                  t        «       «       | j	                  t
        |j                  t        «       «       y)zb
        L{Response.deliverBody} raises L{RuntimeError} if called more than
        once.
        N)rh   r   r»  r   r   r€   rÔ  s     rA   Ú test_multipleStartProducingFailsz.ResponseTests.test_multipleStartProducingFailsâ
  s;   € ô
 )¬Ó):Ó;ˆØ×ÑœX›ZÔ(Ø×Ñœ,¨×(<Ñ(<¼h»jÕIr@   c                 óÎ   — t        t        «       «      }|j                  t        «       «       |j	                  «        | j                  t        |j                  t        «       «       y)zw
        L{Response.deliverBody} raises L{RuntimeError} if called after
        L{Response._bodyDataFinished}.
        N)rh   r   r»  r   rñ   r   r€   rÔ  s     rA   Ú%test_startProducingAfterFinishedFailsz3ResponseTests.test_startProducingAfterFinishedFailsë
  sG   € ô
 )¬Ó):Ó;ˆØ×ÑœX›ZÔ(Ø×"Ñ"Ô$Ø×Ñœ,¨×(<Ñ(<¼h»jÕIr@   c                 óŒ   — t        t        «       «      }|j                  «        | j                  t        |j
                  d«       y)z 
        L{Response._bodyDataReceived} raises L{RuntimeError} if called after
        L{Response._bodyDataFinished} but before L{Response.deliverBody}.
        rÖ   N)rh   r   rñ   r   r€   rð   rÔ  s     rA   Ú'test_bodyDataReceivedAfterFinishedFailsz5ResponseTests.test_bodyDataReceivedAfterFinishedFailsõ
  s5   € ô
 )¬Ó):Ó;ˆØ×"Ñ"Ô$Ø×Ñœ,¨×(BÑ(BÀFÕKr@   c                 ó¾   — t        t        «       «      }|j                  «        |j                  t	        «       «       | j                  t        |j                  d«       y)zŸ
        L{Response._bodyDataReceived} raises L{RuntimeError} if called after
        L{Response._bodyDataFinished} and after L{Response.deliverBody}.
        rÖ   N)rh   r   rñ   r»  r   r   r€   rð   rÔ  s     rA   Ú'test_bodyDataReceivedAfterDeliveryFailsz5ResponseTests.test_bodyDataReceivedAfterDeliveryFailsþ
  sE   € ô
 )¬Ó):Ó;ˆØ×"Ñ"Ô$Ø×ÑœX›ZÔ(Ø×Ñœ,¨×(BÑ(BÀFÕKr@   c                 óŠ   — t        t        «       «      }|j                  «        | j                  t        |j                  «       y)zh
        L{Response._bodyDataFinished} raises L{RuntimeError} if called more
        than once.
        N)rh   r   rñ   r   r€   rÔ  s     rA   Ú'test_bodyDataFinishedAfterFinishedFailsz5ResponseTests.test_bodyDataFinishedAfterFinishedFails  s3   € ô
 )¬Ó):Ó;ˆØ×"Ñ"Ô$Ø×Ñœ,¨×(BÑ(BÕCr@   c                 ó¼   — t        t        «       «      }|j                  «        |j                  t	        «       «       | j                  t        |j                  «       y)z{
        L{Response._bodyDataFinished} raises L{RuntimeError} if called after
        the body has been delivered.
        N)rh   r   rñ   r»  r   r   r€   rÔ  s     rA   Ú'test_bodyDataFinishedAfterDeliveryFailsz5ResponseTests.test_bodyDataFinishedAfterDeliveryFails  sC   € ô
 )¬Ó):Ó;ˆØ×"Ñ"Ô$Ø×ÑœX›ZÔ(Ø×Ñœ,¨×(BÑ(BÕCr@   c                 ó<  ‡— g Š G ˆfd„dt         «      }t        «       }|j                  «         |«       }t        |«      }| j	                  |j
                  d«       |j                  |«       | j	                  ‰dg«       | j	                  |j
                  d«       y)z–
        L{Response.deliverBody} resumes the HTTP connection's transport
        after passing it to the consumer's C{makeConnection} method.
        c                   ó   •— e Zd Zˆ fd„Zy)ú9ResponseTests.test_transportResumed.<locals>.ListConsumerc                 ó<   •— ‰j                  |j                  «       y rp   )rˆ   rò   )rR   rg   ÚtransportStates     €rA   rŠ   zHResponseTests.test_transportResumed.<locals>.ListConsumer.makeConnection#  s   ø€ Ø×%Ñ% i×&=Ñ&=Õ>r@   NrÛ  )r  s   €rA   rç  r  "  s   ø„ õ?r@   rç  r  rï   N)r   r   r9  rh   rL   rò   r»  )rR   rç  rg   rŽ   rÝ   r  s        @rA   Útest_transportResumedz#ResponseTests.test_transportResumed  s‰   ø€ ð
 ˆö	?œ8ô 	?ô $Ó%ˆ	Ø× Ñ Ô"Ù“>ˆÜ(¨Ó3ˆØ×Ñ˜×0Ñ0°(Ô;Ø×Ñ˜XÔ&Ø×Ñ˜¨(¨Ô4Ø×Ñ˜×0Ñ0°+Õ>r@   c                 ó>  — t        «       }t        |«      }|j                  d«       |j                  d«       |j                  «        t	        «       }|j                  |«       | j                  |j                  d«       |j                  j                  t        «       y)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   rh   rð   rñ   r   r»  rL   rÐ   rÏ  rK   r/   ©rR   rg   rÝ   rŽ   s       rA   Ú)test_bodyDataFinishedBeforeStartProducingz7ResponseTests.test_bodyDataFinishedBeforeStartProducing/  s|   € ô $Ó%ˆ	Ü(¨Ó3ˆØ×"Ñ" 6Ô*Ø×"Ñ" 6Ô*Ø×"Ñ"Ô$ä'Ó)ˆØ×Ñ˜XÔ&Ø×Ñ˜Ÿ™¨	Ô2Ø×Ñ×"Ñ"¤<Õ0r@   c                 ó  — t        «       }t        |«      }t        «       }|j                  |«       | j	                  |j
                  d«       |j                  t        t        «       «      «       |j                  j                  t        «       y)a	  
        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   rh   r   r»  rL   r{   rñ   r   r9   rÏ  rK   r
  s       rA   Ú#test_finishedWithErrorWhenConnectedz1ResponseTests.test_finishedWithErrorWhenConnectedA  sn   € ô $Ó%ˆ	Ü(¨Ó3ˆä'Ó)ˆØ×Ñ˜XÔ&ð 	×Ñ˜Ÿ™¨+Ô6Ø×"Ñ"¤7Ô+=Ó+?Ó#@ÔAà×Ñ×"Ñ"Ô#5Õ6r@   c                 ó  — t        «       }t        |«      }| j                  |j                  d«       |j	                  t        t        «       «      «       t        «       }|j                  |«       |j                  j                  t        «       y)a  
        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   rh   rL   r{   rñ   r   r9   r   r»  rÏ  rK   r
  s       rA   Ú!test_finishedWithErrorWhenInitialz/ResponseTests.test_finishedWithErrorWhenInitialT  sn   € ô $Ó%ˆ	Ü(¨Ó3ˆð 	×Ñ˜Ÿ™¨)Ô4Ø×"Ñ"¤7Ô+=Ó+?Ó#@ÔAä'Ó)ˆØ×Ñ˜XÔ&à×Ñ×"Ñ"Ô#5Õ6r@   N)r;   r<   r=   r>   rÕ  rÞ  ré  rð  rö  rø  rú  rü  rþ  r   r  r  r  r  r  r?   r@   rA   rÒ  rÒ  }
  sX   „ ñò;ò?ò,*ò&;ò29ò.JòJòLòLòDòDò?ò(1ò$7ó&7r@   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/   r0   r1   Útwisted.web.httpr2   Útwisted.web.http_headersr3   Útwisted.web.iwebr4   r5   Útwisted.web.test.requesthelperr6   r7   Ú	Exceptionr9   rC   rf   rY   r\   r^   r`   rh   rj   r„   rÁ   rÅ   rÈ   re  rq  rv  r*  r>  rš  r³  r½  rÒ  r?   r@   rA   ú<module>r%     s‘  ðñõ å &Ý .ç JÓ Jß Aß @Ý .÷ó õ .Ý 0Ý *Ý +÷÷ ÷ ÷ ÷ ÷(
÷ 
õ 
õ 'Ý ,ß 5÷ô˜ô ô 	ô ñ ˜' NÐ#3Ð4Ó5€ò%òPTòòòLô6 (ô 6÷BSMñ SMôlÐ+;¸Xô ôÐ.>Àô ôY	.˜Hô Y	.÷xñ ÷0ñ ôfE ô fEñR ˆ]Ó÷ ð  ó ð ôFq;�8ô q;ôhb 8ô bôJ):˜xô ):ôX{- (ô {-ô|h7�Hõ h7r@   