%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f������dZddlmZddlZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZddlmZmZddlmZdd	lmZdd
lmZddlmZmZddlmZmZdd
lmZm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:Z:ddl;m<Z<ddl=m>Z>ddl?m@Z@mAZAddlBmCZCddlDmEZEmFZFddlGmHZHmIZImJZJddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRddlSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[ddl\m]Z]dd l^m_Z_dd!l`maZambZbmcZcmdZdmeZemfZfdd"lgmhZhmiZie	reFZjekZlnekZjeFZl	dd#lmmZnenZmd$Zodd%lpmqZqmrZrdd&lsmtZtdd'lumvZvdd(lwmxZxmyZyeer�Gd)�d*��ZzGd,�d-e-�Z|Gd.�d/�Z}Gd0�d1eF�Z~d2Zd3Z�d4Z�d5Z�d6Z�d7Z�Gd8�d9�Z�Gd:�d;�Z�Gd<�d=�Z�Gd>�d?e,�Z�Gd@�dAeFe��Z�GdB�dC�Z�GdD�dE�Z�eec�GdF�dG��Z�GdH�dIeFe�e�e��Z�GdJ�dKe�eheE�Z�GdL�dMe�eieE�Z�eeodN�GdO�dPeFe�e���Z�GdQ�dReF�Z�GdS�dTeFe��Z�GdU�dV�Z�GdW�dXeFe��Z�GdY�dZeFe�e�e��Z�Gd[�d\e:ef��Z�Gd]�d^e��Z�Gd_�d`eFe�e��Z�Gda�dbe-�Z�Gdc�ddeFe��Z�Gde�dfeFe�e��Z�gdg�Z�Gdh�diej�Z�Gdj�dke�e�e�el�Z�Gdl�dme�e�e�el�Z�Gdn�doe6�Z�Gdp�dq�Z�Gdr�dse��Z�Gdt�dueF�Z�eeodN�Gdv�dweF��Z�Gdx�dyeheE�Z�Gdz�d{eheE�Z�Gd|�d}eieE�Z�Gd~�deieE�Z�y#e{$rdZmd+ZoY���wxYw)�zD
Tests for L{twisted.web.client.Agent} and related new client APIs.
�)�annotationsN)�	CookieJar)�BytesIO)�
TYPE_CHECKING�Dict�List�Optional�Sequence�Tuple)�SkipTest�skipIf��implementer)�verifyObject)�Version)�defer�task)�IPv4Address�IPv6Address)�CancelledError�Deferred�succeed)�HostnameEndpoint�TCP4ClientEndpoint)�ConnectionDone�ConnectionLost�ConnectionRefusedError)�IOpenSSLClientConnectionCreator)�Factory�Protocol)�Clock)�deterministicResolvingReactor)�AccumulatingProtocol�EventLoggingObserver�MemoryReactorClock�StringTransport)�globalLogPublisher)�proxyForInterface)�getDeprecationWarningString)�Failure)�
FakeTransport�IOPump)�!certificatesForAuthorityAndServer)�SynchronousTestCase�TestCase)�client�error�http_headers)�HTTP11ClientProtocol�PotentialDataLoss�RequestNotSent�RequestTransmissionFailed�Response�ResponseFailed�ResponseNeverReceived)�URI�BrowserLikePolicyForHTTPS�FileBodyProducer�HostnameCachingHTTPSPolicy�HTTPConnectionPool�Request�ResponseDone�_HTTP11ClientFactory)�SchemeNotSupported)�Headers)�UNKNOWN_LENGTH�IAgent�IAgentEndpointFactory�
IBodyProducer�IPolicyForHTTPS�	IResponse)�MethodInjectionTestsMixin�URIInjectionTestsMixin)�sslT)�ClientTLSOptions�IOpenSSLTrustRoot)�optionsForClientTLS)�tls)�TLSMemoryBIOFactory�TLSMemoryBIOProtocolc��eZdZdZdZd�Zy)�CustomOpenSSLTrustRootFNc� �d|_||_y�NT)�called�context)�selfrXs  �=/usr/lib/python3/dist-packages/twisted/web/test/test_agent.py�_addCACertsToContextz+CustomOpenSSLTrustRoot._addCACertsToContextms���D�K�"�D�L�)�__name__�
__module__�__qualname__rWrXr[�r\rZrTrThs������	#r\rTFc��eZdZdZdd�Zd�Zy)�StubHTTPProtocolaR
    A protocol like L{HTTP11ClientProtocol} but which does not actually know
    HTTP/1.1 and only collects requests in a list.

    @ivar requests: A C{list} of two-tuples.  Each time a request is made, a
        tuple consisting of the request and the L{Deferred} returned from the
        request method is appended to this list.
    c� �g|_d|_y)N�	QUIESCENT)�requests�state�rYs rZ�__init__zStubHTTPProtocol.__init__|s��CE��
� ��
r\c�T�t�}|jj||f�|S)z�
        Capture the given request for later inspection.

        @return: A L{Deferred} which this code will never fire.
        )rre�append)rY�request�results   rZrkzStubHTTPProtocol.request�s'������
�
���g�v�.�/��
r\N��return�None)r]r^r_�__doc__rhrkr`r\rZrbrbrs���!�r\rbc��eZdZd�Zd�Zy)�FileConsumerc��||_y�N)�
outputFile)rYrus  rZrhzFileConsumer.__init__�s	��$��r\c�:�|jj|�yrt)ru�write)rY�bytess  rZrwzFileConsumer.write�s�������e�$r\N)r]r^r_rhrwr`r\rZrrrr�s��%�%r\rrc�d�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zy)�FileBodyProducerTestszq
    Tests for the L{FileBodyProducer} which reads bytes from a file and writes
    them to an L{IConsumer}.
    c��d�S)al
        This method can be used as the C{terminationPredicateFactory} for a
        L{Cooperator}.  It returns a predicate which immediately returns
        C{False}, indicating that no more work should be done this iteration.
        This has the result of only allowing one iteration of a cooperative
        task to be run per L{Cooperator} iteration.
        c��yrVr`r`r\rZ�<lambda>z4FileBodyProducerTests._termination.<locals>.<lambda>���r\r`rgs rZ�_terminationz"FileBodyProducerTests._termination�s
���r\c��g|_tj|j|jj�|_y)z�
        Create a L{Cooperator} hooked up to an easily controlled, deterministic
        scheduler to use with L{FileBodyProducer}.
        N)�
_scheduledr�
Cooperatorrrj�
cooperatorrgs rZ�setUpzFileBodyProducerTests.setUp�s-��
����/�/�$�*;�*;�T�_�_�=S�=S�T��r\c
�f�|jtttt	d����y)zI
        L{FileBodyProducer} instances provide L{IBodyProducer}.
        r\N)�
assertTruerrGr<rrgs rZ�test_interfacez$FileBodyProducerTests.test_interface�s!��	
����]�4D�W�S�\�4R�S�Tr\c���Gd�d�}Gd�d�}t|��}|jt|j�t|��}|jt|j�y)z�
        If the L{FileBodyProducer} is constructed with a file-like object
        without either a C{seek} or C{tell} method, its C{length} attribute is
        set to C{UNKNOWN_LENGTH}.
        c��eZdZd�Zy)�9FileBodyProducerTests.test_unknownLength.<locals>.HasSeekc��yrtr`)rY�offset�whences   rZ�seekz>FileBodyProducerTests.test_unknownLength.<locals>.HasSeek.seek����r\N)r]r^r_r�r`r\rZ�HasSeekr�����
r\r�c��eZdZd�Zy)�9FileBodyProducerTests.test_unknownLength.<locals>.HasTellc��yrtr`rgs rZ�tellz>FileBodyProducerTests.test_unknownLength.<locals>.HasTell.tell�r�r\N)r]r^r_r�r`r\rZ�HasTellr��r�r\r�N)r<�assertEqualrD�length)rYr�r��producers    rZ�test_unknownLengthz(FileBodyProducerTests.test_unknownLength�sX��	�	�	�	�$�G�I�.���������9�#�G�I�.���������9r\c���d}t|�}|jd�t|�}|jt	|�dz
|j
�|j|j
�d�y)z�
        If the L{FileBodyProducer} is constructed with a file-like object with
        both C{seek} and C{tell} methods, its C{length} attribute is set to the
        size of the file as determined by those methods.
        shere are some bytes�N)rr�r<r��lenr�r�)rY�
inputBytes�	inputFiler�s    rZ�test_knownLengthz&FileBodyProducerTests.test_knownLength�s]��,�
��J�'�	����q��#�I�.������Z��1�,�h�o�o�>�������)�1�-r\c��ttd��}|jtj|j
�y)zw
        If no L{Cooperator} instance is passed to L{FileBodyProducer}, the
        global cooperator is used.
        r\N)r<rr�r�	cooperate�
_cooperate)rYr�s  rZ�test_defaultCooperatorz,FileBodyProducerTests.test_defaultCooperator�s,��
$�G�C�L�1���������)<�)<�=r\c���d}d}t�}t|�}tt|�|j|�}|j	|�}tt
|�|zdz�D]"}|jjd���$|jg|j�|j||j��|jd|j|��y)z�
        L{FileBodyProducer.startProducing} starts writing bytes from the input
        file to the given L{IConsumer} and returns a L{Deferred} which fires
        when they have all been written.
        �hello, world��rN)rrrr<r��startProducing�ranger�r��popr��getvalue�successResultOf)rY�expectedResult�readSize�output�consumerr��complete�is        rZ�test_startProducingz)FileBodyProducerTests.test_startProducing�s���)���������'��#�G�N�$;�T�_�_�h�W���*�*�8�4���s�>�*�h�6��:�;�	%�A�"�D�O�O����"�$�	%�����T�_�_�-��������):�;�����t�3�3�H�=�>r\c�L�d}d}t|�}t||j|�}tt��}|j	|�tt
|�|zdz�D]"}|jjd���$|j|j�y)z
        When L{FileBodyProducer} reaches end-of-file on the input file given to
        it, the input file is closed.
        �ssome friendly bytes�rN)rr<r�rrr�r�r�r�r�r��closed)rYr�r�r�r�r�r�s       rZ�test_inputClosedAtEOFz+FileBodyProducerTests.test_inputClosedAtEOF�s���
��+�
��J�'�	�#�I�t����I����	�*������)��s�:��(�2�Q�6�7�	%�A�"�D�O�O����"�$�	%����	�(�(�)r\c��Gd�d�}t|�|j�}|jtt	���}|j
j
d��|j|�jt�y)z�
        If a read from the input file fails while producing bytes to the
        consumer, the L{Deferred} returned by
        L{FileBodyProducer.startProducing} fires with a L{Failure} wrapping
        that exception.
        c��eZdZd�Zy)�GFileBodyProducerTests.test_failedReadWhileProducing.<locals>.BrokenFilec��td��)NzSimulated bad thing)�OSError)rY�counts  rZ�readzLFileBodyProducerTests.test_failedReadWhileProducing.<locals>.BrokenFile.reads���3�4�4r\N)r]r^r_r�r`r\rZ�
BrokenFiler�s��
5r\r�rN)
r<r�r�rrrr�r��failureResultOf�trap�IOError)rYr�r�r�s    rZ�test_failedReadWhileProducingz3FileBodyProducerTests.test_failedReadWhileProducing�sg��	5�	5�$�J�L�$�/�/�B���*�*�<��	�+B�C��������A�� ����X�&�+�+�G�4r\c��d}d}t�}t|�}t|�}t||j|�}|j	|�}|j�|j
|j�|jjd��|jd|j��|j|�y)z�
        When the L{Deferred} returned by L{FileBodyProducer.startProducing} is
        cancelled, the input file is closed and the task is stopped.
        r�r�rr\N)
rrrr<r�r��cancelr�r�r�r�r�r��assertNoResult�rYr�r�r�r�r�r�r�s        rZ�test_cancelWhileProducingz/FileBodyProducerTests.test_cancelWhileProducings���
)���������'���N�+�	�#�I�t����I���*�*�8�4���������	�(�(�)�������A�� �����f�o�o�/�0����H�%r\c��d}d}t�}t|�}t|�}t||j|�}|j	|�}|j�|j
|j�|jjd��|jd|j��|j|�y)a
        L{FileBodyProducer.stopProducing} stops the underlying L{IPullProducer}
        and the cooperative task responsible for calling C{resumeProducing} and
        closes the input file but does not cause the L{Deferred} returned by
        C{startProducing} to fire.
        r�r�rr\N�
rrrr<r�r��
stopProducingr�r�r�r�r�r�r�r�s        rZ�test_stopProducingz(FileBodyProducerTests.test_stopProducings���)���������'���N�+�	�#�I�t����I���*�*�8�4����� ����	�(�(�)�������A�� �����f�o�o�/�0����H�%r\c��d}d}t�}t|�}tt|�|j|�}|j	|�}|j
j
d��|j|j�|dd�|j�|j
j
d��|j|j�|dd�|jg|j
�|j|�y)z�
        L{FileBodyProducer.pauseProducing} temporarily suspends writing bytes
        from the input file to the given L{IConsumer}.
        r�r�rN)rrrr<r�r�r�r�r�r��pauseProducingr�)rYr�r�r�r�r�r�s       rZ�test_pauseProducingz)FileBodyProducerTests.test_pauseProducing2s���
)���������'��#�G�N�$;�T�_�_�h�W���*�*�8�4��������A�� �������*�N�2�A�,>�?����!�	������A�� �	
������*�N�2�A�,>�?�����T�_�_�-����H�%r\c���d}d}t�}t|�}tt|�|j|�}|j	|�|j
j
d��|j|d||j��|j�|j�|j
j
d��|j|d|dz|j��y)z�
        L{FileBodyProducer.resumeProducing} re-commences writing bytes from the
        input file to the given L{IConsumer} after it was previously paused
        with L{FileBodyProducer.pauseProducing}.
        r�r�rNr�)rrrr<r�r�r�r�r�r�r��resumeProducing)rYr�r�r�r�r�s      rZ�test_resumeProducingz*FileBodyProducerTests.test_resumeProducingLs���)���������'��#�G�N�$;�T�_�_�h�W������)�������A�� �����	��2�F�O�O�4E�F����!�� � �"�������A�� ������(�Q�,�7����9J�Kr\c��d}d}t�}t|�}t|�}t||j|�}|j	|�}|j�|j�|j
|j�|jjd��|jd|j��|j|�y)zv
        L{FileBodyProducer.stopProducing} can be called more than once without
        raising an exception.
        stestr�rr\Nr�r�s        rZ�test_multipleStopz'FileBodyProducerTests.test_multipleStop_s���
!���������'���N�+�	�#�I�t����I���*�*�8�4����� ���� ����	�(�(�)�������A�� �����f�o�o�/�0����H�%r\N)r]r^r_rprr�r�r�r�r�r�r�r�r�r�r�r�r�r`r\rZrzrz�sP���
�U�U�:�(.�>�?�$
*�5�"&�$&�(&�4L�&&r\rz�	127.0.0.7�::7z	127.0.0.8z	127.0.0.9z
127.0.0.10z
127.0.0.11c�6�eZdZdZd�ZGd�d�Zd�Zd�Zy)�FakeReactorAndConnectMixinz�
    A test mixin providing a testable C{Reactor} class and a dummy C{connect}
    method which allows instances to pretend to be endpoints.
    c���t�}t|tgtgtgt
gtgtgdgdgd���}|j|_|j|_	|S)af
        Create a L{MemoryReactorClock} and give it some hostnames it can
        resolve.

        @return: a L{MemoryReactorClock}-like object with a slightly limited
            interface (only C{advance} and C{tcpClients} in addition to its
            formally-declared reactor interfaces), which can resolve a fixed
            set of domains.
        r�r�)�example.comzipv6.example.comzexample.netzexample.org�foozfoo.comr�r�)�hostMap)
r%r"�EXAMPLE_COM_IP�EXAMPLE_COM_V6_IP�EXAMPLE_NET_IP�EXAMPLE_ORG_IP�FOO_LOCAL_IP�
FOO_COM_IP�
tcpClients�advance)rY�mrc�drrs   rZ�
createReactorz(FakeReactorAndConnectMixin.createReactor�sg��!�"��+�� .�/�%6�$7� .�/� .�/�$�~�&�<�)�]��w�	�
�� ������k�k����
r\c��eZdZdZd�Zd�Zy)�'FakeReactorAndConnectMixin.StubEndpointz�
        Endpoint that wraps existing endpoint, substitutes StubHTTPProtocol, and
        resulting protocol instances are attached to the given test case.
        c���|�_|�_d�}t|t�j���_t��_�fd��j_y)Nc��y)zthis function does nothingNr`r`r\rZ�nothingzAFakeReactorAndConnectMixin.StubEndpoint.__init__.<locals>.nothing�r~r\c����jSrt)�protocol)�addrrYs �rZr}zBFakeReactorAndConnectMixin.StubEndpoint.__init__.<locals>.<lambda>�s���d�m�m�r\)�endpoint�testCaserA�repr�factoryrbr��
buildProtocol)rYr�r�r�s`   rZrhz0FakeReactorAndConnectMixin.StubEndpoint.__init__�sE���$�D�M�$�D�M�
1�0���d�m�m�9L�M�D�L�,�.�D�M�)C�D�L�L�&r\c��|j|j_|jj|j�t|j�Srt)r�r�r��connectr�r)rY�ignoredFactorys  rZr�z/FakeReactorAndConnectMixin.StubEndpoint.connect�s7��%)�]�]�D�M�M�"��M�M�!�!�$�,�,�/��4�=�=�)�)r\N)r]r^r_rprhr�r`r\rZ�StubEndpointr��s��	�
		D�	*r\r�c�b���tj|�}|j���fd�|_|S)z�
        Return an Agent suitable for use in tests that wrap the Agent and want
        both a fake reactor and StubHTTPProtocol.
        c�.���j�|���Srt)r�)�args�_oldGetEndpointrYs ��rZr}zEFakeReactorAndConnectMixin.buildAgentForWrapperTest.<locals>.<lambda>�s������o�t�4�d�;�r\)r0�Agent�_getEndpoint)rY�reactor�agentr�s`  @rZ�buildAgentForWrapperTestz3FakeReactorAndConnectMixin.buildAgentForWrapperTest�s/���
���W�%���,�,��
����r\c�\�t�}|jd�||_t|�S)z�
        Fake implementation of an endpoint which synchronously
        succeeds with an instance of L{StubHTTPProtocol} for ease of
        testing.
        N)rb�makeConnectionr�r�rYr�r�s   rZr�z"FakeReactorAndConnectMixin.connect�s,��$�%������%� ��
��x� � r\N)r]r^r_rpr�r�rr�r`r\rZr�r�{s ���
�>*�*�,
�	!r\r�c��eZdZdZd�Zy)�
DummyEndpointz1
    An endpoint that uses a fake transport.
    c�l�|jd�}|jt��t|�Srt�r�rr&rrs   rZr�zDummyEndpoint.connect�s.���(�(��.������ 1�2��x� � r\N�r]r^r_rpr�r`r\rZrr�s���!r\rc��eZdZdZd�Zy)�BadEndpointz/
    An endpoint that shouldn't be called.
    c��td��)Nz(This endpoint should not have been used.)�RuntimeError)rYr�s  rZr�zBadEndpoint.connect�s���E�F�Fr\Nrr`r\rZr
r
�s
���Gr\r
c��eZdZdZd�ZeZy)�DummyFactoryz/
    Create C{StubHTTPProtocol} instances.
    c��yrtr`)rY�quiescentCallback�metadatas   rZrhzDummyFactory.__init__�s��r\N)r]r^r_rprhrbr�r`r\rZrr�s���
� �Hr\rc�X�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zy)�HTTPConnectionPoolTestsz4
    Tests for the L{HTTPConnectionPool} class.
    c��|j�|_t|j�|_t|j_d|j_y�NF)r��fakeReactorr>�poolr�_factory�retryAutomaticallyrgs rZr�zHTTPConnectionPoolTests.setUp�s=���-�-�/���&�t�'7�'7�8��	�)��	�	��',��	�	�$r\c�����j�jji��fd�}d}�jj|t	��}|j|�S)z{
        If there are no cached connections,
        L{HTTPConnectionPool.getConnection} returns a new connection.
        c����j|t��j|�jjj��yrt)�assertIsInstancerb�assertNotInr�_connections�values)�connrYs �rZ�
gotConnectionzMHTTPConnectionPoolTests.test_getReturnsNewIfCacheEmpty.<locals>.gotConnections7����!�!�$�(8�9����T�4�9�9�#9�#9�#@�#@�#B�Cr\��/)r�rr!�
getConnectionr�addCallback)rYr$�
unknownKey�ds`   rZ�test_getReturnsNewIfCacheEmptyz6HTTPConnectionPoolTests.test_getReturnsNewIfCacheEmpty�sS���
	
������/�/��4�	D�
�
��I�I�#�#�J�
��@���}�}�]�+�+r\c�`�t�}|jt��|jj	d|�|j|jjd�|j||jjd�|jjd�|j|jjd�|j||jjd�|j||jj�|jjd�|j|jjd�|j||jjd�|j||jj�y)z�
        If a connection is put back to the pool, a 240-sec timeout is started.

        When the timeout hits, the connection is closed and removed from the
        pool.
        ��http�example.com�PF��g�������?TN)rbrr&r�_putConnectionr��	transport�
disconnecting�assertInr!rr��	_timeoutsr �rYr�s  rZ�test_putStartsTimeoutz-HTTPConnectionPoolTests.test_putStartsTimeout	sB��$�%������ 1�2��	�	� � �!=�x�H�	
����+�+�9�9�5�A��
�
�h��	�	� 6� 6�7S� T�U�	
��� � ��%�����+�+�9�9�5�A��
�
�h��	�	� 6� 6�7S� T�U��
�
�h��	�	� 3� 3�4�	
��� � ��%�����+�+�9�9�4�@�����4�9�9�#9�#9�:V�#W�X�����4�9�9�#6�#6�7r\c�N�|j}t�t�g}|D]-}|jt��|j	d|��/|j|jd|�|jj�}t�}|jt��|j	d|�|jd}|jt|�d�|j||d|g�|j|D�cgc]}|jj��c}ddg�|j|djjd�|j||dj�|j|d|j�ycc}w)z�
        If an idle connection is put back in the cache and the max number of
        persistent connections has been exceeded, one of the connections is
        closed and removed from the cache.
        r,r�r�FrTN)rrbrr&r1r�r!r5�copyr�r2r3r��	cancelledr )rYr�
origCached�p�timeouts�newProtocol�	newCacheds       rZ�test_putExceedsMaxPersistentz4HTTPConnectionPoolTests.test_putExceedsMaxPersistent%sr���y�y��'�(�*:�*<�=�
��	A�A�
���_�.�/���� <�a�@�	A�	
����*�*�+G�H�*�U��>�>�&�&�(��'�(���"�"�?�#4�5����8�+�F��%�%�&B�C�	�����Y���+�����Z��]�K�$@�A����Y�G��!�+�+�3�3�G�%�QV��X�����A��0�0�>�>��E������A��/�9�9�:�����A�����7��Hs�F"c����fd�}g}|j|ddd��|j|ddd��|ddd�|ddd��j�jjd|��jt	�jjd	�d
��jt	�jjd�d
�y)
z�
        C{maxPersistentPerHost} is enforced per C{(scheme, host, port)}:
        different keys have different max connections.
        c���t�}|jt���jj	|||f|�|Srt)rbrr&rr1)�scheme�host�portr<rYs    �rZ�addProtocolzFHTTPConnectionPoolTests.test_maxPersistentPerHost.<locals>.addProtocolIs<��� �"�A�
���_�.�/��I�I�$�$�f�d�D�%9�1�=��Hr\r-r.r/�https��www2.example.comr,)rGr.rHr�)r-rIr/N)rjr�rr!r�)rYrF�
persistents`  rZ�test_maxPersistentPerHostz1HTTPConnectionPoolTests.test_maxPersistentPerHostCs����	��
����+�f�n�b�A�B����+�f�n�b�A�B��G�^�S�1��F�/��4�����I�I�"�"�#?�@�*�	
�	
����T�Y�Y�3�3�4R�S�T�VW�X������	�	�&�&�'H�I�J�A�	
r\c����t���jt���jj	d����fd�}�jjdt
��j|�S)z�
        Getting an address which has a cached connection returns the cached
        connection, removes it from the cache and cancels its timeout.
        r,c�J���j�|��j|�jjd��jjd��j
|jjd��j|�jj�y)Nr,��F)
�assertIdenticalr rr!rr�r�r2r3r5)r#r�rYs ��rZr$zGHTTPConnectionPoolTests.test_getCachedConnection.<locals>.gotConnectiongs{���� � ��4�0����T�4�9�9�#9�#9�:V�#W�X����$�$�S�)����T�^�^�9�9�5�A����T�4�9�9�#6�#6�7r\)rbrr&rr1r&r
r')rYr$r�s` @rZ�test_getCachedConnectionz0HTTPConnectionPoolTests.test_getCachedConnection]se���$�%������ 1�2��	�	� � �!=�x�H�	8��y�y�&�&�(��M�
��+�m�
$�	%r\c�����t���jt��d��jj	������fd�}�jj�t
��}|j|�S)zR
        The pool's C{_newConnection} method constructs a new connection.
        r%c�����j�|��j��jj���j	|�jjj��yrt)�assertNotIdenticalr4rr!r r")�
newConnection�keyr�rYs ���rZr$zAHTTPConnectionPoolTests.test_newConnection.<locals>.gotConnectionsS����#�#�H�m�<��M�M�(�D�I�I�$:�$:�3�$?�@����]�D�I�I�,B�,B�,I�,I�,K�Lr\)rbrr&rr1�_newConnectionrr')rYr$r)rUr�s`  @@rZ�test_newConnectionz*HTTPConnectionPoolTests.test_newConnectionusf���
$�%������ 1�2����	�	� � ��h�/�	M�
�I�I�$�$�S�-�/�:���}�}�]�+�+r\c�"�|j}d}t�t�g}|D]-}|jt��|j	||��/|j|j||�d|d_g}|jj|t��j|j�|j|d|d�|j|j|g�|j|ji�y)z{
        When getting connections out of the cache, disconnected connections
        are removed and not returned.
        r,�DISCONNECTEDrr�N)rrbrr&r1r�r!rfr&r
r'rjrOr5)rYrrUr;r<rls      rZ�test_getSkipsDisconnectedz1HTTPConnectionPoolTests.test_getSkipsDisconnected�s���
�y�y��*��'�(�*:�*<�=�
��	(�A�
���_�.�/�����Q�'�	(�	
����*�*�3�/��<�-�
�1�
�����	�	����[�]�3�?�?��
�
�N����V�A�Y�
�1�
�6�	
����*�*�3�/��4��������,r\c�(�t�}|j|jd�tj|t
�}d|_|jjd|�|jdt|��|d}|d}|j|jt�|j|j�d�|jd|jjj!d��|j#t�y)	ze
        If a non-quiescent connection is put back in the cache, an error is
        logged.
        rd�NOTQUIESCENTr,r�r�log_failurez5BUG: Non-quiescent protocol added to connection pool.N)rbr�rfr$�createWithCleanupr'rr1�assertEqualsr�r�valuer�getErrorMessagerOr!�get�flushLoggedErrors)rYr��logObserver�event�fs     rZ�test_putNotQuiescentz,HTTPConnectionPoolTests.test_putNotQuiescent�s���
$�%���������5�*�<�<�T�CU�V��'����	�	� � �!=�x�H����!�S��-�.��A����-� �����a�g�g�|�4����
����!X�	
�	
����$�)�)�(�(�,�,�-I�J�	
�	
���|�,r\c��Gd�d�}t|jd�}d|_g}d}|j||��j	|j
�|d}|j
|t�d|_|j|�g}|j||��j	|j
�|j|d|�y)	aI
        When L{HTTPConnectionPool.getConnection} connects, it returns a
        C{Deferred} that fires with an instance of L{HTTP11ClientProtocol}
        that has the correct quiescent callback attached. When this callback
        is called the protocol is returned to the cache correctly, using the
        right key.
        c��eZdZd�Zy)�MHTTPConnectionPoolTests.test_getUsesQuiescentCallback.<locals>.StringEndpointc�l�|jd�}|jt��t|�Srtr
)rYr�r<s   rZr�zUHTTPConnectionPoolTests.test_getUsesQuiescentCallback.<locals>.StringEndpoint.connect�s-���)�)�$�/��� � ��!2�3��q�z�!r\N�r]r^r_r�r`r\rZ�StringEndpointrj�s��
"r\rmTFza keyrrdN)r>rrr&r'rjrr3�_state�_quiescentCallbackrO)rYrmrrlrUr��result2s       rZ�test_getUsesQuiescentCallbackz5HTTPConnectionPoolTests.test_getUsesQuiescentCallback�s���	"�	"�"�$�"2�"2�D�9��"'����������3�� 0�1�=�=�f�m�m�L��!�9�����h�(<�=�&����#�#�H�-�
�����3�� 0�1�=�=�g�n�n�M����W�Q�Z��2r\c����g���fd�}|ddd�|ddd��jj�}�D](}�j|jjd��*�j�jj
i��jj�D]}�j|jd�� �j�jji�g}|j|j��j|g��djtt����j|g��djtt����j|d	g�y	)
z�
        L{HTTPConnectionPool.closeCachedConnections} closes all cached
        connections and removes them from the cache. It returns a Deferred
        that fires when they have all lost their connections.
        c���t�}|jt���jj	|||f|��j|�yrt)r3rr&rr1rj)rCrDrEr<rJrYs    ��rZrFzHHTTPConnectionPoolTests.test_closeCachedConnections.<locals>.addProtocol�sE���$�&�A�
���_�.�/��I�I�$�$�f�d�D�%9�1�=����a� r\r-r.r/rITrr�N)r�closeCachedConnectionsr�r2r3r!r�getDelayedCallsr:r5r'rj�connectionLostr*r)rYrF�doneDeferredr<�dcrlrJs`     @rZ�test_closeCachedConnectionsz3HTTPConnectionPoolTests.test_closeCachedConnections�sL����
�	!�	�F�N�B�/��F�/��4��y�y�7�7�9���	>�A����Q�[�[�6�6��=�	>�������/�/��4��"�"�2�2�4�	1�B����R�\�\�4�0�	1�������,�,�b�1���� � ����/������$��1�
�$�$�W�^�-=�%>�?������$��1�
�$�$�W�^�-=�%>�?�����$��(r\c�>��|j|jji�t��G�fd�d�}|jj	d|��}|j�|j|j
��jt�y)z�
        Cancelling the C{Deferred} returned from
        L{HTTPConnectionPool.getConnection} cancels the C{Deferred} returned
        by opening a new connection with the given endpoint.
        c���eZdZ�fd�Zy)�XHTTPConnectionPoolTests.test_cancelGetConnectionCancelsEndpointConnect.<locals>.Endpointc����Srtr`)rYr��connectionResults  �rZr�z`HTTPConnectionPoolTests.test_cancelGetConnectionCancelsEndpointConnect.<locals>.Endpoint.connects	���'�'r\Nrl)r~s�rZ�Endpointr|s���
(r\ri90N)	r�rr!rr&r�r��typer)rYrr)r~s   @rZ�.test_cancelGetConnectionCancelsEndpointConnectzFHTTPConnectionPoolTests.test_cancelGetConnectionCancelsEndpointConnectsv���	
������/�/��4�#�:��	(�	(�
�I�I�#�#�E�8�:�6��	���
�����-�-�.>�?�D�D�n�Ur\N)r]r^r_rpr�r*r7r@rKrPrWrZrgrqryr�r`r\rZrr�sF���-�,� 8�88�<
�4%�0,�*-�8-�6!3�F")�HVr\rc��eZdZdZd�Zy)�AgentTestsMixinz1
    Tests for any L{IAgent} implementation.
    c�^�|jtt|j���y)z6
        The agent object provides L{IAgent}.
        N)r�rrE�	makeAgentrgs rZr�zAgentTestsMixin.test_interfaces��	
����V�T�^�^�-=�>�?r\N)r]r^r_rpr�r`r\rZr�r�s
���@r\r�c�L�eZdZdZd�Zd�Zd�Zd�Zd�ejdfd�Z
y	)
�IntegrationTestingMixinzG
    Transport-to-Agent integration tests for both HTTP and HTTPS.
    c�:�|jdtt�y)z+
        L{Agent} works over IPv4.
        r.N)�integrationTestr�rrgs rZ�test_integrationTestIPv4z0IntegrationTestingMixin.test_integrationTestIPv4+s��	
���^�^�[�Ir\c�2�|jddt�y)zL
        L{Agent} works over IPv4 when hostname is an IPv4 address.
        s	127.0.0.7r�N)r�rrgs rZ�test_integrationTestIPv4Addressz7IntegrationTestingMixin.test_integrationTestIPv4Address1s��	
���\�;��Dr\c�:�|jdtt�y)z+
        L{Agent} works over IPv6.
        sipv6.example.comN)r�r�rrgs rZ�test_integrationTestIPv6z0IntegrationTestingMixin.test_integrationTestIPv67s��	
���0�2C�[�Qr\c�2�|jddt�y)zL
        L{Agent} works over IPv6 when hostname is an IPv6 address.
        s[::7]r�N)r�rrgs rZ�test_integrationTestIPv6Addressz7IntegrationTestingMixin.test_integrationTestIPv6Address=s��	
���X�u�k�:r\c��|Srtr`)�server�_s  rZr}z IntegrationTestingMixin.<lambda>Hs���r\�httpc	����|j��tr|jtd�fd��|��}|j	d|dz|zdz�}�j
d\}	}
}}}
|j
|	|�|d|	|
�}|j|�}t|d|�	�}|j|�tj�fd
���d�_d�_
|���jd�}t|d�}|j|�t||||d��
�}|j�|j!|��jj"j%d�}|j'|dj)d�|d�t+|ddD�cgc]}|s�|j%dd���c}�}|j
|d|�|j!|��jj,j/d�|j�|j1|�}|j3|j4j7d�dd�ycc}w)a�
        L{Agent} will make a TCP connection, send an HTTP request, and return a
        L{Deferred} that fires when the response has been received.

        @param hostName: The hostname to interpolate into the URL to be
            requested.
        @type hostName: L{bytes}

        @param expectedAddress: The expected address string.
        @type expectedAddress: L{bytes}

        @param addressType: The class to construct an address out of.
        @type addressType: L{type}

        @param serverWrapper: A callable that takes a protocol factory and a
            ``Clock`` and returns a protocol factory; used to wrap the server /
            responder side in a TLS server.
        @type serverWrapper:
            serverWrapper(L{twisted.internet.interfaces.IProtocolFactory}) ->
            L{twisted.internet.interfaces.IProtocolFactory}

        @param createAgent: A callable that takes a reactor and produces an
            L{IAgent}; used to construct an agent with an appropriate trust
            root for TLS.
        @type createAgent: createAgent(reactor) -> L{IAgent}

        @param scheme: The scheme to test, C{http} or C{https}
        @type scheme: L{bytes}
        �_get_default_clockc����Srtr`)rs�rZr}z9IntegrationTestingMixin.integrationTest.<locals>.<lambda>ms���'�r\�GET�://�/r�TCPF)�peerAddressc�*��t�}|�_|Srt)r#�currentProtocol)�ap�accumulators �rZr�z<IntegrationTestingMixin.integrationTest.<locals>.accumulatorws���%�'�B�*,�K�'��Ir\NT)�clocks
