HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/twisted/web/__pycache__/distrib.cpython-38.pyc
U


W[e.�@s<dZddlZddlZzddlZWnek
r8dZYnXddlmZddlmZddl	m
Z
ddlmZddl
mZmZmZmZmZddlmZdd	lmZdd
lmZmZddlmZGdd
�d
e
j�ZGdd�de
jej�Ze
� eje�Gdd�d�Z!Gdd�dej"�Z#Gdd�de
j$ej%�Z&Gdd�dej"�Z'dS)z�
Distributed web servers.

This is going to have to be refactored so that argument parsing is done
by each subprocess and not by the main web server (i.e. GET, POST etc.).
�N)�BytesIO)�getDOMImplementation)�pb)�
SIZE_LIMIT)�http�resource�server�util�static)�Headers)�styles)�address�reactor)�Loggerc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�_ReferenceableProducerWrappercCs
||_dS�N)�producer)�selfr�r�5/usr/lib/python3/dist-packages/twisted/web/distrib.py�__init__!sz&_ReferenceableProducerWrapper.__init__cCs|j��dSr)rZresumeProducing�rrrr�remote_resumeProducing$sz4_ReferenceableProducerWrapper.remote_resumeProducingcCs|j��dSr)rZpauseProducingrrrr�remote_pauseProducing'sz3_ReferenceableProducerWrapper.remote_pauseProducingcCs|j��dSr)rZ
stopProducingrrrr�remote_stopProducing*sz2_ReferenceableProducerWrapper.remote_stopProducingN)�__name__�
__module__�__qualname__rrrrrrrrr src@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�Requestzn
    A request which was received by a L{ResourceSubscription} and sent via
    PB to a distributed node.
    cs�dD]H}||�ddd��d���fdd��fdd�d	���}|||<qtt|d
��|d
<tj�||�t|j�|_|j�	d�|_
|j�	d�|_|j�	d
�|_|j�	d�|_
|j�	d�|_|j�	d�|_|j�	d�|_dS)z�
        Initialize this L{twisted.web.distrib.Request} based on the copied
        state so that it closely resembles a L{twisted.web.server.Request}.
        )�hostZclient�TCP�UNIX)ZINETr!rcst���d�d�S)N��)r
ZIPv4Addressr�Zaddrdesc�tuprr�<lambda>;s�z*Request.setCopyableState.<locals>.<lambda>cst��d�S)Nr")r
ZUNIXAddressr)r%rrr&=�)r r!ZrequestHeaders�finish�	setHeader�	addCookie�setETag�setResponseCode�setLastModified�writeN)r�dictr�
RemoteCopy�setCopyableStaterZcontent_dataZcontent�remoteZremoteMethodr(r)r*r+r,r-�_write)r�state�kZaddrrr$rr13s&
��
zRequest.setCopyableStatecCs>d}t}|�|||��|t7}|t7}|t|�krq:qdS)z�
        Write the given bytes to the response body.

        @param bytes: The bytes to write.  If this is longer than 640k, it
            will be split up into smaller pieces.
        rN)rr3�len)r�bytes�start�endrrrr.Osz
Request.writecCs |j�dt|�|��|j�dS)N�registerProducer)r2�
callRemoter�
addErrback�fail)rrZ	streamingrrrr:`s��zRequest.registerProducercCs|j�d��|j�dS)N�unregisterProducer)r2r;r<r=rrrrr>eszRequest.unregisterProducercCs|jjd|d�dS)N�)�failure)�_logr@�rr@rrrr=hszRequest.failN)	rrr�__doc__r1r.r:r>r=rrrrr.src@s*eZdZe�Zdd�Zdd�Zdd�ZdS)�IssuecCs
||_dSr)�request)rrErrrrqszIssue.__init__cCs6|tjkr2t|t�std��|j�|�|j��dS)Nzreturn value not a string)r�NOT_DONE_YET�
isinstance�str�AssertionErrorrEr.r()r�resultrrr�finishedts
zIssue.finishedc
CsLt|�}|j�t�tjddt�|���	|j��|j�
�|j�|�dS)NzServer Connection Lostz&Connection to distributed server lost:)
rHrEr.rZ	ErrorPagerZINTERNAL_SERVER_ERRORr	Z_PRE�renderr(rA�inforBrrr�failedzs����
zIssue.failedN)rrrrrArrKrNrrrrrDnsrDc@sJeZdZdZdZe�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZdS)�ResourceSubscriptionr"rcCs(tj�|�||_||_g|_d|_dSr)r�Resourcerr�port�pending�	publisher)rrrQrrrr�s
zResourceSubscription.__init__cCs(t�|j�}d|d<d|d<g|d<|S)z<Get persistent state for this ResourceSubscription.
        NrSr�waitingrR)�copy�__dict__)rr4rrr�__getstate__�s
z!ResourceSubscription.__getstate__cCsF|j�d�|j�|j�||_d|_|jD]}|�|�q,g|_dS)zFI've connected to a publisher; I'll now send all my requests.
        zconnected to publisherrN)	rArMZbrokerZnotifyOnDisconnect�bootedrSrTrRrL)rrSrErrr�	connected�s
zResourceSubscription.connectedcCsD|jjd|d�d|_d|_|jD]}|�d�|��q"g|_dS)zXI can't connect to a publisher; I'll now reply to all pending
        requests.
        z3could not connect to distributed web service: {msg})�msgrNz(Unable to connect to distributed server.)rArMrTrSrRr.r()rrZrErrr�notConnected�s�


z!ResourceSubscription.notConnectedcCs|�d�dS)Nzconnection dropped)r[rrrrrX�szResourceSubscription.bootedcCs�|jst|j�|�|js�d|_t��}d}|jdkrFt�|j	||�nt�
|j|j	||�|��}|�|j
|j�n"t|�}|j�d|��|j|j�tjS)a:Render this request, from my server.

        This will always be asynchronous, and therefore return NOT_DONE_YET.
        It spins off a request to the pb client, and either adds it to the list
        of pending issues or requests it immediately, depending on if the
        client is already connected.
        r"�
�unixrE)rSrR�appendrTrZPBClientFactoryrrZconnectUNIXrQZ
connectTCPZ
getRootObjectZaddCallbacksrYr[rDr;rKrNrrF)rrEZbfZtimeout�d�irrrrL�s
zResourceSubscription.renderN)
rrrZisLeafrTrrArrWrYr[rXrLrrrrrO�s
rOc@s:eZdZdZe�Zdd�ZdZdd�Zdd�Z	d	d
�Z
dS)�ResourcePublisherz�
    L{ResourcePublisher} exposes a remote API which can be used to respond
    to request.

    @ivar site: The site which will be used for resource lookup.
    @type site: L{twisted.web.server.Site}
    cCs
||_dSr)�site)rrbrrrr�szResourcePublisher.__init__r#cCs*|jj�d�|jj|j=|`|`|`dS)NZweb)ZapplicationZ
authorizerZremoveIdentity�servicesZserviceNameZperspectiveNamerrrr�upgradeToVersion2�s
z#ResourcePublisher.upgradeToVersion2cCs|Srr)r�namerrr�getPerspectiveNamed�sz%ResourcePublisher.getPerspectiveNamedcCsD|j�|�}|j�|�|�|�}|tjk	r>|�|�|��tjS)zK
        Look up the resource for the given request and render it.
        )	rbZgetResourceForrArMrLrrFr.r()rrE�resrJrrr�remote_request�s


