%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/web/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_newclient.cpython-312.pyc

�

Ϫ�f4����dZddlmZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
mZddlmZmZddlmZdd	lmZmZmZmZdd
lmZddlmZddlmZdd
lm Z ddl!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/m0Z0m1Z1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=ddl>m?Z?ddl@mAZAddlBmCZCmDZDddlEmFZFmGZGGd�deH�ZIGd�deH�ZJeAddgi�ZKd�ZLd�ZMd�ZNd�ZOd�ZPGd�d e �ZQGd!�d"�ZRGd#�d$eRe �ZSGd%�d&eRe �ZTGd'�d(e �ZUGd)�d*�ZVGd+�d,�ZWGd-�d.e �ZXeeC�Gd/�d0��ZYGd1�d2e �ZZGd3�d4e �Z[Gd5�d6e �Z\Gd7�d8e �Z]Gd9�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��eZdZdZy)�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.pyr9r9Cs��r@r9c��eZdZdZy)�AnotherArbitraryExceptionzI
    Similar to L{ArbitraryException} but with a different identity.
    Nr:r?r@rArCrCJs��r@rC�host�example.comc�\�����fd�}�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|���jt	|j�t	��d|j�d��d��|S)Nzlen(z	) != len(�))�zip�reasons�trap�assertEqual�len)�err�reason�type�reasonTypes�selfs   ��rA�cbFailedz-assertWrapperExceptionTypes.<locals>.cbFailednsl�������[�9�	�L�F�D��K�K���	�������������3�;�;�-�y��
�Q�7�	
�
�
r@)�
assertFailure�addCallback)rR�deferred�mainTyperQrS�ds`  `  rA�assertWrapperExceptionTypesrYUs-���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}.
    )rYr0�rRrVrQs   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}.
    )rYr,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}.
    )rYr-r[s   rA�assertRequestTransmissionFailedr`�s��
'��h�1�;��r@c�(�tdddt|�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.
    �sHTTP�rc���OK)r.�_boringHeaders)�	transports rA�justTransportResponserh�s���O�S�%���K�Kr@c��eZdZdZd�Zy)�MakeStatefulDispatcherTestsz.
    Tests for L{makeStatefulDispatcher}.
    c��Gd�d�}|�}|j|j�d�d|_|j|j�d�d|_|jt|j�y)z�
        A method defined with L{makeStatefulDispatcher} invokes a second
        method based on the current state of the object.
        c�4�eZdZdZd�Zede�Zd�Zd�Zy)�CMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo�Ac��y�Nr?�rRs rA�barzGMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo.bar�s��r@�quuxc��y)N�ar?rqs rA�_quux_AzKMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo._quux_A����r@c��y)N�br?rqs rA�_quux_BzKMakeStatefulDispatcherTests.test_functionCalledByState.<locals>.Foo._quux_B�rwr@N)r;r<r=�_staterrr(rvrzr?r@rA�Foorm�s$���F�
�)���5�C�
�
r@r|ru�Bry�CN)rLrrr{�assertRaises�RuntimeError)rRr|�statefuls   rA�test_functionCalledByStatez6MakeStatefulDispatcherTests.test_functionCalledByState�sc��	�	��5����������-������������-�������,����5r@N)r;r<r=r>r�r?r@rArjrj�s���6r@rjc�b�eZdZUdZdZeeed<d�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zy)�_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|_|jt	��|j|jt�|jd|jz�|j|dg�|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�makeConnectionrrL�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|_|jt	��|jd|jz�||fS)Nr�)r"�__setitem__�headerReceivedr�rr�r��rR�headerr�s   rA�_headerTestSetupz!_HTTPParserTests._headerTestSetup�sP�����<��"(�"4�"4������� 1�2����0�4�8�8�;�<��x��r@c��|j�\}}|jd|jz�|j|j�|j|ddi�|j|jt
�y)ze
        L{HTTPParser} calls its C{headerReceived} method when it receives a
        header.
        s	X-Foo:bar�X-Foo�barN�r�r�r�rLr�rr�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�\}}|jd|jz�|jd|jz�|jd|jz�|j|j�|j|ddi�|j|jt
�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�\}}|jjgd��}|jd|z�|jd|z�|j|j�|j	|ddd��y)z�
        Leading and trailing linear whitespace is stripped from the header
        value passed to the C{headerReceived} callback.
        )s 	 s bar 	s 	r@sX-Bar:sX-Foo:r�)r�sX-BarN)r�r��joinr�rL)rRr�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�\}���fd�}|�_�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�_yrp)r�r�r)�calledr�s��rA�allHeadersReceivedzD_HTTPParserTests.test_allHeadersCallback.<locals>.allHeadersReceiveds����M�M�(�.�.�)�#�H�Nr@N)r�r�r�r�rLrr�r)rRr�r�r�r�s   @@rA�test_allHeadersCallbackz(_HTTPParserTests.test_allHeadersCallbacksd���
���0�0�2����	$�'9��#����d�h�h�'�����&��*��������0r@c���|j�\}}|j|j�|j|i�|j|jt
�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_noHeaderCallbacksM��
 �0�0�2�������d�h�h�'������$��������.r@c��t�}|jt��|jd|jz�|jd|jz�|jd|jz�|j|j�dddgfg}|j|t
|jj���y)zc
        All headers received by L{HTTPParser} are added to
        L{HTTPParser.headers}.
        r�r��
X-Foo: bazr�r��bazN)	r"r�rr�r�rL�list�headers�getAllRawHeaders)rRr��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�}gd�}|D]'}|j|j|�d|�d���)|j|jd�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-alivestestrailersstransfer-encodingsupgradesproxy-connectionz
Expecting z. to be a connection control header, but wasn'tsdatez`Expecting the arbitrarily selected 'date' header to not be a connection control header, but was.N)r"�
assertTrue�isConnectionControlHeader�assertFalse)rRr��connHeaderNamesr�s    rA�test_connectionControlHeadersz._HTTPParserTests.test_connectionControlHeaders1sh���<��	
��&�	�F��O�O��2�2�6�:�"�%�
�	�	
����.�.�w�7�
4�	
r@c���t�}|jt��|jt	��|jt|jt	��y)zi
        L{HTTPParser.switchToBodyMode} raises L{RuntimeError} if called more
        than once.
        N)r"r�r�switchToBodyMode�objectrr��rRr�s  rA�test_switchToBodyModez&_HTTPParserTests.test_switchToBodyModeOsF��
�<������ 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@rAr�r��sL���
 �C��%���1� �/�/�
G�1�"/�N�
�<Mr@r�c��eZdZdZdZy)�$HTTPParserRFCComplaintDelimeterTestsz<
    L{_HTTPParserTests} using standard CR LF newlines.
    �
N�r;r<r=r>r�r?r@rAr�r�Zs����Cr@r�c��eZdZdZdZy)�'HTTPParserNonRFCComplaintDelimeterTestsz5
    L{_HTTPParserTests} using bare LF newlines.
    �
Nr�r?r@rAr�r�bs����Cr@r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z y) �HTTPClientParserTestszd
    Tests for L{HTTPClientParser} which is responsible for parsing HTTP
    response messages.
    c�^�tdd�}|j|jd�d�y)zj
        L{HTTPClientParser.parseVersion} parses a status line into its three
        components.
        Ns	CANDY/7.2)sCANDY��)r!rL�parseVersionr�s  rA�test_parseVersionz'HTTPClientParserTests.test_parseVersionps,��
$�D�$�/������.�.�|�<�>N�Or@c�����tdd�}t�|j����fd�}|d�|d�|d�|d�|d�|d�y)	zr
        L{HTTPClientParser.parseVersion} raises L{ValueError} when passed an
        unparsable version.
        Nc�d���j��|�}�j|j|�yrp)rrL�data)�s�exc�e�frRs  ���rA�checkParsingz@HTTPClientParserTests.test_parseBadVersion.<locals>.checkParsing�s+����#�#�A�q�!�,�C����S�X�X�q�)r@�foosfoo/bar/bazsfoo/sfoo/..sfoo/a.bs	foo/-1.-1)r!rr�)rRr�r�r�r�s`  @@rA�test_parseBadVersionz*HTTPClientParserTests.test_parseBadVersionxsX���
$�D�$�/�����!�!��	*�	�V���^�$��W���Y���Z� ��\�"r@c�x�tddtd�}t|d�}|jt	��|jd�|j
|jjd�|j
|jjd�|j
|jjd�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
rbrdre�r+rfr!r�rr�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�tddtd�}t|d�}|jt	��|jd�|j
|jjd�|j
|jjd�|j
|jjd�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�NsHTTP/1.1 200
rbrdr@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���tdd����fd�}|d�|d�y)z�
        L{HTTPClientParser.statusReceived} raises L{ParseError} if it is called
        with a status line which cannot be parsed.
        Nc����jt�j|�}�j|j|�yrp)rr$r�rLr�)r�r�r�rRs  ��rAr�zBHTTPClientParserTests.test_badResponseStatus.<locals>.checkParsing�s1����#�#�J��0G�0G��K�C����S�X�X�q�)r@r�sHTTP/1.1 bar OK)r!)rRr�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_�	fd�|j_	|j
