%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/web/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/web/__pycache__/twcgi.cpython-312.pyc

�

Ϫ�f�.��2�dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZmZmZmZGd	�d
ej$e
j&e�ZGd�dej$�ZGd
�de�ZGd�dej.ej0�Zy)zH
I hold resource classes and helper classes that deal with CGI scripts.
�N)�AnyStr)�protocol)�Logger)�filepath)�pb)�http�resource�server�staticc��eZdZd�Zd�Zd�Zy)�CGIDirectoryc��tjj|�tjj||�y�N)r	�Resource�__init__r�FilePath)�self�pathnames  �3/usr/lib/python3/dist-packages/twisted/web/twcgi.pyrzCGIDirectory.__init__s,�����"�"�4�(����"�"�4��2�c���|j|�}|j�stjjS|j�rt
|j�St|j�Sr)	�child�existsr�File�
childNotFound�isdirr
�path�	CGIScript)rr�request�fnps    r�getChildzCGIDirectory.getChildsP���j�j�����z�z�|��;�;�,�,�,�
�Y�Y�[�����)�)��S�X�X�&�&rc�N�tjd�}|j|�S)Nz1CGI directories do not support directory listing.)r	�
NoResource�render)rr�notFounds   rr$zCGIDirectory.render%s&���&�&�?�
�����w�'�'rN)�__name__�
__module__�__qualname__rr!r$�rrr
r
s��3�'�(rr
c�,�eZdZdZdZdd�Zd�Zgfd�Zy)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.
    �Nc�0�||_|�ddlm}||_y)zA
        Initialize, with the name of a CGI script file.
        Nr)�reactor)�filename�twisted.internetr-�_reactor)rr.�registryr-s    rrzCGIScript.__init__7s��!��
��?�
1���
rc
�8�ddj|j�z}|j�jd�d}tj
|d|jt|j�j�|j||j|jd�	}|j�j}|�||d<|j}|rddj|�z|d	<t!|d
�r`|j"j%dd�|j"j'�}|j"j%dd�t|�|d<	|jj)d
�}|j|dzdx}	|d<d|	vrg}
nJ|	jd�D�cgc]/}t*j,j/|j1����1}
}	|j5�j7�D]3\}}
|j9dd�j;�}|dvrd|z}|
||<�5t<j>j7�D]\}}||vs�|||<�|jA|||
�tjBScc}w#t2$r
d|d<g}
Y��wxYw)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)	�SERVER_SOFTWARE�SERVER_NAME�GATEWAY_INTERFACE�SERVER_PROTOCOL�SERVER_PORT�REQUEST_METHOD�SCRIPT_NAME�SCRIPT_FILENAME�REQUEST_URIN�REMOTE_ADDR�/�	PATH_INFO�content��CONTENT_LENGTH�?r+�QUERY_STRING�=�+��-�_)scontent-typescontent-lengthsproxysHTTP_)"�join�prepath�getRequestHostname�splitr
�version�clientproto�str�getHost�port�methodr.�uri�getClientAddress�host�postpath�hasattrrA�seek�tell�index�urllib�parse�unquote�decode�
ValueError�
getAllHeaders�items�replace�upper�os�environ�
runProcess�NOT_DONE_YET)rr�
scriptName�
serverName�env�ip�pp�length�qindex�qs�qargs�x�title�header�envname�key�values                 rr$zCGIScript.renderCsj���D�I�I�g�o�o�6�6�
��/�/�1�7�7��=�a�@�
�%�~�~�%�!*�&�2�2��w���0�5�5�6�%�n�n�%�#�}�}�"�;�;�

���
%�
%�
'�
,�
,��
�>�!#�C�
��
�
�
��
�"�S�X�X�b�\�1�C����7�I�&�
�O�O� � ��A�&��_�_�)�)�+�F��O�O� � ��A�&�$'��K�C� �!�
	S��[�[�&�&�t�,�F�
(/�{�{�6�A�:�<�'@�@�B��^�$��r�z���CE�8�8�D�>�R�a����-�-�a�h�h�j�9�R��R�%�2�2�4�:�:�<�	"�M�E�6��m�m�D�$�/�5�5�7�G��J�J�"�W�,��!�C��L�		"��*�*�*�*�,�	!�J�C���#�~� ��C��	!�	
����W�e�,��"�"�"��S���	�"$�C����E�	�s�J�#4J�J�Jc	���t|�}|jj||j|jg|z|tj
j
|j��y)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)�CGIProcessProtocolr0�spawnProcessr.rfr�dirname�rrlrrr�ps     rrhzCGIScript.runProcess�sO��"
�w�'���
�
�"�"�
��M�M�
�]�]�O�e�#���G�G�O�O�D�M�M�*�	
r)NN)r&r'r(�__doc__�isLeafrr$rhr)rrrr,s#����F�
 �?#�B.0�
rrc��eZdZdZdZgfd�Zy)�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	���t|�}|jj||j|j|jg|z|t
jj|j��y)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)rzr0r{�filterr.rfrr|r}s     rrhzFilteredScript.runProcess�sV��"
�w�'���
�
�"�"�
��K�K�
�[�[�$�-�-�(�5�0���G�G�O�O�D�M�M�*�	
rN)r&r'r(rr�rhr)rrr�r��s��
��F�-/�
rr�c�v�eZdZdZdZdZdZe�ZdZ	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zy)rzr+rrFc�$�|j�yr)�resumeProducing�r�issuers  r�view_resumeProducingz'CGIProcessProtocol.view_resumeProducing�s�����rc�$�|j�yr)�pauseProducingr�s  r�view_pauseProducingz&CGIProcessProtocol.view_pauseProducing�s�����rc�$�|j�yr)�
stopProducingr�s  r�view_stopProducingz%CGIProcessProtocol.view_stopProducing�s�����rc�8�|jj�yr)�	transportr��rs rr�z"CGIProcessProtocol.resumeProducing�s�����&�&�(rc�8�|jj�yr)r�r�r�s rr�z!CGIProcessProtocol.pauseProducing�������%�%�'rc�8�|jj�yr)r��loseConnectionr�s rr�z CGIProcessProtocol.stopProducing�r�rc�x�||_|jj�j|j�yr)r�notifyFinish�addBoth�	_finished)rrs  rrzCGIProcessProtocol.__init__�s(��������!�!�#�+�+�D�N�N�;rc�>�|jj|d�|jjjdd�|jjj	�}|r|j
j
|�|j
j�y)Nr+r)r�registerProducerrArZ�readr��write�
closeStdin)rrAs  r�connectionMadez!CGIProcessProtocol.connectionMade�sm�����%�%�d�A�.������!�!�!�Q�'��,�,�&�&�+�+�-����N�N� � ��)����!�!�#rc�,�|j|z|_yr)�	errortext)r�errors  r�errReceivedzCGIProcessProtocol.errReceived�s�����%�/��rc�<�|j�r�|j|z}g}dD],}|j|�}|dk7s�|j||f��.|�rdd|j_|j
�|d\}}|d||_|dt|�dz}|jj|�}|D]�}|jd�}	|	dk(r|jjd|���7|d|	j�}
||	dzd}|
d	k(r)|jjtj�|
d
k(r+	t|dd�}|jj|���|
j�d
vs��|jj"j%|
|���||t|�zd}d|_|jr||_|js|jj'|�yy#t $r|jjd�Y��fwxYw)z)
        Handle a chunk of input
        )s

s

s

s

���NrrBs: z)ignoring malformed CGI header: {header!r})ruslocationsstatus�zmalformed status header)sserversdate)�handling_headers�
headertext�find�appendr�defaultContentType�sort�lenrN�_logr��lower�setResponseCoder�FOUND�int�
BaseException�responseHeaders�addRawHeaderr�)
r�output�text�
headerEnds�	delimiter�	headerend�	linebreak�headersru�br�
headerName�
headerText�	statusNums
             r�outReceivedzCGIProcessProtocol.outReceived�s��� � ��?�?�V�+�D��J�E�
>�	� �I�I�i�0�	���?��%�%�y�)�&<�=�
>��37����/����!�'1�!�}�$�	�9�"&�z�	�"2���%�&;��I��!�(;�<�	��/�/�/�/�	�:��%�"�F����U�+�B��R�x��	�	���G�PV�(��&,�C�R�[�%6�%6�%8�
�%+�B��F�H�%5�
�%��4� �L�L�8�8����D�%��2�H�,/�
�2�A��,?�	�!%��� <� <�Y� G� *�/�/�1�9M�M� $��� <� <� I� I�$.�
�!"�/"�4�i�#�i�.�8�:�;��()��%��$�$�"&����$�$��L�L���v�&�%��$1�K� $�	�	���0I� J�K�s�:G3�3$H�Hc�*�|jjdk7rF|jjd|jj
|jj��|jr<|jjd|jj
|j��|jr�|jjd|jj
|j��|jsW|jjtjtjdd	�j|j��|js5|jj!�|jj#�yy)
Nrz*CGI {uri} exited with exit code {exitCode})rU�exitCodez"Errors from CGI {uri}: {errorText})rU�	errorTextz/Premature end of headers in {uri}: {headerText})rUr�zCGI Script Errorz Premature end of script headers.)rxr�r�r�rrUr�r�r��_requestFinishedr�r	�	ErrorPager�INTERNAL_SERVER_ERRORr$�unregisterProducer�finish)r�reasons  r�processEndedzCGIProcessProtocol.processEnded1s,���<�<� � �A�%��I�I�O�O�<��L�L�$�$����.�.�
�
�
�>�>��I�I�O�O�4��L�L�$�$��.�.�
�
�� � ��I�I�O�O�A��L�L�$�$��?�?�
�
�
�(�(����"�"��&�&��2�2�*�:���f�T�\�\�*���$�$��L�L�+�+�-��L�L���!�%rc��d|_y)zc
        Record the end of the response generation for the request being
        serviced.
        TN)r�)r�ignoreds  rr�zCGIProcessProtocol._finishedRs��
!%��rN)r&r'r(r��headers_writtenr�r�rr�r�r�r�r�r�r�r�rr�r�r�r�r�r)rrrzrz�sb�����O��J��I��8�D������)�(�(�<�$�0�8'�t"�B%rrz)rrfr]�typingrr/r�twisted.loggerr�twisted.pythonr�twisted.spreadr�twisted.webrr	r
rrrr
rr��ProcessProtocol�Viewablerzr)rr�<module>r�s����

�
��&�!�#��6�6�(�8�$�$�h�&7�&7��&?�(�*p
��!�!�p
�f*
�Y�*
�ZK%��1�1�2�;�;�K%r

Zerion Mini Shell 1.0