AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/web/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/web/test/__pycache__/requesthelper.cpython-310.pyc
o

�b;�@s:dZddgZddlmZddlmZddlmZmZddl	m
Z
ddlmZm
Z
dd	lmZdd
lmZmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlm Z m!Z!m"Z"dd�dD�Z#dZ$dd�e#D�Z%e$�&d�Z'ee�Gdd�d��Z(Gdd�d�Z)Gdd�d�Z*Gdd�dej+�Z,dS)z2
Helpers related to HTTP requests, used by tests.
�DummyChannel�DummyRequest�)�BytesIO)�Optional)�implementer�verify)�Version)�IPv4Address�IPv6Address)�Deferred)�IAddress�
ISSLTransport)�Clock)�
deprecated)�unittest)�FOUND)�Headers)�Resource)�NOT_DONE_YET�Session�SitecCsg|]}d|�d��qS)�Foo�bar�)�.0�lwrr�@/usr/lib/python3/dist-packages/twisted/web/test/requesthelper.py�
<listcomp>sr)�
�
z
zFoo barcCsg|]}|�d��qS)�ascii)�encode)r�	componentrrrr s
�r c@seZdZdZdS)�NullAddressz/
    A null implementation of L{IAddress}.
    N)�__name__�
__module__�__qualname__�__doc__rrrrr#&sr#c@s�eZdZGdd�d�Zee�Gdd�de��Zee��Z	d,dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�ZdS)-rc@sVeZdZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)zDummyChannel.TCP�PFNcCs,|dur
tddd�}||_t�|_g|_dS)N�TCPz192.168.1.1i80)r	�_peerr�written�	producers��self�peerrrr�__init__2s

zDummyChannel.TCP.__init__cC�|jS�N)r*�r.rrr�getPeer9szDummyChannel.TCP.getPeercCs(t|t�std|����|j�|�dS)Nz)Can only write bytes to a transport, not )�
isinstance�bytes�	TypeErrorr+�write�r.�datarrrr8<s
zDummyChannel.TCP.writecCs|D]}|�|�qdSr2)r8)r.�iovecr:rrr�
writeSequenceAs�zDummyChannel.TCP.writeSequencecCstdd|j�S)Nr)z10.0.0.1)r	�portr3rrr�getHostE�zDummyChannel.TCP.getHostcCs|j�||f�dSr2)r,�append�r.�producer�	streamingrrr�registerProducerHsz!DummyChannel.TCP.registerProducercC�dSr2rr3rrr�unregisterProducerK�z#DummyChannel.TCP.unregisterProducercC�
d|_dS)NT)�disconnectedr3rrr�loseConnectionN�
zDummyChannel.TCP.loseConnectionr2)
r$r%r&r=rIr0r4r8r<r>rDrFrJrrrrr).s
r)c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)zDummyChannel.SSLcCrEr2rr3rrr�abortConnectionS�z DummyChannel.SSL.abortConnectioncCrEr2rr3rrr�getTcpKeepAliveWrMz DummyChannel.SSL.getTcpKeepAlivecCrEr2rr3rrr�
getTcpNoDelay[rMzDummyChannel.SSL.getTcpNoDelaycCrEr2rr3rrr�loseWriteConnection_rMz$DummyChannel.SSL.loseWriteConnectioncCrEr2r�r.�enabledrrr�setTcpKeepAlivecrMz DummyChannel.SSL.setTcpKeepAlivecCrEr2rrQrrr�
setTcpNoDelaygrMzDummyChannel.SSL.setTcpNoDelaycCrEr2rr3rrr�getPeerCertificatekrMz#DummyChannel.SSL.getPeerCertificateN)
r$r%r&rLrNrOrPrSrTrUrrrr�SSLQsrVNcCs|�|�|_dSr2)r)�	transportr-rrrr0q�zDummyChannel.__init__cCrEr2r)r.�requestrrr�requestDonetrGzDummyChannel.requestDonecCsL|d|d|d}|g}|�dd�|D��|�d�|j�|�dS)N� �
css$�|]
\}}|d|dVqdS)s: r\Nr)r�name�valuerrr�	<genexpr>zs�"z,DummyChannel.writeHeaders.<locals>.<genexpr>)�extendr@rWr<)r.�version�code�reason�headers�
response_line�headerSequencerrr�writeHeadersws