|�|j|jd�|j|jt�|j|g�|j|dg�|j�	dg�|j|jjd�|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�&���jd�S�NT�r�)�bodyDataFinisheds�rA�<lambda>z3HTTPClientParserTests._noBodyTest.<locals>.<lambda>�s���6F�6M�6M�d�6S�r@�	producingr@Tr)r!r�r�r�rr�r�r��_bodyDataReceived�_bodyDataFinishedrL�
producerStater�r�length)
rRr�r�r�r��finished�bodyr�rgr�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�~�tddtd�}d}d}|j|||�}|j|ddi�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�sContent-Length: 10

sContent-Lengths10)r+rfr�rL)rRr�r�r�r�s     rA�test_headResponsez'HTTPClientParserTests.test_headResponse�sH���'�4���>��'��4���!�!�'�6�8�<������"3�U�!;�<r@c�V�tddtd�}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�NsHTTP/1.1 204 NO CONTENT
r��r+rfr��rRr�r�r�s    rA�test_noContentResponsez,HTTPClientParserTests.test_noContentResponse�s0��
�&�$���=��/��������&�(�3r@c�V�tddtd�}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�NsHTTP/1.1 304 NOT MODIFIED
r�r�r�s    rA�test_notModifiedResponsez.HTTPClientParserTests.test_notModifiedResponse�s0��
�&�$���=��1��������&�(�3r@c���ttddtd�d��}|jt	��|jd�|jd�|jd�|j
|jti��|j
|jjtdd	gi��|j|jjt�y)
zq
        The response headers are added to the response object's C{headers}
        L{Headers} instance.
        r�r�Nc��yrpr?��rests rAr�z<HTTPClientParserTests.test_responseHeaders.<locals>.<lambda>��r@r�sX-Foo: bar
r��x-foor��r!r+rfr�rr�rL�connHeadersr3r�r��assertIdenticalr�rr�s  rA�test_responseHeadersz*HTTPClientParserTests.test_responseHeaderss���
$��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��ttddtd�d��}|jt	��|jd�|jd�|jd�|jd�|j
|jti��|j
|jjtd	d
gi��|j|jjt�y)z�
        The multi-line response headers are folded and added to the response
        object's C{headers} L{Headers} instance.
        r�r�Nc��yrpr?rs rAr�zEHTTPClientParserTests.test_responseHeadersMultiline.<locals>.<lambda>rr@r�sX-Multiline: a
s    b
r�sx-multilinesa    brr�s  rA�test_responseHeadersMultilinez3HTTPClientParserTests.test_responseHeadersMultilines���
$��F�D�.�$�7�9J�
��	���� 1�2����4�5����3�4����l�+����g�&�����-�-�w�r�{�;�������%�%�w����/L�'M�	
�	
���X�.�.�5�5�~�Fr@c��ttddtd�d��}|jt	��|jd�|jd�|jd�|jd�|j
|jjti��|j
|jtd	gd
gd���|j
|jjd�y)
zv
        The connection control headers are added to the parser's C{connHeaders}
        L{Headers} instance.
        r�r�Nc��yrpr?rs rAr�z>HTTPClientParserTests.test_connectionHeaders.<locals>.<lambda>)rr@r��Content-Length: 123
sConnection: close
r��123sclose)r�r��{�r!r+rfr�rr�rLr�r�r3rr�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���ttddtd�d��}|jt	��|jd�|jd�|jd�|j
|jjtdd	gi��|j
|jti��|j
|jjd
�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��yrpr?rs rAr�zRHTTPClientParserTests.test_headResponseContentLengthEntityHeader.<locals>.<lambda>=rr@r�rr�r�rrrr�s  rA�*test_headResponseContentLengthEntityHeaderz@HTTPClientParserTests.test_headResponseContentLengthEntityHeader7s���
$��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}ttddtd�|j�}t	�}|j|�|j
d�g}|j|j_|j
d�|j
d�|j|jd�|j|jt�|j
d�|j|dg�|j|jt�|j
d	�|j|dd	g�|j|jt�|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�sContent-Length: 10
r��pausedsxxxxxxsyyyyr@)r!r+rfr�rr�r�r�r�rLr�r�rr�rRr�r�rgr�s     rA�test_contentLengthz(HTTPClientParserTests.test_contentLengthIs+����#��F�D�.�$�7����
��$�%�	����	�*����4�5���.2�k�k����+����7�8����g�&�	
����0�0�(�;��������.����h�'������z�*��������.����h�'������(�3�4��������.�����C�5�)r@c��g}ttddtd�|j�}|j	t��|j
d�g}|j|j_|j
d�|j
d�|j|jt�|j|g�|j|dg�|j|jjd�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+rfr�r�rr�r�r�rLr�rr��rRr�r�r�s    rA�test_zeroContentLengthz,HTTPClientParserTests.test_zeroContentLengthhs�����#��F�D�.�$�7����
��	���� 1�2����4�5���.2�k�k����+����6�7����g�&��������.�����r�"�����C�5�)�����*�*�1�1�1�5r@c��ttddtd�d�}|jt	��|jt|jd�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�Ns9HTTP/1.1 200 OK
Content-Length: 1
Content-Length: 2

)r!r+rfr�rr�
ValueErrorr�r�s  rA�!test_multipleContentLengthHeadersz7HTTPClientParserTests.test_multipleContentLengthHeaders�sL��$�G�F�D�.�$�$O�QU�V������ 1�2������!�!�
�	
r@c�R�g}ttddtd�|j�}|j	t��|j
d�|j
d�|j
d�|j|jt�|j|dg�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+rfr�r�rr�rLr�r�rRr�r�s   rA�test_extraBytesPassedBackz/HTTPClientParserTests.test_extraBytesPassedBack�s���
��#��F�D�.�$�7����
��	���� 1�2����4�5����6�7����;�<��������.�����$=�#>�?r@c�R�g}ttddtd�|j�}|j	t��|j
d�|j
d�|j
d�|j|jt�|j|dg�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�sContent-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}ttddtd�|j�}|j	t��|j
d�g}|j|j_|j
d�|j
d�|j|g�|j|jjt�|j
d�|j|dg�|j
d	�|j|dd
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�sTransfer-Encoding: chunked
r�s3
a�asbc
sbcs
0

extrasextra)
r!r+rfr�r�rr�r�r�rLrr�rrs    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}ttddtd�|j�}t	�}|j|�|j
d�g}|j|j_|j
d�|j
d�|j
d�|j|ddg�|jtd��|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�zsimulated end of connectionr@)r!r+rfr�rr�r�r�r�rL�connectionLostr
rs     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}ttddtd�|j�}t	�}|j|�|j
d�g}|j|j_|j
d�|j|dg�|j|dg�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+rfr�rr�r�r�r�rLrs     rA�%test_contentLengthAndTransferEncodingz;HTTPClientParserTests.test_contentLengthAndTransferEncoding�s�����#��F�D�.�$�7����
��$�%�	����	�*����4�5���.2�k�k����+����
�	
�	
�����x�(�����C�5�)r@c���t�}ttddtd�d�}|j	|�|j
}|j
tt���t||tg�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)
rr!r+rfr��_responseDeferredr.rr9r\)rRrgr��responseDeferreds    rA�test_connectionLostBeforeBodyz3HTTPClientParserTests.test_connectionLostBeforeBodysi��$�%�	�#�G�F�D�.�$�$O�QU�V�����	�*�#�5�5������(:�(<� =�>�#�D�*:�=O�<P�Q�Qr@c��tj|t�}t�}t	tddtd�d�}|j|�g}|jj|j�|jd�|d}d	d�}||_|jd�|jdt|��|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

