AlkantarClanX12

Your IP : 18.117.168.71


Current Path : /lib64/python3.8/wsgiref/__pycache__/
Upload File :
Current File : //lib64/python3.8/wsgiref/__pycache__/handlers.cpython-38.opt-1.pyc

U

e5d�T�
@sdZddlmZmZmZddlmZddlZddlZddl	Z	dddd	d
dgZ
dd
dddddgZdddddddddddddg
Zdd �Z
d!d"d#d$d%d&d'd(d)d*h
jZd+d,�Zd-d�ZGd.d�d�ZGd/d�de�ZGd0d�de�ZGd1d	�d	e�ZGd2d
�d
e�ZdS)3z/Base classes for server/gateway implementations�)�FileWrapper�guess_scheme�
is_hop_by_hop)�Headers�N�BaseHandler�
SimpleHandler�BaseCGIHandler�
CGIHandler�
IISCGIHandler�read_environZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc
	Cs:t�|�\	}}}}}}}}}	dt||t|||||fS)Nz#%s, %02d %3s %4d %02d:%02d:%02d GMT)�time�gmtime�_weekdayname�
_monthname)
Z	timestampZyearZmonthZdayZhhZmmZssZwd�y�z�r�(/usr/lib64/python3.8/wsgiref/handlers.py�format_date_times�r�SCRIPT_NAME�	PATH_INFOZQUERY_STRINGZREQUEST_METHODZ	AUTH_TYPEZCONTENT_TYPEZCONTENT_LENGTHZHTTPSZREMOTE_USERZREMOTE_IDENTcCs6t|�p4|�d�p4|�d�p4|�d�o4t|dd��S)NZHTTP_ZSSL_Z	REDIRECT_�	)�_is_request�
startswith�_needs_transcode)�krrrrs�rcCs�t��}d}zd�d|�Wntk
r4d}YnXi}tj��D]�\}}t|�r�tjdkr�tj�	dd��
�}|�d�r�|�d��d�}q�|�d	�r�q�|�d
�r�d|kr�|�d��d�}q�|�|d��d�}n|�||��d�}|||<qD|S)z'Read environment, fixing HTTP variables�surrogateescape�zutf-8�replaceZwin32�SERVER_SOFTWAREzmicrosoft-iis/�
iso-8859-1zapache/zsimplehttp/zpython/3)
�sys�getfilesystemencoding�encode�LookupError�os�environ�itemsr�platform�get�lowerr�decode)�encZescr'r�vZsoftwarerrrr"s0

	

��
c@s"eZdZdZdZdZdZdZdZdZ	dZ
e�Ze
ZeZdZdZdgZd	ZdZZdZdZd
Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zd;dd�Z dd�Z!dd�Z"dd�Z#dd �Z$d!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(d)d*�Z)d+d,�Z*d-d.�Z+d/d0�Z,d1d2�Z-d3d4�Z.d5d6�Z/d7d8�Z0d9d:�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
Cstz$|��||j|j�|_|��WnJtttfk
r@YdSz|��Wn|�	��YnXYnXdS)zInvoke the applicationN)
�
setup_environr'�start_response�result�finish_response�ConnectionAbortedError�BrokenPipeError�ConnectionResetError�handle_error�close)�selfZapplicationrrr�run�szBaseHandler.runcCs�|j��}|_|��|��|d<|��|d<|j|d<|j|d<|��|d<|j	|d<|j
|d<|jdk	rx|j|d	<|jr�|j
r�|�d
|j
�dS)z&Set up the environment for one requestz
wsgi.inputzwsgi.errorszwsgi.versionz
wsgi.run_oncezwsgi.url_schemezwsgi.multithreadzwsgi.multiprocessNzwsgi.file_wrapperr )�
os_environ�copyr'�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)r8�envrrrr/�s





zBaseHandler.setup_environcCsdz2|��r|��s0|jD]}|�|�q|��Wn$t|jd�rP|j���Yn
X|��dS)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.
        r7N)�result_is_file�sendfiler1�write�finish_content�hasattrr7�r8�datarrrr2�s

zBaseHandler.finish_responsecCs
t|j�S)z Return the URL scheme being used)rr'�r8rrrrA�szBaseHandler.get_schemec
CsJzt|j�}Wntttfk
r(YnX|dkrFt|j�|jd<dSdS)z@Compute Content-Length or switch to chunked encoding if possibler�Content-LengthN)�lenr1�	TypeError�AttributeError�NotImplementedError�str�
bytes_sent�headers)r8Zblocksrrr�set_content_length�szBaseHandler.set_content_lengthcCsd|jkr|��dS)zqMake any necessary header changes or defaults

        Subclasses can extend this to add other defaults.
        rQN)rXrYrPrrr�cleanup_headers�s
