%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__/requesthelper.cpython-312.pyc

�

Ϫ�fC<���dZddlmZddgZddlmZddlmZmZm	Z	ddl
mZmZddl
mZdd	lmZmZdd
lmZddlmZmZddlmZdd
lmZddlmZddlmZddlm Z ddl!m"Z"ddl#m$Z$m%Z%m&Z&dD�cgc]}d|�d���
c}Z'dZ(e'D�cgc]}|jSd���c}Z*e(jSd�Z+ee�Gd�d��Z,Gd�d�Z-Gd�d�Z.Gd�dej^�Z0ycc}wcc}w)z2
Helpers related to HTTP requests, used by tests.
�)�annotations�DummyChannel�DummyRequest)�BytesIO)�Dict�List�Optional)�implementer�verify)�Version)�IPv4Address�IPv6Address)�Deferred)�IAddress�
ISSLTransport)�Clock)�
deprecated)�unittest)�FOUND)�Headers)�Resource)�NOT_DONE_YET�Session�Site)�
�
z
�Foo�barzFoo bar�asciic��eZdZdZy)�NullAddressz/
    A null implementation of L{IAddress}.
    N)�__name__�
__module__�__qualname__�__doc__���@/usr/lib/python3/dist-packages/twisted/web/test/requesthelper.pyr!r!'s��r'r!c���eZdZGd�d�Zee�Gd�de��Zee��Z	dd�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)rc�F�eZdZdZdZdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zy)
�DummyChannel.TCP�PFNc�\�|�
tddd�}||_t�|_g|_y)N�TCPz192.168.1.1i80)r
�_peerr�written�	producers��self�peers  r(�__init__zDummyChannel.TCP.__init__3s,���|�"�5�-��?���D�J�"�9�D�L��D�Nr'c��|jS�N)r/�r3s r(�getPeerzDummyChannel.TCP.getPeer:s���:�:�r'c�v�t|t�std|����|jj	|�y)Nz)Can only write bytes to a transport, not )�
isinstance�bytes�	TypeErrorr0�write�r3�datas  r(r>zDummyChannel.TCP.write=s1���d�E�*��"K�D�8� T�U�U��L�L���t�$r'c�4�|D]}|j|��yr7)r>)r3�iovecr@s   r(�
writeSequencezDummyChannel.TCP.writeSequenceBs���
!���
�
�4� �
!r'c�0�tdd|j�S)Nr.z10.0.0.1)r
�portr8s r(�getHostzDummyChannel.TCP.getHostFs���u�j�$�)�)�<�<r'c�>�|jj||f�yr7)r1�append�r3�producer�	streamings   r(�registerProducerz!DummyChannel.TCP.registerProducerIs���N�N�!�!�8�Y�"7�8r'c��yr7r&r8s r(�unregisterProducerz#DummyChannel.TCP.unregisterProducerLs��r'c��d|_y)NT)�disconnectedr8s r(�loseConnectionzDummyChannel.TCP.loseConnectionOs
�� $�D�r'r7)
r"r#r$rErPr5r9r>rCrFrLrNrQr&r'r(r.r+/s4������	 �	�	%�
	!�	=�	9�	�	%r'r.c�6�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�DummyChannel.SSLc��yr7r&r8s r(�abortConnectionz DummyChannel.SSL.abortConnectionT���r'c��yr7r&r8s r(�getTcpKeepAlivez DummyChannel.SSL.getTcpKeepAliveXrVr'c��yr7r&r8s r(�
getTcpNoDelayzDummyChannel.SSL.getTcpNoDelay\rVr'c��yr7r&r8s r(�loseWriteConnectionz$DummyChannel.SSL.loseWriteConnection`rVr'c��yr7r&�r3�enableds  r(�setTcpKeepAlivez DummyChannel.SSL.setTcpKeepAlivedrVr'c��yr7r&r^s  r(�
setTcpNoDelayzDummyChannel.SSL.setTcpNoDelayhrVr'c��yr7r&r8s r(�getPeerCertificatez#DummyChannel.SSL.getPeerCertificatelrVr'N)
r"r#r$rUrXrZr\r`rbrdr&r'r(�SSLrSRs%��	�	�	�	�	�	�	r'reNc�0�|j|�|_yr7)r.�	transportr2s  r(r5zDummyChannel.__init__rs�����$���r'c��yr7r&)r3�requests  r(�requestDonezDummyChannel.requestDoneu���r'c��|dz|zdz|zdz}|g}|jd�|D��|jd�|jj|�y)N� �
c3�8K�|]\}}|dz|zdz���y�w)s: rnNr&)�.0�name�values   r(�	<genexpr>z,DummyChannel.writeHeaders.<locals>.<genexpr>{s"����X���u�d�U�l�U�2�W�<�X�s�)�extendrHrgrC)r3�version�code�reason�headers�
response_line�headerSequences       r(�writeHeaderszDummyChannel.writeHeadersxs[���$���-��4�v�=��G�
�'������X�PW�X�X����g�&����$�$�^�4r'c�6�|jj�Sr7)rgr9r8s r(r9zDummyChannel.getPeer����~�~�%�%�'�'r'c�6�|jj�Sr7)rgrFr8s r(rFzDummyChannel.getHost�r}r'c�<�|jj||�yr7)rgrLrIs   r(rLzDummyChannel.registerProducer�s�����'�'��)�<r'c�8�|jj�yr7)rgrNr8s r(rNzDummyChannel.unregisterProducer�s�����)�)�+r'c�:�|jj|�yr7)rgr>r?s  r(r>zDummyChannel.write�s�������T�"r'c�:�|jj|�yr7)rgrC)r3rBs  r(rCzDummyChannel.writeSequence�s�����$�$�U�+r'c�8�|jj�yr7)rgrQr8s r(rQzDummyChannel.loseConnection�s�����%�%�'r'c��yr7r&r8s r(�
endRequestzDummyChannel.endRequest�rkr'c�B�t|j|j�Sr7)r;rgrer8s r(�isSecurezDummyChannel.isSecure�s���$�.�.�$�(�(�3�3r'c��yr7r&r8s r(rUzDummyChannel.abortConnection����r'c��yr7r&r8s r(rXzDummyChannel.getTcpKeepAlive�r�r'c��yr7r&r8s r(rZzDummyChannel.getTcpNoDelay�r�r'c��yr7r&r8s r(r\z DummyChannel.loseWriteConnection�r�r'c��yr7r&r8s r(r`zDummyChannel.setTcpKeepAlive�r�r'c��yr7r&r8s r(rbzDummyChannel.setTcpNoDelay�r�r'c��yr7r&r8s r(rdzDummyChannel.getPeerCertificate�r�r'r7)r"r#r$r.r
rrerr�siter5rjr{r9rFrLrNr>rCrQr�r�rUrXrZr\r`rbrdr&r'r(rr.s���!%�!%�F����c�� ��:��
��D�(�
�5�(�(�=�,�#�,�(�
�4�
�
�
�
�
�
�
r'c�(�eZdZUdZdZdZdZded<ded<ded	<ded
<ded<d
ed<d�Zd�Z			d+							d,d�Z
d�Zd�Zd�Z
d-d�Zd�Zd�Zd.d�Zd�Zd�Zd�Zd-d�Zd�Zd�Zeedd d!d"�d#�$�d%��Zd&�Zd'�Zd(�Zd/d)�Zd*�Zy)0ra
    Represents a dummy or fake request. See L{twisted.web.server.Request}.

    @ivar _finishedDeferreds: L{None} or a C{list} of L{Deferreds} which will
        be called back with L{None} when C{finish} is called or which will be
        errbacked if C{processingFailed} is called.

    @type requestheaders: C{Headers}
    @ivar requestheaders: A Headers instance that stores values for all request
        headers.

    @type responseHeaders: C{Headers}
    @ivar responseHeaders: A Headers instance that stores values for all
        response headers.

    @type responseCode: C{int}
    @ivar responseCode: The response code which was passed to
        C{setResponseCode}.

    @type written: C{list} of C{bytes}
    @ivar written: The bytes which have been written to the request.
    s
http://dummy/sGETN�Optional[IAddress]�clientzList[bytes]�sitepathr0�prepathzDict[bytes, List[bytes]]�argszList[Deferred[None]]�_finishedDeferredsc�f�d|_|jr|j�|jr�yy)z�
        Call an L{IPullProducer}'s C{resumeProducing} method in a
        loop until it unregisters itself.

        @param prod: The producer.
        @type prod: L{IPullProducer}

        @param s: Whether or not the producer is streaming.
        �N)�go�resumeProducing)r3�prod�ss   r(rLzDummyRequest.registerProducer�s'������g�g�� � �"��g�gr'c��d|_y)Nr)r�r8s r(rNzDummyRequest.unregisterProducer�s	����r'c��g|_g|_d|_||_g|_d|_|xst
ddt���|_i|_	t�|_t�|_d|_
g|_d|_d|_y)Nr�0)r��uid�reactorsdummysHTTP/1.0)r�r0�finished�postpathr��sessionrr�protoSessionr�r�requestHeaders�responseHeaders�responseCoder��_serverName�clientproto)r3r�r�r�s    r(r5zDummyRequest.__init__�s�����
������
� ��
�������#�T�w�D�d�E�G�'T�����	�%�i���&�y��� ���"$���#���&��r'c�z�i}|jj�D]\}}|d||j�<�|S)ah
        Return dictionary mapping the names of all received headers to the last
        value received for each.

        Since this method does not return all header information,
        C{self.requestHeaders.getAllRawHeaders()} may be preferred.

        NOTE: This function is a direct copy of
        C{twisted.web.http.Request.getAllRawHeaders}.
        ���)r��getAllRawHeaders�lower)r3rx�k�vs    r(�
getAllHeaderszDummyRequest.getAllHeaders�sD�����'�'�8�8�:�	'�D�A�q�!"�2��G�A�G�G�I��	'��r'c�^�|jj|j�dg�dS)aH
        Retrieve the value of a request header.

        @type name: C{bytes}
        @param name: The name of the request header for which to retrieve the
            value.  Header names are compared case-insensitively.

        @rtype: C{bytes} or L{None}
        @return: The value of the specified request header.
        Nr)r��
getRawHeadersr�)r3rqs  r(�	getHeaderzDummyRequest.getHeaders*���"�"�0�0������v�F�q�I�Ir'c�<�|jj||�y)zATODO: make this assert on write() if the header is content-lengthN)r��addRawHeader�r3rqrrs   r(�	setHeaderzDummyRequest.setHeaders�����)�)�$��6r'c��|jr|jS|jrJd��|j|_|jS)Nz8Session cannot be requested after data has been written.)r�r0r�)r3�sessionInterfaces  r(�
getSessionzDummyRequest.getSession sC���<�<��<�<�����	F�E�	F���(�(����|�|�r'c�z�|j|�}|tury|j|�|j�y)a�
        Render the given resource as a response to this request.

        This implementation only handles a few of the most common behaviors of
        resources.  It can handle a render method that returns a string or
        C{NOT_DONE_YET}.  It doesn't know anything about the semantics of
        request methods (eg HEAD) nor how to set any particular headers.
        Basically, it's largely broken, but sufficient for some tests at least.
        It should B{not} be expanded to do all the same stuff L{Request} does.
        Instead, L{DummyRequest} should be phased out and L{Request} (or some
        other real code factored in a different way) used.
        N)�renderrr>�finish)r3�resource�results   r(r�zDummyRequest.render)s2������&���\�!���
�
�6�����
r'c�p�t|t�std��|jj	|�y)Nzwrite() only accepts bytes)r;r<r=r0rHr?s  r(r>zDummyRequest.write<s*���$��&��8�9�9������D�!r'c�P�t�}|jj|�|S)z�
        Return a L{Deferred} which is called back with L{None} when the request
        is finished.  This will probably only work if you haven't called
        C{finish} yet.
        )rr�rH)r3r�s  r(�notifyFinishzDummyRequest.notifyFinishAs$��$,�:�����&�&�x�0��r'c��|jdz|_|j�,|j}d|_|D]}|jd��yy)z}
        Record that the request is finished and callback and L{Deferred}s
        waiting for notification of this.
        r�N)r�r��callback)r3�	observers�obss   r(r�zDummyRequest.finishKsS��
�
�
��)��
��"�"�.��/�/�I�&*�D�#� �
#�����T�"�
#�/r'c�t�|j�,|j}d|_|D]}|j|��yy)zK
        Errback and L{Deferreds} waiting for finish notification.
        N)r��errback)r3rwr�r�s    r(�processingFailedzDummyRequest.processingFailedWsC���"�"�.��/�/�I�&*�D�#� �
$�����F�#�
$�/r'c�$�|g|j|<yr7)r�r�s   r(�addArgzDummyRequest.addArgas�� �'��	�	�$�r'c��|jr/Jdjdj|j����||_||_y)z{
        Set the HTTP status response code, but takes care that this is called
        before any data is written.
        z;Response code cannot be set after data hasbeen written: {}.�@@@@N)r0�format�joinr��responseMessage)r3rv�messages   r(�setResponseCodezDummyRequest.setResponseCodedsH�����	
�K�R�R��K�K����%�
�	
��!���&��r'c�z�|jr/Jdjdj|j����y)Nz<Last-Modified cannot be set after data has been written: {}.r��r0r�r�)r3�whens  r(�setLastModifiedzDummyRequest.setLastModifiedqs6�����	
�L�S�S��K�K����%�
�	
��r'c�z�|jr/Jdjdj|j����y)Nz3ETag cannot be set after data has been written: {}.r�r�)r3�tags  r(�setETagzDummyRequest.setETagxs6�����	
�C�J�J��K�K����%�
�	
��r'�Twisted��r�getClientAddress)�replacementc�p�t|jttf�r|jjSy)z|
        Return the IPv4 address of the client which made this request, if there
        is one, otherwise L{None}.
        N)r;r�r