rc��t��rp�r9)rNs rA�fakeBodyDataFinishedzPHTTPClientParserTests.test_connectionLostWithError.<locals>.fakeBodyDataFinished0s��$�&�&r@rc�log_failurerp)r�createWithCleanuprrr!r+rfr�r4rUr�r�r�r.�assertEqualsrM�assertIsInstancer�r9�flushLoggedErrors)rR�logObserverrgr�r�r;�eventr�s        rA�test_connectionLostWithErrorz2HTTPClientParserTests.test_connectionLostWithErrors���+�<�<�T�CU�V��#�%�	�#�G�F�D�.�$�$O�QU�V�����	�*����"�"�.�.�x���?����U�V��A�;��	'�&:��"�����%����!�S��-�.��A����-� �����a�g�g�'9�:����1�2r@c���ttddtd�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��yrpr?��igns rAr�z<HTTPClientParserTests.test_noResponseAtAll.<locals>.<lambda>Brr@)
r!r+rfr4r�rr.rrTr1�rRr�rXs   rA�test_noResponseAtAllz*HTTPClientParserTests.test_noResponseAtAll<sb��
$��G�T�>�4�8�:J�
��
�&�&������ 1�2����� 0�1��!�!�!�%:�;�;r@c�B�ttddtd�d��}|j}|j	t��|j
d�|jt��|j|t�j|jt�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��yrpr?rFs rAr�zBHTTPClientParserTests.test_someResponseButNotAll.<locals>.<lambda>Qrr@�2)
r!r+rfr4r�rr�r.rrTr0rUr?rHs   rA�test_someResponseButNotAllz0HTTPClientParserTests.test_someResponseButNotAllJs���$��G�T�>�4�8�:J�
��
�&�&������ 1�2����d�#����� 0�1��!�!�!�^�4�@�@��!�!�>�
�	
r@c�8�d}ttddtd�d��}|jt	��|j|�|j
t|dd�du�|j|jt�|jtt|jj���d�|jtt|jj���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��yrpr?rFs rAr�zCHTTPClientParserTests.test_1XXResponseIsSwallowed.<locals>.<lambda>jrr@r�r)r!r+rfr�rr�r��getattrrLr�rrMr�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}ttddtd�d��}|jt	��|j||z�|j
|jjd�|j
|jjti��|j
|jtdd	gi��|j
|jjd
�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��yrpr?rFs rAr�zUHTTPClientParserTests.test_1XXFollowedByFinalResponseOnlyEmitsFinal.<locals>.<lambda>�rr@rdr�rr�
r!r+rfr�rr�rLr�r�r�r3rr��rRrS�following200Responser�s    rA�-test_1XXFollowedByFinalResponseOnlyEmitsFinalzCHTTPClientParserTests.test_1XXFollowedByFinalResponseOnlyEmitsFinalvs���
�	� 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}ttddtd�d��}|jt	��|j||z|z|z�|j
|jjd�|j
|jjti��|j
|jtdd	gi��|j
|jjd
�y)zp
        It is acceptable for multiple 1XX responses to come through, all of
        which get ignored.
        rOrVr�r�Nc��yrpr?rFs rAr�zKHTTPClientParserTests.test_multiple1XXResponsesAreIgnored.<locals>.<lambda>�rr@rdr�rrrXrYs    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�^�tj|t�}d}tt	ddt
d�d��}|j
t��|j|�|jdt|��|d}|j|dd	�|j|d
d�y)zF
        When a 1XX response is ignored, Twisted emits a log.
        rOr�r�Nc��yrpr?rFs rAr�zHHTTPClientParserTests.test_ignored1XXResponseCausesLog.<locals>.<lambda>�rr@rcr�
log_formatz#Ignoring unexpected {code} responser��g)rr=rr!r+rfr�rr�r>rM)rRrArSr�rBs     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rrrrr!r'r)r,r/r2r6rCrIrMrTr[r^rcr?r@rAr�r�js����
P�#�,:�8�)�&"�H
=�4�4�G� G�&8�(6�$*�>6�2
�$@�"@�"#/�J*�0*�<
R�3�:<�
�$4�48�28�<.r@r�c�(�eZdZdZdZdZdZd�Zd�Zy)�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�|_|jSrp)rr��rRrgs  rA�writeTozSlowRequest.writeTo�s�� �
��
��}�}�r@c��d|_yr���stoppedrqs rA�stopWritingzSlowRequest.stopWriting��	����r@N)	r;r<r=r>�methodrk�
persistentrhrlr?r@rArere�s"��	��F��G��J��r@rec��eZdZdZdZd�Zy)�
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�:�|jd�td�S)N�
SOME BYTES)�writer	rgs  rArhzSimpleRequest.writeTo�s�����
�&��t�}�r@N)r;r<r=r>rorhr?r@rArqrq�s����J�r@rqc���eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d&d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�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�|_|jj	|j�y)zR
        Create an L{HTTP11ClientProtocol} connected to a fake transport.
        N)rrgr)r�r�rqs rA�setUpzHTTP11ClientProtocolTests.setUp�s.��)�*���,�.��
��
�
�$�$�T�^�^�4r@c��|jjt��|j|jj�d�y)z�
        L{HTTP11ClientProtocol.request} accepts a L{Request} and calls its
        C{writeTo} method with its own transport.
        rsN)r�r�rqrLrgr�rqs rA�test_requestz&HTTP11ClientProtocolTests.test_request�s5��
	
�
�
���m�o�.�������-�-�/��?r@c�����jjt���fd�}�j�jjt	��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�jj�d�y�Nr@�rLrgr���ignoredrRs �rA�	cbNotSentz?HTTP11ClientProtocolTests.test_secondRequest.<locals>.cbNotSent� ������T�^�^�1�1�3�S�9r@)r�r�rerTrqr%rU�rRr�rXs`  rA�test_secondRequestz,HTTP11ClientProtocolTests.test_secondRequestsT���	
�
�
���k�m�,�	:�
���t�}�}�4�4�]�_�E�~�V��	�
�
�i� ��r@c����jjttd����fd�}�j	�jjt
��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�jj�d�yr}r~rs �rAr�zLHTTP11ClientProtocolTests.test_requestAfterConnectionLost.<locals>.cbNotSentr�r@)	r�r.rr
rTr�rqr%rUr�s`  rA�test_requestAfterConnectionLostz9HTTP11ClientProtocolTests.test_requestAfterConnectionLosts\���	
�
�
�$�$�W�^�O�-L�%M�N�	:�
���t�}�}�4�4�]�_�E�~�V��	�
�
�i� ��r@c���Gd�d�}�jj|��}�fd�}t�|tg�}|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��eZdZdZd�Zy)�CHTTP11ClientProtocolTests.test_failedWriteTo.<locals>.BrokenRequestFc�(�tt��Srp)rr9rgs  rArhzKHTTP11ClientProtocolTests.test_failedWriteTo.<locals>.BrokenRequest.writeTo,s���.�0�1�1r@N�r;r<r=rorhr?r@rA�
BrokenRequestr�)s���J�
2r@r�c����j�jj��jj	tt
d���y)Nzyou asked for it)r�rg�
disconnectingr�r.rr
rs �rArSz>HTTP11ClientProtocolTests.test_failedWriteTo.<locals>.cbFailed1s8����O�O�D�N�N�8�8�9�
�M�M�(�(���@R�1S�)T�Ur@)r�r�r^r9rU)rRr�rXrSs`   rA�test_failedWriteToz,HTTP11ClientProtocolTests.test_failedWriteTo!sP���	2�	2�
�M�M�!�!�-�/�2��	V�
*�$��4F�3G�H��	�
�
�h���r@c�z�Gd�d�}|jj|��}t||tg�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��eZdZdZd�Zy)�MHTTP11ClientProtocolTests.test_synchronousWriteToError.<locals>.BrokenRequestFc��t��rpr:rgs  rArhzUHTTP11ClientProtocolTests.test_synchronousWriteToError.<locals>.BrokenRequest.writeToEs��(�*�*r@Nr�r?r@rAr�r�Bs���J�
+r@r�)r�r�r^r9)rRr�rXs   rA�test_synchronousWriteToErrorz6HTTP11ClientProtocolTests.test_synchronousWriteToError;s7��	+�	+�
�M�M�!�!�-�/�2��,�T�1�7I�6J�K�Kr@Nc�D�t�}|jj|�}t||tg�}|j|j�|jjtt	���|j|j�|dk(r|jjd�|S|dk(r^|jjtt���|jt�}|jt!|�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)rer�r�r`r9r�rkr.rr�r�r�r�rCr@rLrM)rR�moder�rX�errorss     rA�*test_connectionLostDuringRequestGenerationzDHTTP11ClientProtocolTests.test_connectionLostDuringRequestGenerationKs����-���M�M�!�!�'�*��+�D�!�6H�5I�J��	
������)��
�
�$�$�W�-?�-A�%B�C�	
������(��:�����%�%�d�+����Y�
����$�$�W�-F�-H�%I�J��+�+�,E�F�F����S��[�!�,���
��r@c�$�|jd�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�rqs rA�+test_connectionLostBeforeGenerationFinishedzEHTTP11ClientProtocolTests.test_connectionLostBeforeGenerationFinishedks���>�>�z�J�Jr@c�$�|jd�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�rqs rA�)test_connectionLostBeforeGenerationFailedzCHTTP11ClientProtocolTests.test_connectionLostBeforeGenerationFailedss���>�>�y�I�Ir@c����tj�t����fd�}�jd�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����jdt����d}�jd|��j|dd��j|dd�y)Nrcrr<razJError writing request, but not in valid state to finalize request: {state}r��CONNECTION_LOST)r>rM�assertInrL)�ignorerBrArRs  ��rA�checkznHTTP11ClientProtocolTests.test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse.<locals>.check�sa������a��[�!1�2���N�E��M�M�-��/�����l�#�/�
�

���U�7�^�->�?r@r�)rr=rr�rU)rRr�rAs` @rA�Etest_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfusez_HTTP11ClientProtocolTests.test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse{sA���+�<�<�T�CU�V��		@��>�>�y�I�U�U��
�	
r@c����jjtddtd��}�fd�}|j	|��jjd�|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|jd��j|jt���j	�j
j��j�jjd�y)Nrd�	QUIESCENT)	rLr�r�r3r�rgr�r�r�)r�rRs �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@s9HTTP/1.1 200 OK
Content-Length: 0
Connection: close

�r�r�r+rfrUr��rRrXr�s`  rA�test_receiveSimplestResponsez6HTTP11ClientProtocolTests.test_receiveSimplestResponse�sU���
�M�M�!�!�'�&�$���"M�N��	?�	
�
�
�i� ��
�
�"�"�
�	
��r@c����jjtddtd��}�fd�}|j	|��jjd�|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�\��tdddgi�}�j|j|�y)Nrr�r�)r3rLr�)r�r�rRs  �rAr�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�����fd�}|j|���fd�}|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.
        s8HTTP/1.1 200 OK
