Your IP : 3.137.170.38


Current Path : /opt/alt/python311/lib64/python3.11/wsgiref/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/wsgiref/__pycache__/handlers.cpython-311.pyc

�

c��f.T���dZddlmZmZmZddlmZddlZddlZddl	Z	gd�Z
gd�Zgd�Zd	�Z
hd
�jZd�Zd�ZGd
�d��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZdS)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	��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
          �7/opt/alt/python311/lib64/python3.11/wsgiref/handlers.py�format_date_timer1sO��-1�[��-C�-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|��pU|�d��p@|�d��p+|�d��ot|dd���S)N�HTTP_�SSL_�	REDIRECT_�	)�_is_request�
startswith�_needs_transcode)�ks r0rDrDsd���q�>�>�C�Q�\�\�'�2�2�C�a�l�l�6�6J�6J�C�
�L�L��%�%�A�*:�1�Q�R�R�5�*A�*A�Cr2c�T�tj��}d}	d�d|��n#t$rd}YnwxYwi}tj���D�]F\}}t|���r+tjdkr�tj�	dd���
��}|�d��r)|�d���d��}n�|�d	��rn�|�d
��r-d|vr)|�d���d��}nS|�|d���d��}n)|�||���d��}|||<��H|S)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
"s���

�
#�
%�
%�C�
�C��
�	�	�'�3�������������������G�
�
� � �"�"�+�+���1��A���(	<��|�w�&�&��:�>�>�*;�R�@�@�F�F�H�H���&�&�'7�8�8�F�����)�)�0�0��>�>�A�A��(�(��3�3�F���'�'�
�6�6�
F�"�h�.�.�����)�)�0�0��>�>�A�A�����i�0�0�7�7��E�E�A�A�
�H�H�S�#�&�&�-�-�l�;�;�����
�
��Ns�.�=�=c��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"�Z1dS)$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��|_|���dS#t
ttf$rYdS	|���YdS#|�	���xYwxYw)zInvoke the applicationN)
�
setup_environrR�start_response�result�finish_response�ConnectionAbortedError�BrokenPipeError�ConnectionResetError�handle_error�close)�self�applications  r0�runzBaseHandler.run�s���	���� � � �%�+�d�l�D�4G�H�H�D�K�� � �"�"�"�"�"��&��9M�N�	�	�	�
�F�F�	�
��!�!�#�#�#�#�#�#��
��
�
����������s$�AA�B�!B�#A:�:B�Bc���|j���x}|_|���|���|d<|���|d<|j|d<|j|d<|���|d<|j	|d<|j
|d<|j�
|j|d	<|jr$|j
r|�d
|j
��dSdSdS)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�3��d�l�������#'�>�>�#3�#3��L��#'�?�?�#4�#4��M��#'�#4��N��#'�#5��O��#'�?�?�#4�#4����#'�#8����#'�#9��� ��!�-�'+�'=�C�#�$���	C�$�"6�	C��N�N�,�T�-A�B�B�B�B�B�	C�	C�	C�	Cr2c�N�	|���r|���s3|jD]}|�|���|���|���dS#t
|jd��r|j����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�%�%�D��J�J�t�$�$�$�$��#�#�%�%�%�
�J�J�L�L�L�L�L��	��t�{�G�,�,�
$���!�!�#�#�#����s�AA3�31B$c�*�t|j��S)z Return the URL scheme being used)rrR�rgs r0rrzBaseHandler.get_scheme�s���D�L�)�)�)r2c��	t|j��}|dkrt|j��|jd<dSdS#t
ttf$rYdSwxYw)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�sp��	����%�%�F��q�y�y�14�T�_�1E�1E���-�.����y���.�)<�=�	�	�	��D�D�	���s�<�A�Ac�D�d|jvr|���dSdS)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�s1��
�4�<�/�/��#�#�%�%�%�%�%�0�/r2c�2�|r	|jr�	d}n#d}wxYw|j�td���||_|�|��|_|�|d��}t
|��dks
Jd���|dd����s
Jd���|ddks
Jd	���	|D]Q\}}|�|d��}|�|d��}t|��rJd
|�d|�d�����R|j	S)z4'start_response()' callable as specified by PEP 3333NzHeaders already set!�Status�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 codeTzHeader namezHeader valuezHop-by-hop header, 'z: z', not allowed)
�headers_sentr��AssertionError�status�
headers_class�_convert_string_typer��isdigitrr})rgr�r��exc_info�name�vals      r0r_zBaseHandler.start_response�sn���	9�
 ��$���� ����4������
�\�
%� �!7�8�8�8�����)�)�'�2�2����*�*�6�8�<�<���6�{�{�A�~�~�~�D�~�~�~��b�q�b�z�!�!�#�#�O�O�%O�O�O�#��a�y�#�~�~�~�L�~�~�~�	J�$�
J�
J�	��c��0�0��}�E�E���/�/��^�D�D��(��.�.�J�J�I�d�I�I�c�I�I�I�J�J�.�J��z�s��c��t|��tur|Std�|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_type�sC����;�;�#����L��/�6�6�u�d�5�k�k�J�J�
�
�	
r2c�B�|jr�|���r�|�d|j�d|j�d��d����d|jvrI|�dttj����z�d����|j	r=d|jvr6|�d|j	z�d����d
Sd
Sd
Sd
S|�d	|jz�d����d
S)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;����
	O��$�$�&�&�
`������1B�1B�1B�4�;�;�;�O�W�W�Xd�e�e�f�f�f����-�-��K�K�'�*:�4�9�;�;�*G�*G�G�O�O�P\�]�]�����'�`�H�D�L�,H�,H��K�K�!1�D�4H�!H� P� P�Q]� ^� ^�_�_�_�_�_�
`�
`�`�`�,H�,H�
�K�K�)�D�K�7�?�?��M�M�N�N�N�N�Nr2c�^�t|��tus
Jd���|jstd���|js)t|��|_|���n|xjt|��z
c_|�|��|�	��dS)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�z�U�"�"�"�7�#�"�"��{�	)� �!B�C�C�C��"�	)�!�$�i�i�D�O���������O�O�s�4�y�y�(�O�O�	
���D�������
�
�
�
�
r2c��dS)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	��$�ur2c�v�|js1|j�dd��|���dSdS)z.Ensure headers and content have both been sentr��0N)r�r�rxr�r�s r0r~zBaseHandler.finish_content=sE��� �	�
�L�#�#�$4�c�:�:�:����������Dr2c��	t|jd��r|j���dx|_x|_x|_|_d|_d|_dS#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.closeGs���
	;��t�{�7�+�+�
$���!�!�#�#�#�FJ�J�D�K�J�$�,�J���t�|��D�O�U��!2�!2�!2��GK�J�D�K�J�$�,�J���t�|��D�O�U��!2�!:�!:�!:�!:s�.A�,Bc���|���d|_|jr|���r=|���|�t
|j����dSdS)z1Transmit headers to the client, via self._write()TN)r�r�rvr�r�r�r�r�r�s r0r�zBaseHandler.send_headersTsx�������� ����!�	-�T�%:�%:�%<�%<�	-���� � � ��K�K��d�l�+�+�,�,�,�,�,�	-�	-r2c�B�|j}|duot|j|��S)z@True if 'self.result' is an instance of 'self.wsgi_file_wrapper'N)ru�
isinstancer`)rg�wrappers  r0r{zBaseHandler.result_is_file]s&���(���d�"�F�z�$�+�g�'F�'F�Fr2c�H�|jd���dkS)z,True if client can accept status and headers�SERVER_PROTOCOLzHTTP/0.9)rR�upperr�s r0r�zBaseHandler.client_is_moderncs!���|�-�.�4�4�6�6�*�D�Dr2c���	ddlm}|���}||d|d|d|j|��|���d}dS#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_exceptionhs|��
		�1�1�1�1�1�1��_�_�&�&�F��O����X�a�[�(�1�+��$�f�
�
�
�
�L�L�N�N�N��H�H�H��t�H�O�O�O�Os�AA�Ac���|�tj����|js;|�|j|j��|_|���dSdS)z>Log current error, and send error output to client if possibleN)	r�rMr�r��error_outputrRr_r`rar�s r0rezBaseHandler.handle_errorxse�����3�<�>�>�*�*�*�� �	#��+�+�D�L�$�:M�N�N�D�K�� � �"�"�"�"�"�	#�	#r2c�r�||j|jdd�tj����|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�s8��	��t�(��);�A�A�A�)>�s�|�~�~�N�N�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)2�__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~rfr�r{r�r�rer�r�r�rnrormr�r2r0rr^s������5�5��L������M��M��L��O�
����J�$���M��O�.�L�2�3�M�O�J���F�V��L��G��J����0C�C�C�*���4*�*�*�
	�	�	�&�&�&�����8
