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__/server.cpython-310.pyc
o

�bIs�@sdZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZddlm
ZddlmZddlmZdd	lmZdd
lmZmZddlmZmZddlmZdd
lmZmZm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/ddl0m1Z1dZ2gd�Z3e%edddd�ddd�e%edddd�ddd�e*j4Z5e*j6Z7dZ8dd�Z
d d!�Z9ee+j:�Gd"d#�d#e'e*j;ej<��Z;ee+j=�Gd$d%�d%��Z>ee+j?�Gd&d'�d'��Z@Gd(d)�d)�ZAGd*d+�d+ej<�ZBe#d,ejC���ZCeejD�Gd-d.�d.e*jE��ZFdS)/a�
This is a web server which integrates with the twisted.internet infrastructure.

@var NOT_DONE_YET: A token value which L{twisted.web.resource.IResource.render}
    implementations can return to indicate that the application will later call
    C{.write} and C{.finish} to complete the request, and that the HTTP
    connection should be left open.
@type NOT_DONE_YET: Opaque; do not depend on any particular type for this
    value.
�N)�hexlify)�escape)�List�Optional��quote)�implementer)�Version)�	copyright)�address�
interfaces)�
AlreadyCalled�AlreadyCancelled)�Logger)�
components�failure�reflect)�nativeString�
networkString)�deprecatedModuleAttribute)�Copyable�	ViewPoint)�http�iweb�resource�util)�UnsupportedMethod)�unquote�)�supportedMethods�Request�Session�Site�version�NOT_DONE_YET�GzipEncoderFactory�Twisted�z4Please use twisted.web.http.datetimeToString insteadztwisted.web.server�date_time_stringz4Please use twisted.web.http.stringToDatetime instead�string_date_time)�GET�HEADsPOSTcOs"t|�d�g|�Ri|���d�S)N�charmap)�_quote�decode�encode)�string�args�kwargs�r3�4/usr/lib/python3/dist-packages/twisted/web/server.pyrKs"rcCs8t|tj�r
d|j|jfSt|tj�rd|jfSt|�S)N�INET�UNIX)�
isinstancer�IPv4Address�host�port�UNIXAddress�name�tuple)�addrr3r3r4�_addressToTupleOs

r?c@s@eZdZUdZdZdZdZdZee	e
ed<dZee	e
ed<dZ
dZdZe�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Z d&d'�Z!d>d(d)�Z"d*d+�Z#d,d-�Z$dZ%dZ&e'd.d/��Z(d?d0d1�Z)d2d3�Z*d4d5�Z+d6d7�Z,d8d9�Z-d:d;�Z.d<d=�Z/dS)@r a�
    An HTTP request.

    @ivar defaultContentType: A L{bytes} giving the default I{Content-Type}
        value to send in responses if no other value is set.  L{None} disables
        the default.

    @ivar _insecureSession: The L{Session} object representing state that will
        be transmitted over plain-text HTTP.

    @ivar _secureSession: The L{Session} object representing the state that
        will be transmitted only over HTTPS.
    �	text/htmlN�prepath�postpathzunusednames=issuerFcOs*tjj|g|�Ri|��tj�|�dS�N)rr �__init__r�
Componentized)�selfr1�kwr3r3r4rDsszRequest.__init__cCs�|j��}|d=|d=|d=|d=|j�dd�|j��|d<t||�|d<t|d�|d<t|d	�|d	<t|d
���|d
<|S)N�	transport�channel�content�siter�content_data�remoter9�client�requestHeaders)	�__dict__�copyrJ�seek�readrr?�list�getAllRawHeaders)rF�issuer�xr3r3r4�getStateToCopyForws
zRequest.getStateToCopyForcCs|jrt|j�d|S|S)z�
        Return the text that links to a sibling of the requested resource.

        @param name: The sibling resource
        @type name: C{bytes}

        @return: A relative URL.
        @rtype: C{bytes}
        �../)rB�len)rFr<r3r3r4�sibLink�s