s
GET / HTTPr�s: �HostsLHTTP/1.1 200 OK
X-An-Header: an-value

Content-length: 12

hello world!sx-an-headersan-value)r��
sslPresent�patchrPrkr�r�r�r+rr�forProtocolr��protocolConnectionMader,�flushr��data�splitr��
startswith�dictr2rwr�r_�headers�
getRawHeaders)rY�hostName�expectedAddress�addressType�
serverWrapper�createAgentrCr�deferredrDrEr��timeout�bindr��clientProtocol�clientTransport�wrapper�serverTransport�pump�lines�liner��responser�rs                        @@rZr�z'IntegrationTestingMixin.integrationTestCs8���L�$�$�&���
�J�J�s�0�/�B��G�$���=�=���&��8�)C�d�)J�K��-4�-?�-?��-B�*��d�G�W�d������/�!�%��t�4�� �.�.�{�;��'���;�W���%�%�o�6�	�	�	�	�
�	�
'+��#�-1��*���W�5�C�C�D�I��'���6������/��������

��	
�
�
�����H�%��+�+�0�0�6�6�w�?������a��+�+�M�:�E�!�H�E���q�r��K��d��
�
�5�!�,�K�L�������)�8�4����H�%��#�#�-�-�3�3�
�	
�	
�
�
���'�'��1��������*�*�>�:�1�=�{�	
��Ls�I�$IN)r]r^r_rpr�r�r�r�r0r�r�r`r\rZr�r�&s3���J�E�R�;�/��L�L��X
r\r�c��eZdZdZd�Zy)�StubEndpointFactoryz=
    A stub L{IAgentEndpointFactory} for use in testing.
    c�H�|j|j|jfS)z�
        Testing implementation.

        @param uri: A L{URI}.

        @return: C{(scheme, host, port)} of passed in URI; violation of
            interface but useful for testing.
        @rtype: L{tuple}
        )rCrDrE�rY�uris  rZ�endpointForURIz"StubEndpointFactory.endpointForURI�s���
�
�C�H�H�c�h�h�/�/r\N)r]r^r_rpr�r`r\rZr�r��s���
0r\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�Zeed�d��Zd�Zeed�d��Zd�Zd�Zd�Z d�Z!d�Z"d �Z#y!)"�
AgentTestszA
    Tests for the new HTTP client API provided by L{Agent}.
    c�@�tj|j�S)zE
        @return: a new L{twisted.web.client.Agent} instance
        )r0r�rrgs rZr�zAgentTests.makeAgent�s���|�|�D�L�L�)�)r\c�X�|j�|_|j�|_y��C
        Create an L{Agent} wrapped around a fake reactor.
        N�r�rr�rrgs rZr�zAgentTests.setUp�s"���)�)�+����^�^�%��
r\c�.�tj|j�}|j|jt
�|j
|jjd�|j|j|jj�y)zV
        If no pool is passed in, the L{Agent} creates a non-persistent pool.
        FN)
r0r�rr�_poolr>r�rJrO�_reactor�rYrs  rZ�test_defaultPoolzAgentTests.test_defaultPool�sc�����T�\�\�*�����e�k�k�+=�>�������/�/��7����U�^�^�U�[�[�-A�-A�Br\c���t�j�}tj�j|��}�fd�|_|jdd��j
�jjddjd�y)z�
        If C{persistent} is set to C{True} on the L{HTTPConnectionPool} (the
        default), C{Request}s are created with their C{persistent} flag set to
        C{True}.
        �rc����Srtr`�r�rYs �rZr}z,AgentTests.test_persistent.<locals>.<lambda>�����4�r\r��http://127.0.0.1rTN�
r>rr0r�rrkr�r�rerJ�rYrrs`  rZ�test_persistentzAgentTests.test_persistent�sh���"�$�,�,�/�����T�\�\��5��/���
�
�
�f�1�2�������/�/��2�1�5�@�@�$�Gr\c���t�jd��}tj�j|��}�fd�|_|jdd��j
�jjddjd�y)	a�
        If C{persistent} is set to C{False} when creating the
        L{HTTPConnectionPool}, C{Request}s are created with their
        C{persistent} flag set to C{False}.

        Elsewhere in the tests for the underlying HTTP code we ensure that
        this will result in the disconnection of the HTTP protocol once the
        request is done, so that the connection will not be returned to the
        pool.
        F�rJr�c����Srtr`r�s �rZr}z/AgentTests.test_nonPersistent.<locals>.<lambda>�r�r\r�r�rNr�r�s`  rZ�test_nonPersistentzAgentTests.test_nonPersistent�sj���"�$�,�,�5�A�����T�\�\��5��/���
�
�
�f�1�2�������/�/��2�1�5�@�@�%�Hr\c����t��G��fd�dtj�}G��fd�d�}|�}|�j|��}�j	||j
�t
j�}|jdd�t�}|jdd	||�
��j|j
jd�y)
z�
        When a connection is made by the Agent, it uses its pool's
        C{getConnection} method to do so, with the endpoint returned by
        C{self._getEndpoint}. The key used is C{(scheme, host, port)}.
        c���eZdZ��fd�Zy)�:AgentTests.test_connectUsesConnectionPool.<locals>.MyAgentc�n���j|j|j|jfd��S)N�r��foor/)r�rCrDrE)�thisr�r�rYs  ��rZrzGAgentTests.test_connectUsesConnectionPool.<locals>.MyAgent._getEndpoint�s1���� � ��Z�Z����3�8�8�4�6K�� �r\N)r]r^r_r�r�rYs��rZ�MyAgentr��s���
 r\r�c�"��eZdZdZdZ��fd�Zy)�<AgentTests.test_connectUsesConnectionPool.<locals>.DummyPoolFc���d|_�j|���j|d�tjt	��S)NTr�)�	connectedr�rrrb�r�rU�epr�rYs   ��rZr&zJAgentTests.test_connectUsesConnectionPool.<locals>.DummyPool.getConnection�s@���!%���� � ��X�.�� � ��&;�<��}�}�%5�%7�8�8r\N�r]r^r_r�rJr&r�s��rZ�	DummyPoolr��s����I��J�
9r\r�r��hostr�r��http://foo/)�bodyProducerr�TN)
rr0r�rrOr�r2rC�addRawHeader�objectrkr�r�)rYr�r�rrr�r�r�s`      @rZ�test_connectUsesConnectionPoolz)AgentTests.test_connectUsesConnectionPool�s����!�?��	 �f�l�l�	 �
	9�
	9��{������4�0�����T�5�;�;�/��&�&�(�����W�f�-��x��
�
�
��N��w�	�	
�	
������.�.��5r\c�\�|jt|jjdd�y)zj
        L{Agent.request} raises L{TypeError} when the C{method} argument isn't
        L{bytes}.
        �GET�http://foo.example/N��assertRaises�	TypeErrorrrkrgs rZ�test_nonBytesMethodzAgentTests.test_nonBytesMethod�#��
	
���)�T�Z�Z�%7�%7��@V�Wr\c�b�|j|jjdd�t�S)z�
        L{Agent.request} returns a L{Deferred} which fails with
        L{SchemeNotSupported} if the scheme of the URI passed to it is not
        C{'http'}.
        r�smailto:alice@example.com)�
assertFailurerrkrBrgs rZ�test_unsupportedSchemez!AgentTests.test_unsupportedSchemes/���!�!��J�J���v�'B�C�EW�
�	
r\c�:�|jjdd�}|jjj	�dd\}}}|jdt
t���|jjd�|j|t�y)z�
        The L{Deferred} returned by L{Agent.request} fires with a L{Failure} if
        the TCP connection attempt fails.
        r�r�Nr��
)
rrkrr�r��clientConnectionFailedr*rr�r�)rYrlrDrEr�s     rZ�test_connectionFailedz AgentTests.test_connectionFailed#s|��
���#�#�F�N�;��"�l�l�5�5�9�9�;�B�Q�?���d�G��&�&�t�W�5K�5M�-N�O������R� ����V�%;�<r\c��d}d}|jjtjd||fz��}|j	|j
d�|j	|j|�|j|t�y)zo
        L{Agent._getEndpoint} return a C{HostnameEndpoint} when passed a scheme
        of C{'http'}.
        r.��shttp://%b:%dr�N)	rrr:�	fromBytesr��_hostStr�_portrr)rY�expectedHost�expectedPortr�s    rZ�test_connectHTTPzAgentTests.test_connectHTTP0su��
&�����:�:�*�*��M�M�/�\�<�,H�H�I�
��	
����*�*�M�:��������6����h�(8�9r\c�z�tjd�}dj�|_|j	t
�5}|jj|�ddd�|jjjddjt|j����y#1swY�VxYw)z|
        L{Agent._getEndpoint} when given a non-ASCII decodable URI will raise a
        L{ValueError} saying such.
        shttp://example.com:80u☃.comNrzaThe host of the provided URI ({reprout}) contains non-ASCII octets, it should be ASCII decodable.)�reprout)
r:r�encoderDr��
ValueErrorrrr��	exceptionr��formatr�)rYr��es   rZ�test_nonDecodableURIzAgentTests.test_nonDecodableURI>s���
�m�m�4�5���&�&�(���
�
�
�z�
*�	)�a��J�J�#�#�C�(�	)�	
���
�K�K���Q����f�T�#�(�(�^�f�,�
	
�	)�	)�s�B1�1B:c����fd��j_�jjdd��jjj�\}}�j
|jjd�dg�y)z�
        If L{None} is passed to L{Agent.request} for the C{headers} parameter,
        a L{Headers} instance is created for the request and a I{Host} header
        added to it.
        c����Srtr`r�s �rZr}z.AgentTests.test_hostProvided.<locals>.<lambda>X�����r\r��http://example.com/foo?barr�r.N�	rrrkr�rer�r�r�r��rY�req�ress`  rZ�test_hostProvidedzAgentTests.test_hostProvidedRsd���#5��
�
���
�
���6�#@�A��=�=�)�)�-�-�/���S�������2�2�7�;�n�=M�Nr\c����fd��j_�jjdd��jjj�\}}�j
|jjd�dg�y)z�
        If an IPv6 address is used in the C{uri} passed to L{Agent.request},
        the computed I{Host} header needs to be bracketed.
        c����Srtr`r�s �rZr}z3AgentTests.test_hostIPv6Bracketed.<locals>.<lambda>crr\r�s
http://[::1]/r�s[::1]Nrrs`  rZ�test_hostIPv6Bracketedz!AgentTests.test_hostIPv6Bracketed^sc���
#5��
�
���
�
���6�#3�4��=�=�)�)�-�-�/���S�������2�2�7�;�h�Z�Hr\c�B��tjdgdgd��}�fd��j_�jj	dd|��j
jj�\}}�j|jjd�dg�y)	z�
        If the headers passed to L{Agent.request} includes a value for the
        I{Host} header, that value takes precedence over the one which would
        otherwise be automatically provided.
        �barsquux�r�r�c����Srtr`r�s �rZr}z.AgentTests.test_hostOverride.<locals>.<lambda>prr\r�rr�N)r2rCrrrkr�rer�r�r�r�)rYr�rrs`   rZ�test_hostOverridezAgentTests.test_hostOverrideis~����&�&���G�9�'M�N��"4��
�
���
�
���6�#@�'�J��=�=�)�)�-�-�/���S�������2�2�7�;�g�Y�Gr\c�:��tj�}�fd��j_�jj	dd|��j
}�j
t|j�d��j
|tj��y)z�
        If a I{Host} header must be added to the request, the L{Headers}
        instance passed to L{Agent.request} is not modified.
        c����Srtr`r�s �rZr}z3AgentTests.test_headersUnmodified.<locals>.<lambda>|rr\r��http://example.com/foor�N)	r2rCrrrkr�r�r�re)rYr�r�s`  rZ�test_headersUnmodifiedz!AgentTests.test_headersUnmodifiedvsu���
�&�&�(��"4��
�
���
�
���6�#<�g�F��=�=��	
����X�.�.�/��3�����,�"6�"6�"8�9r\c�^�|j|jjddd�d�y)z�
        When passed a scheme of C{'http'} and a port of C{80},
        L{Agent._computeHostValue} returns a string giving just
        the host name passed to it.
        r�r.r/N�r�r�_computeHostValuergs rZ�test_hostValueStandardHTTPz%AgentTests.test_hostValueStandardHTTP�s*��	
����J�J�(�(��.�"�E�~�	
r\c�^�|j|jjddd�d�y)z�
        When passed a scheme of C{'http'} and a port other than C{80},
        L{Agent._computeHostValue} returns a string giving the
        host passed to it joined together with the port number by C{":"}.
        r�r.�1��example.com:54321Nr)rgs rZ�test_hostValueNonStandardHTTPz(AgentTests.test_hostValueNonStandardHTTP�s+��	
����J�J�(�(��.�%�H� �	
r\c�^�|j|jjddd�d�y)z�
        When passed a scheme of C{'https'} and a port of C{443},
        L{Agent._computeHostValue} returns a string giving just
        the host name passed to it.
        �httpsr.rHNr)rgs rZ�test_hostValueStandardHTTPSz&AgentTests.test_hostValueStandardHTTPS�s*��	
����J�J�(�(��>�3�G��	
r\c�^�|j|jjddd�d�y)z�
        When passed a scheme of C{'https'} and a port other than C{443},
        L{Agent._computeHostValue} returns a string giving the
        host passed to it joined together with the port number by C{":"}.
        r1r.r-r.Nr)rgs rZ�test_hostValueNonStandardHTTPSz)AgentTests.test_hostValueNonStandardHTTPS�s+��	
����J�J�(�(��>�5�I� �	
r\c����fd��j_tjddgi�}t	�}�jjdd||��j}�jt|j�d�|jj�\}}�j|t��j|jd��j|jd��j|jtjdgdgd	����j!|j"|�y
)a_
        L{Agent.request} establishes a new connection to the host indicated by
        the host part of the URI passed to it and issues a request using the
        method, the path portion of the URI, the headers, and the body producer
        passed to it.  It returns a L{Deferred} which fires with an
        L{IResponse} from the server.
        c����Srtr`r�s �rZr}z)AgentTests.test_request.<locals>.<lambda>�rr\r�r r��http://example.com:1234/foo?barr�s/foo?bar�example.com:1234r!N)rrr2rCr�rkr�r�r�rer�rr?�methodr�r�rOr�)rYr��bodyr�rrs`     rZ�test_requestzAgentTests.test_request�s���#5��
�
���&�&����'9�:���x���
�
���6�#E�w�PT�U��=�=��	
����X�.�.�/��3��$�$�(�(�*���S����c�7�+�������V�,�������+�.�����K�K�� � �6�(�>Q�=R�!S�T�	
�	
���S�-�-�t�4r\c���tj|jd��}|jdd�|jjj�d}|j
d|�y)z~
        L{Agent} takes a C{connectTimeout} argument which is forwarded to the
        following C{connectTCP} agent.
        r���connectTimeoutr�r�r�N�r0r�rrkr�r�r��rYrr�s   rZ�test_connectTimeoutzAgentTests.test_connectTimeout�sS��
���T�\�\�!�<��
�
�
�f�n�-��,�,�)�)�-�-�/��2������G�$r\�&SSL not present, cannot run SSL tests.c���tj|jd��}|jdd�|jjj�d}|j
d|�y)z}
        L{Agent} takes a C{connectTimeout} argument which is forwarded to the
        following C{connectTCP} call.
        r�r=r��https://foo/r�Nr?r@s   rZ�test_connectTimeoutHTTPSz#AgentTests.test_connectTimeoutHTTPS�sS�����T�\�\�!�<��
�
�
�f�o�.��,�,�)�)�-�-�/��2������G�$r\c���tj|jd��}|jdd�|jjj�d}|j
d|�y)zz
        L{Agent} takes a C{bindAddress} argument which is forwarded to the
        following C{connectTCP} call.
        �192.168.0.1��bindAddressr�r�r�Nr?�rYr�addresss   rZ�test_bindAddresszAgentTests.test_bindAddress�sS��
���T�\�\�}�E��
�
�
�f�n�-��,�,�)�)�-�-�/��2�������0r\c���tj|jd��}|jdd�|jjj�d}|j
d|�y)zz
        L{Agent} takes a C{bindAddress} argument which is forwarded to the
        following C{connectSSL} call.
        rGrHr�rDr�Nr?rJs   rZ�test_bindAddressSSLzAgentTests.test_bindAddressSSL�sS�����T�\�\�}�E��
�
�
�f�o�.��,�,�)�)�-�-�/��2�������0r\c��d}|j|j�}|jd|�}|jt	|j
j�d�|j
jj�\}}|j|t�tjjdddti�d|�}|j|�|j|�}|j|jj |jj"|jj$f|j |j"|j$f�y)z�
        L{Response}s returned by L{Agent.request} have a reference to the
        L{Request} that was originally issued.
        �http://example.com/r�r��sHTTPr�r����OKN)rrrkr�r�r�rer�rr?r0r7�
_constructrC�callbackr�r9�absoluteURIr�)rYr�rr)rr�respr�s        rZ�test_responseIncludesRequestz'AgentTests.test_responseIncludesRequest�s��
%���-�-�d�l�l�;���M�M�&�#�&��	
����T�]�]�3�3�4�a�8��=�=�)�)�-�-�/���S����c�7�+����)�)��S�%����d�C�
��	���T���'�'��*������ � �'�'�� � �,�,�� � �(�(�
�
�Z�Z����#�+�+�6�
	
r\c�r�d}|j|j�}|jd|�|jt	|j
j�d�|j
jj�\}}|j|t�|j|j|�y)zL
        L{Request.absoluteURI} is the absolute URI of the request.
        s$http://example.com/foo;1234?bar#fragr�r�N)rrrkr�r�r�rer�rr?rV)rYr�rrrs     rZ�test_requestAbsoluteURIz"AgentTests.test_requestAbsoluteURIs���6���-�-�d�l�l�;��
�
�
�f�c�"�	
����T�]�]�3�3�4�a�8��=�=�)�)�-�-�/���S����c�7�+�������#�.r\c�|�tjddt�d�}|j|jd�y)zX
        L{Request.absoluteURI} is L{None} if L{Request._parsedURI} is L{None}.
        �FOOr�N)r0r?rCrOrV)rYrks  rZ�test_requestMissingAbsoluteURIz)AgentTests.test_requestMissingAbsoluteURI#s0���.�.���w�y�$�?�����W�0�0�$�7r\c���t�}tjjd|��}t	j
d�}|j
|�}|j|d�y)z|
        L{Agent.usingEndpointFactory} creates an L{Agent} that uses the given
        factory to create endpoints.
        N)�endpointFactoryrP)r�r.r/)r�r0r��usingEndpointFactoryr:rrr�)rYr�rr��returnedEndpoints     rZ�test_endpointFactoryzAgentTests.test_endpointFactory*sW��
&�'�����1�1�$��1�P���m�m�2�3�� �-�-�c�2�����)�+H�Ir\c��tjj|jt	��}|j
}|j
|j|j|jftd|jf�y)z�
        If no pool is passed in to L{Agent.usingEndpointFactory}, a default
        pool is constructed with no persistent connections.
        FN)r0r�r`rr�r�r��	__class__rJr�r>)rYrrs   rZ�test_endpointFactoryDefaultPoolz*AgentTests.test_endpointFactoryDefaultPool5s]��
���1�1�$�,�,�@S�@U�V���{�{�����
�^�^�T�_�_�d�m�m�<�
�����7�	
r\c��t�}tjj|jt�|�}|j
||j�y)zr
        If a pool is passed in to L{Agent.usingEndpointFactory} it is used as
        the L{Agent} pool.
        N)r�r0r�r`rr��assertIsr�r�s   rZ�test_endpointFactoryPoolz#AgentTests.test_endpointFactoryPoolAsB��
�x�����1�1��L�L�-�/��
��	
�
�
�d�E�K�K�(r\N)$r]r^r_rpr�r�r�r�r�r�r�r�rr
rrrr#r'r+r/r2r4r;rAr
r�rErLrNrXrZr]rbrerhr`r\rZr�r��s����*�&�C�
H�I�"%6�NX�
�=�:�
�(
O�	I�H�:� 
�	
�
�	
�5�<%��
�N�D�E�%�F�%�1��
�N�D�E�1�F�1�
�:/�8�	J�

�	)r\r�c��eZdZdZd�Zy)�AgentMethodInjectionTestsz>
    Test L{client.Agent} against HTTP method injections.
    c��tj|j��}d}|j||t	�d�y)�v
        Attempt a request with the provided method.

        @param method: see L{MethodInjectionTestsMixin}
        �http://twisted.invalidN�r0r�r�rkrC)rYr9rr�s    rZ�!attemptRequestWithMaliciousMethodz;AgentMethodInjectionTests.attemptRequestWithMaliciousMethodVs4�����T�/�/�1�2��'��
�
�
�f�c�7�9�d�3r\N�r]r^r_rpror`r\rZrjrjM���
�4r\rjc��eZdZdZd�Zy)�AgentURIInjectionTestsz6
    Test L{client.Agent} against URI injections.
    c��tj|j��}d}|j||t	�d�y)zp
        Attempt a request with the provided method.

        @param uri: see L{URIInjectionTestsMixin}
        r�Nrn)rYr�rr9s    rZ�attemptRequestWithMaliciousURIz5AgentURIInjectionTests.attemptRequestWithMaliciousURIjs4�����T�/�/�1�2����
�
�
�f�c�7�9�d�3r\N�r]r^r_rprur`r\rZrsrsarqr\rsrBc�T��eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Z�fd
�Z�xZ
S)�AgentHTTPSTestsz@
    Tests for the new HTTP client API that depends on SSL.
    c��tj|j��jt	j
d||fz��S)a�
        Create an L{Agent} with an https scheme and return its endpoint
        created according to the arguments.

        @param host: The host for the endpoint.
        @type host: L{bytes}

        @param port: The port for the endpoint.
        @type port: L{int}

        @return: An endpoint of an L{Agent} constructed according to args.
        @rtype: L{SSL4ClientEndpoint}
        shttps://%b:%d/)r0r�r�rr:r)rYrDrEs   rZ�makeEndpointzAgentHTTPSTests.makeEndpoint{s?���|�|�D�.�.�0�1�>�>��M�M�+�t�T�l�:�;�
�	
r\c��ddlm}|j�}|j||�|j|jt
�y)zr
        L{Agent._getEndpoint} return a L{SSL4ClientEndpoint} when passed a
        scheme of C{'https'}.
        r)�_WrapperEndpointN)�twisted.internet.endpointsr|rzr�_wrappedEndpointr)rYr|r�s   rZ�test_endpointTypez!AgentHTTPSTests.test_endpointType�s>��
	@��$�$�&�����h�(8�9����h�7�7�9I�Jr\c�t�|jd��}|j|jjd�y)z@
        If a host is passed, the endpoint respects it.
        r.)rDr�N)rzr�r~r)rYr�s  rZ�test_hostArgumentIsRespectedz,AgentHTTPSTests.test_hostArgumentIsRespected�s3���$�$�.�$�9������2�2�;�;�]�Kr\c�x�d}|j|��}|j|jj|�y)z@
        If a port is passed, the endpoint respects it.
        ��)rEN)rzr�r~r)rYr	r�s   rZ�test_portArgumentIsRespectedz,AgentHTTPSTests.test_portArgumentIsRespected�s8�����$�$�,�$�7������2�2�8�8�,�Gr\c��|j�}|jd�j}|j|t�|j|jd�y)zY
        L{Agent} wraps its connection creator creator and uses modern TLS APIs.
        Nr�)rz�_wrapperFactory�_connectionCreatorrrMr��	_hostname)rYr��contextFactorys   rZ�test_contextFactoryTypez'AgentHTTPSTests.test_contextFactoryType�sO���$�$�&��!�1�1�$�7�J�J�����n�.>�?�����1�1�=�Ar\c���
��d}d}Gd�d�}g�
tt�G�
�fd�d���|��tt�G�fd�d��}|�}|j�}t	j
||�}|j
tjd	||fz��}|jtjt��|jd
d}	|	jd�}
|
jt!���
d
d
}|j#|t$�|j'�
d
dd||f�|j)�j*�|j)�j,�y)a�
        If a custom L{WebClientConnectionCreator}-like object is passed to
        L{Agent.__init__} it will be used to determine the SSL parameters for
        HTTPS requests.  When an HTTPS request is made, the hostname and port
        number of the request URL will be passed to the connection creator's
        C{creatorForNetloc} method.  The resulting context object will be used
        to establish the SSL connection.
        sexample.orgi�Oc� �eZdZdZdZd�Zd�Zy)�VAgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.JustEnoughConnectionFc��d|_y)zK
                The handshake started.  Record that fact.
                TN)�handshakeStartedrgs rZ�do_handshakezcAgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.JustEnoughConnection.do_handshake�s��)-��%r\c��d|_y)zL
                The connection started.  Record that fact.
                TN)�connectStatergs rZ�set_connect_statezhAgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.JustEnoughConnection.set_connect_state�s��%)��!r\N)r]r^r_r�r�r�r�r`r\rZ�JustEnoughConnectionr��s��$�� �L�
-�
)r\r�c� ��eZdZd�Z��fd�Zy)�SAgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.JustEnoughCreatorc� �||_||_yrt)�hostnamerE)rYr�rEs   rZrhz\AgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.JustEnoughCreator.__init__�s�� (��
� ��	r\c�X���j||j|jf��S)z�
                Implement L{IOpenSSLClientConnectionCreator}.

                @param tlsProtocol: The TLS protocol.
                @type tlsProtocol: L{TLSMemoryBIOProtocol}

                @return: C{expectedConnection}
                )rjr�rE)rY�tlsProtocol�contextArgs�expectedConnections  ��rZ�clientConnectionForTLSzjAgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.JustEnoughCreator.clientConnectionForTLS�s(����"�"�K�����	�	�#J�K�)�)r\N)r]r^r_rhr�)r�r�s��rZ�JustEnoughCreatorr��s
���
!�

*r\r�c���eZdZ�fd�Zy)�_AgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.StubBrowserLikePolicyForHTTPSc����||�S)am
                Emulate L{BrowserLikePolicyForHTTPS}.

                @param hostname: The hostname to verify.
                @type hostname: L{bytes}

                @param port: The port number.
                @type port: L{int}

                @return: a stub L{IOpenSSLClientConnectionCreator}
                @rtype: L{JustEnoughCreator}
                r`)rYr�rEr�s   �rZ�creatorForNetloczpAgentHTTPSTests.test_connectHTTPSCustomConnectionCreator.<locals>.StubBrowserLikePolicyForHTTPS.creatorForNetloc�s���)��4�8�8r\N�r]r^r_r�)r�s�rZ�StubBrowserLikePolicyForHTTPSr��s���

9r\r�s
https://%b:%d���r�Nrr�)rrrHr�r0r�rr:rr�rr�r r�r�rr&rrRr�r�r�r�)rYrr	r�r��expectedCreatorCreatorrrr��
tlsFactoryr�rPr�r�r�s            @@@rZ�(test_connectHTTPSCustomConnectionCreatorz8AgentHTTPSTests.test_connectHTTPSCustomConnectionCreator�sk���&����	)�	)� ��	�4�	5�	*�	*�
6�	*�"2�3��	�_�	%�	9�	9�
&�	9� "?�!@���$�$�&�����W�&<�=���%�%��M�M�*�l�L�-I�I�J�
��	����,�,�X�6�7��'�'��+�A�.�
� �.�.�t�4���"�"�?�#4�5��!�n�Q������c�#7�8�����Q����+�l�L�-I�J����*�;�;�<����*�7�7�8r\c���d�}|�|j|g�}|jt|�d�|\}|j|dt�|j|dd�y)aP
        Passing something that duck-types I{like} a L{web client context
        factory <twisted.web.client.WebClientContextFactory>} - something that
        does not provide L{IPolicyForHTTPS} - to L{Agent} emits a
        L{DeprecationWarning} even if you don't actually C{import
        WebClientContextFactory} to do it.
        c�R�tjtt��d�y)Nz does-not-provide-IPolicyForHTTPS)r0r�r"r%r`r\rZ�warnMez9AgentHTTPSTests.test_deprecatedDuckPolicy.<locals>.warnMes���L�L�-�.@�.B�C�2�
r\r��category�messagez�'does-not-provide-IPolicyForHTTPS' was passed as the HTTPS policy for an Agent, but it does not provide IPolicyForHTTPS.  Since Twisted 14.0, you must pass a provider of IPolicyForHTTPS.N)�
flushWarningsr�r��DeprecationWarning)rYr��warnings�warnings    rZ�test_deprecatedDuckPolicyz)AgentHTTPSTests.test_deprecatedDuckPolicysm��	�	���%�%�v�h�/������X���*��	�������,�.@�A�����I��
O�	
r\c��t�}t|��}|jdd�}|j|j�|jd�}|j
|j|j��y)z�
        L{BrowserLikePolicyForHTTPS.creatorForNetloc} returns an
        L{IOpenSSLClientConnectionCreator} provider which will add certificates
        from the given trust root.
        ��	trustRootsthingyr�N)	rTr;r�r�rWr�rgrX�get_context)rYr��policy�creator�
connections     rZ�test_alternateTrustRootz'AgentHTTPSTests.test_alternateTrustRootsg��+�,�	�*�Y�?���)�)�)�T�:�����	�(�(�)��3�3�D�9�
��
�
�i�'�'��)?�)?�)A�Br\c�����|jd�}t|jd��\���fd�}�fd�}t�	|�|||||d��y)zC
        Wrap L{AgentTestsMixin.integrationTest} with TLS.
        s[]�asciic�<��t�j�d||�Sr)rQ�options)�
serverFactoryrr�s  �rZ�tlsifyz/AgentHTTPSTests.integrationTest.<locals>.tlsify4s���&�v�~�~�'7��
�w�W�Wr\c���ddlm}ddlm}||�G�fd�d��}t	j
||���S)Nrr)rHc���eZdZ�fd�Zy)�AAgentHTTPSTests.integrationTest.<locals>.tlsagent.<locals>.Policyc�<��t|jd����S)Nr�r�)rO�decode)rYr�rE�	authoritys   �rZr�zRAgentHTTPSTests.integrationTest.<locals>.tlsagent.<locals>.Policy.creatorForNetloc>s���.� ����0�I��r\Nr�)r�s�rZ�Policyr�<s���r\r�)r�)�zope.interfacer�twisted.web.iwebrHr0r�)rrrHr�r�s    �rZ�tlsagentz1AgentHTTPSTests.integrationTest.<locals>.tlsagent7s:���2�8�
��
)�
�
�*�
��<�<����A�Ar\r1)r�r�rCN)�stripr-r��superr�)
rYr�r�r��certHostNamer�r�r�r�rds
       @@�rZr�zAgentHTTPSTests.integrationTest+sb��� �~�~�e�,��=�����(�
��	�6�	X�	B�
�G�#����$�$��

$�
r\)r.rH)r]r^r_rprzrr�r�r�r�r�r�r��
__classcell__)rds@rZrxrxusA����
�$	K�L�H�B�Q9�f
�6C�#
�#
r\rxc�z�eZdZdZd�Zd�Zeed�d��Zeed�d��Z	eed�d��Z
y	)
�WebClientContextFactoryTestszr
    Tests for the context factory wrapper for web clients
    L{twisted.web.client.WebClientContextFactory}.
    c�h�ddlm}|jtjg�|_||_y)zU
        Get WebClientContextFactory while quashing its deprecation warning.
        r)�WebClientContextFactoryN)�twisted.web.clientr�r�r�r��warned�webClientContextFactory)rYr�s  rZr�z"WebClientContextFactoryTests.setUpWs+��	?��(�(�*F�*L�*L�)M�N���'>��$r\c�2�|jt|j�d�|j\}|j|dt�|j|dt	|j
t
dddd�t��jdd	��y
)zx
        L{twisted.web.client.WebClientContextFactory} is deprecated.  Importing
        it displays a warning.
        r�r�r��Twisted�r)�replacement�;�:N)	r�r�r�r�r)r�rr;�replace)rYr�s  rZ�test_deprecatedz,WebClientContextFactoryTests.test_deprecated`s���
	
����T�[�[�)�1�-��K�K�	�������,�.@�A�����I��'��,�,��	�2�q�!�,�5�
��W�S�#�
�		
r\zSSL Present.c�d�|jt|j�jdd�y)zl
        If C{getContext} is called and SSL is not available, raise
        L{NotImplementedError}.
        r.rHN)r��NotImplementedErrorr��
getContextrgs rZ�test_missingSSLz,WebClientContextFactoryTests.test_missingSSLss-��	
�����(�(�*�5�5���		
r\rBc��|j�jdd�}|j|tjj
�y)zT
        If SSL is present, C{getContext} returns a L{OpenSSL.SSL.Context}.
        r�rHN)r�r�rrL�SSL�Context)rY�ctxs  rZ�test_returnsContextz0WebClientContextFactoryTests.test_returnsContext�s7��
�*�*�,�7�7�
�s�K�����c�3�7�7�?�?�3r\c��|j�}|jdd�}|j|jtj
�y)zd
        The L{CertificateOptions} has C{trustRoot} set to the default trust
        roots.
        r�rHN)r��_getCertificateOptionsrr�rL�OpenSSLDefaultPaths)rYr��certificateOptionss   rZ�-test_setsTrustRootOnContextToDefaultTrustRootzJWebClientContextFactoryTests.test_setsTrustRootOnContextToDefaultTrustRoot�sB���*�*�,�� �7�7�
�s�K�����0�:�:�C�<S�<S�Tr\N)r]r^r_rpr�r�r
r�r�r�r�r`r\rZr�r�Qsl���
?�
�&�J��'�

�(�

��
�N�D�E�4�F�4��
�N�D�E�U�F�Ur\r�c�^�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zy)�HTTPConnectionPoolRetryTestsz�
    L{client.HTTPConnectionPool}, by using
    L{client._RetryingHTTP11ClientProtocol}, supports retrying requests done
    against previously cached connections.
    c��tjd�}tjd|�}|j|j	dt�d��|j|j	dt�d��|j|j	dt�d��|j|j	dt�d��|j|j	dt�d��|j
|j	dt�d��|j
|j	dt�d��y)	zO
        Only GET, HEAD, OPTIONS, TRACE, DELETE methods cause a retry.
        Nr�sHEADsOPTIONSsTRACEsDELETE�POSTsMYMETHOD)r0r>�_RetryingHTTP11ClientProtocolr��_shouldRetryr5�assertFalse�rYrr�s   rZ�test_onlyRetryIdempotentMethodsz<HTTPConnectionPoolRetryTests.test_onlyRetryIdempotentMethods�s����(�(��.���9�9�$��E�
����
�/�/���8H�$�O�P����
�/�/���9I�4�P�Q����
�/�/�
�N�<L�d�S�T����
�/�/��.�:J�D�Q�R����
�/�/�	�>�;K�T�R�S�����0�0��.�:J�D�Q�R�����0�0��n�>N�PT�U�Vr\c��tjd�}tjd|�}|j|j	dt�d��|j|j	dt
g�d��|j|j	dtg�d��|j|j	dtg�d��|j|j	dt�d��y)z�
        Only L{RequestNotSent}, L{RequestTransmissionFailed} and
        L{ResponseNeverReceived} exceptions cause a retry.
        Nr�)r0r>r�r�r�r5r6r9r�r8rr�s   rZ�"test_onlyRetryIfNoResponseReceivedz?HTTPConnectionPoolRetryTests.test_onlyRetryIfNoResponseReceived�s���
�(�(��.���9�9�$��E�
����
�/�/���8H�$�O�P�����#�#�F�,E�b�,I�4�P�	
�	
����#�#�F�,A�"�,E�t�L�	
�	
����0�0����9K�T�R�S�����#�#�F�,B�,D�d�K�	
r\c���tjd�}tjd|�}tt	tj��g�}|j|jd|d��y)z�
        If a request failed due to the operation being cancelled,
        C{_shouldRetry} returns C{False} to indicate the request should not be
        retried.
        Nr�)	r0r>r�r9r*rrr�r�)rYrr�rs    rZ�!test_dontRetryIfFailedDueToCancelz>HTTPConnectionPoolRetryTests.test_dontRetryIfFailedDueToCancel�s^���(�(��.���9�9�$��E�
�)�7�5�3G�3G�3I�+J�*K�L�	�����0�0���D�I�Jr\c���tjd�}tjd|�}|j|j	dtt
t��g�d��y)z�
        If a request failed with L{ResponseNeverReceived} due to some
        arbitrary exception, C{_shouldRetry} returns C{True} to indicate the
        request should be retried.
        Nr�)r0r>r�r�r�r9r*�	Exceptionr�s   rZ�)test_retryIfFailedDueToNonCancelExceptionzFHTTPConnectionPoolRetryTests.test_retryIfFailedDueToNonCancelException�sW���(�(��.���9�9�$��E�
�����#�#��-�w�y�{�/C�.D�E�t�
�	
r\c����tjt��}t���j	t��|j
d��|jdt��}��fd�}|j|�S)z�
        If L{client.HTTPConnectionPool.getConnection} returns a previously
        cached connection, it will get wrapped in a
        L{client._RetryingHTTP11ClientProtocol}.
        �{c�~���j|tj��j|j��yrt)rr0r�rO�_clientProtocol�r�r�rYs ��rZr$zTHTTPConnectionPoolRetryTests.test_wrappedOnPersistentReturned.<locals>.gotConnection�s/����!�!�*�f�.R�.R�S�� � ��!;�!;�X�Fr\)
r0r>r!rbrr&r1r&rr'�rYrr)r$r�s`   @rZ� test_wrappedOnPersistentReturnedz=HTTPConnectionPoolRetryTests.test_wrappedOnPersistentReturned�so����(�(���1��$�%������ 1�2����C��*�
���s�M�O�4��	G��}�}�]�+�+r\c���tjd�}|jdt��}�fd�}|j	|�S)z|
        If L{client.HTTPConnectionPool.getConnection} returns a new
        connection, it will be returned as is.
        Nr�c�F���j|jt�yrt)rOrdr3)r�rYs �rZr$zPHTTPConnectionPoolRetryTests.test_notWrappedOnNewReturned.<locals>.gotConnection�s���
� � ��!5�!5�7K�Lr\)r0r>r&rr')rYrr)r$s`   rZ�test_notWrappedOnNewReturnedz9HTTPConnectionPoolRetryTests.test_notWrappedOnNewReturned�s@���
�(�(��.�����s�M�O�4��	M�
�}�}�]�+�+r\c������	�g�	�	fd�}t��tjddt��d��}|��	d}tj||�}���fd�}||_|j
|�}�jt�	�d��jt�	dj�d�|jddjt��|�	fS)	zP
        Fail a first request, possibly retrying depending on argument.
        c�d��t�}�j|�tj|�Srt)rbrjrr)r��	protocolss �rZr>z>HTTPConnectionPoolRetryTests.retryAttempt.<locals>.newProtocols(���'�)�H����X�&��=�=��*�*r\r\r�Tr�rc����j|d��j|���j|ttf��S)Nr\)r�rOrr5r9)�mr�bpr�rY�willWeRetrys   ���rZr�z?HTTPConnectionPoolRetryTests.retryAttempt.<locals>._shouldRetrys?������Q��'�� � ��\�2��!�!�!�n�6K�%L�M��r\r�)r�r0r?rCr�r�rkr�r�re�errbackr5)
rYrr>rkr��retrierr�r)r�rs
``      @@rZ�retryAttemptz)HTTPConnectionPoolRetryTests.retryAttempt�s�����	�	+�
�x���.�.���w�y�,�SW�X���
��Q�<���6�6�x��M��	� ,����O�O�G�$��	
����Y���+�����Y�q�\�2�2�3�Q�7�	���!��Q��'�'��(8�9��)�|�r\c���|jd�\}}|jt|�d�t�}|djddj|�|j
|j|�S)z�
        L{client._RetryingHTTP11ClientProtocol} retries when
        L{client._RetryingHTTP11ClientProtocol._shouldRetry} returns C{True}.
        Tr�r�r)rr�r�r�rerUr'rO)rYr)rr�s    rZ�"test_retryIfShouldRetryReturnsTruez?HTTPConnectionPoolRetryTests.test_retryIfShouldRetryReturnsTrue sl��
�(�(��.���9�����Y���+��8���!����a� ��#�,�,�X�6��}�}�T�1�1�8�<�<r\c��|jd�\}}|jt|�d�|j|t�S)z�
        L{client._RetryingHTTP11ClientProtocol} does not retry when
        L{client._RetryingHTTP11ClientProtocol._shouldRetry} returns C{False}.
        Fr�)rr�r�r�r5�rYr)rs   rZ�'test_dontRetryIfShouldRetryReturnsFalsezDHTTPConnectionPoolRetryTests.test_dontRetryIfShouldRetryReturnsFalse,s?��
�(�(��/���9�����Y���+��!�!�!�^�4�4r\c��tjd�}tjd|�}|j|j	dt�d��|j
|j	dt�t���y)a
        L{_RetryingHTTP11ClientProtocol} only retries queries that don't have
        a body.

        This is an implementation restriction; if the restriction is fixed,
        this test should be removed and PUT added to list of methods that
        support retries.
        Nr�)r0r>r�r�r�r5r�r�r�s   rZ�test_onlyRetryWithoutBodyz6HTTPConnectionPoolRetryTests.test_onlyRetryWithoutBody6sf���(�(��.���9�9�$��E�
����
�/�/���8H�$�O�P�����0�0���9I�6�8�T�Ur\c��|jd�\}}|jt|�d�|djddj	tg��|jt|�d�|j
|t
�S)z�
        If a L{client._RetryingHTTP11ClientProtocol} fails more than once on
        an idempotent query before a response is received, it will not retry.
        Tr�r�r)rr�r�rer
r9r�rs   rZ�test_onlyRetryOncez/HTTPConnectionPoolRetryTests.test_onlyRetryOnceDs|��
�(�(��.���9�����Y���+��!����a� ��#�+�+�,A�"�,E�F�����Y���+��!�!�!�%:�;�;r\c����tjt��}d|_t	���jt
��|jd��|jdt��}��fd�}|j|�S)z�
        If L{HTTPConnectionPool.retryAutomatically} is set to C{False}, don't
        wrap connections with retrying logic.
        Fr�c�*���j|��yrt)rOrs ��rZr$z[HTTPConnectionPoolRetryTests.test_dontRetryIfRetryAutomaticallyFalse.<locals>.gotConnectionas���� � ��X�6r\)r0r>r!rrbrr&r1r&rr'rs`   @rZ�'test_dontRetryIfRetryAutomaticallyFalsezDHTTPConnectionPoolRetryTests.test_dontRetryIfRetryAutomaticallyFalseQsv���
�(�(���1��"'���$�%������ 1�2����C��*�
���s�M�O�4��	7��}�}�]�+�+r\c�<������tjt��}d�t��g��fd�}||_t���j
t��|j���|j���}�����fd�}|j|�S)z�
        L{client.HTTPConnectionPool} creates
        {client._RetryingHTTP11ClientProtocol} with a new connection factory
        method that creates a new connection using the same key and endpoint
        as the wrapped connection.
        r�c�,���j||f�yrt)rj)�kr�newConnectionss  �rZrTzOHTTPConnectionPoolRetryTests.test_retryWithNewConnection.<locals>.newConnectionss����!�!�1�a�&�)r\c�X���j|tj��j|j���j�g�|j
��jt��d��j�dd���j�dd��y)Nr�r)rr0r�rOr�r�rVr�)r�r�rUrr�rYs �����rZr$zOHTTPConnectionPoolRetryTests.test_retryWithNewConnection.<locals>.gotConnection�s�����!�!�*�f�.R�.R�S�� � ��!;�!;�X�F�
���^�R�0��%�%�'����S��0�!�4����^�A�.�q�1�3�7�� � ���!2�1�!5�x�@r\)r0r>r!rrVrbrr&r1r&r')	rYrrTr)r$r�rUrr�s	`    @@@@rZ�test_retryWithNewConnectionz8HTTPConnectionPoolRetryTests.test_retryWithNewConnectionfs�����(�(���1���� �?����	*�,���$�%������ 1�2����C��*�
���s�H�-��		A�		A��}�}�]�+�+r\N)r]r^r_rpr�r�r�r�rrrrrrrrr!r`r\rZr�r��sL���W�"
�&	K�
�,�.
,�!�F
=�5�V�<�,�*&,r\r�c�(�eZdZdZ								dd�Zy)�CookieTestsMixinz4
    Mixin for unit tests dealing with cookies.
    c���tjtjdddtd|i�d��}tj|�}|j||�||fS)z/
        Add a cookie to a cookie jar.
        rQrRrS�
Set-CookieN)r0�_FakeStdlibResponser7rC�_FakeStdlibRequest�extract_cookies)rY�	cookieJarr��cookiesr�rks      rZ�
addCookieszCookieTestsMixin.addCookies�sf���-�-��O�O�������0�1��
�
���+�+�C�0���!�!�(�G�4��� � r\N)r)rr�rxr*zlist[bytes]rnz<tuple[client._FakeStdlibRequest, client._FakeStdlibResponse])r]r^r_rpr+r`r\rZr#r#�s,���!�"�!�).�!�9D�!�	E�!r\r#c�,�eZdZdZ		dd�Zdd�Zdd�Zy)�CookieJarTestsz�
    Tests for L{twisted.web.client._FakeStdlibResponse} and
    L{twisted.web.client._FakeStdlibRequest}'s interactions with L{CookieJar}
    instances.
    c�H�t�}|j|dddg�}||fS)zB
        @return: a L{CookieJar} with some sample cookies
        r7s(foo=1; cow=moo; Path=/foo; Comment=hellosbar=2; Comment=goodbye)rr+)rYr)�reqress   rZ�
makeCookieJarzCookieJarTests.makeCookieJar�s5���K�	�����.�
8�:S�T�
��
�&� � r\c�0�|j�d}|D�cic]}|j|��}}|d}|j|jd�|j|jd�|j|jd�|j|j
d�|j|jd�|j|jd�d�|d}|j|jd�|j|jd�|j|jd	�|j|j
d
�|j|jd�|j|jd�d�ycc}w)
z�
        L{CookieJar.extract_cookies} extracts cookie information from our
        stdlib-compatibility wrappers, L{client._FakeStdlibRequest} and
        L{client._FakeStdlibResponse}.
        rr��1z/foo�hello�cow�moo�bar�2�/�goodbyeN)	r0�namer��versionr`�path�comment�get_nonstandard_attrrO)rY�jar�cr*�cookies     rZ�test_extractCookiesz"CookieJarTests.test_extractCookies�sG��� � �"�1�%��&)�*��1�6�6�1�9�*��*������������+�������e�,�������s�+�������f�-��������1�����4�4�U�;�U�C������������+�������e�,�������s�+�������c�*��������3����V�8�8��?��F��!+s�Fc��|j�\}\}}|j|jdd�d�|j|�|j	t|jj��ddgfg�y)z�
        L{CookieJar.add_cookie_header} adds a cookie header to a Twisted
        request via our L{client._FakeStdlibRequest} wrapper.
        �CookieNsCookiesfoo=1; bar=2)r0rO�
get_header�add_cookie_headerr��list�_twistedHeaders�getAllRawHeaders)rYr?rkr�s    rZ�test_sendCookiezCookieJarTests.test_sendCookie�sz��
$(�#5�#5�#7� ��
 �g�x����W�/�/��$�?��F����g�&������(�(�9�9�;�<��/�*�
+�,�	
r\N)rnzNtuple[CookieJar, tuple[client._FakeStdlibRequest, client._FakeStdlibResponse]]rm)r]r^r_rpr0rBrJr`r\rZr-r-�s���!�	W�!�G�2

r\r-c�b�eZdZdZd�Zd�Zd�Zd
d�Zd�Ze	e
d�d��Zd	�Zd
�Z
d�Zy)�CookieAgentTestsz6
    Tests for L{twisted.web.client.CookieAgent}.
    c�p�tj|j|j�t	��S)zB
        @return: a new L{twisted.web.client.CookieAgent}
        )r0�CookieAgentrrrrgs rZr�zCookieAgentTests.makeAgent�s-���!�!��)�)�$�,�,�7���
�	
r\c�.�|j�|_yrt)r�rrgs rZr�zCookieAgentTests.setUp�s���)�)�+��r\c	����t���jt��g��j�j�}tj|��}|jdd�}��fd�}|j|��jjj�\}}�j|jjd�d�tjdddt!d	d
gi�d�}|j#|�|S)a

        L{CookieAgent.request} does not insert any C{'Cookie'} header into the
        L{Request} object if there is no cookie in the cookie jar for the URI
        being requested. Cookies are extracted from the response and stored in
        the cookie jar.
        r�r7c����t��}�jt|�d��j|djd��j|djd�y)Nr�rr�r2)rGr�r�r:r`)�ignoredr*r)rYs  ��rZ�_checkCookiezACookieAgentTests.test_emptyCookieJarRequest.<locals>._checkCookiesR����9�o�G����S��\�1�-����W�Q�Z�_�_�e�4����W�Q�Z�-�-�s�3r\�cookieNrQrRrSr%�foo=1)rr�rGrrr0rNrkr'r�rer�rOr�r�r7rCrU)	rYr�cookieAgentr)rSrrrWr)s	`       @rZ�test_emptyCookieJarRequestz+CookieAgentTests.test_emptyCookieJarRequest�s�����K�	�����i��"�-��-�-�d�l�l�;���(�(��	�:������(J�K��	4�	
�
�
�l�#��=�=�)�)�-�-�/���S����S�[�[�6�6�y�A�4�H��������!� �$��
�
�
��	���T���r\c���d}d}t�}|j|||g�|jtt	|��d�|j|j�}tj||�}|jd|tddgi��|jjj�\}}|j|jjd�dg�y	)
z�
        L{CookieAgent.request} will not insert a C{'Cookie'} header into the
        L{Request} object when there is already a C{'Cookie'} header in the
        request headers parameter.
        r7rUr�r�rAzalready-setrTsalready-setN)rr+r�r�rGrrr0rNrkrCr�rer�r�r��rYr�rAr)rrVrrs        rZ�test_leaveExistingCookieHeaderz/CookieAgentTests.test_leaveExistingCookieHeader"s���1�����K�	����	�3���1�����T�)�_�-�q�1��-�-�d�l�l�;���(�(��	�:�����F�C��(�]�O�1L�)M�N��=�=�)�)�-�-�/���S�������2�2�9�=��?O�Pr\c��d}d}t�}|j|||g�|jtt	|��d�|j|j�}tj||�}|jd|�|jjj�\}}|j|jjd�|g�y)z�
        L{CookieAgent.request} inserts a C{'Cookie'} header into the L{Request}
        object when there is a cookie matching the request URI in the cookie
        jar.
        r7rUr�r�rTN�rr+r�r�rGrrr0rNrkr�rer�r�r�rYs        rZ�test_requestWithCookiez'CookieAgentTests.test_requestWithCookie6s���1�����K�	����	�3���1�����T�)�_�-�q�1��-�-�d�l�l�;���(�(��	�:�����F�C�(��=�=�)�)�-�-�/���S�������2�2�9�=��x�Hr\rBc��d}d}t�}|j|||g�|jtt	|��d�|j|j�}tj||�}|jd|�|jjj�\}}|j|jjd�dg�y)z~
        L{CookieAgent} is able to handle secure cookies, ie cookies which
        should only be handled over https.
        s https://example.com:1234/foo?bar�foo=1;securer�r�rTrUNr\rYs        rZ�test_secureCookiez"CookieAgentTests.test_secureCookieJs���2�� ���K�	����	�3���1�����T�)�_�-�q�1��-�-�d�l�l�;���(�(��	�:�����F�C�(��=�=�)�)�-�-�/���S�������2�2�9�=��z�Jr\c��d}d}t�}|j|||g�|jtt	|��d�|j|j�}tj||�}|jd|�|jjj�\}}|jd|jjd��y)zs
        If a cookie is setup as secure, it won't be sent with the request if
        it's not over HTTPS.
        rr_r�r�NrT)rr+r�r�rGrrr0rNrkr�rer�rOr�r�rYs        rZ�%test_secureCookieOnInsecureConnectionz6CookieAgentTests.test_secureCookieOnInsecureConnection^s���
,�� ���K�	����	�3���1�����T�)�_�-�q�1��-�-�d�l�l�;���(�(��	�:�����F�C�(��=�=�)�)�-�-�/���S����T�3�;�;�#<�#<�Y�#G�Hr\c��d}d}t�}|j|||g�|jtt	|��d�|j|j�}tj||�}|jd|�|jjj�\}}|j|jjd�dg�y)zz
        L{CookieAgent} supports cookies which enforces the port number they
        need to be transferred upon.
        r7�foo=1;port=1234r�r�rTrUNr\rYs        rZ�test_portCookiez CookieAgentTests.test_portCookieqs���
1��#���K�	����	�3���1�����T�)�_�-�q�1��-�-�d�l�l�;���(�(��	�:�����F�C�(��=�=�)�)�-�-�/���S�������2�2�9�=��z�Jr\c��d}d}t�}|j|||g�|jtt	|��d�y)z�
        When creating a cookie with a port directive, it won't be added to the
        L{cookie.CookieJar} if the URI is on a different port.
        shttp://example.com:4567/foo?barrdrN)rr+r�r�rG)rYr�rAr)s    rZ�test_portCookieOnWrongPortz+CookieAgentTests.test_portCookieOnWrongPort�s@��
1��#���K�	����	�3���1�����T�)�_�-�q�1r\Nrm)r]r^r_rpr�r�rWrZr]r
r�r`rbrergr`r\rZrLrL�sU���
�,�(�TQ�(I�(�
�N�D�E�K�F�K�&I�&K�&
2r\rLc��eZdZdZy)�Decoder1�K
    A test decoder to be used by L{client.ContentDecoderAgent} tests.
    N�r]r^r_rpr`r\rZriri����r\ric��eZdZdZy)�Decoder2rjNrkr`r\rZrnrn�rlr\rnc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�ContentDecoderAgentTestsz2
    Tests for L{client.ContentDecoderAgent}.
    c�B�tj|jg�S)zJ
        @return: a new L{twisted.web.client.ContentDecoderAgent}
        )r0�ContentDecoderAgentrrgs rZr�z"ContentDecoderAgentTests.makeAgent�s���)�)�$�*�*�b�9�9r\c�n�|j�|_|j|j�|_yr�)r�rrrrgs rZr�zContentDecoderAgentTests.setUp�s*���)�)�+����2�2�4�<�<�@��
r\c�x�tj|jdtfdtfg�}|jdd�|j}|jt|j�d�|jj�\}}|j|jjd�dg�y)	z�
        L{client.ContentDecoderAgent} sets the I{Accept-Encoding} header to the
        names of the available decoder objects.
        �decoder1�decoder2r�r&r��accept-encoding�decoder1,decoder2N)
r0rrrrirnrkr�r�r�rer�r�r�)rYrr�rrs     rZ�test_acceptHeadersz+ContentDecoderAgentTests.test_acceptHeaders�s���
�*�*��J�J�+�x�0�;��2I�J�
��	�
�
�f�7�8��=�=������X�.�.�/��3��$�$�(�(�*���S�����K�K�%�%�&8�9�<P�;Q�	
r\c���tjdgdgd��}tj|jdt
fdtfg�}|jdd|��|j}|jt|j�d	�|jj�\}}|jtt|jj!���d
ddgfddgfd
dgfg�y)z�
        If there are existing I{Accept-Encoding} fields,
        L{client.ContentDecoderAgent} creates a new field for the decoders it
        knows about.
        r �fizz)r�rwrurvr�r&�r�r�sAccept-Encodingrx�Foor�r.N)r2rCr0rrrrirnrkr�r�r�rer�rG�sortedr�rI)rYr�rr�rrs      rZ�test_existingHeadersz-ContentDecoderAgentTests.test_existingHeaders�s����&�&��X�G�9�=�
���*�*��J�J�+�x�0�;��2I�J�
��	�
�
�f�7��
�I��=�=������X�.�.�/��3��$�$�(�(�*���S���������4�4�6�7�8�#�g�/C�%D�E��&��"��>�*�+�
�	
r\c�l�tj|jdtfdtfg�}|jdd�}|jjj�\}}tdddtj�d�}|j|�|j|j|�S)	z�
        If the response is not encoded despited the request I{Accept-Encoding}
        headers, L{client.ContentDecoderAgent} simply forwards the response.
        rurvr�r&rQrRrSN)r0rrrrirnrkr�rer�r7r2rCrUr'rO)rYrr�rrr�s      rZ�test_plainEncodingResponsez3ContentDecoderAgentTests.test_plainEncodingResponse�s���
�*�*��J�J�+�x�0�;��2I�J�
���=�=��)B�C���=�=�)�)�-�-�/���S��O�S�%��9M�9M�9O�QU�V�����X���#�#�D�$8�$8�(�C�Cr\c�|�tj|jdtfdtfg�}|jdd�}|jjj�\}}tjdgdgd��}tdd	d
|d�}|j|�|j|j|�S)zz
        If an encoding unknown to the L{client.ContentDecoderAgent} is found,
        the response is unchanged.
        rurvr�r&r r{�r��content-encodingrQrRrSN)r0rrrrirnrkr�rer�r2rCr7rUr'rO)rYrr�rrr�r�s       rZ�test_unsupportedEncodingz1ContentDecoderAgentTests.test_unsupportedEncoding�s���
�*�*��J�J�+�x�0�;��2I�J�
���=�=��)B�C���=�=�)�)�-�-�/���S��&�&��X�W�I�>�
���O�S�%��$�G�����X���#�#�D�$8�$8�(�C�Cr\c�v���tj�jdtfdtfg�}|jdd�}�jjj�\}}tjdgdgd��}tdd	d
|d��|j����fd�}|j|�S)
z�
        When L{client.ContentDecoderAgent} encounters a decoder it doesn't know
        about, it stops decoding even if another encoding is known afterwards.
        rurvr�r&r sdecoder1,fizz,decoder2r�rQrRrSNc����j�|��j|t��jdg|jjd��y)Ns
decoder1,fizzr�)rSrrnr�r�r�)rlr�rYs ��rZ�checkz<ContentDecoderAgentTests.test_unknownEncoding.<locals>.check	sI����#�#�H�f�5��!�!�&�(�3����!�"�F�N�N�$@�$@�AT�$U�
r\)r0rrrrirnrkr�rer�r2rCr7rUr')rYrr�rrr�r�r�s`      @rZ�test_unknownEncodingz-ContentDecoderAgentTests.test_unknownEncoding	s����
�*�*��J�J�+�x�0�;��2I�J�
���=�=��)B�C���=�=�)�)�-�-�/���S��&�&��X�5N�4O�P�
���O�S�%��$�G�����X��	��#�#�E�*�*r\N)r]r^r_rpr�r�ryrr�r�r�r`r\rZrprp�s-���:�A�
�&
�6D�"D�(+r\rpc�(�eZdZdZd�Zd�Zd�Zd�Zy)�SimpleAgentProtocola

    A L{Protocol} to be used with an L{client.Agent} to receive data.

    @ivar finished: L{Deferred} firing when C{connectionLost} is called.

    @ivar made: L{Deferred} firing when C{connectionMade} is called.

    @ivar received: C{list} of received data.
    c�N�t�|_t�|_g|_yrt)r�made�finished�receivedrgs rZrhzSimpleAgentProtocol.__init__)	s���J��	� �
��
���
r\c�:�|jjd�yrt)r�rUrgs rZ�connectionMadez"SimpleAgentProtocol.connectionMade.	s���	�	���4� r\c�:�|jjd�yrt)r�rU)rY�reasons  rZrvz"SimpleAgentProtocol.connectionLost1	s���
�
���t�$r\c�:�|jj|�yrt)r�rj�rYr�s  rZ�dataReceivedz SimpleAgentProtocol.dataReceived4	s���
�
���T�"r\N)r]r^r_rprhr�rvr�r`r\rZr�r�	s����
!�%�#r\r�c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)� ContentDecoderAgentWithGzipTestsc��|j�|_|j|j�}tj|dtj
fg�|_y)r��gzipN)r�rrr0rr�GzipDecoderrr�s  rZr�z&ContentDecoderAgentWithGzipTests.setUp9	sJ���)�)�+����-�-�d�l�l�;���/�/���&�BT�BT�8U�7V�W��
r\c�,���	��jjdd�}�jjj	�\}}tjdgdgd��}t�}tddd||��	d	�	_	|j�	�tjd
tjdtjz�}|jd�|jd
�z|j!�z���	�fd�}|j#|�|S)z�
        If the response has a C{gzip} I{Content-Encoding} header,
        L{GzipDecoder} wraps the response to return uncompressed data to the
        user.
        r�r&r r�r�rQrRrS�r��sxxxxxxsyyyyc�����j|���j|jd��j|jd��j|jd��jt|jj��ddgfg��j|jt��jtt|d��j�dd��j�dd��j�t�}|j!|��j|j"dg�t%j&|j(|j*g�S)	NrQrRrSr}r �unknownr�s
xxxxxxyyyy)rSr�r;�code�phraserGr�rIr�rDr��AttributeError�getattr�_bodyDataReceived�_bodyDataFinishedr��deliverBodyr�r�
gatherResultsr�r�)rlr�r�r�rYs  ���rZ�
checkResponsezQContentDecoderAgentWithGzipTests.test_gzipEncodingResponse.<locals>.checkResponseZ	s,����#�#�F�H�5����V�^�^�_�=����V�[�[�#�.����V�]�]�E�2�����V�^�^�4�4�6�7�6�F�8�:L�9M�
�
���V�]�]�N�;����n�g�v�y�I��&�&�t�B�Q�x�0��&�&�t�A�B�x�0��&�&�(�*�,�H����x�(����X�.�.�1D�0E�F��&�&��
�
�x�7H�7H�'I�J�Jr\)rrkr�rer�r2rCr&r7r�rU�zlib�compressobj�DEFLATED�	MAX_WBITS�compressr�r')
rYr�rrr�r2�
compressorr�r�r�s
`       @@rZ�test_gzipEncodingResponsez:ContentDecoderAgentWithGzipTests.test_gzipEncodingResponseA	s�����:�:�%�%�f�.G�H���=�=�)�)�-�-�/���S��&�&��X�W�I�>�
��$�%�	��O�S�%��)�L��������X���%�%�a�����T�^�^�8K�L�
�����)��!�!�(�+�
,���� �
!�	
�	K�*	���]�+��r\c�����	��jjdd�}�jjj	�\}}tjdgdgd��}t�}tddd||��	d	�	_	|j�	�d
���	fd�}|j|��j|tj��fd�}|j|�S)
z�
        If the data received by the L{GzipDecoder} isn't valid gzip-compressed
        data, the call to C{deliverBody} fails with a C{zlib.error}.
        r�r&r r�r�rQrRrSr�snot gzipped contentc�Z���j��|jt��yrt)r�r�r )rlr�r�s ��rZr�zJContentDecoderAgentWithGzipTests.test_brokenContent.<locals>.checkResponse�	s!����&�&�t�,����x�z�*r\c���|jdjtj��j	|j
t�y)Nr��reasonsr�r�r1rr�r7�r1rYs �rZ�checkFailurezIContentDecoderAgentWithGzipTests.test_brokenContent.<locals>.checkFailure�	�2����M�M�!��!�!�$�*�*�-��!�!�%�.�.�(�;r\)rrkr�rer�r2rCr&r7r�rUr'r�r0r8)
rYr�rrr�r2r�r�r�r�s
`       @@rZ�test_brokenContentz3ContentDecoderAgentWithGzipTests.test_brokenContents	s����
�:�:�%�%�f�.G�H���=�=�)�)�-�-�/���S��&�&��X�W�I�>�
��$�%�	��O�S�%��)�L��������X��%��	+�
	���]�+����8�V�%:�%:�;�	<��#�#�L�1�1r\c����	�Gd�d�}tj}|t_�jttd|��jjdd�}�jjj�\}}tjddgi�}t�}tddd	||��	|j�	��	�fd
�}|j|�|S)z�
        When the connection with the server is lost, the gzip protocol calls
        C{flush} on the zlib decompressor object to get uncompressed data which
        may have been buffered.
        c��eZdZd�Zd�Zd�Zy)�FContentDecoderAgentWithGzipTests.test_flushData.<locals>.decompressobjc��yrtr`�rY�wbitss  rZrhzOContentDecoderAgentWithGzipTests.test_flushData.<locals>.decompressobj.__init__�	r�r\c��y�N�xr`r�s  rZ�
decompresszQContentDecoderAgentWithGzipTests.test_flushData.<locals>.decompressobj.decompress�	���r\c��y)N�yr`rgs rZr�zLContentDecoderAgentWithGzipTests.test_flushData.<locals>.decompressobj.flush�	r�r\N�r]r^r_rhr�r�r`r\rZ�
decompressobjr��	s��
�
�
r\r�r�r&r�r�rQrRrSc����jd��j�t�}|j|��j	|j
ddg�t
j|j|jg�S�Nsdatar�r��
r�r�r�r�r�r�rr�r�r��rlr�r�rYs  ��rZr�zFContentDecoderAgentWithGzipTests.test_flushData.<locals>.checkResponse�	�m����&�&�w�/��&�&�(�*�,�H����x�(����X�.�.��t��=��&�&��
�
�x�7H�7H�'I�J�Jr\)r�r��
addCleanup�setattrrrkr�rer�r2rCr&r7rUr')
rYr��oldDecompressObjr�rrr�r2r�r�s
`        @rZ�test_flushDataz/ContentDecoderAgentWithGzipTests.test_flushData�	s����	�	� �-�-��*���������8H�I��:�:�%�%�f�.G�H���=�=�)�)�-�-�/���S��&�&�(;�g�Y�'G�H��#�%�	��O�S�%��)�L�����X��	K�	���]�+��r\c�,��
�Gd�d�}tj}|t_�jttd|��jjdd�}�jjj�\}}tjddgi�}t�}tddd	||��
|j�
��
�fd
�}|j|��j|t j"��fd�}	|j|	�S)z�
        If the C{flush} call in C{connectionLost} fails, the C{zlib.error}
        exception is caught and turned into a L{ResponseFailed}.
        c��eZdZd�Zd�Zd�Zy)�GContentDecoderAgentWithGzipTests.test_flushError.<locals>.decompressobjc��yrtr`r�s  rZrhzPContentDecoderAgentWithGzipTests.test_flushError.<locals>.decompressobj.__init__�	r�r\c��yr�r`r�s  rZr�zRContentDecoderAgentWithGzipTests.test_flushError.<locals>.decompressobj.decompress�	r�r\c�*�tj��rt)r�r1rgs rZr�zMContentDecoderAgentWithGzipTests.test_flushError.<locals>.decompressobj.flush�	s���j�j�l�"r\Nr�r`r\rZr�r��	s��
�
�
#r\r�r�r&r�r�rQrRrSc����jd��j�t�}|j|��j	|j
ddg�t
j|j|jg�Sr�r�r�s  ��rZr�zGContentDecoderAgentWithGzipTests.test_flushError.<locals>.checkResponse�	r�r\c���|jdjtj��j	|j
t�y)Nr�r�r�s �rZr�zFContentDecoderAgentWithGzipTests.test_flushError.<locals>.checkFailure�	r�r\)r�r�r�r�rrkr�rer�r2rCr&r7rUr'r�r0r8)rYr�r�r�rrr�r2r�r�r�s`         @rZ�test_flushErrorz0ContentDecoderAgentWithGzipTests.test_flushError�	s����	#�	#� �-�-��*���������8H�I��:�:�%�%�f�.G�H���=�=�)�)�-�-�/���S��&�&�(;�g�Y�'G�H��#�%�	��O�S�%��)�L�����X��	K�	���]�+����8�V�%:�%:�;�	<��#�#�L�1�1r\N)r]r^r_r�r�r�r�r�r`r\rZr�r�8	s��X�0�d2�B*�X/2r\r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�ProxyAgentTestsz)
    Tests for L{client.ProxyAgent}.
    c�l�tjt|jdd�|j�S)zA
        @return: a new L{twisted.web.client.ProxyAgent}
        z	127.0.0.1r)r0�
ProxyAgentrrrgs rZr�zProxyAgentTests.makeAgent�	s-��� � ��t�|�|�[�$�?����
�	
r\c��|j�|_tjt	|jdd�|j�|_|j
j}|j||�|j
_y)Nr6�.)r�rr0r�rr�_proxyEndpointr�)rY�oldEndpoints  rZr�zProxyAgentTests.setUp�	sd���)�)�+����&�&��t�|�|�U�D�9�4�<�<�
��
��j�j�/�/��$(�$5�$5�k�4�$H��
�
�!r\c�\�|jt|jjdd�y)zo
        L{ProxyAgent.request} raises L{TypeError} when the C{method} argument
        isn't L{bytes}.
        r�r�Nr�rgs rZr�z#ProxyAgentTests.test_nonBytesMethod
r�r\c�N�tjddgi�}t�}|jj	dd||�|j
jj�dd\}}}|j|d�|j|d�|j|jtj�|j}|jt|j�d	�|jj�\}}|j|t �|j|j"d�|j|j$d�|j|j&tjdgd
gd���|j)|j*|�y)z�
        L{client.ProxyAgent} issues an HTTP request against the proxy, with the
        full URI as path, when C{request} is called.
        r�r r�r7Nr�r6r�r�r8r!)r2rCr�rrkrr�r�r�r�_wrappedFactoryr0rAr�r�rer?r9r�r�rOr�)	rYr�r:rDrEr�r�rrs	         rZ�test_proxyRequestz!ProxyAgentTests.test_proxyRequest
s]��
�&�&����'9�:���x���
�
���6�#E�w�PT�U�"�l�l�5�5�9�9�;�B�Q�?���d�G�����u�%�����t�$����g�5�5�v�7R�7R�S��=�=��	
����X�.�.�/��3��$�$�(�(�*���S����c�7�+�������V�,�������"D�E�����K�K�� � �6�(�>Q�=R�!S�T�	
�	
���S�-�-�t�4r\c�d�|j|jjjd�y)zJ
        C{ProxyAgent} connections are not persistent by default.
        FN)r�rr�rJrgs rZr�z"ProxyAgentTests.test_nonPersistent-
s$��	
������)�)�4�4�e�<r\c�0���t��G��fd�d�}|�}tj��j|��}�j	||j
�|j
dd��j|j
jd�y)z�
        When a connection is made by the C{ProxyAgent}, it uses its pool's
        C{getConnection} method to do so, with the endpoint it was constructed
        with and a key of C{("http-proxy", endpoint)}.
        c�"��eZdZdZdZ��fd�Zy)�AProxyAgentTests.test_connectUsesConnectionPool.<locals>.DummyPoolFc���d|_�j|���j|d�f�tjt��S)NTz
http-proxy)r�rOr�rrrbr�s   ��rZr&zOProxyAgentTests.test_connectUsesConnectionPool.<locals>.DummyPool.getConnection?
sD���!%����$�$�R��2�� � ��|�X�&>�?��}�}�%5�%7�8�8r\Nr�r�s��rZr�r�;
s����I��J�
9r\r�r�r�r�TN)	rr0r�rrOr�rkr�r�)rYr�rrr�s`   @rZr�z.ProxyAgentTests.test_connectUsesConnectionPool3
ss���!�?��	9�	9��{���!�!�(�D�L�L�t�D�����T�5�;�;�/�
�
�
�f�n�-�������.�.��5r\N)
r]r^r_rpr�r�r�r�r�r�r`r\rZr�r��	s'���
�I�X�5�>=�6r\r�)�
authorizationrT�cookie2�proxy-authorizationswww-authenticatec���eZdZUdZded<ded<ded<d�Z				d											d d
�Zd�Zd�Zd
�Z	d�Z
d�Z	d!					d"d�Zd#d�Z
d#d�Zd#d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy	)$�_RedirectAgentTestsMixinz^
    Test cases mixin for L{RedirectAgentTests} and
    L{BrowserLikeRedirectAgentTests}.
    rErr%rrbr�c���|jjdd�}|jjj	�\}}tj�}tddd|d�}|j|�|jdt|jj��|j|�}|j||�|j|jd�y)zz
        L{client.RedirectAgent} behaves like L{client.Agent} if the response
        doesn't contain a redirect.
        r�r&rQrRrSNr)rrkr�rer�r2rCr7rUr�r�r�rO�previousResponse)rYr�rrr�r�rls       rZ�test_noRedirectz(_RedirectAgentTestsMixin.test_noRedirectc
s���
�:�:�%�%�f�.G�H���=�=�)�)�-�-�/���S��&�&�(���O�S�%��$�G�����X������C��
�
� 6� 6�7�8��%�%�h�/�����X�v�.����V�4�4�d�;r\Nc���d}t�dnd}|dk(rdnd}|jjd|dz|zd	z|�
�|jjj�dd\}	}
|j
t|	�|j
||
�|jjj�\}}|}
|}|}|r#t�td��|dk(rdnd}
|dk(rdnd}d
}|rd}d}|rdn|}|
dz|z|zdz}tjd|gi�}td|d|d�}|j|�|jjj�\}}|j
d|j�|j
d|j �|jjj�dd\}	}
|j
|rt"nt|	�|j
||
�|S)z�
        When getting a redirect, L{client.RedirectAgent} follows the URL
        specified in the L{Location} header field and make a new request.

        @param code: HTTP status code.
        r.Nr1r�r/rHr�r�s/foor|r�z;Cross-scheme redirects can't be tested without TLS support.r\i� s:8443�example.net�/bar�locationrQrS)rLrrkrr�r�r�r�r�rerr2rCr7rUr9r�r�)rYr��crossScheme�crossDomain�	crossPort�requestHeaders�startDomain�startScheme�	startPortrDrErr�targetScheme�targetDomain�
targetPort�
portSyntax�
locationValuer�r��req2�res2s                      rZ�_testRedirectDefaultz-_RedirectAgentTestsMixin._testRedirectDefaultu
s���%��"%�/�h�w��%��0�B�c�	��
�
����K�&�(�;�6��@�.�	�	
��\�\�,�,�0�0�2�2�A�6�
��d������.�����D�)��=�=�)�)�-�-�/���S�#��"���
���{��Q���(3�g�'=�8�7�L� )�R���R�J��
���J�!�J�)4�~�+��$�v�-��<�z�I�G�S�
��&�&��m�_�'E�F���O�T�5�'�4�H�����X���]�]�+�+�/�/�1�
��d��������-�����$�(�(�+��\�\�,�,�0�0�2�2�A�6�
��d����;��N�D�Q�����T�*��r\c�&�|jd�y)zO
        L{client.RedirectAgent} follows redirects on status code 301.
        �-N�rrgs rZ�test_redirect301z)_RedirectAgentTestsMixin.test_redirect301�
���	
�!�!�#�&r\c�*�|jdd��y)zI
        L{client.RedirectAgent} follows cross-scheme redirects.
        rT�r�Nr	rgs rZ�test_redirect301Schemez/_RedirectAgentTestsMixin.test_redirect301Scheme�
s��	
�!�!���	"�	
r\c�&�|jd�y)zO
        L{client.RedirectAgent} follows redirects on status code 302.
        �.Nr	rgs rZ�test_redirect302z)_RedirectAgentTestsMixin.test_redirect302�
rr\c�&�|jd�y)zO
        L{client.RedirectAgent} follows redirects on status code 307.
        �3Nr	rgs rZ�test_redirect307z)_RedirectAgentTestsMixin.test_redirect307�
rr\c�&�|jd�y)zO
        L{client.RedirectAgent} follows redirects on status code 308.
        i4Nr	rgs rZ�test_redirect308z)_RedirectAgentTestsMixin.test_redirect308�
rr\c	��dgdgdgdgdgdgd�}dd	gi}ti|�|��}|jd
|��}dd�}||j�}|j|d
dgi||���|j	di|�dti|�|��i��}	||	j�}
|j|
d
|gi|t|����y)zv
        L{client.RedirectAgent} scrubs sensitive headers when redirecting
        between differing origins.
        ssensitive-authnzssensitive-cookie-datassensitive-cookie2-datassensitive-proxy-authssensitive-authnssensitive-custom)r�rTr�r�swWw-auThentiCatesx-custom-sensitivesx-random-headersx-random-valuer)r�c�r�|j�D��cic]\}}|j�|��c}}Scc}}wrt)rI�lower)r�r�vs   rZ�normHeaderszC_RedirectAgentTestsMixin._sensitiveHeadersTest.<locals>.normHeaders�
s-��/6�/G�/G�/I�J�V�a��A�G�G�I�q�L�J�J��Js�3r�r.r�N)r�rCrnzDict[bytes, Sequence[bytes]])r)rCrr�r_)rY�expectedHostHeader�crossKwargs�sensitiveHeaderValues�otherHeaderValues�
allHeaders�
redirectedr�sameOriginHeaders�redirectedElsewhere�otherOriginHeaderss           rZ�_sensitiveHeadersTestz._RedirectAgentTestsMixin._sensitiveHeadersTest�
s3�� 3�3�0�1�2�3�%<�$=�"4�!5�$7�#8�
!
��0�2C�1D�E���K� 5�K�9J�K�L�
��.�.�s�:�.�N�
�	K�(�
�(:�(:�;�������.�)�
��j�)�
�	
�8�d�7�7��
��
�#�#Q�&;�#Q�?P�#Q�R�
��
)�)<�)D�)D�E�������,�-�
��g�&7�8�9�
�	
r\c�*�|jdd��y)zv
        L{client.RedirectAgent} scrubs sensitive headers when redirecting
        between differing domains.
        Tr�)r�rN�r%rgs rZ�test_crossDomainHeadersz0_RedirectAgentTestsMixin.test_crossDomainHeaderss��
	
�"�"�t��"�Wr\c�*�|jdd��y)zt
        L{client.RedirectAgent} scrubs sensitive headers when redirecting
        between differing ports.
        Tsexample.com:8443)r�rNr'rgs rZ�test_crossPortHeadersz._RedirectAgentTestsMixin.test_crossPortHeaderss��
	
�"�"��/B�	#�	
r\c�(�|jd��y)zv
        L{client.RedirectAgent} scrubs sensitive headers when redirecting
        between differing schemes.
        Tr
Nr'rgs rZ�test_crossSchemeHeadersz0_RedirectAgentTestsMixin.test_crossSchemeHeaderss��
	
�"�"�t�"�4r\c��|jj|d�|jjj	�\}}tjddgi�}td|d|d�}|j|�|jjj	�\}}|jd|j�|jd|j�y)	z�
        L{client.RedirectAgent} changes the method to I{GET} when getting
        a redirect on a non-I{GET} request.

        @param code: HTTP status code.

        @param method: HTTP request method.
        r&r��http://example.com/barrQrSNr�r�)rrkr�rer�r2rCr7rUr�r9r�)	rYr�r9rrr�r�rrs	         rZ�_testRedirectToGetz+_RedirectAgentTestsMixin._testRedirectToGets���	
�
�
���6�#<�=��=�=�)�)�-�-�/���S��&�&��6O�5P�'Q�R���O�T�5�'�4�H�����X���]�]�+�+�/�/�1�
��d��������-�����$�(�(�+r\c�(�|jdd�y)z�
        L{client.RedirectAgent} changes the method to I{GET} when getting a 303
        redirect on a I{POST} request.
        i/r�N�r/rgs rZ�test_redirect303z)_RedirectAgentTestsMixin.test_redirect303-���
	
����W�-r\c�x�|jjdd�}|jjj	�\}}tj�}tddd|d�}|j|�|j|tj�}|jjdjtj �|j#d|jjdjj$�|j#d|jj&j(�y)z�
        If no L{Location} header field is found when getting a redirect,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping a
        L{error.RedirectWithNoLocation} exception.
        r�r&rQrrSNr)rrkr�rer�r2rCr7rUr�r0r8r`r�r�r1�RedirectWithNoLocationr�r�r�r�)rYr�rrr�r��fails       rZ�test_noLocationFieldz-_RedirectAgentTestsMixin.test_noLocationField4s����:�:�%�%�f�.G�H���=�=�)�)�-�-�/���S��&�&�(���O�S�%��$�G�����X���#�#�H�f�.C�.C�D���
�
���1��"�"�5�#?�#?�@����2�D�J�J�4F�4F�q�4I�4O�4O�4S�4S�T�����d�j�j�1�1�6�6�7r\c�x�|jj|d�}|jjj	�\}}tj�}td|d|d�}|j|�|j|tj�}|jjdjtj �|j#d|jjdjj$�|j#||jj&j(�y)a
        When getting a redirect on an unsupported request method,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.

        @param code: HTTP status code.

        @param method: HTTP request method.
        r&rQrSNr)rrkr�rer�r2rCr7rUr�r0r8r`r�r�r1�PageRedirectr��locationr�r�)	rYr�r9r�rrr�r�r6s	         rZ�_testPageRedirectFailurez1_RedirectAgentTestsMixin._testPageRedirectFailureGs����:�:�%�%�f�.G�H���=�=�)�)�-�-�/���S��&�&�(���O�T�5�'�4�H�����X���#�#�H�f�.C�.C�D���
�
���1��"�"�5�#5�#5�6����%�t�z�z�'9�'9�!�'<�'B�'B�'K�'K�	
�	
����t�z�z�2�2�7�7�8r\c�(�|jdd�y)z�
        When getting a 307 redirect on a I{POST} request,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.
        rr�N�r;rgs rZ�test_307OnPostz'_RedirectAgentTestsMixin.test_307OnPost`���	
�%�%�c�7�3r\c�\�|j|j�}tj|d�}|j	dd�}|j
jj�\}}tjddgi�}tddd|d	�}|j|�|j
jj�\}}	tddd|d	�}
|	j|
�|j|tj�}|jjd
j!t"j$�|j'd|jjd
jj(�|j'd|jj*j,�y	)z�
        If the limit of redirects specified to L{client.RedirectAgent} is
        reached, the deferred fires with L{ResponseFailed} error wrapping
        a L{InfiniteRedirection} exception.
        r�r�r&r�r.rQrrSNr)rrr0�
RedirectAgentrkr�rer�r2rCr7rUr�r8r`r�r�r1�InfiniteRedirectionr�r:r�r�)rYr�
redirectAgentr�rrr�r�rr�	response2r6s            rZ�test_redirectLimitz+_RedirectAgentTestsMixin.test_redirectLimithsU���-�-�d�l�l�;���,�,�U�A�6�
� �(�(��1J�K���=�=�)�)�-�-�/���S��&�&��6O�5P�'Q�R���O�S�%��$�G�����X���]�]�+�+�/�/�1�
��d��_�c�5�'�4�H�	��
�
�i� ��#�#�H�f�.C�.C�D���
�
���1��"�"�5�#<�#<�=����%�t�z�z�'9�'9�!�'<�'B�'B�'K�'K�	
�	
����d�j�j�1�1�6�6�7r\c��|jjd|�|jjj	�\}}tjd|gi�}tddd|d�}|j|�|jjj	�\}}	|jd|j�|j||j�y)a1
        When L{client.RedirectAgent} encounters a relative redirect I{URI}, it
        is resolved against the request I{URI} before following the redirect.

        @param uri: Request URI.

        @param location: I{Location} header redirect URI.

        @param finalURI: Expected final URI.
        r�r�rQrrSN)rrkr�rer�r2rCr7rUr�r9rV)
rYr�r:�finalURIrrr�r�rrs
          rZ�_testRedirectURIz)_RedirectAgentTestsMixin._testRedirectURI�s���	
�
�
���6�3�'��=�=�)�)�-�-�/���S��&�&��h�Z�'@�A���O�S�%��$�G�����X���]�]�+�+�/�/�1�
��d��������-�����4�#3�#3�4r\c�v�|jddd�|jddd�|jddd�y)	z
        L{client.RedirectAgent} resolves and follows relative I{URI}s in
        redirects, preserving query strings.
        �http://example.com/foo/barsbazshttp://example.com/foo/bazs/bazshttp://example.com/baz�/baz?ashttp://example.com/baz?aN�rHrgs rZ�test_relativeURIz)_RedirectAgentTestsMixin.test_relativeURI�sJ��
	
���)�6�3P�	
�	
���)�7�4M�	
�	
���)�9�6Q�	
r\c�P�|jddd�|jddd�y)a
        L{client.RedirectAgent} resolves and follows relative I{URI}s in
        redirects, preserving fragments in way that complies with the HTTP 1.1
        bis draft.

        @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2}
        shttp://example.com/foo/bar#fragrKshttp://example.com/baz?a#fragrJs/baz?a#frag2shttp://example.com/baz?a#frag2NrLrgs rZ�!test_relativeURIPreserveFragmentsz:_RedirectAgentTestsMixin.test_relativeURIPreserveFragments�s4��	
���.��,�	
�
	
���)��-�	
r\c�P�|jddd�|jddd�y)z�
        L{client.RedirectAgent} resolves and follows scheme relative I{URI}s in
        redirects, replacing the hostname and port when required.
        rJs
//foo.com/bazshttp://foo.com/bazs//foo.com:81/bazshttp://foo.com:81/bazNrLrgs rZ�test_relativeURISchemeRelativez7_RedirectAgentTestsMixin.test_relativeURISchemeRelative�s4��
	
���)�+;�=R�	
�	
���)�+>�@X�	
r\c�f�|j|j�}tj|�}|j	dd�}|j
jj�\}}tjddgi�}tddd|d�}|j|�|j
jj�\}}	tdd	d|d�}
|	j|
�|j|�}|j|j|�|j|jd�y)
z�
        L{Response.response} references the previous L{Response} from
        a redirect, or L{None} if there was no previous response.
        r�r&r�r.rQrrSNrR)rrr0rArkr�rer�r2rCr7rUr�rOr�)rYrrCr��redirectReq�redirectResr��redirectResponserrr��
finalResponses            rZ�test_responseHistoryz-_RedirectAgentTestsMixin.test_responseHistory�s��
�-�-�d�l�l�;���,�,�U�3�
� �(�(��1J�K��#'�=�=�#9�#9�#=�#=�#?� ��[��&�&��6O�5P�'Q�R��#�O�S�%��$�O�����-�.��=�=�)�)�-�-�/���S��O�S�%��$�G�����X���,�,�X�6�
����]�;�;�=M�N����-�>�>��Er\)FFFN)r��intr��boolr�rYr�rYr�zOptional[Headers]rnr?)r.)rrxrrYrnrorm)r]r^r_rp�__annotations__r�rr
rrrrr%r(r*r,r/r2r7r;r>rErHrMrOrQrWr`r\rZr�r�Y
s����
�M�
����<�*"�!��,0�
<��<��<��	<�
�<�*�
<�
�<�|'�
�'�'�'�+9�+
�"'�+
�IM�+
�	
�+
�ZX�
�5�,�*.�8�&9�24�8�<5�.