r�hostr8s r(�getClientIPzDummyRequest.getClientIPs*���d�k�k�K��#=�>��;�;�#�#�#�r'c�F�|j�
t�S|jS)z�
        Return the L{IAddress} of the client that made this request.

        @return: an address.
        @rtype: an L{IAddress} provider.
        )r�r!r8s r(r�zDummyRequest.getClientAddress�s ���;�;���=� ��{�{�r'c��|jS)z�
        Get a dummy hostname associated to the HTTP request.

        @rtype: C{bytes}
        @returns: a dummy hostname
        )r�r8s r(�getRequestHostnamezDummyRequest.getRequestHostname�s�����r'c��tddd�S)zz
        Get a dummy transport's host.

        @rtype: C{IPv4Address}
        @returns: a dummy transport's host
        r.�	127.0.0.1r,)r
r8s r(rFzDummyRequest.getHost�s���5�+�r�2�2r'c��||_|j�rd}nd}||k(r|}nd||fz}|jjd|�y)a_
        Change the host and port the request thinks it's using.

        @type host: C{bytes}
        @param host: The value to which to change the host header.

        @type ssl: C{bool}
        @param ssl: A flag which, if C{True}, indicates that the request is
            considered secure (if C{True}, L{isSecure} will return C{True}).
        i�r,s%b:%dshostN)�	_forceSSLr�r�r�)r3r�rE�ssl�default�
hostHeaders      r(�setHostzDummyRequest.setHost�sN������=�=�?��G��G��7�?��J�!�T�4�L�0�J����(�(��*�=r'c�R�|jt�|jd|�y)zu
        Utility function that does a redirect.

        The request should have finish() called after this.
        slocationN)r�rr�)r3�urls  r(�redirectzDummyRequest.redirect�s ��	
���U�#����{�C�(r')NN)r�zlist[bytes]r�zOptional[Session]r�r��return�Noner7)r�zDeferred[None])r) r"r#r$r%�uri�methodr��__annotations__rLrNr5r�r�r�r�r�r>r�r�r�r�r�r�r�rrr�r�r�rFr�r�r&r'r(rr�s����.�C�
�F�!%�F��%���
��
��
"�"�,�,�
#��&*�%)�	'��'�#�'�#�	'�

�'�*� J�7���&"�
�
#�$�"�'�
�
���	�2�q�!�,�:L�M��N��	� �3�>�,)r'c�(�eZdZdZd�Zd�Zd�Zd�Zy)�DummyRequestTestsz$
    Tests for L{DummyRequest}.
    c�>�tg�}|j�|j|jg��}|j	dt|��|\}|j	|j