X-Foo: bar
Content-Length: 6

foobarc�����t��t�x}�_�j���j	�j
d��j
�j��j	�g�|j��fd��S)N�%TRANSMITTING_AFTER_RECEIVING_RESPONSEc� ����jfSrp�r��rG�pr�s ��rAr�zoHTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone.<locals>.cbResponse.<locals>.<lambda>������1�6�6�8J�r@)	rr�closedDeferred�deliverBodyrLr�r�r�rU)r��whenFinishedr�r��quiescentResultrRrgs` @����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|jd��j|jd��j|jd��j|jtddgi���j|d��jjd�y)Nrbrdrerr��foobar)rLr�r�r�r�r3r�r�)�resultr�r�r�rRs   ��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@)rr)r�r�rer�r�rU)rRrXr�r�r�r�r�rgs`   @@@@rA�/test_receiveResponseBeforeRequestGenerationDonezIHTTP11ClientProtocolTests.test_receiveResponseBeforeRequestGenerationDone�s������#�%�	�'��(>�(>�?�����	�*��-�����W�%�����
�	
�	L�	
�
�
�j�!�
	,�	
�
�
�m�$��r@c��t�}t�}||_|j|�dtj
z}|j
tddtd��}|jd|zdz�t||tg�S)zy
        The connection is closed when the server respond with a header which
        is above the maximum line.
        r+r�r�NsHTTP/1.1 200 OK
X-Foo: s
X-Ignored: ignored

)rr)r�r�r�
MAX_LENGTHr�r+rfr�r\r
)rRrgr��longLinerXs     rA�"test_receiveResponseHeadersTooLongz<HTTP11ClientProtocolTests.test_receiveResponseHeadersTooLong�s���
5�6�	�'�)��%�	�����	�*��,�1�1�1�����W�V�T�>�4�H�I�����
�!�
"�%�
�	
�$�D�!�n�-=�>�>r@c�����t���jj��}�jjd�d�}|j	|���fd�}|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.
        s8HTTP/1.1 400 BAD REQUEST
Content-Length: 9

tisk tiskc����t��t�x}�_�j��|j	��fd��S)Nc� ����jfSrpr�r�s ��rAr�z�HTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbResponse.<locals>.<lambda>r�r@)rrr�r�rU)r�r�r�s` @rAr�zrHTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbResponses:���$�&�A�.6�j�8�L�1�+�� � ��#��+�+�,J�K�Kr@c�����jjd��jjt	t����j
�jjd�y)Nr�)r�r�r�r.rr9rLr{)r�r�rRs ��rAr�zuHTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone.<locals>.cbAllResponsesM������%�%�d�+��M�M�(�(��1C�1E�)F�G����T�]�]�1�1�3D�Er@)rer�r�r�rU)rRrXr�r�r�s`   @rA�Dtest_connectionLostAfterReceivingResponseBeforeRequestGenerationDonez^HTTP11ClientProtocolTests.test_connectionLostAfterReceivingResponseBeforeRequestGenerationDonesd����-���M�M�!�!�'�*���
�
�"�"�
�	
�	L�	
�
�
�j�!�	F�	
�
�
�m�$��r@c�&���t��t�x}�_�jj	tddtd��}�jjd�g}|j|j��j|g��jjd�|d}|j���jjd��jjd���fd	�}|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�rr�r�c�|���j�jd��jjt�y)Nr�)rLr��closedReasonrKr/)r�r�rRs ��rAr�zIHTTP11ClientProtocolTests.test_receiveResponseBody.<locals>.cbAllResponseJs+������X�]�]�I�6��!�!�&�&�|�4r@)rrr�r�r�r+rfr�rUr�rLr�)rRr��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�|jjtddtd��}|jj	d�g}|j|j�|d}t�}|j|�|jj	d�|jj	d�|j|jd�|jjttd	���|jjt �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�NsHTTP/1.1 200 OK

rr�r�r�z low-level transport disconnected)r�r�r+rfr�rUr�rr�rLr�r.rr
r�rKr*�rRr�r�r�r�s     rA�Etest_responseBodyFinishedWhenConnectionLostWhenContentLengthIsUnknownz_HTTP11ClientProtocolTests.test_responseBodyFinishedWhenConnectionLostWhenContentLengthIsUnknownQs����-�-�/�/��F�D�.�$�7�
��	
�
�
�"�"�#A�B����#�#�F�M�M�2��!�9��'�)�����X�&��
�
�"�"�6�*��
�
�"�"�6�*�������	�2��
�
�$�$��N�#E�F�G�	
�	���"�"�#4�5r@c�X�|jjtddtd��}|jj	d�g}|j|j�|d}t�}|j|�|jj	d�|jj	d�|j|jd�|jjtt���t|t|j �tt"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
s3
bar
r�)r�r�r+rfr�rUr�rr�rLr�r.rr9r\rr�r2r�s     rA�4test_chunkedResponseBodyUnfinishedWhenConnectionLostzNHTTP11ClientProtocolTests.test_chunkedResponseBodyUnfinishedWhenConnectionLostns����-�-�/�/��F�D�.�$�7�
��	
�
�
�"�"�L�	
����#�#�F�M�M�2��!�9��'�)�����X�&��
�
�"�"�?�3��
�
�"�"�?�3�������	�2��
�
�$�$�W�-?�-A�%B�C�#��$�x�,�,�-�0B�I�/N�
�	
r@c�����jjtddtd��}�jj	d�t�|tg�}�fd�}|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�Nsunparseable garbage goes here
c����j�jj��j|jdj
jd��jjttd���y)Nrsunparseable garbage goes herez
it is done)r�rgr�rLrJr�r�r�r.rr
)r�rRs �rArSzLHTTP11ClientProtocolTests.test_parserDataReceivedException.<locals>.cbFailed�s_����O�O�D�N�N�8�8�9�������A��$�$�)�)�+K�
�
�M�M�(�(����1M�)N�Or@)r�r�r+rfr�r\r$rU)rRr�rXrSs`   rA� test_parserDataReceivedExceptionz:HTTP11ClientProtocolTests.test_parserDataReceivedException�se����-�-�/�/��F�D�.�$�7�
��	
�
�
�"�"�#G�H� �����E��
	P�	
�
�
�h���r@c��|jjtddtd��}|jjj
}|j
|j|j
�|jjttd���|j
|jd�t||tg�S)z�
        When the HTTP response parser is disconnected, the
        L{TransportProxyProducer} which was connected to it as a transport is
        stopped.
        r�r�Nzconnection done)r�r�r+rf�_parserrgr�	_producer�_disconnectParserrr
r\)rRr�rgs   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
||fggf�|j|j�|jtt���|j
|dg�|j
|dg�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)rr)r��abortrUr�rLr�r�r.rr
)rRrgr��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|�|jt	t���g}|j
�j|j�|j|dg�|j|jd�y)z�
        L{HTTP11ClientProtocol.abort} called after the connection is lost
        returns a C{Deferred} that fires immediately.
        Nr�)rr)r�r.rr
r�rUr�rLr{�rRrgr�r�s    rA�test_abortAfterConnectionLostz7HTTP11ClientProtocolTests.test_abortAfterConnectionLost�s}��
$�%�	�'�)�����	�*������(8� 9�:�������$�$�V�]�]�3�����$��(�������*;�<r@c�L�t�}t�}|j|�|jt	ddt
d��}|j
�|j|j�|jtt���t||tg�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)rr)r�r�r+rfr�r�r�r.rr
r\rr�s    rA�test_abortBeforeResponseBodyz6HTTP11ClientProtocolTests.test_abortBeforeResponseBody�s���$�%�	�'�)�����	�*��!�!�'�&�$���"M�N���������	�/�/�0������(8� 9�:�#�D�&�3D�2E�F�Fr@c�������td���t���j���jt	ddt
d��}�j
d�t��G��fd�dt������fd	�}�fd
�}|j|�t��ttg�}|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�Nr8c�&��eZdZdZ�fd�Z�fd�Zy)�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.connectionMades������ r@c�(���j|�y)z�
                Make the reason for the losing of the connection available to
                the unit test via C{testResult}.
                N)r�)rRrO�
testResults  �rAr.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��jt	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.rr
)r�r�r�rRrgs ����rAr�zMHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.deliverBodys>���
� � ��!2�3��O�O�I�3�3�4��#�#�G�N�,<�$=�>r@c�F���j|jt�yrp)r?r�r.)�errorrRs �rA�
checkErrorzLHTTP11ClientProtocolTests.test_abortAfterResponseHeaders.<locals>.checkErrors����!�!�%�.�.�(�;r@)
rr)r�r�r+rfr�rrrUr\rr2)	rRr�r�r�rVr�r�r�rgs	`    @@@@rA�test_abortAfterResponseHeadersz8HTTP11ClientProtocolTests.test_abortAfterResponseHeaders�s����$�D�1�	�'�)�����	�*��!�!�'�&�$���"M�N�����U�V��Z�
�	+�h�	+�&	?�	<�	���;�'�'��*�0�)�<�
���#�#�J�/�/r@c	�h����g����fd�}t�}t|���j|��jt	ddt
dd���}�j
d��j�g�g}|j|j�|d}t�}t�|_|jj�fd	��|j|��j
d
�|jjt ��j��dg��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|jd��j|�y�Nr��rLr�r��r�r�r�rRs ���rAr�zHHTTP11ClientProtocolTests.test_quiescentCallbackCalled.<locals>.callback5�5������Q��)����Q�W�W�k�2��"�"�1�%r@r�r�NT�ros&HTTP/1.1 200 OK
Content-length: 3