�
�&

�Fr\r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�RedirectAgentTestsz,
    Tests for L{client.RedirectAgent}.
    c�d�tj|j|j�dg��S)zD
        @return: a new L{twisted.web.client.RedirectAgent}
        sX-Custom-sensitive��sensitiveHeaderNames)r0rArrrgs rZr�zRedirectAgentTests.makeAgent�s/���#�#��)�)�$�,�,�7�"7�!8�
�	
r\c�X�|j�|_|j�|_yrtr�rgs rZr�zRedirectAgentTests.setUp�� ���)�)�+����^�^�%��
r\c�(�|jdd�y)z�
        When getting a 301 redirect on a I{POST} request,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.
        rr�Nr=rgs rZ�test_301OnPostz!RedirectAgentTests.test_301OnPost�r?r\c�(�|jdd�y)z�
        When getting a 302 redirect on a I{POST} request,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.
        rr�Nr=rgs rZ�test_302OnPostz!RedirectAgentTests.test_302OnPostr?r\N)r]r^r_rpr�r�rcrer`r\rZr\r\�s���
�&�4�4r\r\c�(�eZdZdZd�Zd�Zd�Zd�Zy)�BrowserLikeRedirectAgentTestsz7
    Tests for L{client.BrowserLikeRedirectAgent}.
    c�d�tj|j|j�dg��S)zO
        @return: a new L{twisted.web.client.BrowserLikeRedirectAgent}
        sx-Custom-sensitiver^)r0�BrowserLikeRedirectAgentrrrgs rZr�z'BrowserLikeRedirectAgentTests.makeAgents/���.�.��)�)�$�,�,�7�"7�!8�
�	
r\c�X�|j�|_|j�|_yrtr�rgs rZr�z#BrowserLikeRedirectAgentTests.setUp rar\c�(�|jdd�y)��
        L{client.BrowserLikeRedirectAgent} changes the method to I{GET} when
        getting a 302 redirect on a I{POST} request.
        rr�Nr1rgs rZ�test_redirectToGet301z3BrowserLikeRedirectAgentTests.test_redirectToGet301$r3r\c�(�|jdd�y)rlrr�Nr1rgs rZ�test_redirectToGet302z3BrowserLikeRedirectAgentTests.test_redirectToGet302+r3r\N)r]r^r_rpr�r�rmror`r\rZrgrg
s���
�&�.�.r\rgc��eZdZdZdZd�Zy)�AbortableStringTransportzK
    A version of L{StringTransport} that supports C{abortConnection}.
    Fc�2�d|_|j�y)z�
        A testable version of the C{ITCPTransport.abortConnection} method.

        Since this is a special case of closing the connection,
        C{loseConnection} is also called.
        TN)�aborting�loseConnectionrgs rZ�abortConnectionz(AbortableStringTransport.abortConnection;s����
����r\N)r]r^r_rprsrur`r\rZrqrq3s���
�H�r\rqc�*�eZdZdZdZdZdefd�Zd�Zy)�
DummyResponsea�
    Fake L{IResponse} for testing readBody that captures the protocol passed to
    deliverBody and uses it to make a connection with a transport.

    @ivar protocol: After C{deliverBody} is called, the protocol it was called
        with.

    @ivar transport: An instance created by calling C{transportFactory} which
        is used by L{DummyResponse.protocol} to make a connection.
    rRrSNc�B�|�
t�}||_|�|_y)z�
        @param headers: The headers for this response.  If L{None}, an empty
            L{Headers} instance will be used.
        @type headers: L{Headers}

        @param transportFactory: A callable used to construct the transport.
        N)rCr�r2)rYr��transportFactorys   rZrhzDummyResponse.__init__Us!���?��i�G����)�+��r\c�\�||_|jj|j�y)zt
        Record the given protocol and use it to make a connection with
        L{DummyResponse.transport}.
        N�r�rr2r6s  rZr�zDummyResponse.deliverBodybs!��
!��
��
�
�$�$�T�^�^�4r\)	r]r^r_rpr�r�rqrhr�r`r\rZrwrwFs#��	��D�
�F�#�6N�,�5r\rwc��eZdZdZd�Zy)�AlreadyCompletedDummyResponsezE
    A dummy response that has already had its transport closed.
    c�~�||_|jj|j�d|j_y)zA
        Make the connection, then remove the transport.
        Nr{r6s  rZr�z)AlreadyCompletedDummyResponse.deliverBodyps-��!��
��
�
�$�$�T�^�^�4�"&��
�
�r\N)r]r^r_rpr�r`r\rZr}r}ks���'r\r}c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�
ReadBodyTestsz&
    Tests for L{client.readBody}
    c�H�t�}tj|�}|jj	d�|jj	d�|jjt
t���|j|j|�d�y)z�
        L{client.readBody} returns a L{Deferred} which fires with the complete
        body of the L{IResponse} provider passed to it.
        �first�second�firstsecondN)
rwr0�readBodyr�r�rvr*r@r�r�)rYr�r)s   rZ�test_successzReadBodyTests.test_success~sw��
!�?���O�O�H�%�����&�&�x�0����&�&�y�1����(�(����)@�A�����-�-�a�0�.�Ar\c���t�}tj|�}|j�|j	|t
j�|j|jj�y)z�
        When cancelling the L{Deferred} returned by L{client.readBody}, the
        connection to the server will be aborted.
        N)
rwr0r�r�r�rrr�r2rs)rYr�r�s   rZ�test_cancelzReadBodyTests.test_cancel�sQ��
!�?���?�?�8�,���������X�u�';�';�<�����*�*�3�3�4r\c��t�}tj|�}|jj	d�|jj	d�|jjt
t���|j|�}|jtj�|j|jj|jj|jjd�dddd��y)a
        If the full body of the L{IResponse} passed to L{client.readBody} is
        not definitely received, the L{Deferred} returned by L{client.readBody}
        fires with a L{Failure} wrapping L{client.PartialDownloadError} with
        the content that was received.
        r�r�)�statusr�r:s200rSr�N)rwr0r�r�r�rvr*r4r�r��PartialDownloadErrorr�r`r�r�r�)rYr�r)�failures    rZ�test_withPotentialDataLossz(ReadBodyTests.test_withPotentialDataLoss�s���!�?���O�O�H�%�����&�&�x�0����&�&�y�1����(�(��1B�1D�)E�F��&�&�q�)�����V�0�0�1����!�-�-�.�.�"�=�=�0�0��
�
�.�.�
�!� �&�
�
	
r\c�j�t�}tj|�}|jj	d�|jjt
td���|j|�}|jt�|j|jjd�y)z�
        If there is an exception other than L{client.PotentialDataLoss} while
        L{client.readBody} is collecting the response body, the L{Deferred}
        returned by {client.readBody} fires with that exception.
        r��mystery problem)r�N)
rwr0r�r�r�rvr*rr�r�r�r`r�)rYr�r)r�s    rZ�test_otherErrorszReadBodyTests.test_otherErrors�s���!�?���O�O�H�%�����&�&�x�0����(�(���@Q�1R�)S�T��%�%�a�(�����N�#�������*�*�,@�Ar\c����tt���d�j_|j	t
dt�fd��}|j�|j|tj�y)z�
        Calling L{client.readBody} with a transport that does not implement
        L{twisted.internet.interfaces.ITCPTransport} produces a deprecation
        warning, but no exception when cancelling.
        )ryNzLUsing readBody with a transport that does not have an abortConnection methodc�.��tj��Srt)r0r�)r�s�rZr}z8ReadBodyTests.test_deprecatedTransport.<locals>.<lambda>�s���F�O�O�H�-�r\)rwr&r2ru�assertWarnsr��__file__r�r�rr)rYr)r�s  @rZ�test_deprecatedTransportz&ReadBodyTests.test_deprecatedTransport�s\���!�/�B��-1����*�����
%��-�
��	
���
����Q�� 4� 4�5r\c��t�}tj|�|j�}|j	t|�d�y)z�
        Calling L{client.readBody} with a response that has already had its
        transport closed (eg. for a very small request) will not trigger a
        deprecation warning.
        rN)r}r0r�r�r�r�)rYr�r�s   rZ�!test_deprecatedTransportNoWarningz/ReadBodyTests.test_deprecatedTransportNoWarning�s:��1�2������!��%�%�'������X���*r\N)
r]r^r_rpr�r�r�r�r�r�r`r\rZr�r�ys'���
B�	5�
�6B�6�$
+r\r�c��eZdZd�Zd�Zd�Zy)�HostnameCachingHTTPSPolicyTestsc���t�}t|��}t|�}|jdd�}|j	|j
�d|_|j
dt|j��|jd�}|j|j|j��|jdd�|j|j
�y)z�
        Verify that the connection creator is added to the
        policy's cache, and that it is reused on subsequent calls
        to creatorForNetLoc.

        r�r�i5Fr�N)rTr;r=r�r�rWr_r��_cacher�rgrXr�r�)rYr��
wrappedPolicyr�r�r�s      rZ�test_cacheIsUsedz0HostnameCachingHTTPSPolicyTests.test_cacheIsUsed�s���+�,�	�1�I�F�
�+�M�:���)�)�&�$�7�����	�(�(�)� �	�����!�S����/�0��3�3�D�9�
��
�
�i�'�'��)?�)?�)A�B������-�����)�)�*r\c��t�}t|��}t|�}tdd�D]1}dt	|�z}|j|j
d�d��3d}|j|j
d�d�|j||j�|jdt|j��d	}|j|j
d�d�d
}|j||j�|jdt|j��|j||j�|j||j�td�D]#}	|j|j
d�d��%d}
|j|
j
d�d�|jd
|j�|jdt|j��|j|
|j�|j||j�|j||j�y)zt
        Verify that when the cache is full, and a new entry is added,
        the oldest entry is removed.
        r�r�rDr���!�host0�5�new�host1�new1i �host2N�rTr;r=r��strr�r
r4r�r_r�r )rYr�r�r�r�r�r��hostnr�r��
hostNPlus1s           rZ�test_cacheRemovesOldestz7HostnameCachingHTTPSPolicyTests.test_cacheRemovesOldest�s���
+�,�	�1�I�F�
�+�M�:���q�"��	D�A���A���H��#�#�H�O�O�G�$<�d�C�	D�
��������W� 5�s�;��
�
�e�V�]�]�+����"�c�&�-�-�0�1���������W� 5�s�;��������
�
�.����"�c�&�-�-�0�1��
�
�e�V�]�]�+��
�
�e�V�]�]�+��r��	A�A��#�#�E�L�L��$9�4�@�	A��
����
� 1� 1�'� :�C�@�����&�-�-�0����"�c�&�-�-�0�1��
�
�j�&�-�-�0��
�
�e�V�]�]�+��
�
�e�V�]�]�+r\c�P�t�}t|��}t|d��}tdd�D]1}dt	|�z}|j|j
d�d��3d}|j||j�|jdt|j��d	}|j|j
d�d
�|j||j�|jdt|j��|j||j�y)z�
        Verify that changing the cache size results in a policy that
        respects the new cache size and not the default.

        r�r�)�	cacheSizerrDr�r�r�r�r�Nr�)rYr�r�r�r�r��firstr�s        rZ�test_changeCacheSizez4HostnameCachingHTTPSPolicyTests.test_changeCacheSize
s���+�,�	�1�I�F�
�+�M�Q�G���q�!��	D�A���A���H��#�#�H�O�O�G�$<�d�C�	D����
�
�e�V�]�]�+����!�S����/�0���������W� 5�s�;������
�
�.����!�S����/�0��
�
�e�V�]�]�+r\N)r]r^r_r�r�r�r`r\rZr�r��s��+�(),�V,r\r�c��eZdZdZd�Zy)�RequestMethodInjectionTestsz@
    Test L{client.Request} against HTTP method injections.
    c�Z�tj|dtj�d��y)rlrmN�r9r�r�r��r0r?r2rC)rYr9s  rZroz=RequestMethodInjectionTests.attemptRequestWithMaliciousMethod?
s%��	����)� �(�(�*��		
r\Nrpr`r\rZr�r�7
����
r\r�c��eZdZdZd�Zy)�"RequestWriteToMethodInjectionTests�H
    Test L{client.Request.writeTo} against HTTP method injections.
    c��tjddgi�}tjdd|d��}||_|jt
��y)rlr��twisted.invalidr�rmNr�)r2rCr0r?r9�writeTor&)rYr9r�rs    rZrozDRequestWriteToMethodInjectionTests.attemptRequestWithMaliciousMethodU
sO���&�&��2D�1E�'F�G���n�n��)���	
����
����O�%�&r\Nrpr`r\rZr�r�M
����'r\r�c��eZdZdZd�Zy)�RequestURIInjectionTestsz=
    Test L{client.Request} against HTTP URI injections.
    c�Z�tjd|tj�d��y)zp
        Attempt a request with the provided URI.

        @param method: see L{URIInjectionTestsMixin}
        r�Nr�r�r�s  rZruz7RequestURIInjectionTests.attemptRequestWithMaliciousURIn
s%��	����� �(�(�*��		
r\Nrvr`r\rZr�r�f
r�r\r�c��eZdZdZd�Zy)�RequestWriteToURIInjectionTestsr�c��tjddgi�}tjdd|d��}||_|jt
��y)zs
        Attempt a request with the provided method.

        @param method: see L{URIInjectionTestsMixin}
        r�r�r�rmNr�)r2rCr0r?r�r�r&)rYr�r�rs    rZruz>RequestWriteToURIInjectionTests.attemptRequestWithMaliciousURI�
sO���&�&��2D�1E�'F�G���n�n��)���	
��������O�%�&r\Nrvr`r\rZr�r�|
r�r\r�)�rp�
__future__rr��http.cookiejarr�ior�typingrrrr	r
r�unittestrr
�zope.interface.declarationsr�zope.interface.verifyr�incrementalr�twisted.internetrr�twisted.internet.addressrr�twisted.internet.deferrrrr}rr�twisted.internet.errorrrr�twisted.internet.interfacesr�twisted.internet.protocolrr �twisted.internet.taskr!�$twisted.internet.test.test_endpointsr"�twisted.internet.testingr#r$r%r&�twisted.loggerr'�twisted.python.componentsr(�twisted.python.deprecater)�twisted.python.failurer*�twisted.test.iosimr+r,�twisted.test.test_sslverifyr-�twisted.trial.unittestr.r/�twisted.webr0r1r2�twisted.web._newclientr3r4r5r6r7r8r9r�r:r;r<r=r>r?r@rA�twisted.web.errorrB�twisted.web.http_headersrCr�rDrErFrGrHrI�!twisted.web.test.injectionhelpersrJrK�testMixinClassr��runtimeTestCaserL�_sslr��twisted.internet._sslverifyrMrN�twisted.internet.sslrO�twisted.protocolsrP�twisted.protocols.tlsrQrRrT�ImportErrorrbrrrzr�r�r�r�r�r�r�rr
rrr�r�r�r�rjrsrxr�r�r#r-rLrirnrpr�r�r��SENSITIVE_HEADERSr�r\rgrqrwr}r�r�r�r�r�r�r`r\rZ�<module>r�s����#��$��G�G�%�3�.��(�=�D�D�K���
H�7�'�N���.�7�@�*�4�I�@�3�3����	�	�	�1�,������N��O��N��O�#�,�
�C��J�O�8�%�O��"�#�#�#�$�#��x��2%�%�]&�H�]&�@����������
�
�P!�P!�f!�!�G�G� �7� �jV�h�(B�jV�Z		@�	@�u
�u
�p
�
"�#�0�0�$�0�$Y)��(�/�;R�Y)�x4����4�(4����4�(�J��@�A�X
�h� :�<S�X
�B�X
�v?U�8�?U�Dy,�8�-G�y,�x!�!�2;
�X�/�;
�|h2��� :�O�h2�V� ��+���x��~+�x�)C�_�~+�B#�(�#�4w2�x�1K�w2�t[6�h� :�O�[6�|��IF�~�IF�X%4�����	%4�P#.�����	#.�L���&"5�"5�J'�M�'�a+�H�a+�H�J��@�A�V,�h�V,�B�V,�r
���
�,'���'�2
���
�,'���'��h��
�C��J��s�#M�	M�M

Zerion Mini Shell 1.0