zBaseHandler.cleanup_headerscCsh|r2z$|jr&|d|d��|d��W5d}Xn|jdk	rDtd��||_|�|�|_|�|d�}|jS)z4'start_response()' callable as specified by PEP 3333Nrr�zHeaders already set!ZStatus)�headers_sent�with_tracebackrX�AssertionError�status�
headers_class�_convert_string_typerK)r8r_rX�exc_inforrrr0�s
zBaseHandler.start_responsecCs(t|�tkr|Std�|t|����dS)zConvert/check value type.z!{0} must be of type str (got {1})N)�typerVr^�format�repr)r8�value�titlerrrra�s
�z BaseHandler._convert_string_typecCs�|jrx|��r�|�d|j|jf�d��d|jkrP|�dtt����d��|j	r�d|jkr�|�d|j	�d��n|�d|j�d��dS)	z6Transmit version/status/date/server, via self._write()zHTTP/%s %s
r!ZDatez
Date: %s
ZServerzServer: %s
zStatus: %s
N)
rE�client_is_modern�_write�http_versionr_r$rXrr
rFrPrrr�
send_preambles
�zBaseHandler.send_preamblecCsR|jstd��n,|js*t|�|_|��n|jt|�7_|�|�|��dS)z+'write()' callable as specified by PEP 3333zwrite() before start_response()N)r_r^r\rRrW�send_headersri�_flushrNrrrrKs



zBaseHandler.writecCsdS)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.
        FrrPrrrrJ)szBaseHandler.sendfilecCs"|js|j�dd�|��ndS)z.Ensure headers and content have both been sentrQ�0N)r\rXrGrlrPrrrrL>s
zBaseHandler.finish_contentc	CsFzt|jd�r|j��W5d|_|_|_|_d|_d|_XdS)z�Close the iterable (if needed) and reset all instance vars

        Subclasses may want to also drop the client connection.
        NrFr7)r1rXr_r'rWr\rMr7rPrrrr7HszBaseHandler.closecCs8|��d|_|jr|��r4|��|�t|j��dS)z1Transmit headers to the client, via self._write()TN)rZr\rErhrkri�bytesrXrPrrrrlUs
zBaseHandler.send_headerscCs|j}|dk	ot|j|�S)z@True if 'self.result' is an instance of 'self.wsgi_file_wrapper'N)rD�
isinstancer1)r8�wrapperrrrrI^szBaseHandler.result_is_filecCs|jd��dkS)z,True if client can accept status and headersZSERVER_PROTOCOLzHTTP/0.9)r'�upperrPrrrrhdszBaseHandler.client_is_moderncCsJz>ddlm}|��}||d|d|d|j|�|��W5d}XdS)z�Log the 'exc_info' tuple in the server log

        Subclasses may override to retarget the output or change its format.
        Nr)�print_exceptionrr[)�	tracebackrsr>�traceback_limit�flush)r8rbrs�stderrrrr�
log_exceptionis�zBaseHandler.log_exceptioncCs2|�t���|js.|�|j|j�|_|��dS)z>Log current error, and send error output to client if possibleN)	rxr"rbr\�error_outputr'r0r1r2rPrrrr6yszBaseHandler.handle_errorcCs$||j|jdd�t���|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_headersr"rb�
error_body)r8r'r0rrrry�s
zBaseHandler.error_outputcCst�dS)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.
        N�rUrNrrrri�szBaseHandler._writecCst�dS)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.
        Nr}rPrrrrm�szBaseHandler._flushcCst�dS)z4Override in subclass to return suitable 'wsgi.input'Nr}rPrrrr=�szBaseHandler.get_stdincCst�dS)z5Override in subclass to return suitable 'wsgi.errors'Nr}rPrrrr>�szBaseHandler.get_stderrcCst�dS)z>Override in subclass to insert CGI variables in 'self.environ'Nr}rPrrrr<�szBaseHandler.add_cgi_vars)N)2�__name__�
__module__�__qualname__�__doc__r?rBrCr@rErjrFrr:rrDrr`rurzr{r|r_r1r\rXrWr9r/r2rArYrZr0rarkrKrJrLr7rlrIrhrxr6ryrirmr=r>r<rrrrr^sV



		c@sBeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)raqHandler 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)TFcCs(||_||_||_||_||_||_dS�N)�stdin�stdoutrw�base_envrBrC)r8r�r�rwr'�multithread�multiprocessrrr�__init__�szSimpleHandler.__init__cCs|jSr�)r�rPrrrr=�szSimpleHandler.get_stdincCs|jSr�)rwrPrrrr>�szSimpleHandler.get_stderrcCs|j�|j�dSr�)r'�updater�rPrrrr<�szSimpleHandler.add_cgi_varscCs^|j�|�}|dks |t|�kr$dSddlm}|dt�||d�}|sLqZ|j�|�}q:dS)Nr)�warnz9SimpleHandler.stdout.write() should not do partial writes)r�rKrR�warningsr��DeprecationWarning)r8rOr1r�rrrri�s�zSimpleHandler._writecCs|j��|jj|_dSr�)r�rvrmrPrrrrm�s
zSimpleHandler._flushN)TF)
r~rr�r�r�r=r>r<rirmrrrrr�s
�


c@seZdZdZdZdS)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~rr�r�rErrrrr	�sc@s eZdZdZdZiZdd�ZdS)r
a�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	Cs(tj|tjjtjjtjt�ddd�dS)NFT�r�r�)r	r�r"r��bufferr�rwrrPrrrr�s�zCGIHandler.__init__N�r~rr�r�r@r:r�rrrrr
�sc@s eZdZdZdZiZdd�ZdS)raCGI-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	Csjt�}|�dd�}|�dd�}|d�|d�rD|t|�d�|d<tj|tjjtj	jtj
|ddd�dS)Nrrr�/FTr�)rr*rrRr	r�r"r�r�r�rw)r8r'�pathZscriptrrrr�2s�zIISCGIHandler.__init__Nr�rrrrrs)r��utilrrrrXrr"r&r
�__all__rrr�__contains__rrrrrr	r
rrrrr�<module>s\���<V2