%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_web.cpython-312.pyc

�

Ϫ�f���dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZmZdd	lmZdd
lmZmZddlmZmZddlmZmZdd
lmZddlmZddlm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,ddl-m.Z.ddl/m0Z0m1Z1ddl2m3Z3Gd�de jh�Z5Gd�de%jP�Z6Gd�de%jP�Z7Gd�de%jP�Z8Gd�d e jh�Z9Gd!�d"e jh�Z:d#�Z;d$�Z<d%�Z=Gd&�d'e jh�Z>Gd(�d)e jh�Z?Gd*�d+e jh�Z@Gd,�d-e%jP�ZAGd.�d/e jh�ZBGd0�d1e%jP�ZCee%j��Gd2�d3��ZEGd4�d5e jh�ZFGd6�d7e%jP�ZGGd8�d9e jh�ZHGd:�d;e1�ZIGd<�d=�ZJGd>�d?eJe jh�ZKGd@�dAeJe jh�ZLGdB�dCe jh�ZMGdD�dEe jh�ZNGdF�dGe jh�ZOGdH�dIe jh�ZPGdJ�dKe jh�ZQGdL�dMe(�ZRGdN�dOe jh�ZSy)Pz,
Tests for various parts of L{twisted.web}.
�N)�BytesIO)�List)�implementer)�verifyObject)�
interfaces)�IPv4Address�IPv6Address)�Clock)�EventLoggingObserver�StringTransport)�LogLevel�globalLogPublisher)�failure�reflect)�	iterbytes)�FilePath)�unittest)�error�http�iweb�resource�server)�Resource)�NOT_DONE_YET�Request�Site)�Data)�DummyChannel�DummyRequest�)�assertIsFilesystemTemporaryc��eZdZd�Zy)�
ResourceTestsc�l�tj�}|jg|j��y�N)rr�assertEqual�listEntities)�self�rs  �;/usr/lib/python3/dist-packages/twisted/web/test/test_web.py�testListEntitieszResourceTests.testListEntities"s'�����������Q�^�^�-�.�N)�__name__�
__module__�__qualname__r+�r,r*r#r#!s��/r,r#c��eZdZdZdd�Zd�Zy)�SimpleResourcez�
    @ivar _contentType: L{None} or a C{str} giving the value of the
        I{Content-Type} header in the response this resource will render.  If it
        is L{None}, no I{Content-Type} header will be set in the response.
    Nc�P�tjj|�||_yr%)rr�__init__�_contentType)r(�contentTypes  r*r4zSimpleResource.__init__.s�����"�"�4�(�'��r,c���|j�'|jjd|jg�tj|jd�|j
d�fvryy)N�content-type�
�MatchingTagr,�correct)r5�responseHeaders�
setRawHeadersr�CACHED�setLastModified�setETag�r(�requests  r*�renderzSimpleResource.render2s`�����(��#�#�1�1�/�D�DU�DU�CV�W��;�;��#�#�B�'��O�O�N�+�
�
��r,r%)r-r.r/�__doc__r4rCr0r,r*r2r2's���(�
r,r2c��eZdZdZd�Zy)�ZeroLengthResourcez@
    A resource that always returns a zero-length response.
    c��y�Nr,r0rAs  r*rCzZeroLengthResource.renderDs��r,N�r-r.r/rDrCr0r,r*rFrF?s���r,rFc��eZdZdZd�Zy)�NoContentResourcezf
    A resource that always returns a 204 No Content response without setting
    Content-Length.
    c�B�|jtj�yrH)�setResponseCoder�
NO_CONTENTrAs  r*rCzNoContentResource.renderNs��������0�r,NrIr0r,r*rKrKHs���
r,rKc�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�SiteTestz(
    Unit tests for L{server.Site}.
    c�\�|j�}|j|j�|S)z�
        Create a new session which auto expires at cleanup.

        @param site: The site on which the session is created.
        @type site: L{server.Site}

        @return: A newly created session.
        @rtype: L{server.Session}
        )�makeSession�
addCleanup�expire�r(�site�sessions   r*�getAutoExpiringSessionzSiteTest.getAutoExpiringSessionXs'���"�"�$��������'��r,c���t�}t�}|jd|�tj|�}|j	|jt
dg��|d�y)z�
        L{Site.getResourceFor} returns the C{b""} child of the root resource it
        is constructed with when processing a request for I{/}.
        r,zGot the wrong resource.N)r2�putChildrr�assertIdentical�getResourceForr)r(�sres1�sres2rVs    r*�test_simplestSitezSiteTest.test_simplestSitegsX��
� ��� ��
���s�E�"��{�{�5�!���������c�U� 3�4�e�=V�	
r,c��tjt���}|jtj|j
�y)zC
        L{server.Request} is the default request factory.
        )rN)rrr2�assertIsr�requestFactory�r(rVs  r*�test_defaultRequestFactoryz#SiteTest.test_defaultRequestFactoryts-���{�{�N�$4�5���
�
�f�n�n�d�&9�&9�:r,c��t�}tjt�|��}|j	||j
�y)zB
        Can be initialized with a custom requestFactory.
        )rrbN)�objectrrr2rarb)r(�
customFactoryrVs   r*�test_constructorRequestFactoryz'SiteTest.test_constructorRequestFactory|s2����
��{�{�N�$4�]�S���
�
�m�T�%8�%8�9r,c���tjt��}|jd�}|j	||j
�|j	|j|j�y)z�
        Returns a C{Channel} whose C{site} and C{requestFactory} attributes are
        assigned from the C{site} instance.
        N)rrr2�
buildProtocolrarVrb)r(rV�channels   r*�test_buildProtocolzSiteTest.test_buildProtocol�sQ��
�{�{�>�+�,���$�$�T�*���
�
�d�G�L�L�)��
�
�d�)�)�7�+A�+A�Br,c���tjtj��}|j	|�}|j|tj�|j|jt�y)zn
        L{site.getSession} generates a new C{Session} instance with an uid of
        type L{bytes}.
        N)	rrrrrX�assertIsInstance�Session�uid�bytesrUs   r*�test_makeSessionzSiteTest.test_makeSession�sS��
�{�{�8�,�,�.�/���-�-�d�3�����g�v�~�~�6����g�k�k�5�1r,c����tjtj��}|j	|j
tj��fd��d�_|j|d��|j|�}|j|�}|j|jd�|j|jd�|j|jd�y)z}
        L{site.getSession} generates L{Session} objects with distinct UIDs from
        a secure source of entropy.
        c�|���xjdz
c_t�j�|zjd�S)Nr �charmap)�x�chr�encode)�n�predictableEntropys �r*rzz>SiteTest.test_sessionUIDGeneration.<locals>.predictableEntropy�s6���� � �A�%� ��*�,�,�-��1�9�9�)�D�Dr,r�_entropys@0101010101010101010101010101010101010101010101010101010101010101s@0202020202020202020202020202020202020202020202020202020202020202�N)rrrrr[r{�os�urandomrv�patchrXr&rp�counter)r(rV�a�brzs    @r*�test_sessionUIDGenerationz"SiteTest.test_sessionUIDGeneration�s����
�{�{�8�,�,�.�/��	
���T�]�]�B�J�J�7�	E� !����
�
�4��%7�8��'�'��-���'�'��-���������-��������-�
	
������q�)r,c���tjtj��}|j	|�}|j|j�}|j||�y)zc
        L{site.getSession} gets a previously generated session, by its unique
        ID.
        N)rrrrrX�
getSessionrpra)r(rV�createdSession�retrievedSessions    r*�test_getSessionExistentz SiteTest.test_getSessionExistent�sO��
�{�{�8�,�,�.�/���4�4�T�:���?�?�>�+=�+=�>���
�
�n�&6�7r,c��tjtj��}|j	t
|jd�y)zV
        L{site.getSession} raises a L{KeyError} if the session is not found.
        sno-such-uidN)rrrr�assertRaises�KeyErrorr�rcs  r*�test_getSessionNonExistentz#SiteTest.test_getSessionNonExistent�s1���{�{�8�,�,�.�/�����(�D�O�O�^�Dr,N)
r-r.r/rDrXr_rdrhrlrrr�r�r�r0r,r*rPrPSs6���
�
�;�:�
C�	2�*�4
8�Er,rPc�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�SessionTestsz&
    Tests for L{server.Session}.
    c�X�t�|_d|_tjtj�|j��|_tj|j|j�|_	|j|jj|j<y)zo
        Create a site with one active session using a deterministic, easily
        controlled clock.
        sunique��reactorN)r
�clockrprrrrrVrorW�sessions�r(s r*�setUpzSessionTests.setUp�si��
�W��
�����K�K�� 1� 1� 3�T�Z�Z�H��	��~�~�d�i�i����:���'+�|�|��	�	���4�8�8�$r,c���tjtj�t	���}tj
|d�}|j
|j|j�y)z|
        If no value is passed to L{server.Session.__init__}, the reactor
        associated with the site is used.
        r��123N)	rrrrr
ror[�_reactorr�rUs   r*�test_defaultReactorz SessionTests.test_defaultReactor�sI��
�{�{�8�,�,�.���@���.�.��v�.�����W�-�-�t�|�|�<r,c���tjtj��}t	�}tj
|d|��}|j
|j|�y)zG
        L{Session} accepts the reactor to use as a parameter.
        r�r�N)rrrrr
ror[r�)r(rV�otherReactorrWs    r*�test_explicitReactorz!SessionTests.test_explicitReactor�sJ���{�{�8�,�,�.�/���w���.�.��v�|�D�����W�-�-�|�<r,c���|jj�|jj|jjdz
�|j|j|jj�|jjd�|j|j|jj�|j|jj�y)z�
        L{server.Session.startCheckingExpiration} causes the session to expire
        after L{server.Session.sessionTimeout} seconds without activity.
        r N)rW�startCheckingExpirationr��advance�sessionTimeout�assertInrprVr��assertNotIn�assertFalse�callsr�s r*�test_startCheckingExpirationz)SessionTests.test_startCheckingExpiration�s���
	
���,�,�.�	
�
�
���4�<�<�6�6��:�;��
�
�d�h�h��	�	� 2� 2�3�	
�
�
���1��������4�9�9�#5�#5�6�	
������)�)�*r,c���|jj�|j|j|jj
�|j
|jj�y)z?
        L{server.Session.expire} expires the session.
        N)	rWrTr�rprVr�r�r�r�r�s r*�test_expirezSessionTests.test_expiresJ��	
������������4�9�9�#5�#5�6�������)�)�*r,c�X�|jj�|j�y)zn
        L{server.Session.expire} expires the session even if the timeout call
        isn't due yet.
        N)rWr�r�r�s r*�test_expireWhileCheckingz%SessionTests.test_expireWhileCheckings ��
	
���,�,�.����r,c���dg��fd�}|jj|�|jj�|j�d�y)zy
        A function registered with L{server.Session.notifyOnExpire} is called
        when the session expires.
        Fc���d�d<y)NTrr0)�callbackRans�r*�expiredz1SessionTests.test_notifyOnExpire.<locals>.expireds���!�K��Nr,rN)rW�notifyOnExpirerT�
assertTrue)r(r�r�s  @r*�test_notifyOnExpirez SessionTests.test_notifyOnExpiresE���
�g��	"�	
���#�#�G�,�����������A��'r,c���|jjd�|jj�|j	|jj
d�|jj
�|jj|jjdz
�|jj�|jj|jjdz
�|j|j|jj�|jjd�|j|j|jj�y)zt
        L{server.Session.touch} updates L{server.Session.lastModified} and
        delays session timeout.
        �r N)
r�r�rW�touchr&�lastModifiedr�r�r�rprVr�r�r�s r*�
test_touchzSessionTests.test_touch"s���	
�
�
���1��������������2�2�A�6�	
���,�,�.��
�
���4�<�<�6�6��:�;��������
�
���4�<�<�6�6��:�;��
�
�d�h�h��	�	� 2� 2�3�	
�
�
���1��������4�9�9�#5�#5�6r,N)r-r.r/rDr�r�r�r�r�r�r�r�r0r,r*r�r��s/���	4�=�	=�+�$+��(�7r,r�c�,�|jdd�dS)N�

r )�split)�wholes r*�httpBodyr�Bs���;�;�{�A�&�q�)�)r,c��|j�}|jdd�d}|jd�D]F}|j�j|�s�#|jdd�dj�cSy)Nr�r r�
�:)�lowerr��
startswith�strip)r��key�headers�headers    r*�
httpHeaderr�Fsr��

�)�)�+�C��k�k�+�q�)�!�,�G��-�-��(�4���<�<�>�$�$�S�)��<�<��a�(��+�1�1�3�3�4�r,c�d�|jdd�d}t|j�d�S)Nr�r r)r��int)r��l1s  r*�httpCoder�Os,��	���W�a�	 ��	#�B��r�x�x�z�!�}��r,c�Z�eZdZdZd�Zd�Zdd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zy)�ConditionalTestszM
    web.server's handling of conditional requests for cache validation.
    c���t�|_|jjd|j�|jjdtd��tj|j�|_|j
j
�|j|j
j�|j
jd�|_
tj�|_
d�|j_d�|j_d�|j_d�|j_|jj%|j�y)Nr,swith-content-type�
image/jpegc��yr%r0�r��kws  r*�<lambda>z(ConditionalTests.setUp.<locals>.<lambda>d��r,c��y)Nrr0r�s  r*r�z(ConditionalTests.setUp.<locals>.<lambda>er�r,c��y)N�peerr0r�s  r*r�z(ConditionalTests.setUp.<locals>.<lambda>fr�r,c��y)N�hostr0r�s  r*r�z(ConditionalTests.setUp.<locals>.<lambda>gr�r,)r2�resrcrZrrrV�startFactoryrS�stopFactoryrjrkrr�	transport�close�
disconnecting�getPeer�getHost�makeConnectionr�s r*r�zConditionalTests.setUpYs���#�%��
��
�
���C����,��
�
���0�.��2O�P��K�K��
�
�+��	��	�	��� �����	�	�-�-�.��y�y�.�.�t�4����-�-�/���4�����'9����$�!8�����!8��������#�#�D�N�N�3r,c�:�|jjd�yr%)rk�connectionLostr�s r*�tearDownzConditionalTests.tearDownjs�����#�#�D�)r,Nc�b�|�d|z}nd|z}d|dfD] }|jj|dz��"|jj�}|j	t|�tj�|j	t|�d�|j	t|d�d	�y)
a

        Given the value C{modifiedSince} for the I{If-Modified-Since} header or
        the value C{etag} for the I{If-Not-Match} header, verify that a response
        with a 200 code, a default Content-Type, and the resource as the body is
        returned.
        N�If-Modified-Since: sIf-Not-Match: �GET / HTTP/1.1r,r�r;�Content-Types	text/html)
rk�dataReceivedr��getvaluer&r�r�OKr�r�)r(�
modifiedSince�etag�	validator�line�results      r*�
_modifiedTestzConditionalTests._modifiedTestms����$�.��>�I�)�D�0�I�&�	�3�7�	6�D��L�L�%�%�d�W�n�5�	6����(�(�*������&�)�4�7�7�3�����&�)�:�6�����F�O�<�l�Kr,c�N�|jtjd���y)a
        If a request is made with an I{If-Modified-Since} header value with
        a timestamp indicating a time before the last modification of the
        requested resource, a 200 response is returned along with a response
        body containing the resource.
        r �r�N)r�r�datetimeToStringr�s r*�
test_modifiedzConditionalTests.test_modifieds ��	
����)>�)>�q�)A��Br,c�t�ddtjd�zdfD] }|jj|dz��"|jj�}|j
t|�tj�|j
t|�d�|j
t|d�d�y)a=
        If a request is made with an I{If-Modified-Since} header value with a
        timestamp indicating a time after the last modification of the request
        resource, a 304 response is returned along with an empty response body
        and no Content-Type header if the application does not set one.
        r�r��dr,r�r�N)rr�rkr�r�r�r&r��NOT_MODIFIEDr�r��r(r�r�s   r*�test_unmodifiedz ConditionalTests.test_unmodified�s���
�"�T�%:�%:�3�%?�?��
�	6�D�

�L�L�%�%�d�W�n�5�	6����(�(�*������&�)�4�+<�+<�=�����&�)�3�/�	
����F�O�<�d�Cr,c�(�|jd��y)a
        If a request is made with an I{If-Modified-Since} header value which
        cannot be parsed, the header is treated as not having been present
        and a normal 200 response is returned with a response body
        containing the resource.
        s like, maybe a week ago, I guess?r�N�r�r�s r*�test_invalidTimestampz&ConditionalTests.test_invalidTimestamp�s��	
���)L��Mr,c�(�|jd��y)a3
        If a request is made with an I{If-Modified-Since} header value which
        contains a string in the year position which is not an integer, the
        header is treated as not having been present and a normal 200
        response is returned with a response body containing the resource.
        sThu, 01 Jan blah 00:00:10 GMTr�Nr�r�s r*�test_invalidTimestampYearz*ConditionalTests.test_invalidTimestampYear����	
���)I��Jr,c�(�|jd��y)a
        If a request is made with an I{If-Modified-Since} header value which
        contains a year before the epoch, the header is treated as not
        having been present and a normal 200 response is returned with a
        response body containing the resource.
        sThu, 01 Jan 1899 00:00:10 GMTr�Nr�r�s r*�test_invalidTimestampTooLongAgoz0ConditionalTests.test_invalidTimestampTooLongAgo�r�r,c�(�|jd��y)aQ
        If a request is made with an I{If-Modified-Since} header value which
        contains a string in the month position which is not a recognized
        month abbreviation, the header is treated as not having been present
        and a normal 200 response is returned with a response body
        containing the resource.
        sThu, 01 Blah 1970 00:00:10 GMTr�Nr�r�s r*�test_invalidTimestampMonthz+ConditionalTests.test_invalidTimestampMonth�s��	
���)J��Kr,c�(�|jd��y)a"
        If a request is made with an I{If-None-Match} ETag which does not match
        the current ETag of the requested resource, the header is treated as not
        having been present and a normal 200 response is returned with a
        response body containing the resource.
        sunmatchedTag)r�Nr�r�s r*�test_etagMatchedNotz$ConditionalTests.test_etagMatchedNot�s��	
�����0r,c�B�dD] }|jj|dz��"|jj�}|j	t|d�d�|j	t
|�tj�|j	t|�d�y)z�
        If a request is made with an I{If-None-Match} ETag which does match the
        current ETag of the requested resource, a 304 response is returned along
        with an empty response body.
        )r��If-None-Match: MatchingTagr,r�sETagr:r,N)
rkr�r�r�r&r�r�rr�r�r�s   r*�test_etagMatchedz!ConditionalTests.test_etagMatched�s���L�	6�D��L�L�%�%�d�W�n�5�	6����(�(�*������F�G�4�n�E�����&�)�4�+<�+<�=�����&�)�3�/r,c�B�dD] }|jj|dz��"|jj�}|j	t|�tj�|j	t|�d�|j	t|d�d�y)aL
        Similar to L{test_etagMatched}, but the response should include a
        I{Content-Type} header if the application explicitly sets one.

        This I{Content-Type} header SHOULD NOT be present according to RFC 2616,
        section 10.3.5.  It will only be present if the application explicitly
        sets it.
        )sGET /with-content-type HTTP/1.1rr,r�r,r�r�N)
rkr�r�r�r&r�rr�r�r�r�s   r*�test_unmodifiedWithContentTypez/ConditionalTests.test_unmodifiedWithContentType�s���
�	6�D�

�L�L�%�%�d�W�n�5�	6����(�(�*������&�)�4�+<�+<�=�����&�)�3�/�����F�O�<�m�Lr,)NN)r-r.r/rDr�r�r�r�r�r�r�rrrrr	r0r,r*r�r�TsK���4�"*�L�$C�D�*N�K�K�L�1�0�Mr,r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z y) �RequestTestsz>
    Tests for the HTTP request class, L{server.Request}.
    c	��|jttjt	j
t
�d���y)zG
        L{server.Request} instances provide L{iweb.IRequest}.
        TN)r�rr�IRequestrrrr�s r*�test_interfacezRequestTests.test_interface�s+��	
����������|�~�t�(L�M�	
r,c�V�tjt�d�}t|�y)zY
        L{server.Request} instances are hashable, thus can be put in a mapping.
        TN)rrr�hashrAs  r*�
test_hashablezRequestTests.test_hashable�s���.�.����6���W�
r,c��tjt�d�}|jd�|j	ddd�|j|j
d�d�tjt�d�}|jd�|j	ddd�|j|j
d�d�y)	Nr r�GET�/foo/bar�HTTP/1.0sbazsbar/baz�	/foo/bar/)rrr�	gotLength�requestReceivedr&�	childLinkrAs  r*�
testChildLinkzRequestTests.testChildLinks����.�.����3�����!�������[�A�����*�*�6�2�J�?��.�.����3�����!�������k�B�����*�*�6�2�F�;r,c���tjt�d�}|jd�|j	ddd�|jdd�|j
|j�d�y)	Nr rrrr�example.com�Pshttp://example.com/foo/bar)rrrrr�setHostr&�
prePathURLrAs  r*�testPrePathURLSimplez!RequestTests.testPrePathURLSimples\���.�.����3�����!�������[�A������+�����+�+�-�/L�Mr,c��t�}d|j_tj|d�}|jdd�|j
d�|jddd�|j|j�d�y)	N�Qr rrrrrshttp://example.com:81/foo/bar�
rr��portrrrrrr&r�r(�drBs   r*�testPrePathURLNonDefaultz%RequestTests.testPrePathURLNonDefaultsm���N��������.�.��A�&�������+����!�������[�A�����+�+�-�/O�Pr,c��t�}d|j_tj|d�}|jdd�|j
d�|jddd�|j|j�d�y)	N�r rrrrrshttp://example.com:443/foo/barr#r%s   r*�testPrePathURLSSLPortz"RequestTests.testPrePathURLSSLPortsm���N��������.�.��A�&�������,����!�������[�A�����+�+�-�/P�Qr,c�D�t�}tj�|_d|j_t	j
|d�}|j
dd�|jd�|jddd�|j|j�d�y)	Nr)r rrrrrshttps://example.com/foo/bar�r�SSLr�r$rrrrrr&rr%s   r*�testPrePathURLSSLPortAndSSLz(RequestTests.testPrePathURLSSLPortAndSSL$s}���N��"�&�&�(���������.�.��A�&�������,����!�������[�A�����+�+�-�/M�Nr,c�D�t�}tj�|_d|j_t	j
|d�}|j
dd�|jd�|jddd�|j|j�d�y)	Nrr rrrrrshttps://example.com:80/foo/barr,r%s   r*�testPrePathURLHTTPPortAndSSLz)RequestTests.testPrePathURLHTTPPortAndSSL.�}���N��"�&�&�(���������.�.��A�&�������+����!�������[�A�����+�+�-�/P�Qr,c�D�t�}tj�|_d|j_t	j
|d�}|j
dd�|jd�|jddd�|j|j�d�y)	Nr"r rrrrrshttps://example.com:81/foo/barr,r%s   r*�testPrePathURLSSLNonDefaultz(RequestTests.testPrePathURLSSLNonDefault8r1r,c��t�}d|j_tj|d�}|jddd�|j
d�|jddd�|j|j�d�y)	Nr"r sfoo.comrrrrshttps://foo.com:81/foo/barr#r%s   r*�testPrePathURLSetSSLHostz%RequestTests.testPrePathURLSetSSLHostBso���N��������.�.��A�&�����
�B��*����!�������[�A�����+�+�-�/L�Mr,c���t�}tj|d�}|jdd�|j	d�|jddd�|j
|j�d�y	)
z
        L{Request.prePathURL} quotes special characters in the URL segments to
        preserve the original meaning.
        r rrrrs
/foo%2Fbarrshttp://example.com/foo%2FbarN)rrrrrrr&rr%s   r*�test_prePathURLQuotingz#RequestTests.test_prePathURLQuotingKsc��

�N���.�.��A�&�������+����!������
�{�C�����+�+�-�/N�Or,c��tj|t�}t�}t	j
|d�}t	jtj��|_	tjtd��}|j|�|jd|jj j#��|j%d|jj j#��|j'dt)|��|d}|d}|j+|j,t�|j'|j/�d�|j1dt)|j3���y)z�
        By default, L{Request.processingFailed} does not write out the failure,
        but give a generic error message, as L{Site.displayTracebacks} is
        disabled by default.
        r �Oh no!�Oh no!�Processing Failedr�log_failureN)r�createWithCleanuprrrrrrrrVr�Failure�	Exception�processingFailedr�r��writtenr�r��assertEquals�lenrn�value�getErrorMessager&�flushLoggedErrors�r(�logObserverr&rB�fail�event�fs       r*�)test_processingFailedNoTracebackByDefaultz6RequestTests.test_processingFailedNoTracebackByDefaultWs&��+�<�<�T�CU�V���N���.�.��A�&���{�{�8�#4�#4�#6�7������y��2�3��� � ��&�����G�$5�$5�$=�$=�$F�$F�$H�I��
�
�*�G�,=�,=�,E�,E�,N�,N�,P�Q����!�S��-�.��A����-� �����a�g�g�y�1����!�+�+�-�x�8�	
����C�� 6� 6� 8�9�:r,c�<�tj|t�}t�}t	j
|d�}t	jtj��|_	d|j_
tjtd��}|j|�|jd|j j"j%��|j'd|j j"j%��|j)dt+|��|d}|d}|j-|j.t�|j)|j1�d�|j3dt+|j5���y)	z�
        L{Request.processingFailed} when the site has C{displayTracebacks} set
        to C{False} does not write out the failure, but give a generic error
        message.
        r Fr9r:r;rr<N)rr=rrrrrrrrV�displayTracebacksrr>r?r@r�r�rAr�r�rBrCrnrDrEr&rFrGs       r*� test_processingFailedNoTracebackz-RequestTests.test_processingFailedNoTracebackrs2��+�<�<�T�CU�V���N���.�.��A�&���{�{�8�#4�#4�#6�7���).����&����y��2�3��� � ��&�����G�$5�$5�$=�$=�$F�$F�$H�I��
�
�*�G�,=�,=�,E�,E�,N�,N�,P�Q����!�S��-�.��A����-� �����a�g�g�y�1����!�+�+�-�x�8�	
����C�� 6� 6� 8�9�:r,c��tj|t�}t�}t	j
|d�}t	jtj��|_	d|j_
tjtd��}|j|�|jd|j j"j%��|d}|d}|j'|j(t�|j+|j-�d�|j/dt1|j3���y)z�
        L{Request.processingFailed} when the site has C{displayTracebacks} set
        to C{True} writes out the failure.
        r Tr9r:rr<N)rr=rrrrrrrrVrNrr>r?r@r�r�rAr�rnrDrBrEr&rCrFrGs       r*�%test_processingFailedDisplayTracebackz2RequestTests.test_processingFailedDisplayTraceback�s���
+�<�<�T�CU�V���N���.�.��A�&���{�{�8�#4�#4�#6�7���)-����&����y��2�3��� � ��&��
�
�i��!2�!2�!:�!:�!C�!C�!E�F��A����-� �����a�g�g�y�1����!�+�+�-�x�8�	
����C�� 6� 6� 8�9�:r,c��tj|t�}t�}t	j
|d�}t	jtj��|_	d|j_
tjtd��}|j|�|jd|j j"j%��|j't(�|d}|d}|j+|j,t�|j/dt1|j'���y)z�
        L{Request.processingFailed} when the site has C{displayTracebacks} set
        to C{True} writes out the failure, making UTF-8 items into HTML
        entities.
        r Tu☃s&#9731;rr<N)rr=rrrrrrrrVrNrr>r?r@r�r�rAr�rF�UnicodeErrorrnrDr&rCrGs       r*�3test_processingFailedDisplayTracebackHandlesUnicodez@RequestTests.test_processingFailedDisplayTracebackHandlesUnicode�s���+�<�<�T�CU�V���N���.�.��A�&���{�{�8�#4�#4�#6�7���)-����&����y��2�3��� � ��&��
�
�j�'�"3�"3�";�";�"D�"D�"F�G�	
���|�,��A����-� �����a�g�g�y�1�	
����C�� 6� 6� 8�9�:r,c���t�}tj�|_tj|d�}tj
t
j��|_g|_	|j�}|j|�|j|j�|j|jdj!d�dd�|jd��}|j|�|j|jdj!d�dd�|j|j�|j#|j$|j$�y)	z�
        L{Request.session} and L{Request.secure_session} should be two separate
        sessions with unique ids and different cookies.
        r r�=sTWISTED_SECURE_SESSIONT��forceNotSecure�TWISTED_SESSIONN)rr-r�rrrrrrV�sitepathr��assertIsNotNonerSrTr&�cookiesr��assertNotEqualrp)r(r&rB�
secureSessionrWs     r*�&test_sessionDifferentFromSecureSessionz3RequestTests.test_sessionDifferentFromSecureSession�s��

�N��"�&�&�(����.�.��A�&���{�{�8�#4�#4�#6�7�������*�*�,�
����]�+����
�,�,�-��������+�1�1�$�7��:�<U�V��$�$�D�$�9�����W�%��������+�1�1�$�7��:�<N�O�������'����G�K�K��):�):�;r,c��tjtj��}t	�}t	j
�|_tj|d�}||_g|_	|j|jd�|jd��}|j|j�|j|jd�|j�}|j|j�|j|d�|j||�|j|j|�y)z�
        On a L{Request}, the C{session} attribute retrieves the associated
        L{Session} only if it has been initialized.  If the request is secure,
        it retrieves the secure session.
        r NTrW)rrrrrr-r�rrVrZrarWr�rSrT�assertIsNot)r(rVr&rB�insecureSessionr^s      r*�test_sessionAttributez"RequestTests.test_sessionAttribute�s����{�{�8�,�,�.�/���N��"�&�&�(����.�.��A�&���������
�
�g�o�o�t�,�!�,�,�D�,�A������.�.�/��
�
�g�o�o�t�,��*�*�,�
����
�,�,�-������-������8��
�
�g�o�o�}�5r,c�H�tjtj��}t	�}tj
|d�}||_g|_|j�}|j|j�|j�}|j||�y)z�
        L{Request.getSession} creates the session object only once per request;
        if it is called twice it returns the identical result.
        r N)rrrrrrrVrZr�rSrTra)r(rVr&rB�session1�session2s      r*�test_sessionCachingz RequestTests.test_sessionCaching�s{��
�{�{�8�,�,�.�/���N���.�.��A�&���������%�%�'��������(��%�%�'���
�
�h��)r,c�~�tjtj��}t	�}tj
|d�}||_g|_tj|d�}||j|j<|j|jd<|j|j�|�y)z�
        L{Request.getSession} retrieves an existing session if the relevant
        cookie is set in the incoming request.
        r s
special-idrYN)rrrrrrrVrZror�rp�received_cookiesrar�)r(rVr&rB�	mySessions     r*�test_retrieveExistingSessionz)RequestTests.test_retrieveExistingSession�s���
�{�{�8�,�,�.�/���N���.�.��A�&���������N�N�4��7�	�'0��
�
�i�m�m�$�7@�}�}�� � �!3�4��
�
�g�(�(�*�I�6r,c���tjtj��}t	�}tj
|d�}||_g|_d|jd<|j�}|j|�|j|j�|j|jdjd��|j!d|jd�y)z�
        L{Request.getSession} generates a new session if the session ID
        advertised in the cookie from the incoming request is not found.
        r sdoes-not-existrYrsTWISTED_SESSION=N)rrrrrrrVrZrir�r[rSrTr�r\r�r�)r(rVr&rBrWs     r*�test_retrieveNonExistentSessionz,RequestTests.test_retrieveNonExistentSessions���
�{�{�8�,�,�.�/���N���.�.��A�&��������7H�� � �!3�4��$�$�&�����W�%�������'��������*�5�5�6I�J�K����*�G�O�O�A�,>�?r,c����t��tjtj��}t�}tj|d�}||_g|_��fd�}|j�||_	|j�}�j�j�|j�}|j|j�|j||�|j!|j"|j"�y)zn
        L{Request.getSession} generates a new session when the previous
        session has expired.
        r c�(���||�}�|_|S)ap
            Forward to normal session factory, but inject the clock.

            @param site: The site on which the session is created.
            @type site: L{server.Site}

            @param uid: A unique identifier for the session.
            @type uid: C{bytes}

            @return: A newly created session.
            @rtype: L{server.Session}
            )r�)rVrprWr��sessionFactorys   ��r*�sessionFactoryWithClockzDRequestTests.test_getSessionExpired.<locals>.sessionFactoryWithClock*s���%�T�3�/�G�$�G���Nr,N)r
rrrrrrrVrZrpr�r�r�rSrTrar]rp)	r(rVr&rBrq�initialSession�
newSessionr�rps	       @@r*�test_getSessionExpiredz#RequestTests.test_getSessionExpireds����
����{�{�8�,�,�.�/���N���.�.��A�&��������	�$�,�,��5��� �+�+�-��	�
�
�n�3�3�4��'�'�)�
����
�)�)�*������4����N�.�.�
���?r,c�\�t�}tj|d�}|jdd�|j	d�|jddd�|jjj�}|j|jd��|jd	|�y
)zf
        L{Request} handles OPTIONS * requests by doing a fast-path return of
        200 OK.
        r rrrsOPTIONS�*�HTTP/1.1sHTTP/1.1 200 OK�Content-Length: 0
N�rrrrrrr�rAr�r�r�r��r(r&rB�responses    r*�test_OPTIONSStarzRequestTests.test_OPTIONSStarJs���

�N���.�.��A�&�������+����!�����
�D�+�>��;�;�&�&�/�/�1������+�+�,>�?�@��
�
�.��9r,c��t�}tj|d�}|jdd�|j	d�|jddd�|jjj�}|j|jd��|jd	|�|jd
|�y)z�
        L{Request} handles any non-OPTIONS verb requesting the * path by doing
        a fast-return 405 Method Not Allowed, indicating only the support for
        OPTIONS.
        r rrrrrvrwsHTTP/1.1 405 Method Not AllowedrxsAllow: OPTIONS
Nryrzs    r*�test_rejectNonOPTIONSStarz&RequestTests.test_rejectNonOPTIONSStarYs���
�N���.�.��A�&�������+����!�������k�:��;�;�&�&�/�/�1������+�+�,N�O�P��
�
�.��9��
�
�+�X�6r,c��t�}|jd|�tj|�}t	�}||_tj|d�}||_|jdd�|jd�|jddd�|jd	|jjj�j��y
)zV
        Responses with no length do not have a default content-type applied.
        r,r rrrr�/rwr8N)rFrZrrrrVrrrrr�r�rAr�r�)r(r�rVr&rBs     r*�-test_noDefaultContentTypeOnZeroLengthResponsez:RequestTests.test_noDefaultContentTypeOnZeroLengthResponsejs���#�$��
���s�E�"��{�{�5�!���N������.�.��A�&����������+����!�������k�:�����'�*;�*;�*C�*C�*L�*L�*N�*T�*T�*V�Wr,c��t�}|jd|�tj|�}t	�}||_tj|d�}||_|jdd�|jd�|jddd�|jjj�}|j|jd	��|jd
|j!��y)zX
        Responses with a 204 status code have no default content-type applied.
        r,r rrrrr�rwsHTTP/1.1 204 No Content
r8N)rKrZrrrrVrrrrr�rAr�r�r�r�r�)r(r�rVr&rBr{s      r*�&test_noDefaultContentTypeOn204Responsez3RequestTests.test_noDefaultContentTypeOn204Response{s���"�#��
���s�E�"��{�{�5�!���N������.�.��A�&����������+����!�������k�:��$�$�,�,�5�5�7������+�+�,J�K�L�����(�.�.�*:�;r,c��tjt��}|jd�|j	|j
t�y)z�
        L{http.Request} creates a L{BytesIO} if the content length is small and
        the site doesn't offer to create one.
        i��N)rrrrrn�contentrrAs  r*�test_defaultSmallContentFilez)RequestTests.test_defaultSmallContentFile�s6��
�.�.���0�����*�%����g�o�o�w�7r,c��tjt��}|jd�t	||j
�y)z�
        L{http.Request} creates a temporary file on the filesystem if the
        content length is larger and the site doesn't offer to create one.
        i��N�rrrrr!r�rAs  r*�test_defaultLargerContentFilez*RequestTests.test_defaultLargerContentFile�s0��
�.�.���0�����&�!�#�D�'�/�/�:r,c��tjt��}|jd�t	||j
�y)z�
        L{http.Request} creates a temporary file on the filesystem if the
        content length is not known and the site doesn't offer to create one.
        Nr�rAs  r*�"test_defaultUnknownSizeContentFilez/RequestTests.test_defaultUnknownSizeContentFile�s0��
�.�.���0�����$��#�D�'�/�/�:r,c�T���g�t��tjtj��}��fd�}||_t
�}||_tj|�}|jd�|jdg��|j�|j�y)z�
        L{http.Request} uses L{Site.getContentFile}, if it exists, to get a
        file-like object for the request content.
        c�*���j|��Sr%)�append)�length�contentFile�lengthss ��r*�getContentFilezARequestTests.test_siteSuppliedContentFile.<locals>.getContentFile�s����N�N�6�"��r,�90N)
rrrrrr�rrVrrr&rar�)r(rVr�rkrBr�r�s     @@r*�test_siteSuppliedContentFilez)RequestTests.test_siteSuppliedContentFile�s����
���i���{�{�8�,�,�.�/��	�-����.������.�.��)�����%� ����%��'�*��
�
�k�7�?�?�3r,N)!r-r.r/rDrrrr r'r*r.r0r3r5r7rLrOrQrTr_rcrgrkrmrtr|r~r�r�r�r�r�r�r0r,r*rr�s����
��<�N�Q�R�O�R�R�N�
P�;�6;�8;�0;�<<�(6�,
*�
7�@�$*@�X
:�7�"X�"<�&8�;�;�4r,rc�<�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�GzipEncoderTestsc���t�|_tdd�}tj|tj�g�}|jjjjd|�y)N�	Some dataz
text/plain�foo)	rrkrr�EncodingResourceWrapperr�GzipEncoderFactoryrVrZ)r(�staticResource�wrappeds   r*r�zGzipEncoderTests.setUp�sZ��#�~����l�L�9���2�2��V�6�6�8�9�
��	
�����"�"�+�+�F�G�<r,c��tj|jd�}|jd�|jjddg�tj�}|jttj|��|j|�}|jttj|��y)z�
        L{server.GzipEncoderFactory} implements the
        L{iweb._IRequestEncoderFactory} and its C{encoderForRequest} returns an
        instance of L{server._GzipEncoder} which implements
        L{iweb._IRequestEncoder}.
        Fr�Accept-Encoding�gzip,deflateN)
rrrkr�requestHeadersr=r�r�rr�_IRequestEncoderFactory�encoderForRequest�_IRequestEncoder)r(rB�factory�encoders    r*�test_interfacesz GzipEncoderTests.test_interfaces�s����.�.����u�5�����!�����,�,�-?�/�AR�S��+�+�-������T�%A�%A�7�K�L��+�+�G�4������T�%:�%:�G�D�Er,c��tj|jd�}|jd�|jjddg�|j
ddd�|jjjj�}|jd|�|jd	|�||jd
�dzd}|jd
tj|dtj z��y)z�
        If the client request passes a I{Accept-Encoding} header which mentions
        gzip, L{server._GzipEncoder} automatically compresses the data.
        Frr�r�r�/foor�Content-Length�Content-Encoding: gzip
r��Nr���rrrkrr�r=rr�rAr�r�r��findr&�zlib�
decompress�	MAX_WBITS�r(rB�data�bodys    r*�
test_encodingzGzipEncoderTests.test_encoding�s���
�.�.����u�5�����!�����,�,�-?�/�AR�S�������=��|�|�%�%�-�-�6�6�8�����*�D�1��
�
�3�T�:��D�I�I�k�*�Q�.�0�1������t���t�R�$�.�.�=P�'Q�Rr,c��tj|jd�}|jd�|jjddg�|j
ddd�|jjjj�}|jd|�|jd	|�||jd
�dzd}|jd
tj|dtj z��y)z�
        If the client request passes a I{Accept-Encoding} header which mentions
        gzip, with whitespace inbetween the encoding name and the commas,
        L{server._GzipEncoder} automatically compresses the data.
        Frr�s
deflate, gziprr�rr�r�r�r�Nr�r�r�r�s    r*�test_whitespaceInAcceptEncodingz0GzipEncoderTests.test_whitespaceInAcceptEncoding�s����.�.����u�5�����!�����,�,�-?�BR�AS�T�������=��|�|�%�%�-�-�6�6�8�����*�D�1��
�
�3�T�:��D�I�I�k�*�Q�.�0�1������t���t�R�$�.�.�=P�'Q�Rr,c��tj|jd�}|jd�|jjddg�|j
ddd�|jjjj�}|jd|�|jd	|�||jd
�dzd}|jd
|�y)z�
        L{server.GzipEncoderFactory} doesn't return a L{server._GzipEncoder} if
        the I{Accept-Encoding} header doesn't mention gzip support.
        Frr�sfoo,barrr�rr�r�r�r�Nr�)rrrkrr�r=rr�rAr�r�r�r�r&r�s    r*�test_nonEncodingz!GzipEncoderTests.test_nonEncoding�s���
�.�.����u�5�����!�����,�,�-?�*��N�������=��|�|�%�%�-�-�6�6�8���
�
�'��.����6��=��D�I�I�k�*�Q�.�0�1������t�,r,c��tj|jd�}|jd�|jjdddg�|j
ddd�|jjjj�}|jd	|�|jd
|�||jd�dzd
}|jdtj|dtj z��y
)z�
        If there are multiple I{Accept-Encoding} header,
        L{server.GzipEncoderFactory} reads them properly to detect if gzip is
        supported.
        Frr��deflate�gziprr�rr�r�r�r�Nr�r�r�r�s    r*�test_multipleAcceptz$GzipEncoderTests.test_multipleAccepts����.�.����u�5�����!�����,�,�-?�*�g�AV�W�������=��|�|�%�%�-�-�6�6�8�����*�D�1��
�
�3�T�:��D�I�I�k�*�Q�.�0�1������t���t�R�$�.�.�=P�'Q�Rr,c�B�tj|jd�}|jd�|jjdddg�|jjddg�|jddd	�|jjjj�}|jd
|�|jd|�||jd�d
zd}|jdtj |dtj"z��y)z�
        If the content is already encoded and the I{Content-Encoding} header is
        set, L{server.GzipEncoderFactory} properly appends gzip to it.
        Frr�r�r��Content-Encodingrr�rr�s Content-Encoding: deflate,gzip
r�r�Nr�r��rrrkrr�r=r<rr�rAr�r�r�r�r&r�r�r�r�s    r*�test_alreadyEncodedz$GzipEncoderTests.test_alreadyEncodeds���
�.�.����u�5�����!�����,�,�-?�*�g�AV�W����-�-�.A�J�<�P�������=��|�|�%�%�-�-�6�6�8�����*�D�1��
�
�;�T�B��D�I�I�k�*�Q�.�0�1������t���t�R�$�.�.�=P�'Q�Rr,c�D�tj|jd�}|jd�|jjdddg�|jjdddg�|jd	d
d�|jjjj�}|jd|�|jd
|�||jd�dzd}|jdtj |dtj"z��y)z�
        If there are several I{Content-Encoding} headers,
        L{server.GzipEncoderFactory} normalizes it and appends gzip to the
        field value.
        Frr�r�r�r�r��barrr�rr�s Content-Encoding: foo,bar,gzip
r�r�Nr�r�r�r�s    r*�test_multipleEncodingLinesz+GzipEncoderTests.test_multipleEncodingLines(s����.�.����u�5�����!�����,�,�-?�*�g�AV�W����-�-�.A�F�F�CS�T�������=��|�|�%�%�-�-�6�6�8�����*�D�1��
�
�;�T�B��D�I�I�k�*�Q�.�0�1������t���t�R�$�.�.�=P�'Q�Rr,N)r-r.r/r�r�r�r�r�r�r�r�r0r,r*r�r��s0��=�F� 
S�S� 
-�S� S� Sr,r�c��eZdZdZd�Zd�Zy)�RootResourcerc�d�|j�tjj|||�Sr%)�rememberRootURLrr�getChildWithDefault�r(�namerBs   r*r�z RootResource.getChildWithDefault=s)�����!�� � �4�4�T�4��I�Ir,c��y)N�r0rAs  r*rCzRootResource.renderAs��r,N)r-r.r/�isLeafr�rCr0r,r*r�r�:s��
�F�J�r,r�c�"�eZdZdZd�Zd�Zd�Zy)�RememberURLTestszB
    Tests for L{server.Site}'s root request URL calculation.
    c�N�t�}tj|�|_|S)a
        Create a L{server.Site} bound to a L{DummyChannel} and the
        given resource as its root.

        @param r: The root resource.
        @type r: L{resource.Resource}

        @return: The channel to which the site is bound.
        @rtype: L{DummyChannel}
        )rrrrV)r(r)�chans   r*�createServerzRememberURLTests.createServerJs���~���K�K��N��	��r,c���tj�}d|_t�}|j	d|�|j	d|�|j	dtj��|j|�}dD]n}t
j|d�}|jdd�|jd�|jd	|d
�|j|j�d��py)
z�
        The path component of the root URL of a L{server.Site} whose
        root resource is below C{/} is that resource's path, and the
        netloc component is the L{site.Server}'s own host and port.
        rr�r,r�)s/foo/rs/foo/bar/bazrr rr"rrshttp://example.com:81/fooN)
rrr�r�rZr�rrrrrr&�
getRootURL)r(r)�rrr��urlrBs      r*�
testSimplezRememberURLTests.testSimpleYs���
��������
�^��	�
�
�6�2��
���C���
���F�H�-�-�/�0�� � ��#��I�	Q�C��n�n�T�1�-�G��O�O�N�B�/����a� ��#�#�F�C��=����W�/�/�1�3O�P�	Qr,c��t�}|jd|�|jdtj��|j	|�}dD]n}tj|d�}|jdd�|jd�|jd|d	�|j|j�d
��py)z�
        The path component of the root URL of a L{server.Site} whose
        root resource is at C{/} is C{/}, and the netloc component is
        the L{site.Server}'s own host and port.
        r,r�)r�s/bars/bar/bazs/bar/r rr"rrrshttp://example.com:81/N)r�rZrrr�rrrrrr&r�)r(r�r�r�rBs     r*�testRootzRememberURLTests.testRootms����^��
���C���
���F�H�-�-�/�0�� � ��$��9�	N�C��n�n�T�1�-�G��O�O�N�B�/����a� ��#�#�F�C��=����W�/�/�1�3L�M�	Nr,N)r-r.r/rDr�r�r�r0r,r*r�r�Es���
�Q�(Nr,r�c��eZdZd�Zd�Zy)�NewRenderResourcec��y)N�hi hir0rAs  r*�
render_GETzNewRenderResource.render_GET����r,c��y)N�ho hor0rAs  r*�
render_HEHzNewRenderResource.render_HEH�r�r,N)r-r.r/r�r�r0r,r*r�r�s���r,r�c�.�eZdZdZdgZd�Zd�Zd�Zd�Zy)�HeadlessResourcez6
    A resource that implements GET but not HEAD.
    rc���||_|j|jvrtj|j��|jjd�tjS)z;
        Leave the request open for future writes.
        s	some data)rB�method�allowedMethodsr�UnsupportedMethod�writerrrAs  r*rCzHeadlessResource.render�sR������>�>��!4�!4�4��)�)�$�*=�*=�>�>������<�(��"�"�"r,c��t��)z$
        # IResource.isLeaf
        ��NotImplementedErrorr�s r*r�zHeadlessResource.isLeaf��
��"�#�#r,c��t��)z1
        # IResource.getChildWithDefault
        r�r�s   r*r�z$HeadlessResource.getChildWithDefault�r�r,c��t��)z&
        # IResource.putChild
        r�)r(�path�childs   r*rZzHeadlessResource.putChild�r�r,N)	r-r.r/rDr�rCr�r�rZr0r,r*r�r��s$����X�N�#�$�$�$r,r�c�<�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
y)�NewRenderTestsz-
    Tests for L{server.Request.render}.
    Nc��t�}|�
t�}|jjj	d|�d|j
_tj|d�}|jdd�|jd�|S)z�
        Create a request object with a stub channel and install the
        passed resource at /newrender. If no resource is passed,
        create one.
        s	newrenderr"r rr)rr�rVrrZr�r$rrrr)r(rr&rBs    r*�_getReqzNewRenderTests._getReq�sn��
�N����(�*�H�	����� � ��x�8�������.�.��A�&�������+����!���r,c��|j�}|jddd�|j|jjj�j
�dd�|j�}|jddd�|j|jjj�j
�dd�y)Nr�
/newrenderr���r��HEHr�)r�rr&r�rAr��
splitlines�r(�reqs  r*�testGoodMethodszNewRenderTests.testGoodMethods�s����l�l�n�����F�M�;�?�������.�.�7�7�9�D�D�F�r�J�H�U��l�l�n�����F�M�;�?�������.�.�7�7�9�D�D�F�r�J�H�Ur,c��|j�}|jddd�|j|jd�|j�}|jddd�|j|jd�y)NsCONNECTr�r�s	hlalauguG)r�rr&�coder�s  r*�testBadMethodszNewRenderTests.testBadMethods�sd���l�l�n�����J�
�{�C�������3�'��l�l�n�����L�-��E�������3�'r,c�|�|j�}|jddd�|j|jd�|j	|j
j
d��|j
jd�d}td�|jd�D��}|jgd	�|�y
)z�
        When trying to invoke a method not in the allowed method list, we get
        a response saying it is not allowed.
        �POSTr�r��allowrc3�<K�|]}|j����y�wr%)r�)�.0�hs  r*�	<genexpr>z7NewRenderTests.test_notAllowedMethod.<locals>.<genexpr>�s����C�q�����C�s��,)r�HEADr�N)
r�rr&rr�r<�	hasHeader�
getRawHeaders�sortedr�)r(r��
raw_header�alloweds    r*�test_notAllowedMethodz$NewRenderTests.test_notAllowedMethod�s���
�l�l�n�����G�]�K�@�������3�'�����+�+�5�5�h�?�@��(�(�6�6�x�@��C�
��C�J�,<�,<�T�,B�C�C�����2�G�<r,c���tj|t�}|j�}|j	ddd�|j|jd�|jd|jjj�jd��|jdt|��|d}|j|d	tj�y)
Nr
r�r��r�r�r r�	log_level)rr=rr�rr&rr�rAr�r�rBrCr
�info)r(rHr�rJs    r*�testImplicitHeadzNewRenderTests.testImplicitHead�s���*�<�<�T�CU�V���l�l�n�����G�]�K�@�������3�'�����S�]�]�2�2�;�;�=�B�B�8�L�M����!�S��-�.��A������%��,�h�m�m�<r,c��tj|t�}t�}|j	|�}|jddd�|jjj�jd�\}}|j|jd�|j|d�|jdt|��y)	z�
        HEAD requests against resource that only claim support for GET
        should not include a body in the response.
        r
r�rr�rr,r|N)rr=rr�r�rr�rAr�r�r&rrBrC)r(rHrr�r�r�s      r*�test_unsupportedHeadz#NewRenderTests.test_unsupportedHead�s���
+�<�<�T�CU�V��#�%���l�l�8�$�����G�]�K�@��
�
�-�-�6�6�8�>�>�{�K�
���������3�'�����s�#����!�S��-�.r,c�,��Gd�d�}|��tj�}�fd�|_|j|�}|j	ddd�|j
jj�jd�\}}|j|jd�d	d
ddd
dtj|�dd�dtj|�dd�d�ddd	g	}|jdj|�jd�|�y)zw
        When implemented C{render} method does not return bytes an internal
        server error is returned.
        c��eZdZdefd�Zy)�5NewRenderTests.test_noBytesResult.<locals>.RiggedRepr�returnc��y)Nzmy>reprr0r�s r*�__repr__z>NewRenderTests.test_noBytesResult.<locals>.RiggedRepr.__repr__s�� r,N)r-r.r/�strr r0r,r*�
RiggedReprrs��
!�#�
!r,r"c����Sr%r0)rBr�s �r*r�z3NewRenderTests.test_noBytesResult.<locals>.<lambda>s���6�r,rr�rr�i�r�z<html>z@  <head><title>500 - Request did not return bytes</title></head>z  <body>z)    <h1>Request did not return bytes</h1>z    <p>Request: <pre>&lt;r r�z#&gt;</pre><br />Resource: <pre>&lt;z0&gt;</pre><br />Value: <pre>my&gt;repr</pre></p>z	  </body>z</html>�
�asciiN)rrrCr�rr�rAr�r�r&rr�	safe_repr�joinrx)r(r"�no_bytes_resourcerBr�r��expectedr�s       @r*�test_noBytesResultz!NewRenderTests.test_noBytesResult�s���	!�	!����$�-�-�/��#9�� ��,�,�0�1������
�{�C��)�)�1�1�:�:�<�B�B�;�O�
���������s�+���N��7�
�!�!�'�*�1�R�0��!�!�"3�4�Q�r�:�
�
���
��"	
������8�,�3�3�G�<�d�Cr,r%)r-r.r/rDr�r�rrrrr*r0r,r*r�r��s,���� V�(�=�
=�/� $Dr,r�c��eZdZdZd�Zd�Zy)�GettableResourcezD
    Used by AllowedMethodsTests to simulate an allowed method.
    c��yr%r0r�s r*r�zGettableResource.render_GET(s��r,c��y)z�
        The unusual method name is designed to test the culling method
        in C{twisted.web.resource._computeAllowedMethods}.
        Nr0r�s r*�render_fred_render_ethelz)GettableResource.render_fred_render_ethel+s��
	
r,N)r-r.r/rDr�r/r0r,r*r,r,#s���
�
r,r,c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�AllowedMethodsTestsz�
    'C{twisted.web.resource._computeAllowedMethods} is provided by a
    default should the subclass not provide the method.
    c�
�t�}|jjjdt	��d|j
_tj|d�}|jdd�|jd�|S)zU
        Generate a dummy request for use by C{_computeAllowedMethod} tests.
        sgettableresourcer"r rr)rrVrrZr,r�r$rrrrr%s   r*r�zAllowedMethodsTests._getReq9se��
�N��	����� � �!4�6F�6H�I�������.�.��A�&�������+����!���r,c�|�t�}tj|�}|jt	|�hd��y)a3
        C{_computeAllowedMethods} will search through the
        'gettableresource' for all attributes/methods of the form
        'render_{method}' ('render_GET', for example) and return a list of
        the methods. 'HEAD' will always be included from the
        resource.Resource superclass.
        ��fred_render_ethelrr
N)r,r�_computeAllowedMethodsr&�set)r(�resr�s   r*�test_computeAllowedMethodsz.AllowedMethodsTests.test_computeAllowedMethodsEs2��� ��!�8�8��=������^�,�.U�Vr,c��|j�}|jddd�|j|jd�|jt	|j
j
d�djd��hd��y	)
a7
        When an unsupported method is requested, the default
        L{_computeAllowedMethods} method will be called to determine the
        allowed methods, and the HTTP 405 'Method Not Allowed' status will
        be returned with the allowed methods will be returned in the
        'Allow' header.
        r�/gettableresourcerrrrs, r4N)r�rr&rr7r<rr�r�s  r*�test_notAllowedz#AllowedMethodsTests.test_notAllowedQsp���l�l�n�����G�%9�;�G�������3�'������#�#�1�1�(�;�A�>�D�D�U�K�L�3�	
r,c��|j�}|jddd�|j|jd�|jj
j
�}|jd|�|jd|�y)a
        When an unsupported method response is generated, an HTML message will
        be displayed.  That message should include a quoted form of the URI and,
        since that value come from a browser and shouldn't necessarily be
        trusted.
        rs#/gettableresource?value=<script>badrrs<script>bads&lt;script&gt;badN�	r�rr&rr�rAr�r�r��r(r��renderedPages   r*�test_notAllowedQuotingz*AllowedMethodsTests.test_notAllowedQuotingasr���l�l�n������?��	
�	
������3�'��}�}�,�,�5�5�7�������6��
�
�*�L�9r,c��|j�}|jddd�|j|jd�|jj
j
�}|jd|�|jd|�y)a
        When an not-implemented method response is generated, an HTML message
        will be displayed.  That message should include a quoted form of the
        requested method, since that value come from a browser and shouldn't
        necessarily be trusted.
        s
<style>badr;rrs&lt;style&gt;badNr>r?s   r*�test_notImplementedQuotingz.AllowedMethodsTests.test_notImplementedQuotingqsm���l�l�n�����M�+?��M�������3�'��}�}�,�,�5�5�7�������5��
�
�)�<�8r,N)	r-r.r/rDr�r9r<rArCr0r,r*r1r13s!���

�
W�
� :� 9r,r1c�6�eZdZdZdZdZdZeddd�Zd�Z	y)	�DummyRequestForLogTests/dummy�{rN�TCP�1.2.3.4r�c��td��)zS
        As L{getClientIP} is deprecated, no log formatter should call it.
        zDCall to deprecated getClientIP method (use getClientAddress instead)r�r�s r*�getClientIPz"DummyRequestForLogTest.getClientIP�s��"�U�
�	
r,)
r-r.r/�urir�clientproto�
sentLengthr�clientrJr0r,r*rErE�s)��
�C��D��K��J�
��	�5�
1�F�
r,rEc�"�eZdZdZd�Zd�Zd�Zy)�AccessLogTestsMixinzp
    A mixin for L{TestCase} subclasses defining tests that apply to
    L{HTTPFactory} and its subclasses.
    c��td��)zq
        Get the factory class to apply logging tests to.

        Subclasses must override this method.
        z#Subclass failed to override factoryr��r(�args�kwargss   r*r�zAccessLogTestsMixin.factory�s��"�"G�H�Hr,c�r�t�}|jd�|j�}|j||��}|j	�	|jt
|��|j�|jdt|�j��y#|j�wxYw)zu
        The factory's C{log} method writes a I{combined log format} line to the
        factory's log file.
        ���I)�logPathr�sO"1.2.3.4" - - [13/Feb/2009:23:31:30 +0000] "GET /dummy HTTP/1.0" 123 - "-" "-"
N)r
r��mktempr�r��logrEr�r&r�
getContent)r(r�rWr�s    r*�test_combinedLogFormatz*AccessLogTestsMixin.test_combinedLogFormat�s���
�'��	���
�#��+�+�-���,�,�w��,�@������	"��K�K�.�w�7�8����!����
�
�W��(�(�*�#	
��
���!�s�B$�$B6c��d�}t�}|jd�|j�}|j||��}||_|j�	|j
t|��|j�|jdt|�j��y#|j�wxYw)z�
        If the factory is initialized with a custom log formatter then that
        formatter is used to generate lines for the log file.
        c��y)Nzthis is a bad log formatr0)�	timestamprBs  r*�notVeryGoodFormatterzHAccessLogTestsMixin.test_logFormatOverride.<locals>.notVeryGoodFormatter�s��-r,rV)rW�logFormattersthis is a bad log format
N)r
r�rXr�r�r�rYrEr�r&rrZ)r(r_r�rWr�s     r*�test_logFormatOverridez*AccessLogTestsMixin.test_logFormatOverride�s���	.��'�����
�#��+�+�-���,�,�w�=Q�,�R��"�������	"��K�K�.�w�7�8����!����6���8I�8T�8T�8V�W��
���!�s�B.�.CN)r-r.r/rDr�r[rar0r,r*rPrP�s���
I�&
�PXr,rPc�(�eZdZdZej
Zy)�HTTPFactoryAccessLogTestsz,
    Tests for L{http.HTTPFactory.log}.
    N)r-r.r/rDr�HTTPFactoryr�r0r,r*rcrc�s������Gr,rcc��eZdZdZd�Zy)�SiteAccessLogTestsz'
    Tests for L{server.Site.log}.
    c�X�tjtj�g|��i|��Sr%)rrrrrRs   r*r�zSiteAccessLogTests.factory�s$���{�{�8�,�,�.�@��@��@�@r,N)r-r.r/rDr�r0r,r*rfrf�s
���Ar,rfc�(�eZdZdZd�Zd�Zd�Zd�Zy)�CombinedLogFormatterTestsz=
    Tests for L{twisted.web.http.combinedLogFormatter}.
    c�r�|jttjtj
��y)zJ
        L{combinedLogFormatter} provides L{IAccessLogFormatter}.
        N)r�rr�IAccessLogFormatterr�combinedLogFormatterr�s r*rz(CombinedLogFormatterTests.test_interface�s&��	
�����1�1�4�3L�3L�M�	
r,c��t�}|jd�tj|j	��}ttj|���}tddd�|_d|_	d|_
|jjdd	�|jjd
d�tj||�}|jd|�y
)zo
        Bytes in fields of the request which are not part of ASCII are escaped
        in the result.
        rVr�rGsevil x-forwarded-for �r�sPOS�sHTTP/1.��referersevil ��
user-agentsevil �zt"evil x-forwarded-for \x80" - - [13/Feb/2009:23:31:30 +0000] "POS\x81 /dummy HTTP/1.0" 123 - "evil \x83" "evil \x84"N)r
r�r�datetimeToLogString�secondsrErdrrNr��protocolr��addRawHeaderrlr&�r(r�r^rBr�s     r*�
test_nonASCIIz'CombinedLogFormatterTests.test_nonASCII�s���
�'�����
�#��,�,�W�_�_�->�?�	�(��)9�)9�'�)J�K��$�U�,H�%�P���#���)������+�+�J��E����+�+�M�<�H��(�(��G�<�����
I��	
r,c�2�t�}|jd�tj|j	��}ttj|���}tddd�|_tj||�}|jd|�y)zO
        A request from an IPv6 client is logged with that IP address.
        rVr�rGs::1r�zJ"::1" - - [13/Feb/2009:23:31:30 +0000] "GET /dummy HTTP/1.0" 123 - "-" "-"N)r
r�rrprqrErdr	rNrlr&rts     r*�test_clientAddrIPv6z-CombinedLogFormatterTests.test_clientAddrIPv6s{���'�����
�#��,�,�W�_�_�->�?�	�(��)9�)9�'�)J�K��$�U�F�E�:����(�(��G�<�����
2��	
r,c��ttj�Gd�d��}t�}|j	d�tj|j��}ttj|���}|�|_
tj||�}|j|jd��y)zR
        A request made from an unknown address type is logged as C{"-"}.
        c��eZdZdZy)�KCombinedLogFormatterTests.test_clientAddrUnknown.<locals>.UnknowableAddresszp
            An L{IAddress} which L{combinedLogFormatter} cannot have
            foreknowledge of.
            N)r-r.r/rDr0r,r*�UnknowableAddressrz+s��
r,r{rVr�z"-" N)rr�IAddressr
r�rrprqrErdrNrlr�r�)r(r{r�r^rBr�s      r*�test_clientAddrUnknownz0CombinedLogFormatterTests.test_clientAddrUnknown&s���

�Z�(�(�	)�	�	�
*�	��'�����
�#��,�,�W�_�_�->�?�	�(��)9�)9�'�)J�K��*�,����(�(��G�<���������/�0r,N)r-r.r/rDrrurwr}r0r,r*riri�s���
�
�.
�$1r,ric�(�eZdZdZd�Zd�Zd�Zd�Zy)�ProxiedLogFormatterTestsz<
    Tests for L{twisted.web.http.proxiedLogFormatter}.
    c�r�|jttjtj
��y)zI
        L{proxiedLogFormatter} provides L{IAccessLogFormatter}.
        N)r�rrrkr�proxiedLogFormatterr�s r*rz'ProxiedLogFormatterTests.test_interfaceBs&��	
�����1�1�4�3K�3K�L�	
r,c��t�}|jd�tj|j	��}ttj|���}tj||�jdd�}|jjd|g�tj||�}|j||�y)a�
        Assert that a request with the given value in its I{X-Forwarded-For}
        header is logged by L{proxiedLogFormatter} the same way it would have
        been logged by L{combinedLogFormatter} but with 172.16.1.2 as the
        client address instead of the normal value.

        @param header: An I{X-Forwarded-For} header with left-most address of
            172.16.1.2.
        rVr�rHz
172.16.1.2sx-forwarded-forN)
r
r�rrprqrErdrl�replacer�r=r�r&)r(r�r�r^rBr)r�s       r*�_xforwardedforTestz+ProxiedLogFormatterTests._xforwardedforTestJs����'�����
�#��,�,�W�_�_�->�?�	�(��)9�)9�'�)J�K���,�,�Y��@�H�H��|�
��	���,�,�-?�&��J��'�'�	�7�;������4�(r,c�&�|jd�y)z�
        L{proxiedLogFormatter} logs the value of the I{X-Forwarded-For} header
        in place of the client address field.
        s!172.16.1.2, 10.0.0.3, 192.168.1.4N�r�r�s r*�test_xforwardedforz+ProxiedLogFormatterTests.test_xforwardedforas��
	
��� D�Er,c�&�|jd�y)z�
        Any extra spaces around the address in the I{X-Forwarded-For} header
        are stripped and not included in the log string.
        s# 172.16.1.2 , 10.0.0.3, 192.168.1.4Nr�r�s r*�test_extraForwardedSpacesz2ProxiedLogFormatterTests.test_extraForwardedSpaceshs��
	
��� F�Gr,N)r-r.r/rDrr�r�r�r0r,r*rr=s���
�)�.F�Hr,rc�<�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�LogEscapingTestsc���|j�|_tj|j�|_|jj�t
|jd�|_y)NF)rXrWrrdrVr�rErBr�s r*r�zLogEscapingTests.setUpqsG���{�{�}����$�$�T�\�\�2��	��	�	��� �-�d�i�i��?��r,c�,�	|jj|j�|jj�t	|j
�j
�}|j||�y#|jj�wxYw)aF
        Assert that if C{self.request} is logged using C{self.site} then
        C{line} is written to the site's access log file.

        @param line: The expected line.
        @type line: L{bytes}

        @raise self.failureException: If the log file contains something other
            than the expected line.
        N)rVrYrBr�rrWrZr&)r(r��loggeds   r*�
assertLogszLogEscapingTests.assertLogswsf��	$��I�I�M�M�$�,�,�'��I�I�!�!�#��$�,�,�'�2�2�4������v�&��
�I�I�!�!�#�s�%A7�7Bc�N�ddz|j_|jd�y)zC
        A I{GET} request is logged with no extra escapes.
        �#[%02d/%3s/%4d:%02d:%02d:%02d +0000]���Octi����;sO"1.2.3.4" - - [25/Oct/2004:12:31:59 +0000] "GET /dummy HTTP/1.0" 123 - "-" "-"
N)rV�_logDateTimer�r�s r*�test_simplezLogEscapingTests.test_simple�s/��"G�J
�"
��	�	��	
���
5�	
r,c�p�ddz|j_d|j_|j	d�y)zT
        If the HTTP request method includes a quote, the quote is escaped.
        r�r�sG"TsP"1.2.3.4" - - [25/Oct/2004:12:31:59 +0000] "G\"T /dummy HTTP/1.0" 123 - "-" "-"
N)rVr�rBr�r�r�s r*�test_methodQuotez!LogEscapingTests.test_methodQuote�s;��"G�J
�"
��	�	��%��������
7�	
r,c�p�ddz|j_d|j_|j	d�y)zR
        If the HTTP request path includes a quote, the quote is escaped.
        r�r�s/dummy"withquotesZ"1.2.3.4" - - [25/Oct/2004:12:31:59 +0000] "GET /dummy\"withquote HTTP/1.0" 123 - "-" "-"
N)rVr�rBrKr�r�s r*�test_requestQuotez"LogEscapingTests.test_requestQuote�s<��"G�J
�"
��	�	��/��������
A�	
r,c�p�ddz|j_d|j_|j	d�y)zU
        If the HTTP request version includes a quote, the quote is escaped.
        r�r�sHT"P/1.0sP"1.2.3.4" - - [25/Oct/2004:12:31:59 +0000] "GET /dummy HT\"P/1.0" 123 - "-" "-"
N)rVr�rBrLr�r�s r*�test_protoQuotez LogEscapingTests.test_protoQuote�s;��"G�J
�"
��	�	��$/���� ����
7�	
r,c��ddz|j_|jjj	dd�|jd�y)zg
        If the value of the I{Referer} header contains a quote, the quote is
        escaped.
        r�r�rns#http://malicious" ".website.invalidss"1.2.3.4" - - [25/Oct/2004:12:31:59 +0000] "GET /dummy HTTP/1.0" 123 - "http://malicious\" \".website.invalid" "-"
N�rVr�rBr�rsr�r�s r*�test_refererQuotez"LogEscapingTests.test_refererQuote�sO��
"G�J
�"
��	�	��	
���#�#�0�0��>�	
�	
���
?�	
r,c��ddz|j_|jjj	dd�|jd�y)zj
        If the value of the I{User-Agent} header contains a quote, the quote is
        escaped.
        r�r�rosMalicious Web" Evilsb"1.2.3.4" - - [25/Oct/2004:12:31:59 +0000] "GET /dummy HTTP/1.0" 123 - "-" "Malicious Web\" Evil"
Nr�r�s r*�test_userAgentQuotez$LogEscapingTests.test_userAgentQuote�sK��
"G�J
�"
��	�	��	
���#�#�0�0��@V�W����
I�	
r,N)r-r.r/r�r�r�r�r�r�r�r�r0r,r*r�r�ps+��@�'�$
�"
�$
�$
�$
�,
r,r�c��eZdZdZd�Zd�Zy)�ServerAttributesTestszw
    Tests that deprecated twisted.web.server attributes raise the appropriate
    deprecation warnings when used.
    c��tj|j|jg��}|j	t|�d�|j	|ddt�|j	|ddd�y)z�
        twisted.web.server.date_time_string should not be used; instead use
        twisted.web.http.datetimeToString directly
        ��offendingFunctionsr r�category�messagezztwisted.web.server.date_time_string was deprecated in Twisted 12.1.0: Please use twisted.web.http.datetimeToString insteadN)r�date_time_string�
flushWarnings�&test_deprecatedAttributeDateTimeStringr&rC�DeprecationWarning�r(�warningss  r*r�z<ServerAttributesTests.test_deprecatedAttributeDateTimeString�~��
	����%�%� $� K� K�L�&�
��	
����X���*�����!��Z�0�2D�E�����Q�K�	�"�O�	
r,c��tj|j|jg��}|j	t|�d�|j	|ddt�|j	|ddd�y)z�
        twisted.web.server.string_date_time should not be used; instead use
        twisted.web.http.stringToDatetime directly
        r�r rr�r�zztwisted.web.server.string_date_time was deprecated in Twisted 12.1.0: Please use twisted.web.http.stringToDatetime insteadN)r�string_date_timer��&test_deprecatedAttributeStringDateTimer&rCr�r�s  r*r�z<ServerAttributesTests.test_deprecatedAttributeStringDateTimer�r,N)r-r.r/rDr�r�r0r,r*r�r��s���

�(
r,r�c��eZdZdZd�Zd�Zy)�ExplicitHTTPFactoryReactorzA
    L{http.HTTPFactory} accepts explicit reactor selection.
    c�l�d}tj|��}|j|j|�y)z~
        L{http.HTTPFactory.__init__} accepts a reactor argument which is set on
        L{http.HTTPFactory.reactor}.
        zI am a reactor!r�N)rrdrar��r(r�r�s   r*r�z/ExplicitHTTPFactoryReactor.test_explicitReactor.s+��
$���"�"�7�3���
�
�g�o�o�w�/r,c�p�ddlm}tj�}|j	|j|�y)z}
        Giving no reactor argument to L{http.HTTPFactory.__init__} means it
        will select the global reactor.
        rr�N)�twisted.internetr�rrdrar�s   r*r�z.ExplicitHTTPFactoryReactor.test_defaultReactor7s'��
	-��"�"�$���
�
�g�o�o�w�/r,N)r-r.r/rDr�r�r0r,r*r�r�)s���0�0r,r�c�8��eZdZdZdZd�fd�Zdedefd�Z�xZ	S)�
QueueResourcez�
    Add all requests to an internal queue,
    without responding to the requests.
    You can access the requests from the queue and handle their response.
    Trc�0��t�|��g|_yr%)�superr4�dispatchedRequests)r(�	__class__s �r*r4zQueueResource.__init__Ks���
����13��r,rBc�D�|jj|�tSr%)r�r�rrAs  r*r�zQueueResource.render_GETOs�����&�&�w�/��r,�rN)
r-r.r/rDr�r4rr�r��
__classcell__)r�s@r*r�r�Bs'�����F�4��'��c�r,r�c� �eZdZdZdd�Zdd�Zy)�TestRFC9112Section932z=
    Verify that HTTP/1.1 request ordering is preserved.
    Nc�v�t�}t|�}|jd�}t�}|j	|�|jd�|j
t|j�d�|jdj�|j
t|j�d�y)zq
        Twisted MUST NOT respond to a second HTTP/1.1 request while the first
        is still pending.
        N�AGET /first HTTP/1.1
Host: a

GET /second HTTP/1.1
Host: a

r rr|)
r�rrjrr�r�r&rCr��finish)r(�qrrV�proto�serverTransports     r*�!test_multipleRequestsInOneSegmentz7TestRFC9112Section932.test_multipleRequestsInOneSegmentYs���
�_���B�x���"�"�4�(��)�+��
���_�-�
���
7�	
�	
����R�2�2�3�Q�7�	���a� �'�'�)�����R�2�2�3�Q�7r,c��t�}t|�}|jd�}t�}|j	|�d}t|�D]}|j
|��|jt|j�d�|jdj�|jt|j�d�y)z�
        Twisted MUST NOT respond to a second HTTP/1.1 request while the first
        is still pending, even if the second request is received in a separate
        TCP package.
        Nr�r rr|)r�rrjrr�rr�r&rCr�r�)r(r�rVr�r��raw_data�chunks       r*�(test_multipleRequestsInDifferentSegmentsz>TestRFC9112Section932.test_multipleRequestsInDifferentSegmentsps����_���B�x���"�"�4�(��)�+��
���_�-�
7�	��x�(�	&�E����u�%�	&�
	
����R�2�2�3�Q�7�	���a� �'�'�)�����R�2�2�3�Q�7r,r�)r-r.r/rDr�r�r0r,r*r�r�Ts���8�.8r,r�)TrDr}r��ior�typingr�zope.interfacer�zope.interface.verifyrr�r�twisted.internet.addressrr	�twisted.internet.taskr
�twisted.internet.testingrr�twisted.loggerr
r�twisted.pythonrr�twisted.python.compatr�twisted.python.filepathr�
twisted.trialr�twisted.webrrrrr�twisted.web.resourcer�twisted.web.serverrrr�twisted.web.staticr�twisted.web.test.requesthelperrr�_utilr!�TestCaser#r2rFrKrPr�r�r�r�r�rr�r�r�r��	IResourcer�r�r,r1rErPrcrfrirr�r�r�r�r�r0r,r*�<module>r�s|���
����&�.�'�=�'�J�7�+�+�,�"�;�;�)�:�:�#�E�.�/�H�%�%�/��X�&�&��0��*�*����)�)��vE�x� � �vE�ri7�8�$�$�i7�l*���
VM�x�(�(�VM�rQ4�8�$�$�Q4�hvS�x�(�(�vS�r�8�$�$��7N�x�(�(�7N�t��)�)��
�X�
�
� �!$�!$�!�!$�HtD�X�&�&�tD�n

�x�(�(�

� J9�(�+�+�J9�Z
�\�
�"KX�KX�\� 3�X�5F�5F��A�,�h�.?�.?�A�J1�� 1� 1�J1�Z0H�x�0�0�0H�fG
�x�(�(�G
�T,
�H�-�-�,
�^0��!2�!2�0�2�H��$68�H�-�-�68r,

Zerion Mini Shell 1.0