rc�&���jd�S)N�
response doner�)rGr�s �rAr�zHHTTP11ClientProtocolTests.test_quiescentCallbackCalled.<locals>.<lambda>Os����.�.��?�r@r1r)rr)r�r�r+rfr�rLrUr�rrr�r�r�rKr/r��_finishedRequest�_currentRequest�_transportProxyr4)	rRr�rgr�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����fd�}t�}t|���j|��jt	ddt
dd���}�j
d��j|�}�j|jd��jt��d	��j|jd
�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|jd��j|�yr�r�r�s ���rAr�z]HTTP11ClientProtocolTests.test_transportProducingWhenQuiescentAfterFullBody.<locals>.callbackmr�r@r�r�NTr�s)HTTP/1.1 200 OK
Content-length: 3

BBB�DEFERRED_CLOSErcr�)rr)r�r�r+rfr��successResultOfrLr{rMr�)rRr�rgr�r�r�r�s`    @@rA�1test_transportProducingWhenQuiescentAfterFullBodyzKHTTP11ClientProtocolTests.test_transportProducingWhenQuiescentAfterFullBody`s������	&�
$�%�	�'��1�����	�*�"�*�*��F�D�.�$�4�H�
��	���
�	
��'�'��8��	
������*:�;�
	
����_�-�q�1�
	
����0�0�+�>r@c	�����g����fd�}t�}t|���j|��jt	ddt
dd���}|j
�j��jd��jt��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|jd��j|�yr�r�r�s ���rAr�zUHTTP11ClientProtocolTests.test_quiescentCallbackCalledEmptyResponse.<locals>.callback�r�r@r�r�NTr��&HTTP/1.1 200 OK
Content-length: 0

r�rrc)rr)r�r�r+rfrUr�r�rLrMrr?r.)rRr�rgr�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	tddtdd���}|jd�g}|j|j�|d}t�}|j|�|jjt�|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�s9HTTP/1.1 200 OK
Content-length: 0
Connection: close

r�rr)r�r�r�r+rfr�rUrr�r�rKr/rLr�r��rRr�rgr�r�r�r�rs        rA�test_quiescentCallbackNotCalledz9HTTP11ClientProtocolTests.test_quiescentCallbackNotCalled�s�����#�%�	�'��(>�(>�?�����	�*�"�*�*��F�D�.�$�4�H�
��	���
�	
����#�#�F�M�M�2��!�9��+�-�����\�*��!�!�&�&�|�4�����"�-����	�/�/�0r@c	���g}t�}t|j�}|j|�|j	tddtdd���}|jd�g}|j|j�|d}t�}|j|�|jjt�|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
rrrs        rA�1test_quiescentCallbackNotCalledNonPersistentQueryzKHTTP11ClientProtocolTests.test_quiescentCallbackNotCalledNonPersistentQuery�s���
��#�%�	�'��(>�(>�?�����	�*�"�*�*��F�D�.�$�5�I�
��	���U�V����#�#�F�M�M�2��!�9��+�-�����\�*��!�!�&�&�|�4�����"�-����	�/�/�0r@c	��d�}tj|t�}t�}t	|�}|j|�|j
tddtdd���}|jd�g}|j|j�|d}t�}|j|�|jjt �|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 rAr�zHHTTP11ClientProtocolTests.test_quiescentCallbackThrows.<locals>.callback�s��#�%�%r@r�r�NTr�r
rrcr<)rr=rrr)r�r�r+rfr�rUr�rr�r�rKr/r>rMr?r�rr@r�r�)rRr�rArgr�r�r�r�rrBr�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|�|jt	ddt
d��}|j
�|j|j�t||ttg�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)rr)r�r�r+rf�cancelr��disconnectedrYr1rr�s    rA�test_cancelBeforeResponsez3HTTP11ClientProtocolTests.test_cancelBeforeResponsesr��$�%�	�'�)�����	�*��!�!�'�&�$���"M�N���
�
�����	�.�.�/�*��&�/�.�1A�
�	
r@c�*�t�}t�}|j|�|jt	ddt
d��}|j
d�|j�|j|j�t||tg�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�)rr)r�r�r+rfr�rr�rr\rr�s    rA�test_cancelDuringResponsez3HTTP11ClientProtocolTests.test_cancelDuringResponsesy��$�%�	�'�)�����	�*��!�!�'�&�$���"M�N�����4�5��
�
�����	�.�.�/�#�D�&�>�2B�C�Cr@c�����t�}t�}|j|�t|��ddi��fd����fd�}|�_|jt
ddt���}�jjd�|j�|j|j�|j�d�t||tg�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 �rArzJHTTP11ClientProtocolTests.assertCancelDuringBodyProduction.<locals>.cancel2s
���$(�H�[�!r@c�J��|�_t���_�jSrp��consumerrr�)r%r�producers ��rA�startProducingzRHTTP11ClientProtocolTests.assertCancelDuringBodyProduction.<locals>.startProducing5s$��� (�H�� (�� 0�H���$�$�$r@�POST�/barsxxxxx)rr)r��StringProducerr'r�r+rfr%rtrr�rr^r)	rR�producerLengthrgr�r'r�rr"r&s	      @@@rA� assertCancelDuringBodyProductionz:HTTP11ClientProtocolTests.assertCancelDuringBodyProduction$s����$�%�	�'�)�����	�*�!�.�1����'��	)�	%�
#1����!�!�'�'�7�N�H�"U�V��������)��
�
�����	�.�.�/������-�.�,�T�6�N�;K�L�Lr@c�$�|jd�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,rqs rA�test_cancelDuringBodyProductionz9HTTP11ClientProtocolTests.test_cancelDuringBodyProductionCs���4�4�R�8�8r@c�,�|jt�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,rrqs rA�&test_cancelDuringChunkedBodyProductionz@HTTP11ClientProtocolTests.test_cancelDuringChunkedBodyProductionLs���4�4�^�D�Dr@rp)'r;r<r=r>rxrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrrrrr,r/r1r?r@rArvrv�s����
5�@�
�
��4L� �@K�J�
�0�.�$0�d?�4�@'�R6�:
�@�8
M�%�*
=�G� 80�t7;�r,?�\<�41�>1�2!1�F
�"D� M�>9�Er@rvc�2�eZdZdZdZd�Zd�Zd�Zd�Zd�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��||_yrp)r�)rRr�s  rA�__init__zStringProducer.__init__fs	����r@c�F�||_t�|_|jSrpr$)rRr%s  rAr'zStringProducer.startProducingis�� ��
� �
��
��}�}�r@c��d|_yr�rjrqs rA�
stopProducingzStringProducer.stopProducingnrmr@c��yrpr?rqs rA�pauseProducingzStringProducer.pauseProducingq���r@c��yrpr?rqs rA�resumeProducingzStringProducer.resumeProducingur:r@N)
r;r<r=r>rkr4r'r7r9r<r?r@rAr*r*Vs'��
��G���
�
�
r@r*c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zy)�RequestTestsz
    Tests for L{Request}.
    c�"�t�|_yrp)rrgrqs rArxzRequestTests.setUps��(�*��r@c��tddtd�j|j�|j	|jj�d�y)zk
        L{Request.writeTo} formats the request data and writes it to the given
        transport.
        r�r�Ns8GET / HTTP/1.1