zRequest.sibLinkcCsXt|j�}|dkr|dd|S|dkr|St|j�r*|jdr*|jdd|S|S)z�
        Return the text that links to a child of the requested resource.

        @param name: The child resource
        @type name: C{bytes}

        @return: A relative URL.
        @rtype: C{bytes}
        rrY����/)rZrBrA)rFr<�lppr3r3r4�	childLink�s

zRequest.childLinkcCs@z|jjj}Wntytj�||�YdSw||�|_dS)a0
        Called when HTTP channel got length of content in this request.

        This method is not intended for users.

        @param length: The length of the request body, as indicated by the
            request headers.  L{None} if the request headers do not indicate a
            length.
        N)rIrK�getContentFile�AttributeErrorrr �	gotLengthrJ)rF�lengthr`r3r3r4rb�s
�zRequest.gotLengthcCs�|jj|_|�dt�|�dt���g|_ttt	|j
dd��d���|_|j
dkr1|�
�dSz |j�|�}tj�|�rJ|�|�}|durJ||_|�|�WdStyb|�t���YdSw)z�
        Process a request.

        Find the addressed resource in this request's L{Site},
        and call L{self.render()<Request.render()>} with it.

        @see: L{Site.getResourceFor()}
        sserversdaterNr]�*)rIrK�	setHeaderr#r�datetimeToStringrArT�mapr�path�splitrB�_handleStar�getResourceForr�_IEncodingResource�
providedBy�
getEncoder�_encoder�render�
BaseException�processingFailedr�Failure)rF�resrc�encoderr3r3r4�process�s$
 

�zRequest.processcCs�|js6|jtjtjfv}|j�d�}|j�d�}|o|ddk}|r6|dur6|jdur6|s6|j�d|jg�|j	sK|j
rB|j
�|�}tj�
||�dSdS)z�
        Write data to the transport (if not responding to a HEAD request).

        @param data: A string to write to the response.
        @type data: L{bytes}
        �content-type�content-lengthr�0N)�startedWriting�coder�NOT_MODIFIED�
NO_CONTENT�responseHeaders�
getRawHeaders�defaultContentType�
setRawHeaders�_inFakeHeadror/r �write)rF�data�needsCT�contentType�
contentLength�contentLengthZeror3r3r4r��s&�
��	�z
Request.writecCs.|jr|j��}|rtj�||�tj�|�S)zH
        Override C{http.Request.finish} for possible encoding.
        )ro�finishrr r��rFr�r3r3r4r�
s

zRequest.finishcCsZz|�|�}Wn�ty�}z�|j}|jdkr\d|vr\|jjd|d�d|_d|_|�|�}|tur;|jjd|d�n|�ddt	|�f�d	|_d|_|�
d
�|��WYd}~dS|jtvr�|�dd
�
|��dtt|j��t|j�t	|�dkr}dp~dd�
dd�|D��d�}t�tjd|�}|�|�}nt�tjddt|j�d��f�}|�|�}WYd}~nd}~ww|tur�dSt|t�s�t�tjddt�t�|��ddt�t�|��ddt�t�|����|�}|jdk�rt	|�dk�r|jjd ||d!�|�ddt	|�f�|�
d
�n|�ddt	|�f�|�
|�|��dS)"ah
        Ask a resource to render itself.

        If the resource does not support the requested method,
        generate a C{NOT IMPLEMENTED} or C{NOT ALLOWED} response.

        @param resrc: The resource to render.
        @type resrc: L{twisted.web.resource.IResource}

        @see: L{IResource.render()<twisted.web.resource.IResource.render()>}
        r+r*z,Using GET to fake a HEAD request for {resrc})rtTzBTried to fake a HEAD request for {resrc}, but it got away from me.rx�%dF�N�Allows, zzYour browser approached me (at %(URI)s) with the method "%(method)s".  I only allow the method%(plural)s %(allowed)s here.r�s�z, cSsg|]}t|��qSr3)r)�.0rWr3r3r4�
<listcomp>Osz"Request.render.<locals>.<listcomp>)�URI�method�plural�allowedzMethod Not AllowedzHuh?z'I don't know how to treat a %s request.r,zRequest did not return bytesz	Request: z<br />z
Resource: zValue: rzbWarning: HEAD request {slf} for resource {resrc} is returning a message body. I think I'll eat it.)�slfrt)rpr�allowedMethodsr��_log�infor�r$rerZr�r�r�joinrr�urir�	ErrorPager�NOT_ALLOWED�NOT_IMPLEMENTEDr.r7�bytes�INTERNAL_SERVER_ERRORr�_PREr�	safe_repr)rFrt�body�er�r��epager3r3r4rps��
�

�����
��9
���������
�
zRequest.rendercCst|jjd|d�|jjrdt�|�d}nd}|�tj�|�	dd�|�	dd	t
|�f�|�|�|��|S)
aO
        Finish this request with an indication that processing failed and
        possibly display a traceback.

        @param reason: Reason this request has failed.
        @type reason: L{twisted.python.failure.Failure}

        @return: The reason passed to this method.
        @rtype: L{twisted.python.failure.Failure}
        r�)rs�<html><head><title>web.Server Traceback (most recent call last)</title></head><body><b>web.Server Traceback (most recent call last):</b>

s

</body></html>
s_<html><head><title>Processing Failed</title></head><body><b>Processing Failed</b></body></html>rwr@rxr�)
r�rrK�displayTracebacksr�
formatFailure�setResponseCoderr�rerZr�r�)rF�reasonr�r3r3r4rr~s ���
�
zRequest.processingFailedcC�|�|�dS)z(Remote version of write; same interface.N)r�)rFrVr�r3r3r4�
view_write��zRequest.view_writecCs|��dS)z)Remote version of finish; same interface.N)r��rFrVr3r3r4�view_finish�szRequest.view_finishcKs|j||fi|��dS)z,Remote version of addCookie; same interface.N)�	addCookie)rFrV�k�vr2r3r3r4�view_addCookie�szRequest.view_addCookiecC�|�||�dS)z,Remote version of setHeader; same interface.N)re)rFrVr�r�r3r3r4�view_setHeader�szRequest.view_setHeadercCr�)z2Remote version of setLastModified; same interface.N)�setLastModified)rFrV�whenr3r3r4�view_setLastModified�r�zRequest.view_setLastModifiedcCr�)z*Remote version of setETag; same interface.N)�setETag)rFrV�tagr3r3r4�view_setETag�r�zRequest.view_setETagcCr�)zD
        Remote version of setResponseCode; same interface.
        N)r�)rFrVr{�messager3r3r4�view_setResponseCode��zRequest.view_setResponseCodecCs|�t|�|�dS)zbRemote version of registerProducer; same interface.
        (requires a remote producer.)
        N)�registerProducer�_RemoteProducerWrapper)rFrV�producer�	streamingr3r3r4�view_registerProducer�szRequest.view_registerProducercCs|��dSrC)�unregisterProducerr�r3r3r4�view_unregisterProducer��zRequest.view_unregisterProducercCs|��r|jS|jS)a�
        If a session has already been created or looked up with
        L{Request.getSession}, this will return that object.  (This will always
        be the session that matches the security of the request; so if
        C{forceNotSecure} is used on a secure request, this will not return
        that session.)

        @return: the session attribute
        @rtype: L{Session} or L{None}
        )�isSecure�_secureSession�_insecureSession�rFr3r3r4�session�szRequest.sessionc		Cs�|��o|}|sd}d}nd}d}t||�}|dur/z|��Wn
ttfy.d}Ynw|durfd�|g|j�}|�|�}|rUz|j�	|�}Wn	t
yTYnw|sf|j��}|j||j
d|d�t|||�|rs|�|�S|S)	a
        Check if there is a session cookie, and if not, create it.

        By default, the cookie with be secure for HTTPS requests and not secure
        for HTTP requests.  If for some reason you need access to the insecure
        cookie from a secure request you can set C{forceNotSecure = True}.

        @param forceNotSecure: Should we retrieve a session that will be
            transmitted over HTTP, even if this L{Request} was delivered over
            HTTPS?
        @type forceNotSecure: L{bool}
        sTWISTED_SESSIONr�sTWISTED_SECURE_SESSIONr�N�_r])rh�secure)r��getattr�touchr
rr��sitepath�	getCookierK�
getSession�KeyError�makeSessionr��uid�setattr�getComponent)	rF�sessionInterface�forceNotSecurer��cookieString�sessionAttributer��
cookiename�
sessionCookier3r3r4r��s:
�
�

zRequest.getSessioncCst|��j}|��rd}nd}||krd}nd|}td|��r!dp"dt|���|f�}d�dd	�|D��}||S)
Ni��Pr�z:%dzhttp%s://%s%s/r�r]cSsg|]}t|dd��qS)r�)�safer)r��segmentr3r3r4r�'sz'Request._prePathURL.<locals>.<listcomp>)�getHostr:r�rr�getRequestHostnamer�)rFrAr:�default�hostport�prefixrhr3r3r4�_prePathURLs"

���zRequest._prePathURLcCs|�|j�SrC)r�rAr�r3r3r4�
prePathURL*r�zRequest.prePathURLcCsddlm}|j�|�S)Nr)�urlpath)�twisted.pythonr��URLPath�fromRequest)rFr�r3r3r4r�-szRequest.URLPathcCs|�|jdd��}||_dS)z_
        Remember the currently-processed part of the URL for later
        recalling.
        Nr\)r�rA�
appRootURL)rF�urlr3r3r4�rememberRootURL2s
zRequest.rememberRootURLcCs|jS)zn
        Get a previously-remembered URL.

        @return: An absolute URL.
        @rtype: L{bytes}
        )r�r�r3r3r4�
getRootURL:szRequest.getRootURLcCsH|jdkr|�tj�n|�tj�|�dd�|�dd�|��dS)a�
        Handle receiving a request whose path is '*'.

        RFC 7231 defines an OPTIONS * request as being something that a client
        can send as a low-effort way to probe server capabilities or readiness.
        Rather than bother the user with this, we simply fast-path it back to
        an empty 200 OK. Any non-OPTIONS verb gets a 405 Method Not Allowed
        telling the client they can only use OPTIONS.
        sOPTIONSr�sContent-LengthryN)r�r�r�OKr�rer�r�r3r3r4rjCs

zRequest._handleStarrC)NF)0�__name__�
__module__�__qualname__�__doc__r�rKr�rArrr��__annotations__rB�
__pychecker__r�rorr�rDrXr[r_rbrvr�r�rprrr�r�r�r�r�r�r�r�r�r�r��propertyr�r�r�r�r�r�r�rjr3r3r3r4r XsR
$&
g#


7	r c@s&eZdZdZe�d�ZdZdd�ZdS)r%z~
    @cvar compressLevel: The compression level used by the compressor, default
        to 9 (highest).

    @since: 12.3
    s(:?^|[\s,])gzip(:?$|[\s,])�	cCsfd�|j�dg��}|j�|�r1|j�d�}|r!d�|dg�}nd}|j�d|g�t|j|�SdS)zo
        Check the headers if the client accepts gzip encoding, and encodes the
        request if so.
        �,saccept-encodingscontent-encodingsgzipN)	r�rOr�_gzipCheckRegex�searchr~r��_GzipEncoder�
compressLevel)rF�request�
acceptHeaders�encodingr3r3r4�encoderForRequestes��z$GzipEncoderFactory.encoderForRequestN)	r�r�r�r��re�compiler�r�rr3r3r3r4r%Ys

r%c@s,eZdZdZdZdd�Zdd�Zdd�ZdS)	r�z�
    An encoder which supports gzip.

    @ivar _zlibCompressor: The zlib compressor instance used to compress the
        stream.

    @ivar _request: A reference to the originating request.

    @since: 12.3
    NcCs"t�|tjdtj�|_||_dS)N�)�zlib�compressobj�DEFLATED�	MAX_WBITS�_zlibCompressor�_request)rFr�r�r3r3r4rD�s�
z_GzipEncoder.__init__cCs"|jjs|jj�d�|j�|�S)zR
        Write to the request, automatically compressing data on the fly.
        rx)r	rzr~�removeHeaderr�compressr�r3r3r4r/�sz_GzipEncoder.encodecCs|j��}d|_|S)zf
        Finish handling the request request, flushing any data from the zlib
        buffer.
        N)r�flush)rF�remainr3r3r4r��s
z_GzipEncoder.finish)r�r�r�r�rrDr/r�r3r3r3r4r�xs
r�c@seZdZdd�ZdS)r�cCs(|�d�|_|�d�|_|�d�|_dS)N�resumeProducing�pauseProducing�
stopProducing)�remoteMethodrrr)rFrMr3r3r4rD�sz_RemoteProducerWrapper.__init__N)r�r�r�rDr3r3r3r4r��sr�csJeZdZdZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Z	dd
�Z
�ZS)r!a�
    A user's session with a system.

    This utility class contains no functionality, but is used to
    represent a session.

    @ivar site: The L{Site} that generated the session.
    @type site: L{Site}

    @ivar uid: A unique identifier for the session.
    @type uid: L{bytes}

    @ivar _reactor: An object providing L{IReactorTime} to use for scheduling
        expiration.

    @ivar sessionTimeout: Time after last modification the session will expire,
        in seconds.
    @type sessionTimeout: L{float}

    @ivar lastModified: Time the C{touch()} method was last called (or time the
        session was created). A UNIX timestamp as returned by
        L{IReactorTime.seconds()}.
    @type lastModified: L{float}
    i�NcsBt���|dur|j}||_||_||_g|_|��i|_dS)z�
        Initialize a session with a unique ID for that session.

        @param reactor: L{IReactorTime} used to schedule expiration of the
            session. If C{None}, the reactor associated with I{site} is used.
        N)	�superrD�reactor�_reactorrKr��expireCallbacksr��sessionNamespaces)rFrKr�r��	__class__r3r4rD�s

zSession.__init__cCs|j�|j|j�|_dS)zF
        Start expiration tracking.

        @return: L{None}
        N)r�	callLater�sessionTimeout�expire�_expireCallr�r3r3r4�startCheckingExpiration�szSession.startCheckingExpirationcCs|j�|�dS)zJ
        Call this callback when the session expires or logs out.
        N)r�append)rF�callbackr3r3r4�notifyOnExpire�r�zSession.notifyOnExpirecCsP|jj|j=|jD]}|�q	g|_|jr$|j��r&|j��d|_dSdSdS)z/
        Expire/logout of the session.
        N)rK�sessionsr�rr�active�cancel)rF�cr3r3r4r�s


�zSession.expirecCs,|j��|_|jdur|j�|j�dSdS)zN
        Mark the session as modified, which resets expiration timer.
        N)r�seconds�lastModifiedr�resetrr�r3r3r4r��s
�z
Session.touchrC)r�r�r�r�rrrDrr rr��
__classcell__r3r3rr4r!�s
r!zTwistedWeb/cs�eZdZdZdZeZdZeZ	dZ
ejZ
d�fdd�	Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z�fdd�ZdZdd�Zdd�Zdd�Zdd�Z�ZS)r"a*
    A web site: manage log, sessions, and resources.

    @ivar requestFactory: A factory which is called with (channel)
        and creates L{Request} instances. Default to L{Request}.

    @ivar displayTracebacks: If set, unhandled exceptions raised during
        rendering are returned to the client as HTML. Default to C{False}.

    @ivar sessionFactory: factory for sessions objects. Default to L{Session}.

    @ivar sessions: Mapping of session IDs to objects returned by
        C{sessionFactory}.
    @type sessions: L{dict} mapping L{bytes} to L{Session} given the default
        C{sessionFactory}

    @ivar counter: The number of sessions that have been generated.
    @type counter: L{int}

    @ivar sessionCheckTime: Deprecated and unused. See
        L{Session.sessionTimeout} instead.
    rFiNcs4t�j|i|��i|_||_|dur||_dSdS)a�
        @param resource: The root of the resource hierarchy.  All request
            traversal for requests received by this factory will begin at this
            resource.
        @type resource: L{IResource} provider
        @param requestFactory: Overwrite for default requestFactory.
        @type requestFactory: C{callable} or C{class}.

        @see: L{twisted.web.http.HTTPFactory.__init__}
        N)rrDr!r�requestFactory)rFrr)r1r2rr3r4rD s
�z
Site.__init__cCs(ddlm}|�tj�|�tj�|��S)Nr)�logfile)r�r*�LogFile�osrh�basename�dirname)rFrhr*r3r3r4�_openLogFile1szSite._openLogFilecCs|j��}i|d<|S)Nr!)rPrQ)rF�dr3r3r4�__getstate__6s
zSite.__getstate__cCs|jd|_t|�d��S)zP
        (internal) Generate an opaque, unique ID for a user's session.
        r� )�counterr�_entropyr�r3r3r4�_mkuid;szSite._mkuidcCs*|��}|�||�}|j|<|��|S)zU
        Generate a new Session instance, and store it for future reference.
        )r5�sessionFactoryr!r)rFr�r�r3r3r4r�BszSite.makeSessioncCs
|j|S)z�
        Get a previously generated session.

        @param uid: Unique ID of the session.
        @type uid: L{bytes}.

        @raise KeyError: If the session is not found.
        )r!)rFr�r3r3r4r�Ks
	zSite.getSessioncst��|�}|j|_||_|S)z;
        Generate a channel attached to this site.
        )r�
buildProtocolr)rK)rFr>rIrr3r4r7VszSite.buildProtocolcCs|�|��d�|��dS)z@
        Redirect because a Site is always a directory.
        r]N)�redirectr�r��rFr�r3r3r4rpaszSite.rendercCs||_|j�||�S)z7
        Emulate a resource's getChild method.
        )rKr�getChildWithDefault)rF�pathElr�r3r3r4r:hszSite.getChildWithDefaultcCs"||_t�|j�|_t�|j|�S)z�
        Get a resource for a request.

        This iterates through the resource hierarchy, calling
        getChildWithDefault on each resource it finds for a path element,
        stopping when it hits an element where isLeaf is true.
        )rKrQrAr�r�getChildForRequestr9r3r3r4rkoszSite.getResourceForcCsdg}tjr|�dd�|S)z2
        Protocols this server can speak.
        shttp/1.1rsh2)r�
H2_ENABLED�insert)rF�
baseProtocolsr3r3r4�acceptableProtocols~szSite.acceptableProtocolsrC)r�r�r�r�r3r r)r�r!r6�sessionCheckTimer,�urandomr4rDr/r1r5r�r�r7�isLeafrpr:rkr@r(r3r3rr4r"s(		r")Gr�rQr,rr�binasciir�htmlr�typingrr�urllib.parserr-�zope.interfacer�incrementalr	�twistedr
�twisted.internetrr�twisted.internet.errorr
r�twisted.loggerrr�rrr�twisted.python.compatrr�twisted.python.deprecater�twisted.spread.pbrr�twisted.webrrrr�twisted.web.errorr�twisted.web.httprr$�__all__rfr(�stringToDatetimer)rr?�IRequestr rE�_IRequestEncoderFactoryr%�_IRequestEncoderr�r�r!r#�IProtocolNegotiationFactory�HTTPFactoryr"r3r3r3r4�<module>sp��	(U

Spamworldpro Mini