Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/web/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�b�&�@s�dZddlmZmZmZddlmZddlm	Z	ddl
mZmZm
Z
mZddlmZddlmZGdd	�d	e
�ZGd
d�de	�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)aT
Simplistic HTTP proxy support.

This comes in two main variants - the Proxy and the ReverseProxy.

When a Proxy is in use, a browser trying to connect to a server (say,
www.yahoo.com) will be intercepted by the Proxy, and the proxy will covertly
connect to the server, and return the result.

When a ReverseProxy is in use, the client connects directly to the ReverseProxy
(say, www.yahoo.com) which farms off the request to one of a pool of servers,
and returns the result.

Normally, a Proxy is used on the client end of an Internet connection, while a
ReverseProxy is used on the server end.
�)�quote�urlparse�
urlunparse)�reactor)�
ClientFactory)�_QUEUED_SENTINEL�HTTPChannel�
HTTPClient�Request)�Resource)�NOT_DONE_YETc@sDeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�ProxyClientz�
    Used by ProxyClientFactory to implement a simple web proxy.

    @ivar _finished: A flag which indicates whether or not the original request
        has been finished yet.
    FcCsD||_||_||_d|vr|d=d|d<|�dd�||_||_dS)Nsproxy-connectionscloses
connections
keep-alive)�father�command�rest�pop�headers�data��selfrr�versionrrr�r�3/usr/lib/python3/dist-packages/twisted/web/proxy.py�__init__)s
zProxyClient.__init__cCsJ|�|j|j�|j��D]
\}}|�||�q
|��|j�|j	�dS�N)
�sendCommandrrr�items�
sendHeader�
endHeaders�	transport�writer)r�header�valuerrr�connectionMade4s
zProxyClient.connectionMadecCs|j�t|�|�dSr)r�setResponseCode�int)rr�code�messagerrr�handleStatus;szProxyClient.handleStatuscCs6|��dvr|jj�||g�dS|jj�||�dS)N)sserversdatescontent-type)�lowerr�responseHeaders�
setRawHeaders�addRawHeader)r�keyr"rrr�handleHeader>szProxyClient.handleHeadercCs|j�|�dSr)rr )r�bufferrrr�handleResponsePartHszProxyClient.handleResponsePartcCs(|jsd|_|j��|j��dSdS)z�
        Finish the original request, indicating that the response has been
        completely written to it, and disconnect the outgoing transport.
        TN)�	_finishedr�finishr�loseConnection)rrrr�handleResponseEndKs

�zProxyClient.handleResponseEndN)�__name__�
__module__�__qualname__�__doc__r1rr#r(r.r0r4rrrrr
s
r
c@s,eZdZdZeZdd�Zdd�Zdd�ZdS)	�ProxyClientFactoryz?
    Used by ProxyRequest to implement a simple web proxy.
    cCs(||_||_||_||_||_||_dSr)rrrrrrrrrrr^s
zProxyClientFactory.__init__cCs |�|j|j|j|j|j|j�Sr)�protocolrrrrrr)r�addrrrr�
buildProtocolfs�z ProxyClientFactory.buildProtocolcCs8|j�dd�|jj�dd�|j�d�|j��dS)zh
        Report a connection failure in a response to the incoming request as
        an error.
        i�s
Gateway errorsContent-Types	text/htmls<H1>Could not connect</H1>N)rr$r*r,r r2)r�	connector�reasonrrr�clientConnectionFailedksz)ProxyClientFactory.clientConnectionFailedN)	r5r6r7r8r
r:rr<r?rrrrr9Vsr9c@s6eZdZdZdeiZddiZeefdd�Z	dd�Z
dS)	�ProxyRequestz�
    Used by Proxy to implement a simple web proxy.

    @ivar reactor: the reactor used to create connections.
    @type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
    shttp�PcC�t�|||�||_dSr�r
rr�r�channel�queuedrrrrr��
zProxyRequest.__init__c
Cs�t|j�}|d}|d�d�}|j|}d|vr$|�d�\}}t|�}td|dd��}|s4|d}|j|}|���	�}d|vrJ|�
d�|d<|j�dd�|j�
�}||j||j|||�}	|j�|||	�dS)	Nr��ascii�:)�rK��/�host)r�uri�decode�ports�splitr%r�	protocols�
getAllHeaders�copy�encode�content�seek�read�method�clientprotor�
connectTCP)
r�parsedr:�host�portr�class_r�s�
clientFactoryrrr�process�s$