Connection: close
Host: example.com

�r+rfrhrgrLr�rqs rA�test_sendSimplestRequestz%RequestTests.test_sendSimplestRequest�sD��
	���n�d�3�;�;�D�N�N�K�����N�N� � �"�
�	
r@c��tddtdd��}|j|j�|j	|jj�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�tddgdgd��}tdd|d�j|j�|jj	�jd�}|j
|d	d
�|j
|ddddg�|d	=|dd�=|j�|j
|gd
��y)zf
        L{Request.writeTo} formats header data and writes it to the given
        transport.
        r�r�rE)rrDr��/fooNr�r�GET /foo HTTP/1.1���r@)�Connection: closesHost: example.comr�r�)r3r+rhrgr��splitrL�sort)rRr��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���tD]�}t||gddgi�}t�}tdd|d�j	|�|j�j
d�}|j|dd�|j|d	dd
d
g�|d=|d	d�=|jd�|jd�d
jttg�}|j||g���y)z_
        Linear whitespace in request headers is replaced with a single
        space.
        rDsexample.invalidr�rGNr�rrHrIr@rJsHost: example.invalids: )r6r3rr+rhr�rKrL�remover�r7)rR�	componentr�rgrM�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��tt�}tddt|�}|j	|j
�|j
|jd�|j|j
j|�|j|j
j�|j|j
j�d�|j
j�|jjd�|jjd�|j j#d�|j|j
jd�|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)NsXPOST /bar HTTP/1.1
Connection: close
Transfer-Encoding: chunked
Host: example.com

sxxxsyyyyyyyyyyyyyyys!3
xxx
f
yyyyyyyyyyyyyyy
0

)r*rr+rfrhrg�assertNotIdenticalr%rr&r��	streamingrLr��clearrtr�r��rRr&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��tt�}tddt|�}|j	�j
�}�j
j
�|jjt���fd�}�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�jj�d��j�jjd�yr})rLrgr�rr&rs �rArSzCRequestTests.test_sendChunkedRequestBodyWithError.<locals>.cbFailed�s:������T�^�^�1�1�3�S�9�� � ����!8�!8�$�?r@)r*rr+rfrhrgrWr�r�r9rTrU)rRr&r��
writeDeferredrSrXs`     rA�$test_sendChunkedRequestBodyWithErrorz1RequestTests.test_sendChunkedRequestBodyWithError�s����"�.�1���'�7�N�H�E��������7�
����������!�!�"4�"6�7�	@�
���}�.@�A��	�
�
�h���r@c���td�}tddt|�}|j|j�|j|jd�|j|jj|�|j|jj�|j|jj�d�|jj�|jjd�|jj!d�|j|jjd�|j|jj�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)NsOPOST /bar HTTP/1.1
Connection: close
Content-Length: 3
Host: example.com

r1)r*r+rfrhrgrUr%rr&r�rVrLr�rWrtr�r�rXs   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|dtd�}|j|j�|j	|jj�|dz�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}
        rGNsK /foo HTTP/1.1
Connection: close
Content-Length: 0
Host: example.com

rA)rRrnr�s   rA�_sendRequestEmptyBodyWithLengthz,RequestTests._sendRequestEmptyBodyWithLengthsO���&�'�>�4�@��������'�����N�N� � �"���
�	
r@c�&�|jd�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.
        sPUTN�rbrqs rA�test_sendPUTRequestEmptyBodyz)RequestTests.test_sendPUTRequestEmptyBody(s��	
�,�,�V�4r@c�&�|jd�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(Nrdrqs rA�test_sendPOSTRequestEmptyBodyz*RequestTests.test_sendPOSTRequestEmptyBody0s��	
�,�,�W�5r@c�V�td�}tddt|�}|j|j�}|j
j
d�|jjd�|j|jjd�|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+rfrhrgr%rtr�r�rr&rTr'�rRr&r�r\s    rA�#test_sendRequestBodyWithTooFewBytesz0RequestTests.test_sendRequestBodyWithTooFewBytes8s���"�!�$���'�7�N�H�E��������7�
�������&����"�"�4�(����T�^�^�4�4�d�;��!�!�-��A�Ar@c�����td��tddt��}|j�j�}�j
j
d��j�j��j
j
d��j�j��j�jjd����fd�}�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�jj�d��jj��j	t
�jjd�����j�jj�d�y)NsQPOST /bar HTTP/1.1
Connection: close
Content-Length: 3
Host: example.com

absefr@)rLrgr�rWrr r%rt)r��finisherr&rRs ���rArSzCRequestTests._sendRequestBodyWithTooManyBytesTest.<locals>.cbFailedgs����
������$�$�&��
�
�N�N� � �"�
���k�8�+<�+<�+B�+B�E�J�

�X��
���T�^�^�1�1�3�S�9r@)r*r+rfrhrgr%rtr�rkr�rr&rTr'rU)rRror�r\rSrXr&s``    @rA�$_sendRequestBodyWithTooManyBytesTestz1RequestTests._sendRequestBodyWithTooManyBytesTestGs����"�!�$���'�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�:�|jjd�yrp�r�r��r&s rArozCRequestTests.test_sendRequestBodyWithTooManyBytes.<locals>.finisher�������&�&�t�,r@)rp�rRros  rA�$test_sendRequestBodyWithTooManyBytesz1RequestTests.test_sendRequestBodyWithTooManyBytes�s��	-��8�8��B�Br@c�h���tj�t����fd�}�j|�S)rrc�$��|jjt���d}�jd|�|d}�j	|j
t��j
t�}�jt|�d�y)Nrr<rc)	r�r�r9r�r?r�r@rLrM)r&rBr�r�rArRs    ��rArozHRequestTests.test_sendRequestBodyErrorWithTooManyBytes.<locals>.finisher�sv������%�%�&8�&:�;���N�E��M�M�-��/��m�$�A��!�!�!�'�'�+=�>��+�+�,>�?�F����S��[�!�,r@)rr=rrp)rRrorAs` @rA�)test_sendRequestBodyErrorWithTooManyBytesz6RequestTests.test_sendRequestBodyErrorWithTooManyBytes�s0���+�<�<�T�CU�V��	-��8�8��B�Br@c�F�tj|t�}td�}t	ddt
|�}|j
|j�|jj}|jjd�|jjd�|jt��|d}|jd|�|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)r1Nrr<rc)rr=rr*r+rfrhrgr%�	_finishedrtr�r�r�r9r�r?r�rLrMr@)rRrAr&r��finishedConsumingrBr�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���td�}tddt|�}|j|j�}|j
j
d�||�|j|jjd�|jj�|jt|j
jd�|j|jj�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)riNrmr@)r*r+rfrhrgr%rtrr&rWrr rLr�)rRror&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�:�|jjd�yrprtrus rArozPRequestTests.test_sendRequestBodyFinishedEarlyThenTooManyBytes.<locals>.finisher�rvr@)rTr�r'rws  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�|jjt��yrp)r�r�r9rus rArozORequestTests.test_sendRequestBodyErroredEarlyThenTooManyBytes.<locals>.finisher�s�����%�%�&8�&:�;r@)rTr�r9rws  rA�0test_sendRequestBodyErroredEarlyThenTooManyBytesz=RequestTests.test_sendRequestBodyErroredEarlyThenTooManyBytes�s-��	<��!�!��>�>�x�H��
�	
r@Nc��tt�}tddt|�}|j	|j
�}|jj|�|j
j�|jt|jjd�|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*rr+rfrhrgr�r�rWrr r%rtrLr�)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�|jtt���}|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�rr9rT)rRrXs  rA�9test_sendChunkedRequestBodyFinishedWithErrorThenWriteMorezFRequestTests.test_sendChunkedRequestBodyFinishedWithErrorThenWriteMore	s6��
�A�A��&�(�)�
���!�!�!�%7�8�8r@c��td�}tddt|�}|j|j�}|j|jj|�|j|jj�|jjd�|j|jj�d�|j|jj�|jj!t#t%���|j|jj�|j|jj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)risQPOST /bar HTTP/1.1
Connection: close
Content-Length: 5
Host: example.com