z ResourcePublisher.remote_requestN)rrrrCrrArZpersistenceVersionrdrfrhrrrrra�srac@s>eZdZdZdZdZdZddd�Zdd	�Zd
d�Z	dd
�Z
dS)�
UserDirectoryz�
    A resource which lists available user resources and serves them as
    children.

    @ivar _pwd: An object like L{pwd} which is used to enumerate users and
        their home directories.
    Zpublic_htmlz.twistd-web-pba�
<html>
    <head>
    <title>twisted.web.distrib.UserDirectory</title>
    <style>

    a
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        color: #369;
        text-decoration: none;
    }

    th
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        font-weight: bold;
        text-decoration: none;
        text-align: left;
    }

    pre, code
    {
        font-family: "Courier New", Courier, monospace;
    }

    p, body, td, ol, ul, menu, blockquote, div
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        color: #000;
    }
    </style>
    </head>

    <body>
    <h1>twisted.web.distrib.UserDirectory</h1>

    %(users)s
</body>
</html>
NcCs"tj�|�|dkrt}||_dSr)rrPr�pwd�_pwd)rZuserDatabaserrrr7szUserDirectory.__init__c
Cs�g}|j��D]�}|\}}}}}}}	|�d�d}
|
s:|}
tj�tj�||j��rd|�||
df�tj�||j	�}tj�|�r|d}|�||
df�q|S)z|
        Return a list of two-tuples giving links to user resources and text to
        associate with those links.
        �,rz (file)�.twistdz	 (twistd))
rkZgetpwall�split�os�path�exists�join�userDirNamer^�userSocketName)
r�users�userreZpasswdZuid�gidZgecos�dir�shellZrealname�
twistdsockZlinkNamerrr�_users>szUserDirectory._userscCs�t�}|�ddd�}|j}|��D]T\}}|�d�}|�d|d�|�|�}|�|�|�d�}	|	�|�|�|	�q"|jd|�	�i}
|
�
d�S)	zm
        Render as HTML a listing of all known users with links to their
        personal resources.
        NZul�aZhref�/Zliruzutf-8)rZcreateDocumentZdocumentElementr{Z
createElementZsetAttributeZcreateTextNodeZappendChild�templateZtoxml�encode)rrEZdomImplZnewDocZlisting�link�textZlinkElementZtextNode�itemZhtmlDocrrr�
render_GETRs




zUserDirectory.render_GETcCs�|dkr|Sd}|t|�d�|kr>|dt|��}d}n|}d}z|j�|�\}}}}	}
}}Wntk
r�t��YSX|r�tj�||j	�}
t
d|
�}|�||�|Stj�||j�}tj�
|�s�t��St�|�SdS)Nr?rmr"rr])r6rk�getpwnam�KeyErrorrZ
NoResourcerorprrrtrOZputChildrsrqr
ZFile)rrerEZtdZusername�subZpw_nameZ	pw_passwdZpw_uidZpw_gidZpw_gecos�pw_dirZpw_shellrzZrsrprrr�getChildhs,
�
zUserDirectory.getChild)N)rrrrCrsrtr~rr{r�r�rrrrris*
ri)(rCrorUrj�ImportError�iorZxml.dom.minidomrZtwisted.spreadrZtwisted.spread.bananarZtwisted.webrrrr	r
Ztwisted.web.http_headersrZtwisted.persistedrZtwisted.internetr
rZtwisted.loggerrZ
Referenceablerr0rZsetUnjellyableForClassrDrPrOZRootZ	Versionedrarirrrr�<module>s*
>R(