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__/twcgi.cpython-38.pyc
U

��W[O,�@s�dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZmZGdd	�d	e
jej�ZGd
d�de
j�ZGdd
�d
e�ZGdd�deje
j�ZdS)zH
I hold resource classes and helper classes that deal with CGI scripts.
�N)�protocol)�Logger)�filepath)�pb)�http�resource�server�staticc@s$eZdZdd�Zdd�Zdd�ZdS)�CGIDirectorycCstj�|�tj�||�dS�N)r�Resource�__init__r�FilePath)�self�pathname�r�3/usr/lib/python3/dist-packages/twisted/web/twcgi.pyr
szCGIDirectory.__init__cCs>|�|�}|��stjjS|��r,t|j�St|j�St	�
�Sr)Zchild�existsr	ZFileZ
childNotFound�isdirr
�path�	CGIScriptr�
NoResource)rr�requestZfnprrr�getChilds


zCGIDirectory.getChildcCst�d�}|�|�S)Nz1CGI directories do not support directory listing.)rr�render)rrZnotFoundrrrr's�zCGIDirectory.renderN)�__name__�
__module__�__qualname__r
rrrrrrr
sr
c@s2eZdZdZdZd
dd�Zdd�Zgfdd	�ZdS)rz�
    L{CGIScript} is a resource which runs child processes according to the CGI
    specification.

    The implementation is complex due to the fact that it requires asynchronous
    IPC with an external process with an unpleasant protocol.
    �NcCs$||_|dkrddlm}||_dS)zA
        Initialize, with the name of a CGI script file.
        Nr)�reactor)�filename�twisted.internetr�_reactor)rr �registryrrrrr
7szCGIScript.__init__c
Cs�dd�|j�}|���d�d}tj|d|jt|��j	�|j
||j|jd�	}|�
�j}|dk	rh||d<|j}|r�dd�|�|d	<t|d
�r�|j�dd�|j��}|j�dd�t|�|d<z|j�d
�}Wn tk
r�d|d<g}	Yn@X|j|dd�}
|d<d|
k�rg}	ndd�|
�d�D�}	|����D]4\}}|�dd���}
|dk�rfd|
}
|||
<�q<tj��D]\}}||k�r||||<�q||�|||	�tjS)a
        Do various things to conform to the CGI specification.

        I will set up the usual slew of environment variables, then spin off a
        process.

        @type request: L{twisted.web.http.Request}
        @param request: An HTTP request.
        �/�:rzCGI/1.1)	ZSERVER_SOFTWAREZSERVER_NAMEZGATEWAY_INTERFACEZSERVER_PROTOCOLZSERVER_PORTZREQUEST_METHODZSCRIPT_NAMEZSCRIPT_FILENAMEZREQUEST_URINZREMOTE_ADDR�/Z	PATH_INFO�content�ZCONTENT_LENGTH�?�ZQUERY_STRINGr�=cSsg|]}t�|��qSr)�urllibZunquote)�.0�xrrr�
<listcomp>ssz$CGIScript.render.<locals>.<listcomp>�+�-�_)scontent-typescontent-lengthsproxysHTTP_)�joinZprepathZgetRequestHostname�splitr�versionZclientproto�strZgetHostZport�methodr �uriZgetClientAddressZhostZpostpath�hasattrr'�seek�tell�index�
ValueErrorZ
getAllHeaders�items�replace�upper�os�environ�
runProcessZNOT_DONE_YET)rrZ
scriptNameZ
serverName�envZipZppZlengthZqindex�qargsZqs�title�headerZenvname�key�valuerrrrDsT
�







zCGIScript.renderc	Cs4t|�}|j�||j|jg||tj�|j��dS)aI
        Run the cgi script.

        @type env: A L{dict} of L{str}, or L{None}
        @param env: The environment variables to pass to the process that will
            get spawned. See
            L{twisted.internet.interfaces.IReactorProcess.spawnProcess} for
            more information about environments and process creation.

        @type request: L{twisted.web.http.Request}
        @param request: An HTTP request.

        @type qargs: A L{list} of L{str}
        @param qargs: The command line arguments to pass to the process that
            will get spawned.
        N)�CGIProcessProtocolr"�spawnProcessr rAr�dirname�rrDrrE�prrrrC�s
�zCGIScript.runProcess)NN)rrr�__doc__ZisLeafr
rrCrrrrr.s