zDummyChannel.writeHeaderscC�
|j��Sr2)rWr4r3rrrr4~rKzDummyChannel.getPeercCrhr2)rWr>r3rrrr>�rKzDummyChannel.getHostcCs|j�||�dSr2)rWrDrArrrrD�szDummyChannel.registerProducercC�|j��dSr2)rWrFr3rrrrF�r?zDummyChannel.unregisterProducercC�|j�|�dSr2)rWr8r9rrrr8�rXzDummyChannel.writecCrjr2)rWr<)r.r;rrrr<�rXzDummyChannel.writeSequencecCrir2)rWrJr3rrrrJ�r?zDummyChannel.loseConnectioncCrEr2rr3rrr�
endRequest�rGzDummyChannel.endRequestcCst|j|j�Sr2)r5rWrVr3rrr�isSecure�r?zDummyChannel.isSecurecCrEr2rr3rrrrL�rMzDummyChannel.abortConnectioncCrEr2rr3rrrrN�rMzDummyChannel.getTcpKeepAlivecCrEr2rr3rrrrO�rMzDummyChannel.getTcpNoDelaycCrEr2rr3rrrrP�rMz DummyChannel.loseWriteConnectioncCrEr2rr3rrrrS�rMzDummyChannel.setTcpKeepAlivecCrEr2rr3rrrrT�rMzDummyChannel.setTcpNoDelaycCrEr2rr3rrrrU�rMzDummyChannel.getPeerCertificater2)r$r%r&r)rr
rVrr�siter0rZrgr4r>rDrFr8r<rJrkrlrLrNrOrPrSrTrUrrrrr-s0#

c@seZdZUdZdZdZdZeee	d<dd�Z
dd	�Zd9d
d�Zdd
�Z
dd�Zdd�Zd:dd�Zdd�Zdd�Zdedfdd�Zdd�Zdd�Zdd �Zd:d!d"�Zd#d$�Zd%d&�Zeed'd(d)d*�d+d,�d-d.��Zd/d0�Zd1d2�Zd3d4�Z d;d5d6�Z!d7d8�Z"dS)<ra
    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�clientcCs"d|_|jr|��|jsdSdS)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)r.�prod�srrrrD�s�zDummyRequest.registerProducercCrH)Nr)rpr3rrrrF�rKzDummyRequest.unregisterProducercCslg|_g|_d|_||_g|_d|_|ptddt�d�|_i|_	t
�|_t
�|_d|_
g|_d|_d|_dS)Nr�0)rm�uid�reactorsdummysHTTP/1.0)�sitepathr+�finished�postpath�prepath�sessionrr�protoSession�argsr�requestHeaders�responseHeaders�responseCode�_finishedDeferreds�_serverName�clientproto)r.ryr{rnrrrr0�s
zDummyRequest.__init__cCs,i}|j��D]\}}|d||��<q|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)r.rd�k�vrrr�
getAllHeaders�szDummyRequest.getAllHeaderscCs|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�)r.r]rrr�	getHeaderszDummyRequest.getHeadercCs|j�||�dS)zATODO: make this assert on write() if the header is content-lengthN)r�addRawHeader�r.r]r^rrr�	setHeaderszDummyRequest.setHeadercCs(|jr|jS|jr
Jd��|j|_|jS)Nz8Session cannot be requested after data has been written.)r{r+r|)r.�sessionInterfacerrr�
getSessions��zDummyRequest.getSessioncCs,|�|�}|turdS|�|�|��dS)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)�renderrr8�finish)r.�resource�resultrrrr�s



zDummyRequest.rendercCs"t|t�s	td��|j�|�dS)Nzwrite() only accepts bytes)r5r6r7r+r@r9rrrr81s
zDummyRequest.write�returncCst�}|j�|�|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�r@)r.rxrrr�notifyFinish6szDummyRequest.notifyFinishcCs>|jd|_|jdur|j}d|_|D]	}|�d�qdSdS)z}
        Record that the request is finished and callback and L{Deferred}s
        waiting for notification of this.
        roN)rxr��callback)r.�	observers�obsrrrr�@s
�zDummyRequest.finishcCs2|jdur|j}d|_|D]	}|�|�q
dSdS)zK
        Errback and L{Deferreds} waiting for finish notification.
        N)r��errback)r.rcr�r�rrr�processingFailedLs