zProxyRequest.processN)r5r6r7r8r9rSrQrrrrcrrrrr@vsr@c@�eZdZdZeZdS)�Proxyao
    This class implements a simple web proxy.

    Since it inherits from L{twisted.web.http.HTTPChannel}, to use it you
    should do something like this::

        from twisted.web import http
        f = http.HTTPFactory()
        f.protocol = Proxy

    Make the HTTPFactory a listener on a port as per usual, and you have
    a fully-functioning web proxy!
    N)r5r6r7r8r@�requestFactoryrrrrre�srec@s*eZdZdZeZeefdd�Zdd�Z	dS)�ReverseProxyRequestal
    Used by ReverseProxy to implement a simple reverse proxy.

    @ivar proxyClientFactoryClass: a proxy client factory class, used to create
        new connections.
    @type proxyClientFactoryClass: L{ClientFactory}

    @ivar reactor: the reactor used to create connections.
    @type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
    cCrBrrCrDrrrr�rGzReverseProxyRequest.__init__cCsZ|j�d|jj�d�g�|�|j|j|j|�	�|j
��|�}|j�
|jj|jj|�dS)z�
        Handle this request by connecting to the proxied server and forwarding
        it there, then forwarding the response back as the response to this
        request.
        rNrIN)�requestHeadersr+�factoryr^rV�proxyClientFactoryClassrZrOr[rTrWrYrr\r_)rrbrrrrc�s�zReverseProxyRequest.processN)
r5r6r7r8r9rjrrrrcrrrrrg�s
rgc@rd)�ReverseProxyzo
    Implements a simple reverse proxy.

    For details of usage, see the file examples/reverse-proxy.py.
    N)r5r6r7r8rgrfrrrrrk�srkc@s0eZdZdZeZefdd�Zdd�Zdd�Z	dS)	�ReverseProxyResourcea�
    Resource that renders the results gotten from another server

    Put this resource in the tree to cause everything below it to be relayed
    to a different server.

    @ivar proxyClientFactoryClass: a proxy client factory class, used to create
        new connections.
    @type proxyClientFactoryClass: L{ClientFactory}

    @ivar reactor: the reactor used to create connections.
    @type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
    cCs&t�|�||_||_||_||_dS)aU
        @param host: the host of the web server to proxy.
        @type host: C{str}

        @param port: the port of the web server to proxy.
        @type port: C{port}

        @param path: the base path to fetch data from. Note that you shouldn't
            put any trailing slashes in it, it will be added automatically in
            request. For example, if you put B{/foo}, a request on B{/bar} will
            be proxied to B{/foo/bar}.  Any required encoding of special
            characters (such as " " or "/") should have been done already.

        @type path: C{bytes}
        N)rrr^r_�pathr)rr^r_rmrrrrr�s


zReverseProxyResource.__init__cCs,t|j|j|jdt|dd��d�|j�S)z�
        Create and return a proxy resource with the same proxy configuration
        as this one, except that its path also contains the segment given by
        C{path} at the end.
        rMrK)�safezutf-8)rlr^r_rm�urlquoterVr)rrm�requestrrr�getChilds�zReverseProxyResource.getChildcCs�|jdkr	|j}nd|j|jf}|j�d|�d�g�|j�dd�t|j�d}|r4|j	d|}n|j	}|�
|j||j|�
�|j��|�}|j�|j|j|�tS)zJ
        Render a request by forwarding it to the proxied server.
        rAz%s:%drNrIr��?)r_r^rhr+rVrWrXrrOrmrjrZr[rTrYrr\r)rrpr^�qsrrbrrr�renders&
�zReverseProxyResource.renderN)
r5r6r7r8r9rjrrrqrurrrrrl�s
rlN)r8�urllib.parserrorr�twisted.internetr�twisted.internet.protocolr�twisted.web.httprrr	r
�twisted.web.resourcer�twisted.web.serverrr
r9r@rergrkrlrrrr�<module>s7 $$

Spamworldpro Mini