d�t�|j	|j
d�d�y)zp
        L{DummyRequest.getClientIP} is deprecated in favor of
        L{DummyRequest.getClientAddress}
        )�offendingFunctionsr��categoryr�z}twisted.web.test.requesthelper.DummyRequest.getClientIP was deprecated in Twisted 18.4.0; please use getClientAddress insteadN)rr��
flushWarnings�test_getClientIPDeprecated�assertEqual�len�get�DeprecationWarning)r3ri�warnings�warnings    r(r�z,DummyRequestTests.test_getClientIPDeprecated�s����r�"�������%�%� $� ?� ?�@�&�
��	
����C��M�*��	��������Z�0�2D�E�����K�K�	�"�6�	
r'c��tg�}tddd�}||_|jd|j	��y)z�
        L{DummyRequest.getClientIP} supports IPv6 addresses, just like
        L{twisted.web.http.Request.getClientIP}.
        r.z::1�90N)rrr�r�r�)r3rir�s   r(�test_getClientIPSupportsIPv6z.DummyRequestTests.test_getClientIPSupportsIPv6�s<��
�r�"���U�E�5�1���������� 3� 3� 5�6r'c�n�tg�}|j�}tjt|�y)zu
        L{DummyRequest.getClientAddress} returns an L{IAddress}
        provider no C{client} has been set.
        N)rr�r�verifyObjectr)r3ri�nulls   r(�"test_getClientAddressWithoutClientz4DummyRequestTests.test_getClientAddressWithoutClient�s,��
�r�"���'�'�)�����H�d�+r'c��tg�}tddd�}||_|j�}|j	||�y)zI
        L{DummyRequest.getClientAddress} returns the C{client}.
        r.r�rN)rr
r�r��assertIs)r3rir��addresss    r(�test_getClientAddressz'DummyRequestTests.test_getClientAddress�s?���r�"���U�K��7������*�*�,���
�
�g�v�&r'N)r"r#r$r%r�rr
rr&r'r(r�r��s���
�2	7�,�'r'r�N)1r%�
__future__r�__all__�ior�typingrrr	�zope.interfacer
r�incrementalr�twisted.internet.addressr
r�twisted.internet.deferr�twisted.internet.interfacesrr�twisted.internet.taskr�twisted.python.deprecater�
twisted.trialr�twisted.web._responsesr�twisted.web.http_headersr�twisted.web.resourcer�twisted.web.serverrrr�textLinearWhitespaceComponents�
sanitizedText�encode�bytesLinearWhitespaceComponents�sanitizedBytesr!rr�SynchronousTestCaser�)�lw�	components00r(�<module>r's����#��>�
*���'�'�.��=�+�?�'�/�"�(�,�)�:�:�:N�!O�B�C��t�3�-�!O���
�/M�#�"+�I���W��#���%�%�g�.��
�X������F
�F
�RL)�L)�^:'��4�4�:'��Q
"P��#s�3
C4�	C9

Zerion Mini Shell 1.0