�zDummyRequest.processingFailedcCs|g|j|<dSr2)r}r�rrr�addArgVrXzDummyRequest.addArgcCs,|jrJd�d�|j����||_||_dS)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)r+�format�joinr��responseMessage)r.rb�messagerrr�setResponseCodeYs�
��
zDummyRequest.setResponseCodecC� |jrJd�d�|j����dS)Nz<Last-Modified cannot be set after data has been written: {}.r��r+r�r�)r.�whenrrr�setLastModifiedf��
��zDummyRequest.setLastModifiedcCr�)Nz3ETag cannot be set after data has been written: {}.r�r�)r.�tagrrr�setETagmr�zDummyRequest.setETag�Twisted��r�getClientAddress)�replacementcCst|jttf�r|jjSdS)z|
        Return the IPv4 address of the client which made this request, if there
        is one, otherwise L{None}.
        N)r5rnr	r
�hostr3rrr�getClientIPtszDummyRequest.getClientIPcCs|jdurt�S|jS)z�
        Return the L{IAddress} of the client that made this request.

        @return: an address.
        @rtype: an L{IAddress} provider.
        N)rnr#r3rrrr�~s
zDummyRequest.getClientAddresscCr1)z�
        Get a dummy hostname associated to the HTTP request.

        @rtype: C{bytes}
        @returns: a dummy hostname
        )r�r3rrr�getRequestHostname�szDummyRequest.getRequestHostnamecCstddd�S)zz
        Get a dummy transport's host.

        @rtype: C{IPv4Address}
        @returns: a dummy transport's host
        r)�	127.0.0.1r()r	r3rrrr>�szDummyRequest.getHostcCsD||_|��r
d}nd}||kr|}nd||f}|j�d|�dS)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)�	_forceSSLrlr~r�)r.r�r=�ssl�default�
hostHeaderrrr�setHost�szDummyRequest.setHostcCs|�t�|�d|�dS)zu
        Utility function that does a redirect.

        The request should have finish() called after this.
        slocationN)r�rr�)r.�urlrrr�redirect�s
zDummyRequest.redirect)NNr2)r)#r$r%r&r'�uri�methodrnrr�__annotations__rDrFr0r�r�r�r�r�r8rr�r�r�r�r�r�r�rrr�r�r�r>r�r�rrrrr�s8


	




		
	c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�DummyRequestTestsz$
    Tests for L{DummyRequest}.
    cCs^tg�}|��|j|jgd�}|�dt|��|\}|�|�d�t�|�|�d�d�dS)zp
        L{DummyRequest.getClientIP} is deprecated in favor of
        L{DummyRequest.getClientAddress}
        )�offendingFunctionsro�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)r.rY�warnings�warningrrrr��s��z,DummyRequestTests.test_getClientIPDeprecatedcCs.tg�}tddd�}||_|�d|���dS)z�
        L{DummyRequest.getClientIP} supports IPv6 addresses, just like
        L{twisted.web.http.Request.getClientIP}.
        r)z::1�90N)rr
rnr�r�)r.rYrnrrr�test_getClientIPSupportsIPv6�sz.DummyRequestTests.test_getClientIPSupportsIPv6cCs tg�}|��}t�t|�dS)zu
        L{DummyRequest.getClientAddress} returns an L{IAddress}
        provider no C{client} has been set.
        N)rr�r�verifyObjectr)r.rY�nullrrr�"test_getClientAddressWithoutClient�sz4DummyRequestTests.test_getClientAddressWithoutClientcCs2tg�}tddd�}||_|��}|�||�dS)zI
        L{DummyRequest.getClientAddress} returns the C{client}.
        r)r�r�N)rr	rnr��assertIs)r.rYrn�addressrrr�test_getClientAddress�s
z'DummyRequestTests.test_getClientAddressN)r$r%r&r'r�r�r�r�rrrrr��s	r�N)-r'�__all__�ior�typingr�zope.interfacerr�incrementalr�twisted.internet.addressr	r
�twisted.internet.deferr�twisted.internet.interfacesrr
�twisted.internet.taskr�twisted.python.deprecater�
twisted.trialr�twisted.web._responsesr�twisted.web.http_headersr�twisted.web.resourcer�twisted.web.serverrrr�textLinearWhitespaceComponents�
sanitizedText�bytesLinearWhitespaceComponentsr!�sanitizedBytesr#rr�SynchronousTestCaser�rrrr�<module>s<�



Anon7 - 2022
AnonSec Team