abN)r*r+rfrhrgrr&r�rVr%rtrLr�r�r�r�r�rr9rTrjs    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	��tddti�d�}|jt|j|j
�|j
|j
j�d�tddtdddgi�d�}|jt|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@sHostrEsexample.org)r+r3rrrhrgrLr�)rRr�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��td�}tddt|�}|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+rfrhrgr�rkrlr�rXs   rA�test_stopWritingzRequestTests.test_stopWritingJ	s`��
"�!�$���&�$���A��������'�����)�)�*���������(�(�)r@c���tj|t�}td�}d�}||_tddt|�}|j|j�|j�|jt|jt��d�|jdt|��|d}|jd|�|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��td���NzstopProducing is bustedr:r?r@rA�brokenStopProducingzBRequestTests.test_brokenStopProducing.<locals>.brokenStopProducing^	s��$�%>�?�?r@r�r�rcrr<N)rr=rr*r7r+rfrhrgrlrLrMr@r9r>r�r?r�)rRrAr&r�r�rBr�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>rxrBrErNrSrYr]r`rbrergrkrprxr{rr�r�r�r�r�r�r�r�r�r?r@rAr>r>zs����+�
�	
�
�";�$
�B�.9�:
�*5�6�
B�?�BC�C�(M�6�&
� 
� �"
9�%E�N
6�
*�;r@r>c�B�eZdZdZd�Zd�Zd�Zdd�Zd�Zd�Z	d�Z
d	�Zy
)�LengthEnforcingConsumerTestsz/
    Tests for L{LengthEnforcingConsumer}.
    c��t�|_td�|_t	�|_t
|j|j
|j�|_y)Nr.)rr�r*r&rrgr#�enforcerrqs rArxz"LengthEnforcingConsumerTests.setUps	s@���j���&�r�*��
�(�*���/��M�M�4�>�>�4�;�;�
��
r@c�L�|jjd�|j|jj	�d�|jj�|jjd�|j|jj	�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.
        r1sdefN)r�rtrLrgr�rWrqs rA�
test_writez'LengthEnforcingConsumerTests.test_write{	sr��	
�
�
���F�#�������-�-�/��8��������
�
���F�#�������-�-�/��8r@c��|jjd�|jt|jj�y)z�
        L{LengthEnforcingConsumer._noMoreWritesExpected} raises
        L{WrongBodyLength} if it is called before the indicated number of bytes
        have been written.
        s	xxxxxxxxxN)r�rtrr'�_noMoreWritesExpectedrqs rA�test_finishedEarlyz/LengthEnforcingConsumerTests.test_finishedEarly�	s0��	
�
�
���H�%����/�4�=�=�+N�+N�Or@c�z�|jjd�|j|jj�|jjd�|j|jj�|r|jj
�|j|jt�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�rtr�r&rkr�r�rTr�r')rR�_unregisterAfters  rA�test_writeTooManyz.LengthEnforcingConsumerTests.test_writeTooMany�	s���	
�
�
���I�&�������.�.�/��
�
���D�!�����
�
�-�-�.���M�M�/�/�1��!�!�$�+�+��?�?r@c�X�|jjd�|jj�|j|jj
�|j
t|jjd�|j|jj
�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�rtr�r�r&rkrr r�rqs rA�test_writeAfterNoMoreExpectedz:LengthEnforcingConsumerTests.test_writeAfterNoMoreExpected�	sp��	
�
�
���I�&��
�
�+�+�-�������.�.�/����+�t�}�}�':�':�D�A�����
�
�-�-�.r@c�$�|jd�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�rqs rA�test_finishedLatez.LengthEnforcingConsumerTests.test_finishedLate�	s���%�%�d�+�+r@c��|jjd�|j|jj�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�rtrr�rqs rA�
test_finishedz*LengthEnforcingConsumerTests.test_finished�	s3��
	
�
�
���I�&����T�]�]�@�@�B�D�Ir@c����fd�}|�j_�fd�}�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��tj�j�td��r�)r*r7r&r9rqs�rAr�zRLengthEnforcingConsumerTests.test_stopProducingRaises.<locals>.brokenStopProducing�	s!����(�(����7�$�%>�?�?r@c�b���jt�jt��d�y)Nrc)rLrMr@r9rs �rA�
cbFinishedzILengthEnforcingConsumerTests.test_stopProducingRaises.<locals>.cbFinished�	s$������S��!7�!7�8J�!K�L�a�Pr@)r&r7r�rU)rRr�r�rXs`   rA�test_stopProducingRaisesz5LengthEnforcingConsumerTests.test_stopProducingRaises�	s>���	@�':��
�
�#�	Q�
�"�"�$��	�
�
�j�!��r@N)F)r;r<r=r>rxr�r�r�r�r�r�r�r?r@rAr�r�n	s2���
�
9�P�@� 
/�,�J�r@r�c�"�eZdZdZd�Zd�Zd�Zy)�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�|jtttt	����y)zC
        L{ChunkedEncoder} instances provide L{IConsumer}.
        N)r�rrrrrqs rA�test_interfacez'RequestBodyConsumerTests.test_interface�	s��	
����Y���?P�0Q�R�Sr@c��t�}t|�}|jd�|j|j	�d�|j�|jd�|j|j	�d�y)z}
        L{ChunkedEncoder.write} writes to the transport the chunked encoded
        form of the bytes passed to it.
        r�r�sxxxxxxxxxxxxxxxxs10
xxxxxxxxxxxxxxxx
N)rrrtrLr�rW)rRrg�encoders   rAr�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.
        TNs0

)rr�r�registerProducerrr&r�rV�unregisterProducerrLr�)rRrgr&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@rAr�r��	s���T�M�:r@r�c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�TransportProxyProducerTestszn
    Tests for L{TransportProxyProducer} which proxies the L{IPushProducer}
    interface of a transport.
    c�T�|jtttd���y)zO
        L{TransportProxyProducer} instances provide L{IPushProducer}.
        N)r�rr
r&rqs rAr�z*TransportProxyProducerTests.test_interface
s��	
����]�4J�4�4P�Q�Rr@c��t�}t|�}|j|j|�|j	�|j|jd�y)z~
        L{TransportProxyProducer.stopProxying} drops the reference to the
        wrapped L{IPushProducer} provider.
        N)rr&rr��stopProxying�rRrg�proxys   rA�%test_stopProxyingUnreferencesProducerzATransportProxyProducerTests.test_stopProxyingUnreferencesProducer
sJ��
$�%�	�&�y�1�����U�_�_�i�8�
�������U�_�_�d�3r@c�v�t�}|j�t|�}|j|jd�|j�|j|jd�|j�|j
�|j�|j|jd�y)z�
        L{TransportProxyProducer.resumeProducing} calls the wrapped
        transport's C{resumeProducing} method unless told to stop proxying.
        rr�N)rr9r&rLr�r<r�r�s   rA�test_resumeProducingz0TransportProxyProducerTests.test_resumeProducing
s���
$�%�	�� � �"�&�y�1������0�0�(�;�
��������0�0�+�>�� � �"�
����	��������0�0�(�;r@c�V�t�}t|�}|j|jd�|j	�|j|jd�|j�|j
�|j	�|j|jd�y)z�
        L{TransportProxyProducer.pauseProducing} calls the wrapped transport's
        C{pauseProducing} method unless told to stop proxying.
        r�rN)rr&rLr�r9r<r�r�s   rA�test_pauseProducingz/TransportProxyProducerTests.test_pauseProducing,
s���
$�%�	�&�y�1������0�0�+�>�
��������0�0�(�;��!�!�#�
����	��������0�0�+�>r@c�`�t�}t|�}|j|jd�|j	�|j|jd�t�}t|�}|j�|j	�|j|jd�y)z�
        L{TransportProxyProducer.stopProducing} calls the wrapped transport's
        C{stopProducing} method unless told to stop proxying.
        r�rkN)rr&rLr�r7r�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|jd�|j�|j|jd�|j|j�y)zs
        L{TransportProxyProducer.loseConnection} calls the wrapped transport's
        C{loseConnection}.
        r�N)rrr�r�r&r��	connectedrLr��loseConnectionr��rRrgr�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)	rrr�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@rAr�r��	s+���
S�	4�<�,?�*?�(.�*-r@r�c�j�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zy)�
ResponseTestsz 
    Tests for L{Response}.
    c�h�tt��}|jtt|��y)z=
        L{Response} instances provide L{IResponse}.
        N)rhrr�rr5�rRr�s  rA�test_verifyInterfacez"ResponseTests.test_verifyInterface�
s$��)��):�;������Y��9�:r@c�>��g�t�}G�fd�dt�}|�}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���eZdZ�fd�Zy)�7ResponseTests.test_makeConnection.<locals>.SomeProtocolc�(���j|�yrpr�)rRr&�	producerss  �rAr�zFResponseTests.test_makeConnection.<locals>.SomeProtocol.makeConnection�
s���� � ��*r@N�r;r<r=r�)r�s�rA�SomeProtocolr��
s���
+r@r�rr�N)rrrhr�r9rLr�r<)rRrgr�r%r��theProducerr�s      @rA�test_makeConnectionz!ResponseTests.test_makeConnection�
s�����	�#�%�	�	+�8�	+� �>��(��3�����X�&�!�
���"�"�$�����0�0�(�;��#�#�%�����0�0�+�>r@c����g�G�fd�dt�}|�}tt��}|j|�|j	d�|j�dg�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���eZdZ�fd�Zy)�5ResponseTests.test_dataReceived.<locals>.ListConsumerc�(���j|�yrpr��rRr�r�s  �rAr�zBResponseTests.test_dataReceived.<locals>.ListConsumer.dataReceived�
�������T�"r@N�r;r<r=r��r�s�rA�ListConsumerr��
����
#r@r�r�N)rrhrr�r�rL)rRr�r%r�r�s    @rA�test_dataReceivedzResponseTests.test_dataReceived�
sZ�����	#�8�	#� �>��(��):�;�����X�&��"�"�6�*�������)r@c�@��g�G�fd�dt�}|�}tt��}|j|�|j	��djt�|jt��d�|j|jd�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���eZdZ�fd�Zy)�7ResponseTests.test_connectionLost.<locals>.ListConsumerc�(���j|�yrpr�)rRrO�losts  �rAr.zFResponseTests.test_connectionLost.<locals>.ListConsumer.connectionLost�
s������F�#r@N)r;r<r=r.)r�s�rAr�r��
s���
$r@r�rrcN)rrhrr�r�rKr/rLrMr�
_bodyProtocol)rRr�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�fd�dt�}|�}tt��}|jd�|jd�|j	|�|jd�|j�gd��|j
|jd�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���eZdZ�fd�Zy)�8ResponseTests.test_bufferEarlyData.<locals>.ListConsumerc�(���j|�yrpr�r�s  �rAr�zEResponseTests.test_bufferEarlyData.<locals>.ListConsumer.dataReceived�
r�r@Nr�r�s�rAr�r��
r�r@r�r�r�r�)r�r�r�N)rrhrr�r�rLr�_bodyBuffer)rRr�r�r�r�s    @rA�test_bufferEarlyDataz"ResponseTests.test_bufferEarlyData�
s������	#�8�	#� �>��(��):�;���"�"�6�*��"�"�6�*����X�&��"�"�6�*����� 8�9�	
���X�1�1�4�8r@c��tt��}|jt��|j	t
|jt��y)zb
        L{Response.deliverBody} raises L{RuntimeError} if called more than
        once.
        N)rhrr�rrr�r�s  rA� test_multipleStartProducingFailsz.ResponseTests.test_multipleStartProducingFails�
s;��
)��):�;�����X�Z�(����,��(<�(<�h�j�Ir@c���tt��}|jt��|j	�|jt|jt��y)zw
        L{Response.deliverBody} raises L{RuntimeError} if called after
        L{Response._bodyDataFinished}.
        N)rhrr�rr�rr�r�s  rA�%test_startProducingAfterFinishedFailsz3ResponseTests.test_startProducingAfterFinishedFails�
sG��
)��):�;�����X�Z�(��"�"�$����,��(<�(<�h�j�Ir@c��tt��}|j�|jt|j
d�y)z�
        L{Response._bodyDataReceived} raises L{RuntimeError} if called after
        L{Response._bodyDataFinished} but before L{Response.deliverBody}.
        r�N)rhrr�rr�r�r�s  rA�'test_bodyDataReceivedAfterFinishedFailsz5ResponseTests.test_bodyDataReceivedAfterFinishedFails�
s5��
)��):�;���"�"�$����,��(B�(B�F�Kr@c��tt��}|j�|jt	��|jt|jd�y)z�
        L{Response._bodyDataReceived} raises L{RuntimeError} if called after
        L{Response._bodyDataFinished} and after L{Response.deliverBody}.
        r�N)rhrr�r�rrr�r�r�s  rA�'test_bodyDataReceivedAfterDeliveryFailsz5ResponseTests.test_bodyDataReceivedAfterDeliveryFails�
sE��
)��):�;���"�"�$����X�Z�(����,��(B�(B�F�Kr@c��tt��}|j�|jt|j�y)zh
        L{Response._bodyDataFinished} raises L{RuntimeError} if called more
        than once.
        N)rhrr�rr�r�s  rA�'test_bodyDataFinishedAfterFinishedFailsz5ResponseTests.test_bodyDataFinishedAfterFinishedFailss3��
)��):�;���"�"�$����,��(B�(B�Cr@c��tt��}|j�|jt	��|jt|j�y)z{
        L{Response._bodyDataFinished} raises L{RuntimeError} if called after
        the body has been delivered.
        N)rhrr�r�rrr�r�s  rA�'test_bodyDataFinishedAfterDeliveryFailsz5ResponseTests.test_bodyDataFinishedAfterDeliveryFailssC��
)��):�;���"�"�$����X�Z�(����,��(B�(B�Cr@c�<��g�G�fd�dt�}t�}|j�|�}t|�}|j	|j
d�|j
|�|j	�dg�|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���eZdZ�fd�Zy)�9ResponseTests.test_transportResumed.<locals>.ListConsumerc�<���j|j�yrp)r�r�)rRrg�transportStates  �rAr�zHResponseTests.test_transportResumed.<locals>.ListConsumer.makeConnection#s����%�%�i�&=�&=�>r@Nr�)rs�rAr�r"s���
?r@r�rr�N)rrr9rhrLr�r�)rRr�rgr�r�rs     @rA�test_transportResumedz#ResponseTests.test_transportResumeds����
��	?�8�	?�$�%�	�� � �"��>��(��3������0�0�(�;����X�&�����(��4�����0�0�+�>r@c�>�t�}t|�}|jd�|jd�|j�t	�}|j|�|j
|jd�|jjt�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)rrhr�r�rr�rLr�r�rKr/�rRrgr�r�s    rA�)test_bodyDataFinishedBeforeStartProducingz7ResponseTests.test_bodyDataFinishedBeforeStartProducing/s|��$�%�	�(��3���"�"�6�*��"�"�6�*��"�"�$�'�)�����X�&�������	�2����"�"�<�0r@c��t�}t|�}t�}|j|�|j	|j
d�|j
tt���|jjt�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)rrhrr�rLr{r�rr9r�rKr
s    rA�#test_finishedWithErrorWhenConnectedz1ResponseTests.test_finishedWithErrorWhenConnectedAsn��$�%�	�(��3��'�)�����X�&�	
������+�6��"�"�7�+=�+?�#@�A����"�"�#5�6r@c��t�}t|�}|j|jd�|j	tt
���t�}|j|�|jjt�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)rrhrLr{r�rr9rr�r�rKr
s    rA�!test_finishedWithErrorWhenInitialz/ResponseTests.test_finishedWithErrorWhenInitialTsn��$�%�	�(��3��	
������)�4��"�"�7�+=�+?�#@�A�'�)�����X�&����"�"�#5�6r@N)r;r<r=r>r�r�r�r�r�r�r�r�r�rrrrrrr?r@rAr�r�}
sX���;�?�,*�&;�29�.J�J�L�L�D�D�?�(1�$7�&7r@r�N)_r>�typingr�zope.interfacer�zope.interface.verifyr�twisted.internet.deferrrrr	�twisted.internet.errorr
r�twisted.internet.interfacesrr
�twisted.internet.protocolr�twisted.internet.testingrrrr�twisted.loggerr�twisted.protocols.basicr�twisted.python.failurer�twisted.trial.unittestr�twisted.web._newclientrrrrrrrrrr r!r"r#r$r%r&r'r(�twisted.web.clientr)r*r+r,r-r.r/r0r1�twisted.web.httpr2�twisted.web.http_headersr3�twisted.web.iwebr4r5�twisted.web.test.requesthelperr6r7�	Exceptionr9rCrfrYr\r^r`rhrjr�r�r�r�rerqrvr*r>r�r�r�r�r?r@rA�<module>r%s�����&�.�J�J�A�@�.���.�0�*�+������(
�
�
�'�,�5������	���'�N�#3�4�5��%
�PT���L�6�(�6�BSM�SM�l�+;�X���.>���Y	.�H�Y	.�x��0��f
E��f
E�R
�]�� 
� 
�� 
�Fq;�8�q;�hb�8�b�J):�x�):�X{-�(�{-�|h7�H�h7r@

Zerion Mini Shell 1.0