%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.12/wsgiref/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.12/wsgiref/__pycache__/handlers.cpython-312.pyc

�

���f�T����dZddlmZmZmZddlmZddlZddlZddl	Z	gd�Z
gd�Zgd�Zd	�Z
hd
�jZd�Zd�ZGd
�d�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Zy)z/Base classes for server/gateway implementations�)�FileWrapper�guess_scheme�
is_hop_by_hop)�Headers�N)�BaseHandler�
SimpleHandler�BaseCGIHandler�
CGIHandler�
IISCGIHandler�read_environ)�Mon�Tue�Wed�Thu�Fri�Sat�Sun)
N�Jan�Feb�Mar�Apr�May�Jun�Jul�Aug�Sep�Oct�Nov�Decc	�t�tj|�\	}}}}}}}}}	dt||t|||||fzS)Nz#%s, %02d %3s %4d %02d:%02d:%02d GMT)�time�gmtime�_weekdayname�
_monthname)
�	timestamp�year�month�day�hh�mm�ss�wd�y�zs
          �'/usr/lib/python3.12/wsgiref/handlers.py�format_date_timer1sN��-1�[�[��-C�*�D�%��b�"�b�"�a��0��R��#�z�%�0�$��B��4���>
�HTTPS�	AUTH_TYPE�	PATH_INFO�REMOTE_USER�SCRIPT_NAME�CONTENT_TYPE�QUERY_STRING�REMOTE_IDENT�CONTENT_LENGTH�REQUEST_METHODc��t|�xsG|jd�xs4|jd�xs!|jd�xrt|dd�S)N�HTTP_�SSL_�	REDIRECT_�	)�_is_request�
startswith�_needs_transcode)�ks r0rDrDsT���q�>�C�Q�\�\�'�2�C�a�l�l�6�6J�C�
�L�L��%�A�*:�1�Q�R�5�*A�Cr2c���tj�}d}	djd|�i}tj
j
�D�]\}}t|�r�tjdk(r�tj
jdd�j�}|jd�r!|jd�jd�}n�|jd	�rny|jd
�r%d|vr!|jd�jd�}nC|j|d�jd�}n!|j||�jd�}|||<��|S#t$rd}Y��HwxYw)z'Read environment, fixing HTTP variables�surrogateescape�zutf-8�replace�win32�SERVER_SOFTWAREzmicrosoft-iis/�
iso-8859-1zapache/zsimplehttp/zpython/3)
�sys�getfilesystemencoding�encode�LookupError�os�environ�itemsrD�platform�get�lowerrC�decode)�enc�escrRrE�v�softwares      r0r
r
"sV��

�
#�
#�
%�C�
�C��
�	�	�'�3���G�
�
�
� � �"�+���1��A���|�|�w�&��:�:�>�>�*;�R�@�F�F�H���&�&�'7�8�����)�0�0��>�A��(�(��3���'�'�
�6�"�h�.�����)�0�0��>�A�����i�0�7�7��E�A�
�H�H�S�#�&�-�-�l�;�����
�W+�X�N��g�����s�E$�$E3�2E3c��eZdZdZdZdZdZdZdZdZ	dZ
e�Ze
ZeZdZdZdgZd	ZdxZZdZdZd
Zd�Zd�Zd
�Zd�Zd�Zd�Zd$d�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d �Z/d!�Z0d"�Z1d#�Z2y)%rz+Manage the invocation of a WSGI application)rrTFz1.0Nz500 Internal Server Error)zContent-Typez
text/plains;A server error occurred.  Please contact the administrator.rc��	|j�||j|j�|_|j	�y#t
ttf$rYy	|j�Yy#|j��xYwxYw)zInvoke the applicationN)
�
setup_environrR�start_response�result�finish_response�ConnectionAbortedError�BrokenPipeError�ConnectionResetError�handle_error�close)�self�applications  r0�runzBaseHandler.run�sv��	���� �%�d�l�l�D�4G�4G�H�D�K�� � �"��&��9M�N�	�
�	�
��!�!�#��
��
�
���s$�AA�B�B�A/�/B�Bc���|jj�x}|_|j�|j	�|d<|j�|d<|j|d<|j|d<|j�|d<|j|d<|j|d<|j�|j|d	<|jr*|jr|jd
|j�yyy)z&Set up the environment for one requestz
wsgi.inputzwsgi.errorszwsgi.versionz
wsgi.run_oncezwsgi.url_schemezwsgi.multithreadzwsgi.multiprocessNzwsgi.file_wrapperrK)�
os_environ�copyrR�add_cgi_vars�	get_stdin�
get_stderr�wsgi_version�
wsgi_run_once�
get_scheme�wsgi_multithread�wsgi_multiprocess�wsgi_file_wrapper�
origin_server�server_software�
setdefault)rg�envs  r0r^zBaseHandler.setup_environ�s���"�_�_�1�1�3�3��d�l�����#'�>�>�#3��L��#'�?�?�#4��M��#'�#4�#4��N��#'�#5�#5��O��#'�?�?�#4����#'�#8�#8����#'�#9�#9��� ��!�!�-�'+�'=�'=�C�#�$����$�"6�"6��N�N�,�T�-A�-A�B�#7�r2c�6�	|j�r|j�s2|jD]}|j|��|j	�|j�y#t
|jd�r|jj��xYw)a>Send any iterable data, then close self and the iterable

        Subclasses intended for use in asynchronous servers will
        want to redefine this method, such that it sets up callbacks
        in the event loop to iterate over the data, and to call
        'self.close()' once the response is finished.
        rfN)�result_is_file�sendfiler`�write�finish_contentrf�hasattr�rg�datas  r0razBaseHandler.finish_response�s{��	��&�&�(��
�
�� �K�K�%�D��J�J�t�$�%��#�#�%�
�J�J�L��	��t�{�{�G�,����!�!�#��s�AA%�%3Bc�,�t|j�S)z Return the URL scheme being used)rrR�rgs r0rrzBaseHandler.get_scheme�s���D�L�L�)�)r2c��	t|j�}|dk(r#t|j�|jd<yy#t
ttf$rYywxYw)z@Compute Content-Length or switch to chunked encoding if possibler�Content-LengthN)�lenr`�str�
bytes_sent�headers�	TypeError�AttributeError�NotImplementedError)rg�blockss  r0�set_content_lengthzBaseHandler.set_content_length�sZ��	�����%�F��q�y�14�T�_�_�1E����-�.�����.�)<�=�	��	�s�A�A�Ac�B�d|jvr|j�yy)zqMake any necessary header changes or defaults

        Subclasses can extend this to add other defaults.
        r�N)r�r�r�s r0�cleanup_headerszBaseHandler.cleanup_headers�s!��
�4�<�<�/��#�#�%�0r2c��|r	|jr�	d}n|j�td��||_|j	|�|_|j|d�}|j
|�	|D]B\}}|j|d�}|j|d�}t|�s�6Jd|�d|�d���|jS#d}wxYw)	z4'start_response()' callable as specified by PEP 3333NzHeaders already set!�StatuszHeader namezHeader valuezHop-by-hop header, 'z: z', not allowed)	�headers_sentr��AssertionError�status�
headers_class�_convert_string_type�_validate_statusrr})rgr�r��exc_info�name�vals      r0r_zBaseHandler.start_response�s����
 ��$�$��%� ��
�\�\�
%� �!7�8�8�����)�)�'�2����*�*�6�8�<�����f�%��$�
J�	��c��0�0��}�E���/�/��^�D��(��.�J�-�d�V�2�c�U�.�I�J�.�
J��z�z���! ��s�
C�Cc��t|�dkrtd��|ddj�std��|ddk7rtd��y)N�z$Status must be at least 4 characters�z(Status message must begin w/3-digit code� z+Status message must have a space after code)r�r��isdigit)rgr�s  r0r�zBaseHandler._validate_status�sT���v�;��?� �!G�H�H��b�q�z�!�!�#� �!K�L�L��!�9��� �!N�O�O�r2c�p�t|�tur|Stdj|t	|����)zConvert/check value type.z!{0} must be of type str (got {1}))�typer�r��format�repr)rg�value�titles   r0r�z BaseHandler._convert_string_types4����;�#���L��/�6�6�u�d�5�k�J�
�	
r2c�:�|jr�|j�r�|jd|j�d|j�d�jd��d|jvr>|jdttj��zjd��|jr=d|jvr.|jd|jzjd��y
y
y
y
|jd	|jzjd��y
)z6Transmit version/status/date/server, via self._write()zHTTP/r�z
rL�Datez
Date: %s
�ServerzServer: %s
zStatus: %s
N)
rv�client_is_modern�_write�http_versionr�rOr�r1r"rwr�s r0�
send_preamblezBaseHandler.send_preambles�������$�$�&�����1B�1B�4�;�;�O�W�W�Xd�e�f�����-��K�K�'�*:�4�9�9�;�*G�G�O�O�P\�]���'�'�H�D�L�L�,H��K�K�!1�D�4H�4H�!H� P� P�Q]� ^�_�-I�'�
'�
�K�K�)�D�K�K�7�?�?��M�Nr2c�:�t|�tusJd��|jstd��|js!t|�|_|j�n|xjt|�z
c_|j|�|j�y)z+'write()' callable as specified by PEP 3333z)write() argument must be a bytes instancezwrite() before start_response()N)
r��bytesr�r�r�r�r��send_headersr��_flushr�s  r0r}zBaseHandler.writes~���D�z�U�"�	8�7�	8�"��{�{� �!B�C�C��"�"�!�$�i�D�O������O�O�s�4�y�(�O�	
���D�����
r2c��y)aPlatform-specific file transmission

        Override this method in subclasses to support platform-specific
        file transmission.  It is only called if the application's
        return iterable ('self.result') is an instance of
        'self.wsgi_file_wrapper'.

        This method should return a true value if it was able to actually
        transmit the wrapped file-like object using a platform-specific
        approach.  It should return a false value if normal iteration
        should be used instead.  An exception can be raised to indicate
        that transmission was attempted, but failed.

        NOTE: this method should call 'self.send_headers()' if
        'self.headers_sent' is false and it is going to attempt direct
        transmission of the file.
        F�r�s r0r|zBaseHandler.sendfile.s��$r2c�v�|js-|jjdd�|j�yy)z.Ensure headers and content have both been sentr��0N)r�r�rxr�r�s r0r~zBaseHandler.finish_contentCs1��� � �
�L�L�#�#�$4�c�:�����r2c��	t|jd�r|jj�dx|_x|_x|_|_d|_d|_y#dx|_x|_x|_|_d|_d|_wxYw)z�Close the iterable (if needed) and reset all instance vars

        Subclasses may want to also drop the client connection.
        rfNrF)rr`rfr�r�rRr�r�r�s r0rfzBaseHandler.closeMs��
	;��t�{�{�7�+����!�!�#�FJ�J�D�K�J�$�,�J���t�|��D�O�U��!2��GK�J�D�K�J�$�,�J���t�|��D�O�U��!2�s�0A�,B	c���|j�d|_|jr|j�r5|j	�|jt
|j��yy)z1Transmit headers to the client, via self._write()TN)r�r�rvr�r�r�r�r�r�s r0r�zBaseHandler.send_headersZsP������ ����!�!�T�%:�%:�%<���� ��K�K��d�l�l�+�,�&=r2c�R�|j}|duxrt|j|�S)z@True if 'self.result' is an instance of 'self.wsgi_file_wrapper'N)ru�
isinstancer`)rg�wrappers  r0r{zBaseHandler.result_is_filecs(���(�(���d�"�F�z�$�+�+�g�'F�Fr2c�B�|jdj�dk7S)z,True if client can accept status and headers�SERVER_PROTOCOLzHTTP/0.9)rR�upperr�s r0r�zBaseHandler.client_is_modernis ���|�|�-�.�4�4�6�*�D�Dr2c��	ddlm}|j�}||d|d|d|j|�|j	�d}y#d}wxYw)z�Log the 'exc_info' tuple in the server log

        Subclasses may override to retarget the output or change its format.
        r)�print_exceptionr�N)�	tracebackr�ro�traceback_limit�flush)rgr�r��stderrs    r0�
log_exceptionzBaseHandler.log_exceptionnsR��
		�1��_�_�&�F�����X�a�[�(�1�+��$�$�f�
�
�L�L�N��H��t�H�s�AA
�
Ac���|jtj��|js<|j	|j
|j�|_|j�yy)z>Log current error, and send error output to client if possibleN)	r�rMr�r��error_outputrRr_r`rar�s r0rezBaseHandler.handle_error~sN�����3�<�<�>�*�� � ��+�+�D�L�L�$�:M�:M�N�D�K�� � �"�!r2c��||j|jddtj��|jgS)aZWSGI mini-app to create error output

        By default, this just uses the 'error_status', 'error_headers',
        and 'error_body' attributes to generate an output page.  It can
        be overridden in a subclass to dynamically generate diagnostics,
        choose an appropriate message for the user's preferred language, etc.

        Note, however, that it's not recommended from a security perspective to
        spit out diagnostics to any old user; ideally, you should have to do
        something special to enable diagnostic output, which is why we don't
        include any here!
        N)�error_status�
error_headersrMr��
error_body)rgrRr_s   r0r�zBaseHandler.error_output�s4��	�t�(�(��);�);�A�)>�s�|�|�~�N���� � r2c��t�)aOverride in subclass to buffer data for send to client

        It's okay if this method actually transmits the data; BaseHandler
        just separates write and flush operations for greater efficiency
        when the underlying system actually has such a distinction.
        �r�r�s  r0r�zBaseHandler._write�s
��"�!r2c��t�)z�Override in subclass to force sending of recent '_write()' calls

        It's okay if this method is a no-op (i.e., if '_write()' actually
        sends the data.
        r�r�s r0r�zBaseHandler._flush�s
��"�!r2c��t�)z4Override in subclass to return suitable 'wsgi.input'r�r�s r0rnzBaseHandler.get_stdin����!�!r2c��t�)z5Override in subclass to return suitable 'wsgi.errors'r�r�s r0rozBaseHandler.get_stderr�r�r2c��t�)z>Override in subclass to insert CGI variables in 'self.environ'r�r�s r0rmzBaseHandler.add_cgi_vars�r�r2�N)3�__name__�
__module__�__qualname__�__doc__rprsrtrqrvr�rwr
rkrrurr�r�r�r�r�r�r`r�r�r�rir^rarrr�r�r_r�r�r�r}r|r~rfr�r{r�r�rer�r�r�rnrormr�r2r0rr^s���5��L������M��M��L��O�
��J�$���M��O�.�L�2�3�M�O�J���F�V��L��G��J��0C�*�4*�
	�&��4P�
�O��*�*�
;�-�G�E�
� #�!�&"�"�"�"�"r2rc�8�eZdZdZ	d	d�Zd�Zd�Zd�Zd�Zd�Z	y)
r	aqHandler that's just initialized with streams, environment, etc.

    This handler subclass is intended for synchronous HTTP/1.0 origin servers,
    and handles sending the entire response output, given the correct inputs.

    Usage::

        handler = SimpleHandler(
            inp,out,err,env, multithread=False, multiprocess=True
        )
        handler.run(app)c�X�||_||_||_||_||_||_yr�)�stdin�stdoutr��base_envrsrt)rgr�r�r�rR�multithread�multiprocesss       r0�__init__zSimpleHandler.__init__�s0����
���������
� +���!-��r2c��|jSr�)r�r�s r0rnzSimpleHandler.get_stdin�s���z�z�r2c��|jSr�)r�r�s r0rozSimpleHandler.get_stderr�s���{�{�r2c�N�|jj|j�yr�)rR�updater�r�s r0rmzSimpleHandler.add_cgi_vars�s�������D�M�M�*r2c���|jj|�}|�|t|�k(ryddlm}|dt
�||dx}r$|jj|�}||dx}r�#yy)Nr)�warnz9SimpleHandler.stdout.write() should not do partial writes)r�r}r��warningsr��DeprecationWarning)rgr�r`r�s    r0r�zSimpleHandler._write�sr�����"�"�4�(���>�V�s�4�y�0��!��
H��	 ��6�7�m�#�d�#��[�[�&�&�t�,�F��6�7�m�#�d�#r2c�n�|jj�|jj|_yr�)r�r�r�r�s r0r�zSimpleHandler._flush�s#���������k�k�'�'��r2N)TF)
r�r�r�r�r�rnrormr�r�r�r2r0r	r	�s*��
�(-�.���+�-�(r2r	c��eZdZdZdZy)r
a�CGI-like systems using input/output/error streams and environ mapping

    Usage::

        handler = BaseCGIHandler(inp,out,err,env)
        handler.run(app)

    This handler class is useful for gateway protocols like ReadyExec and
    FastCGI, that have usable input/output/error streams and an environment
    mapping.  It's also the base class for CGIHandler, which just uses
    sys.stdin, os.environ, and so on.

    The constructor also takes keyword arguments 'multithread' and
    'multiprocess' (defaulting to 'True' and 'False' respectively) to control
    the configuration sent to the application.  It sets 'origin_server' to
    False (to enable CGI-like output), and assumes that 'wsgi.run_once' is
    False.
    FN)r�r�r�r�rvr�r2r0r
r
�s���&�Mr2r
c��eZdZdZdZiZd�Zy)ra�CGI-based invocation via sys.stdin/stdout/stderr and os.environ

    Usage::

        CGIHandler().run(app)

    The difference between this class and BaseCGIHandler is that it always
    uses 'wsgi.run_once' of 'True', 'wsgi.multithread' of 'False', and
    'wsgi.multiprocess' of 'True'.  It does not take any initialization
    parameters, but always uses 'sys.stdin', 'os.environ', and friends.

    If you need to override any of these parameters, use BaseCGIHandler
    instead.
    Tc	���tj|tjjtj
jtjt�dd��y)NFT�r�r�)r
r�rMr��bufferr�r�r
r�s r0r�zCGIHandler.__init__s?������#�)�)�"�"�C�J�J�$5�$5�s�z�z��N��D�	 �	
r2N�r�r�r�r�rqrkr�r�r2r0rr�s��
��M��J�
r2rc��eZdZdZdZiZd�Zy)raCGI-based invocation with workaround for IIS path bug

    This handler should be used in preference to CGIHandler when deploying on
    Microsoft IIS without having set the config allowPathInfo option (IIS>=7)
    or metabase allowPathInfoForScriptMappings (IIS<7).
    Tc	�d�t�}|jdd�}|jdd�}|dzj|dz�r|t|�d|d<tj|tjjtjjtj|dd��y)Nr5rHr7�/FTr�)r
rUrCr�r
r�rMr�r�r�r�)rgrR�path�scripts    r0r�zIISCGIHandler.__init__4s�������{�{�;��+�����]�B�/����H� � ����,�#'��F���#5�G�K� �����#�)�)�"�"�C�J�J�$5�$5�s�z�z���T�	 �	
r2Nr�r�r2r0rrs����M��J� 	
r2r)r��utilrrrr�rrMrQr"�__all__r$r%r1�__contains__rBrDr
rr	r
rrr�r2r0�<module>r�s���5�:�:������A��8�
����,��
C�9�xV"�V"�r
,(�K�,(�^�]��0
��
�<!
�N�!
r2

Zerion Mini Shell 1.0