�
�
�O�O�O����*���*���
;�
;�
;�-�-�-�G�G�G�E�E�E�
��� #�#�#�!�!�!�&"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"r2rc�:�eZdZdZ	dd�Zd�Zd�Zd�Zd�Zd	�Z	d
S)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)TFc�Z�||_||_||_||_||_||_dSr�)�stdin�stdoutr��base_envrsrt)rgr�r�r�rR�multithread�multiprocesss       r0�__init__zSimpleHandler.__init__�s6����
���������
� +���!-����r2c��|jSr�)r�r�s r0rnzSimpleHandler.get_stdin�s
���z�r2c��|jSr�)r�r�s r0rozSimpleHandler.get_stderr�s
���{�r2c�D�|j�|j��dSr�)rR�updater�r�s r0rmzSimpleHandler.add_cgi_vars�s ������D�M�*�*�*�*�*r2c���|j�|��}|�|t|��krdSddlm}|dt
��	||d�}|sdS|j�|��}�))Nr)�warnz9SimpleHandler.stdout.write() should not do partial writes)r�r}r��warningsr��DeprecationWarning)rgr�r`r�s    r0r�zSimpleHandler._write�s�����"�"�4�(�(���>�V�s�4�y�y�0�0��F�!�!�!�!�!�!���
H��	 �	 �	 �	-�����=�D��
����[�&�&�t�,�,�F�		-r2c�Z�|j���|jj|_dSr�)r�r�r�r�s r0r�zSimpleHandler._flush�s&����������k�'����r2N)TF)
r�r�r�r�r�rnrormr�r�r�r2r0r	r	�s�������
�
�(-�.�.�.�.�������+�+�+�-�-�-�(�(�(�(�(r2r	c��eZdZdZdZdS)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��������&�M�M�Mr2r
c� �eZdZdZdZiZd�ZdS)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	��t�|tjjtjjtjt��dd���dS)NFT�r�r�)r
r�rMr��bufferr�r�r
r�s r0r�zCGIHandler.__init__sI������#�)�"�C�J�$5�s�z��N�N��D�	 �	
�	
�	
�	
�	
r2N�r�r�r�r�rqrkr�r�r2r0rr�s;������
�
��M��J�
�
�
�
�
r2rc� �eZdZdZdZiZd�ZdS)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	�v�t��}|�dd��}|�dd��}|dz�|dz��r|t|��d�|d<t�|tjjtj	jtj
|dd���dS)Nr5rHr7�/FTr�)r
rUrCr�r
r�rMr�r�r�r�)rgrR�path�scripts    r0r�zIISCGIHandler.__init__1s��������{�{�;��+�+�����]�B�/�/����H� � ����,�,�	6�#'��F�����#5�G�K� �����#�)�"�C�J�$5�s�z���T�	 �	
�	
�	
�	
�	
r2Nr�r�r2r0rrs9���������M��J� 	
�	
�	
�	
�	
r2r)r��utilrrrr�rrMrQr"�__all__r$r%r1�__contains__rBrDr
rr	r
rrr�r2r0�<module>r�s���5�5�:�:�:�:�:�:�:�:�:�:�����������������������A�@�@��8�8�8�
���������
C�C�C�9�9�9�xP"�P"�P"�P"�P"�P"�P"�P"�f
/(�/(�/(�/(�/(�K�/(�/(�/(�d�����]����0
�
�
�
�
��
�
�
�<!
�!
�!
�!
�!
�N�!
�!
�!
�!
�!
r2

?>