@rc@s eZdZdZdZgfdd�ZdS)�FilteredScripta
    I am a special version of a CGI script, that uses a specific executable.

    This is useful for interfacing with other scripting languages that adhere
    to the CGI standard. My C{filter} attribute specifies what executable to
    run, and my C{filename} init parameter describes which script to pass to
    the first argument of that script.

    To customize me for a particular location of a CGI interpreter, override
    C{filter}.

    @type filter: L{str}
    @ivar filter: The absolute path to the executable.
    z/usr/bin/catc	Cs8t|�}|j�||j|j|jg||tj�|j��dS)ad
        Run a script through the C{filter} executable.

        @type env: A L{dict} of L{str}, or L{None}
        @param env: The environment variables to pass to the process that will
            get spawned. See
            L{twisted.internet.interfaces.IReactorProcess.spawnProcess}
            for more information about environments and process creation.

        @type request: L{twisted.web.http.Request}
        @param request: An HTTP request.

        @type qargs: A L{list} of L{str}
        @param qargs: The command line arguments to pass to the process that
            will get spawned.
        N)rJr"rK�filterr rArrLrMrrrrC�s�zFilteredScript.runProcessN)rrrrOrQrCrrrrrP�srPc@szeZdZdZdZdZdZe�Zdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)rJrr�cCs|��dSr)�resumeProducing�rZissuerrrr�view_resumeProducing�sz'CGIProcessProtocol.view_resumeProducingcCs|��dSr)�pauseProducingrTrrr�view_pauseProducing�sz&CGIProcessProtocol.view_pauseProducingcCs|��dSr)�
stopProducingrTrrr�view_stopProducing�sz%CGIProcessProtocol.view_stopProducingcCs|j��dSr)�	transportrS�rrrrrS�sz"CGIProcessProtocol.resumeProducingcCs|j��dSr)rZrVr[rrrrV�sz!CGIProcessProtocol.pauseProducingcCs|j��dSr)rZZloseConnectionr[rrrrX�sz CGIProcessProtocol.stopProducingcCs
||_dSr)r)rrrrrr
�szCGIProcessProtocol.__init__cCsH|j�|d�|jj�dd�|jj��}|r:|j�|�|j��dS)Nrr)rZregisterProducerr'r:�readrZ�writeZ
closeStdin)rr'rrr�connectionMade�sz!CGIProcessProtocol.connectionMadecCs|j||_dSr)�	errortext)r�errorrrr�errReceived�szCGIProcessProtocol.errReceivedc
Cs�|j�r~|j|}g}dD]$}|�|�}|dkr|�||f�q|�rpd|j_|��|d\}}|d|�|_|dt|�d�}|j�|�}|D]�}|�d�}	|	dkr�|j	j
d|d�q�|d|	���}
||	dd�}|
d	kr�|j�t
j�|
d
k�r8zt|dd��}Wn|j	�
d�YnX|j�|�q�|
��d
kr�|jj�|
|�q�||t|�d�}d|_|j�r~||_|j�s�|j�|�dS)z)
        Handle a chunk of input
        )s

s

s

s

���Nrr(s: z)ignoring malformed CGI header: {header!r})rGslocationsstatus�zmalformed status header)sserversdate)�handling_headers�
headertext�find�appendrZdefaultContentType�sort�lenr4�_logr`�lowerZsetResponseCoderZFOUND�intZresponseHeadersZaddRawHeaderr])
r�output�textZ
headerEndsZ	delimiterZ	headerendZ	linebreakZheadersrG�brZ
headerName�
headerTextZ	statusNumrrr�outReceived�sT


�
�zCGIProcessProtocol.outReceivedcCs�|jjdkr&|jjd|jj|jjd�|jrD|jjd|jj|jd�|jr�|jjd|jj|jd�|j�	t
�tj
dd	��|j��|j��|j��dS)
Nrz*CGI {uri} exited with exit code {exitCode})r8�exitCodez"Errors from CGI {uri}: {errorText})r8Z	errorTextz/Premature end of headers in {uri}: {headerText})r8rpzCGI Script Errorz Premature end of script headers.)rIrrrjr`rr8r_rdrer]rZ	ErrorPagerZINTERNAL_SERVER_ERRORrZunregisterProducerZfinish)r�reasonrrr�processEnded2s2������
zCGIProcessProtocol.processEndedN)rrrrdZheaders_writtenrer_rrjrUrWrYrSrVrXr
r^rarqrtrrrrrJ�s 	:rJ)rOrAr,r!rZtwisted.loggerrZtwisted.pythonrZtwisted.spreadrZtwisted.webrrrr	rrr
rrPZProcessProtocolZViewablerJrrrr�<module>sm+