AlkantarClanX12

Your IP : 3.141.21.199


Current Path : /opt/alt/python311/lib64/python3.11/http/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/http/__pycache__/server.cpython-311.opt-1.pyc

�

c��f_���z�dZdZgd�ZddlZddlZddlZddlZddlZ	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddl	mZdZdZGd�d	ej��ZGd
�deje��ZGd�d
ej��ZGd�de��Z d�Z!da"d�Z#d�Z$Gd�de ��Z%d�Z&eedddfd�Z'e(dkr�ddl)Z)ddl*Z*e)j+��Z,e,�-ddd���e,�-ddd d!�"��e,�-d#d$e
j.��d%�&��e,�-d'd(d)dd*�+��e,�-d,de/d-d.�/��e,�0��Z1e1j2re%Z3ne Z3Gd0�d1e��Z4e'e3e4e1j5e1j6e1j7�2��dSdS)3a@HTTP server classes.

Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see
SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST,
and CGIHTTPRequestHandler for CGI scripts.

It does, however, optionally implement HTTP/1.1 persistent connections,
as of version 0.3.

Notes on CGIHTTPRequestHandler
------------------------------

This class implements GET and POST requests to cgi-bin scripts.

If the os.fork() function is not present (e.g. on Windows),
subprocess.Popen() is used as a fallback, with slightly altered semantics.

In all cases, the implementation is intentionally naive -- all
requests are executed synchronously.

SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL
-- it may execute arbitrary Python code or external programs.

Note that status code 200 is sent prior to execution of a CGI script, so
scripts cannot send other status codes such as 302 (redirect).

XXX To do:

- log requests even later (to capture byte count)
- log user-agent header and other interesting goodies
- send error log to separate file
z0.6)�
HTTPServer�ThreadingHTTPServer�BaseHTTPRequestHandler�SimpleHTTPRequestHandler�CGIHTTPRequestHandler�N)�
HTTPStatusaD<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error response</title>
    </head>
    <body>
        <h1>Error response</h1>
        <p>Error code: %(code)d</p>
        <p>Message: %(message)s.</p>
        <p>Error code explanation: %(code)s - %(explain)s.</p>
    </body>
</html>
ztext/html;charset=utf-8c��eZdZdZd�ZdS)r�c��tj�|��|jdd�\}}t	j|��|_||_dS)z.Override server_bind to store the server name.N�)�socketserver�	TCPServer�server_bind�server_address�socket�getfqdn�server_name�server_port)�self�host�ports   �2/opt/alt/python311/lib64/python3.11/http/server.pyrzHTTPServer.server_bind�sN����*�*�4�0�0�0��(��!��,�
��d�!�>�$�/�/��������N)�__name__�
__module__�__qualname__�allow_reuse_addressr�rrrr�s)�������� � � � � rrc��eZdZdZdS)rTN)rrr�daemon_threadsrrrrr�s�������N�N�Nrrc
���eZdZdZdej���dzZdezZ	e
ZeZ
dZd�Zd�Zd�Zd	�Zd#d�Zd$d�Zd$d
�Zd�Zd�Zd�Zd%d�Zd�Ze�d�ejed��edd����D����Z de e!d��<d�Z"d�Z#d$d�Z$d�Z%gd�Z&gd�Z'd �Z(d!Z)e*j+j,Z-d"�e.j/�0��D��Z1d
S)&ra�HTTP request handler base class.

    The following explanation of HTTP serves to guide you through the
    code as well as to expose any misunderstandings I may have about
    HTTP (so you don't need to read the code to figure out I'm wrong
    :-).

    HTTP (HyperText Transfer Protocol) is an extensible protocol on
    top of a reliable stream transport (e.g. TCP/IP).  The protocol
    recognizes three parts to a request:

    1. One line identifying the request type and path
    2. An optional set of RFC-822-style headers
    3. An optional data part

    The headers and data are separated by a blank line.

    The first line of the request has the form

    <command> <path> <version>

    where <command> is a (case-sensitive) keyword such as GET or POST,
    <path> is a string containing path information for the request,
    and <version> should be the string "HTTP/1.0" or "HTTP/1.1".
    <path> is encoded using the URL encoding scheme (using %xx to signify
    the ASCII character with hex code xx).

    The specification specifies that lines are separated by CRLF but
    for compatibility with the widest range of clients recommends
    servers also handle LF.  Similarly, whitespace in the request line
    is treated sensibly (allowing multiple spaces between components
    and allowing trailing whitespace).

    Similarly, for output, lines ought to be separated by CRLF pairs
    but most clients grok LF characters just fine.

    If the first line of the request has the form

    <command> <path>

    (i.e. <version> is left out) then this is assumed to be an HTTP
    0.9 request; this form has no optional headers and data part and
    the reply consists of just the data.

    The reply form of the HTTP 1.x protocol again has three parts:

    1. One line giving the response code
    2. An optional set of RFC-822-style headers
    3. The data

    Again, the headers and data are separated by a blank line.

    The response code line has the form

    <version> <responsecode> <responsestring>

    where <version> is the protocol version ("HTTP/1.0" or "HTTP/1.1"),
    <responsecode> is a 3-digit response code indicating success or
    failure of the request, and <responsestring> is an optional
    human-readable string explaining what the response code means.

    This server parses the request and the headers, and then calls a
    function specific to the request type (<command>).  Specifically,
    a request SPAM will be handled by a method do_SPAM().  If no
    such method exists the server sends an error response to the
    client.  If it exists, it is called with no arguments:

    do_SPAM()

    Note that the request name is case sensitive (i.e. SPAM and spam
    are different requests).

    The various request details are stored in instance variables:

    - client_address is the client IP address in the form (host,
    port);

    - command, path and version are the broken-down request line;

    - headers is an instance of email.message.Message (or a derived
    class) containing the header information;

    - rfile is a file object open for reading positioned at the
    start of the optional input data part;

    - wfile is a file object open for writing.

    IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING!

    The first thing to be written must be the response line.  Then
    follow 0 or more header lines, then a blank line, and then the
    actual data (if any).  The meaning of the header lines depends on
    the command executed by the server; in most cases, when data is
    returned, there should be at least one header line of the form

    Content-type: <type>/<subtype>

    where <type> and <subtype> should be registered MIME types,
    e.g. "text/html" or "text/plain".

    zPython/rz	BaseHTTP/�HTTP/0.9c���d|_|jx|_}d|_t	|jd��}|�d��}||_|���}t|��dkrdSt|��dk�rp|d}	|�
d	��st�|�d
d��d}|�d��}t|��d
krt�td�|D����rtd���td�|D����rtd���t|d��t|d��f}n;#ttf$r'|�t jd|z��YdSwxYw|dkr|jdkrd|_|dkr%|�t jd|z��dS||_d
t|��cxkrdks'n|�t jd|z��dS|dd
�\}}t|��d
kr2d|_|dkr%|�t jd|z��dS||c|_|_|j�
d��r"d
|j�d
��z|_	t,j�|j|j���|_n�#t,jj$r9}|�t jdt	|����Yd}~dSd}~wt,jj$r9}|�t jdt	|����Yd}~dSd}~wwxYw|j�dd��}	|	� ��d krd|_n*|	� ��d!kr|jdkrd|_|j�d"d��}
|
� ��d#kr,|jdkr!|jdkr|�!��sdSdS)$aHParse a request (internal).

        The request should be stored in self.raw_requestline; the results
        are in self.command, self.path, self.request_version and
        self.headers.

        Return True for success, False for failure; on failure, any relevant
        error response has already been sent back.

        NTz
iso-8859-1�
rF����zHTTP/�/r
�.rc3�@K�|]}|���V��dS�N)�isdigit��.0�	components  r�	<genexpr>z7BaseHTTPRequestHandler.parse_request.<locals>.<genexpr>/s1����O�O�9�9�,�,�.�.�.�O�O�O�O�O�Orznon digit in http versionc3�<K�|]}t|��dkV��dS)�
N)�lenr,s  rr/z7BaseHTTPRequestHandler.parse_request.<locals>.<genexpr>1s-����K�K�y�s�9�~�~��*�K�K�K�K�K�Krz unreasonable length http versionzBad request version (%r))r
r
zHTTP/1.1)rrzInvalid HTTP version (%s)zBad request syntax (%r)�GETzBad HTTP/0.9 request type (%r)z//)�_classz
Line too longzToo many headers�
Connection��close�
keep-alive�Expectz100-continue)"�command�default_request_version�request_version�close_connection�str�raw_requestline�rstrip�requestline�splitr2�
startswith�
ValueError�any�int�
IndexError�
send_errorr�BAD_REQUEST�protocol_version�HTTP_VERSION_NOT_SUPPORTED�path�lstrip�http�client�
parse_headers�rfile�MessageClass�headers�LineTooLong�REQUEST_HEADER_FIELDS_TOO_LARGE�
HTTPException�get�lower�handle_expect_100)r�versionrA�words�base_version_number�version_numberr:rL�err�conntype�expects           r�
parse_requestz$BaseHTTPRequestHandler.parse_requests������)-�)E�E���w� $����$�.��=�=��!�(�(��0�0��&����!�!�#�#���u�:�:��?�?��5��u�:�:��?�?��B�i�G�
��)�)�'�2�2�%�$�$�&-�m�m�C��&;�&;�A�&>�#�!4�!:�!:�3�!?�!?���~�&�&�!�+�+�$�$��O�O��O�O�O�O�O�B�$�%@�A�A�A��K�K�N�K�K�K�K�K�I�$�%G�H�H�H�!$�^�A�%6�!7�!7��^�A�=N�9O�9O�!O�����
�+�
�
�
�����*�.��8�:�:�:��u�u�	
����
��'�'�D�,A�Z�,O�,O�(-��%���'�'�����9�/�2E�E�G�G�G��u�#*�D� ��C��J�J�#�#�#�#�!�#�#�#�#��O�O��&�)�K�7�
9�
9�
9��5��b�q�b�	�
����u�:�:��?�?�$(�D�!��%�������*�4�w�>�@�@�@��u�")�4����d�i��9����%�%�	4��d�i�.�.�s�3�3�3�D�I�	��;�4�4�T�Z�<@�<M�5�O�O�D�L�L���{�&�	�	�	��O�O��:���C���
�
�
��5�5�5�5�5������{�(�	�	�	��O�O��:�"��C���
�
�
�
�5�5�5�5�5�����
	�����<�#�#�L�"�5�5���>�>���w�&�&�$(�D�!�!��n�n���,�.�.��#�z�1�1�$)�D�!���!�!�(�B�/�/���L�L�N�N�n�,�,��%��3�3��$�
�2�2��)�)�+�+�
��u��ts7�C!E6�64F.�-F.�0L�N#�.M�N#�*.N�N#c�l�|�tj��|���dS)a7Decide what to do with an "Expect: 100-continue" header.

        If the client is expecting a 100 Continue response, we must
        respond with either a 100 Continue or a final response before
        waiting for the request body. The default is to always respond
        with a 100 Continue. You can behave differently (for example,
        reject unauthorized requests) by overriding this method.

        This method should either return True (possibly after sending
        a 100 Continue response) or send an error response and return
        False.

        T)�send_response_onlyr�CONTINUE�end_headers�rs rrYz(BaseHTTPRequestHandler.handle_expect_100ys2��	
���
� 3�4�4�4��������trc��	|j�d��|_t|j��dkr6d|_d|_d|_|�tj	��dS|js	d|_
dS|���sdSd|jz}t||��s*|�tj
d|jz��dSt||��}|��|j���dS#t"$r(}|�d|��d|_
Yd}~dSd}~wwxYw)	z�Handle a single HTTP request.

        You normally don't need to override this method; see the class
        __doc__ string for information on how to handle specific HTTP
        commands such as GET and POST.

        iir6NT�do_zUnsupported method (%r)zRequest timed out: %r)rQ�readliner?r2rAr<r:rHr�REQUEST_URI_TOO_LONGr=ra�hasattr�NOT_IMPLEMENTED�getattr�wfile�flush�TimeoutError�	log_error)r�mname�method�es    r�handle_one_requestz)BaseHTTPRequestHandler.handle_one_request�s_��	�#'�:�#6�#6�u�#=�#=�D� ��4�'�(�(�5�0�0�#%�� �')��$�!������
� ?�@�@�@����'�
�(,��%����%�%�'�'�
����D�L�(�E��4��'�'�
�����.�-���<�>�>�>����T�5�)�)�F��F�H�H�H��J����������	�	�	��N�N�2�A�6�6�6�$(�D�!��F�F�F�F�F�����		���s1�A+D�/D�?D�AD�3D�
E�D;�;Ec��d|_|���|js|���|j�dSdS)z&Handle multiple requests if necessary.TN)r=rurfs r�handlezBaseHTTPRequestHandler.handle�sZ�� $������!�!�!��'�	&��#�#�%�%�%��'�	&�	&�	&�	&�	&rNc���	|j|\}}n#t$rd\}}YnwxYw|�|}|�|}|�d||��|�||��|�dd��d}|dkr�|t
jt
jt
jfvr�|j	|tj|d���tj|d���d	�z}|�d
d��}|�d|j
��|�d
tt|������|���|jdkr|r|j�|��dSdSdS)akSend and log an error reply.

        Arguments are
        * code:    an HTTP error code
                   3 digits
        * message: a simple optional 1 line reason phrase.
                   *( HTAB / SP / VCHAR / %x80-FF )
                   defaults to short entry matching the response code
        * explain: a detailed message defaults to the long entry
                   matching the response code.

        This sends an error response (so it must be called before any
        output has been generated), logs the error, and finally sends
        a piece of HTML explaining the error to the user.

        )�???ryNzcode %d, message %sr5r7��F��quote)�code�message�explainzUTF-8�replacezContent-Type�Content-Length�HEAD)�	responses�KeyErrorrq�
send_response�send_headerr�
NO_CONTENT�
RESET_CONTENT�NOT_MODIFIED�error_message_format�html�escape�encode�error_content_typer>r2rer:rn�write)rr}r~r�shortmsg�longmsg�body�contents        rrHz!BaseHTTPRequestHandler.send_error�s���$	-� $��t� 4��H�g�g���	-�	-�	-� ,��H�g�g�g�	-�����?��G��?��G����,�d�G�<�<�<����4��)�)�)�����w�/�/�/�
���C�K�K���.�#�1�#�0�2�
2�
2�
�0���;�w�e�<�<�<��;�w�e�<�<�<�4�4��G�
�>�>�'�9�5�5�D����^�T�-D�E�E�E����-�s�3�t�9�9�~�~�>�>�>��������<�6�!�!�d�!��J���T�"�"�"�"�"�"�!�!�!s��%�%c��|�|��|�||��|�d|�����|�d|�����dS)z�Add the response header to the headers buffer and log the
        response code.

        Also send two standard headers with the server software
        version and the current date.

        �Server�DateN)�log_requestrcr��version_string�date_time_string�rr}r~s   rr�z$BaseHTTPRequestHandler.send_response�sx��	
�����������g�.�.�.�����4�#6�#6�#8�#8�9�9�9������!6�!6�!8�!8�9�9�9�9�9rc��|jdkrs|�||jvr|j|d}nd}t|d��sg|_|j�d|j||fz�dd����dSdS)	zSend the response header only.r"Nrr6�_headers_bufferz
%s %d %s
�latin-1�strict)r<r�rkr��appendrJr�r�s   rrcz)BaseHTTPRequestHandler.send_response_only�s�����:�-�-����4�>�)�)�"�n�T�2�1�5�G�G� �G��4�!2�3�3�
*�')��$�� �'�'���*�D�'�:�*;�<B�F�!�8�=-�=-�
.�
.�
.�
.�
.�.�-rc�j�|jdkrKt|d��sg|_|j�|�d|�d��dd����|���dkrB|���dkr	d	|_dS|���d
krd|_dSdSdS)
z)Send a MIME header to the headers buffer.r"r�z: r$r�r��
connectionr7Tr8FN)r<rkr�r�r�rXr=)r�keyword�values   rr�z"BaseHTTPRequestHandler.send_headers�����:�-�-��4�!2�3�3�
*�')��$�� �'�'�!(���%�%�%�0�8�8��H�M�M�
O�
O�
O��=�=�?�?�l�*�*��{�{�}�}��'�'�(,��%�%�%������,�.�.�(-��%�%�%�	+�*�/�.rc�|�|jdkr0|j�d��|���dSdS)z,Send the blank line ending the MIME headers.r"s
N)r<r�r��
flush_headersrfs rrez"BaseHTTPRequestHandler.end_headerssG����:�-�-�� �'�'��0�0�0���� � � � � �.�-rc��t|d��r;|j�d�|j����g|_dSdS)Nr�r)rkrnr��joinr�rfs rr�z$BaseHTTPRequestHandler.flush_headerssR���4�*�+�+�	&��J���S�X�X�d�&:�;�;�<�<�<�#%�D� � � �	&�	&r�-c��t|t��r|j}|�d|jt|��t|����dS)zNLog an accepted request.

        This is called by send_response().

        z
"%s" %s %sN)�
isinstancerr��log_messagerAr>)rr}�sizes   rr�z"BaseHTTPRequestHandler.log_request!s\���d�J�'�'�	��:�D������)�3�t�9�9�c�$�i�i�	A�	A�	A�	A�	Arc�"�|j|g|�R�dS)z�Log an error.

        This is called when a request cannot be fulfilled.  By
        default it passes the message on to log_message().

        Arguments are the same as for log_message().

        XXX This should go to the separate error log.

        N)r�)r�format�argss   rrqz BaseHTTPRequestHandler.log_error,s%��	����'�$�'�'�'�'�'�'rc��i|]	}|d|d����
S)z\x�02xr)r-�cs  r�
<dictcomp>z!BaseHTTPRequestHandler.<dictcomp><s"��V�V�V�!�Q�
�a�
�
�
�V�V�Vr� ��z\\�\c	���||z}tj�|����d|����d|�|j���d���dS)aZLog an arbitrary message.

        This is used by all other logging functions.  Override
        it if you have specific logging wishes.

        The first argument, FORMAT, is a format string for the
        message to be logged.  If the format string contains
        any % escapes requiring parameters, they should be
        specified as subsequent arguments (it's just like
        printf!).

        The client ip and current date/time are prefixed to
        every message.

        Unicode control characters are replaced with escaped hex
        before writing the output to stderr.

        z - - [z] �
N)�sys�stderrr��address_string�log_date_time_string�	translate�_control_char_table)rr�r�r~s    rr�z"BaseHTTPRequestHandler.log_message?s���(�4�-���
����-�-�/�/�/�/��3�3�5�5�5�5�!�+�+�D�,D�E�E�E�E�G�	H�	H�	H�	H�	Hrc�&�|jdz|jzS)z*Return the server software version string.� )�server_version�sys_versionrfs rr�z%BaseHTTPRequestHandler.version_stringYs���"�S�(�4�+;�;�;rc�n�|�tj��}tj�|d���S)z@Return the current date and time formatted for a message header.NT)�usegmt)�time�email�utils�
formatdate)r�	timestamps  rr�z'BaseHTTPRequestHandler.date_time_string]s.�����	���I��{�%�%�i��%�=�=�=rc	��tj��}tj|��\	}}}}}}}}	}
d||j|||||fz}|S)z.Return the current time formatted for logging.z%02d/%3s/%04d %02d:%02d:%02d)r��	localtime�	monthname)r�now�year�month�day�hh�mm�ss�x�y�z�ss            rr�z+BaseHTTPRequestHandler.log_date_time_stringcsW���i�k�k��04��s�0C�0C�-��e�S�"�b�"�a��A�*��T�^�E�*�D�"�b�"�.>�
>���r)�Mon�Tue�Wed�Thu�Fri�Sat�Sun)
N�Jan�Feb�Mar�Apr�May�Jun�Jul�Aug�Sep�Oct�Nov�Decc��|jdS)zReturn the client address.r)�client_addressrfs rr�z%BaseHTTPRequestHandler.address_stringqs���"�1�%�%r�HTTP/1.0c�,�i|]}||j|jf��Sr)�phrase�description)r-�vs  rr�z!BaseHTTPRequestHandler.<dictcomp>�s3�����
�	
�A�H�a�m�$���r)NNr*)r�r�)2rrr�__doc__r�rZrBr��__version__r��DEFAULT_ERROR_MESSAGEr��DEFAULT_ERROR_CONTENT_TYPEr�r;rarYrurwrHr�rcr�rer�r�rqr>�	maketrans�	itertools�chain�ranger��ordr�r�r�r��weekdaynamer�r�rJrNrO�HTTPMessagerRr�__members__�valuesr�rrrrr�s=������d�d�N�c�k�/�/�1�1�!�4�4�K�
!�;�.�N�0��3��)��l�l�l�\���$#�#�#�J&�&�&�3#�3#�3#�3#�j:�:�:�:�.�.�.�.�.�.�.�!�!�!�&�&�&�
	A�	A�	A�	A�(�(�(��-�-�V�V��y��u�u�T�{�{�E�E�$�t�DT�DT�'U�'U�V�V�V�X�X��%*����D�	�	�"�H�H�H�4<�<�<�>�>�>�>����D�C�C�K�;�;�;�I�&�&�&�"���;�*�L����'�.�.�0�0����I�I�Irrc�n��eZdZdZdezZddddd�xZZdd	��fd
�
Zd�Z	d�Z
d
�Zd�Zd�Z
d�Zd�Z�xZS)raWSimple HTTP request handler with GET and HEAD commands.

    This serves files from the current directory and any of its
    subdirectories.  The MIME type for files is determined by
    calling the .guess_type() method.

    The GET and HEAD requests are identical except that the HEAD
    request omits the actual contents of the file.

    zSimpleHTTP/zapplication/gzip�application/octet-streamzapplication/x-bzip2zapplication/x-xz)z.gzz.Zz.bz2z.xzN��	directoryc���|�tj��}tj|��|_t	��j|i|��dSr*)�os�getcwd�fspathr�super�__init__)rrr��kwargs�	__class__s    �rr	z!SimpleHTTPRequestHandler.__init__�sG������	���I���9�-�-��������$�)�&�)�)�)�)�)rc���|���}|rK	|�||j��|���dS#|���wxYwdS)zServe a GET request.N)�	send_head�copyfilernr7�r�fs  r�do_GETzSimpleHTTPRequestHandler.do_GET�sa���N�N�����	�
��
�
�a���,�,�,����	�	�	�	�	�����	�	�	�	����		�	s�A	�	Ac�^�|���}|r|���dSdS)zServe a HEAD request.N)r
r7rs  r�do_HEADz SimpleHTTPRequestHandler.do_HEAD�s4���N�N�����	�
�G�G�I�I�I�I�I�	�	rc�d�|�|j��}d}tj�|���rCtj�|j��}|j�d��s�|�tj
��|d|d|ddz|d|df}tj�|��}|�d|��|�d	d
��|�
��dSdD]E}tj�||��}tj�|��r|}n�F|�|��S|�|��}|�d��r"|�tjd��dS	t)|d
��}n1#t*$r$|�tjd��YdSwxYw	tj|�����}d|jv�r6d|jv�r,	t2j�|jd��}	|	j�%|	�t<jj ���}	|	jt<jj ur�t<j�!|j"t<jj ��}
|
�d���}
|
|	krI|�tj#��|�
��|�$��dSn##tJtLtNtPf$rYnwxYw|�tj)��|�d|��|�d	tU|d����|�d|�+|j"����|�
��|S#|�$���xYw)a{Common code for GET and HEAD commands.

        This sends the response code and MIME headers.

        Return value is either a file object (which has to be copied
        to the outputfile by the caller unless the command was HEAD,
        and must be closed by the caller under all circumstances), or
        None, in which case the caller has nothing further to do.

        Nr'rr
rr%��Locationr��0)z
index.htmlz	index.htmzFile not found�rbzIf-Modified-Sincez
If-None-Match)�tzinfo)�microsecond�Content-type�z
Last-Modified),�translate_pathrLr�isdir�urllib�parse�urlsplit�endswithr�r�MOVED_PERMANENTLY�
urlunsplitr�rer��isfile�list_directory�
guess_typerH�	NOT_FOUND�open�OSError�fstat�filenorSr�r��parsedate_to_datetimerr��datetime�timezone�utc�
fromtimestamp�st_mtimer�r7�	TypeErrorrG�
OverflowErrorrD�OKr>r�)rrLr�parts�	new_parts�new_url�index�ctype�fs�ims�
last_modifs           rr
z"SimpleHTTPRequestHandler.send_head�s����"�"�4�9�-�-����
�7�=�=����	1��L�)�)�$�)�4�4�E��:�&�&�s�+�+�	
��"�"�:�#?�@�@�@�"�1�X�u�Q�x��q��C��"�1�X�u�Q�x�1�	� �,�1�1�)�<�<��� � ��W�5�5�5�� � �!1�3�7�7�7�� � �"�"�"��t�2�
1�
1������T�5�1�1���7�>�>�%�(�(�� �D��E���*�*�4�0�0�0�����%�%���=�=����	��O�O�J�0�2B�C�C�C��4�	��T�4� � �A�A���	�	�	��O�O�J�0�2B�C�C�C��4�4�	����'	���!�(�(�*�*�%�%�B�#�t�|�3�3�'�t�|�;�;�(��+�;�;���%8�9�;�;�C��z�)�"�k�k��1B�1F�k�G�G���z�X�%6�%:�:�:�%-�%6�%D�%D��K��):�)>�&@�&@�
�&0�%7�%7�A�%7�%F�%F�
�%��,�,� �.�.�z�/F�G�G�G� �,�,�.�.�.��G�G�I�I�I�#'�4���'"�:�}�j�I�����D�����*
���z�}�-�-�-����^�U�3�3�3����-�s�2�a�5�z�z�:�:�:����_��%�%�b�k�2�2�
4�
4�
4��������H��	�
�G�G�I�I�I����sJ�
G�*H�H�:P�*M�5CP�P�M3�0P�2M3�3B$P�P/c
��	tj|��}n1#t$r$|�tjd��YdSwxYw|�d����g}	tj�	|j
d���}n4#t$r'tj�	|j
��}YnwxYwtj
|d���}tj��}d	|��}|�d
��|�d��|�d��|�d
|�d���|�d|�d���|�d|�d���|�d��|D]�}tj
�||��}|x}	}
tj
�|��r
|dz}	|dz}
tj
�|��r|dz}	|�dtj�|
d����dtj
|	d����d�����|�d��d�|���|d��}t-j��}|�|��|�d��|�tj��|�dd|z��|�dt;t=|������|���|S)z�Helper to produce a directory listing (absent index.html).

        Return value is either a file object, or None (indicating an
        error).  In either case, the headers are sent, making the
        interface the same as for send_head().

        zNo permission to list directoryNc�*�|���Sr*)rX)�as r�<lambda>z9SimpleHTTPRequestHandler.list_directory.<locals>.<lambda>s�����	�	�r)�key�
surrogatepass��errorsFr{zDirectory listing for z<!DOCTYPE HTML>z<html lang="en">z<head>z<meta charset="z">z<title>z</title>
</head>z<body>
<h1>z</h1>z	<hr>
<ul>r'�@z
<li><a href="z	</a></li>z</ul>
<hr>
</body>
</html>
r��surrogateescaperrztext/html; charset=%sr�) r�listdirr*rHrr(�sortrr �unquoterL�UnicodeDecodeErrorr�r�r��getfilesystemencodingr�r�r�islinkr|r��io�BytesIOr��seekr�r5r�r>r2re)
rrL�list�r�displaypath�enc�title�name�fullname�displayname�linkname�encodedrs
             rr&z'SimpleHTTPRequestHandler.list_directorysZ��	��:�d�#�#�D�D���	�	�	��O�O��$�1�
3�
3�
3��4�4�		����
	
�	�	�)�)�	�*�*�*���	:� �,�.�.�t�y�6E�/�G�G�K�K��!�	:�	:�	:� �,�.�.�t�y�9�9�K�K�K�	:�����k�+�U�;�;�;���'�)�)��6��6�6��	���"�#�#�#�	���#�$�$�$�	�������	���*�3�*�*�*�+�+�+�	���3�5�3�3�3�4�4�4�	���,��,�,�,�-�-�-�	��������
	?�
	?�D��w�|�|�D�$�/�/�H�%)�)�K�(��w�}�}�X�&�&�
&�"�S�j���#�:���w�~�~�h�'�'�
)�"�S�j��
�H�H�H��|�)�)�(�1@�*�B�B�B�B��{�;�e�<�<�<�<�<�>�
?�
?�
?�
?�	
���2�3�3�3��)�)�A�,�,�%�%�c�+<�=�=���J�L�L��	�������	���q�	�	�	����:�=�)�)�)�����)@�3�)F�G�G�G����)�3�s�7�|�|�+<�+<�=�=�=��������s!��*A�A�"&B	�	.B:�9B:c��|�dd��d}|�dd��d}|����d��}	tj�|d���}n/#t$r"tj�|��}YnwxYwtj|��}|�d��}td|��}|j
}|D]\}tj�
|��s|tjtjfvr�<tj�||��}�]|r|dz
}|S)	z�Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        �?r
r�#r'rCrDN)rBr@r"rr rJrK�	posixpath�normpath�filterrrrL�dirname�curdir�pardirr�)rrL�trailing_slashr[�words     rrz'SimpleHTTPRequestHandler.translate_pathAsA���z�z�#�a� � ��#���z�z�#�a� � ��#�������/�/��4�4��	.��<�'�'��_�'�E�E�D�D��!�	.�	.�	.��<�'�'��-�-�D�D�D�	.�����!�$�'�'���
�
�3�����t�U�#�#���~���	,�	,�D��w���t�$�$�
����B�I�0F�(F�(F���7�<�<��d�+�+�D�D��	��C�K�D��s�!!B�)B/�.B/c�0�tj||��dS)a�Copy all data between two file objects.

        The SOURCE argument is a file object open for reading
        (or anything with a read() method) and the DESTINATION
        argument is a file object open for writing (or
        anything with a write() method).

        The only reason for overriding this would be to change
        the block size or perhaps to replace newlines by CRLF
        -- note however that this the default server uses this
        to copy binary data as well.

        N)�shutil�copyfileobj)r�source�
outputfiles   rrz!SimpleHTTPRequestHandler.copyfile_s��	��6�:�.�.�.�.�.rc���tj|��\}}||jvr
|j|S|���}||jvr
|j|St	j|��\}}|r|SdS)a�Guess the type of a file.

        Argument is a PATH (a filename).

        Return value is a string of the form type/subtype,
        usable for a MIME Content-type header.

        The default implementation looks the file's extension
        up in the table self.extensions_map, using application/octet-stream
        as a default; however it would be permissible (if
        slow) to look inside the data to make a better guess.

        r)r^�splitext�extensions_maprX�	mimetypesr')rrL�base�ext�guess�_s      rr'z#SimpleHTTPRequestHandler.guess_typeos����&�t�,�,�	��c��$�%�%�%��&�s�+�+��i�i�k�k���$�%�%�%��&�s�+�+��'��-�-���q��	��L�)�)r)rrrr�r�r�rm�_encodings_map_defaultr	rrr
r&rrr'�
__classcell__�rs@rrr�s��������	�	�#�[�0�N�!�(�%�!�	/�/��N�+�)-�*�*�*�*�*�*�*�������V�V�V�p7�7�7�r���</�/�/� *�*�*�*�*�*�*rrc�>�|�d��\}}}tj�|��}|�d��}g}|dd�D]:}|dkr|����|r|dkr|�|���;|r<|���}|r%|dkr|���d}n|dkrd}nd}|rd�||f��}dd�|��z|f}d�|��}|S)a�
    Given a URL path, remove extra '/'s and '.' path elements and collapse
    any '..' references and returns a collapsed path.

    Implements something akin to RFC-2396 5.2 step 6 to parse relative paths.
    The utility of this function is limited to is_cgi method and helps
    preventing some security attacks.

    Returns: The reconstituted URL, which will always start with a '/'.

    Raises: IndexError if too many '..' occur within the path.

    r\r'Nr&z..r(r6)�	partitionrr rJrB�popr�r�)	rLrr�query�
path_parts�
head_parts�part�	tail_part�	splitpath�collapsed_paths	         r�_url_collapse_pathr��sE���^�^�C�(�(�N�D�!�U��<����%�%�D����C���J��J��3�B�3��&�&���4�<�<��N�N�����
�	&�d�c�k�k����t�%�%�%���	��N�N�$�$�	��	��D� � ���� � � ��	�	��c�!�!��	���	��1��H�H�i��/�0�0�	��s�x�x�
�+�+�+�Y�7�I��X�X�i�(�(�N��rc��trtS	ddl}n#t$rYdSwxYw	|�d��dan>#t$r1dtd�|���D����zaYnwxYwtS)z$Internal routine to get nobody's uidrNr&�nobodyrr
c3�&K�|]}|dV��
dS)rNr)r-r�s  rr/znobody_uid.<locals>.<genexpr>�s&����6�6�!��1��6�6�6�6�6�6r)r��pwd�ImportError�getpwnamr��max�getpwall)r�s r�
nobody_uidr��s������
���
�
�
�
�������r�r�����7����h�'�'��*�����7�7�7��S�6�6�s�|�|�~�~�6�6�6�6�6�6����7�����Ms��
#�#�A�8A>�=A>c�@�tj|tj��S)zTest for executable file.)r�access�X_OK)rLs r�
executabler��s��
�9�T�2�7�#�#�#rc�Z�eZdZdZeed��ZdZd�Zd�Z	d�Z
ddgZd	�Zd
�Z
d�ZdS)
rz�Complete HTTP server with GET, HEAD and POST commands.

    GET and HEAD also support running CGI scripts.

    The POST command is *only* implemented for CGI scripts.

    �forkrc��|���r|���dS|�tjd��dS)zRServe a POST request.

        This is only implemented for CGI scripts.

        zCan only POST to CGI scriptsN)�is_cgi�run_cgirHrrlrfs r�do_POSTzCGIHTTPRequestHandler.do_POST�sN���;�;�=�=�	0��L�L�N�N�N�N�N��O�O��*�.�
0�
0�
0�
0�
0rc��|���r|���St�|��S)z-Version of send_head that support CGI scripts)r�r�rr
rfs rr
zCGIHTTPRequestHandler.send_head�s4���;�;�=�=�	<��<�<�>�>�!�+�5�5�d�;�;�;rc�8�t|j��}|�dd��}|dkrA|d|�|jvr0|�d|dz��}|dkr|d|�|jv�0|dkr"|d|�||dzd�}}||f|_dSdS)a3Test whether self.path corresponds to a CGI script.

        Returns True and updates the cgi_info attribute to the tuple
        (dir, rest) if self.path requires running a CGI script.
        Returns False otherwise.

        If any exception is raised, the caller should assume that
        self.path was rejected as invalid and act accordingly.

        The default implementation tests whether the normalized url
        path begins with one of the strings in self.cgi_directories
        (and the next character is a '/' or the end of the string).

        r'r
rNTF)r�rL�find�cgi_directories�cgi_info)rr�dir_sep�head�tails     rr�zCGIHTTPRequestHandler.is_cgi�s���,�D�I�6�6�� �%�%�c�1�-�-����k�k�.��'��":�d�>R�"R�"R�$�)�)�#�w�q�y�9�9�G���k�k�.��'��":�d�>R�"R�"R��Q�;�;�'����1�>�'�!�)�*�*�3M�$�D� �$�J�D�M��4��urz/cgi-binz/htbinc� �t|��S)z1Test whether argument path is an executable file.)r�)rrLs  r�
is_executablez#CGIHTTPRequestHandler.is_executables���$���rc�r�tj�|��\}}|���dvS)z.Test whether argument path is a Python script.)z.pyz.pyw)rrLrlrX)rrLr�r�s    r�	is_pythonzCGIHTTPRequestHandler.is_pythons.���W�%�%�d�+�+�
��d��z�z�|�|��.�.rc�P�|j\}}|dz|z}|�dt|��dz��}|dkr}|d|�}||dzd�}|�|��}tj�|��r+||}}|�dt|��dz��}nn|dk�}|�d��\}}}	|�d��}|dkr|d|�||d�}}
n|d}}
|dz|
z}|�|��}tj�|��s%|�	tjd|z��dStj�|��s%|�	tj
d|z��dS|�|��}
|js|
s:|�|��s%|�	tj
d	|z��dSt#jtj��}|���|d
<|jj|d<d|d
<|j|d<t1|jj��|d<|j|d<t6j�|��}||d<|�|��|d<||d<|	|d<|jd|d<|j� d��}|r�|�!��}t|��dkr�ddl"}ddl#}|d|d<|d�$��dkr�	|d�%d��}|�&|���'d��}|�!d��}t|��dkr|d|d<n#|j(tRf$rYnwxYw|j� d���|j�*��|d<n|jd|d<|j� d��}|r||d <|j� d!��}|r||d"<|j�+d#d$��}d%�,|��|d&<|j� d'��}|r||d(<t[d|j�+d)g����}d*�,|��}|r||d+<d,D]}|�.|d���|�/tj0d-��|�1��|	�2d.d/��}|j�r�|
g}d0|vr|�3|��ti��}|j5�6��t	j7��}|dkr�t	j8|d��\}}tsj9|j:gggd��dr>|j:�;d��sn#tsj9|j:gggd��d�>t	j<|��}|r|�=d1|����dS		t	j>|��n#t~$rYnwxYwt	j@|j:�A��d��t	j@|j5�A��d��t	jB|||��dS#|j�C|jD|j��t	jEd2��YdSxYwddlF} |g}!|�|��rOt�jH}"|"�$���Id3��r|"dd4�|"d5d�z}"|"d6g|!z}!d0|	vr|!�3|	��|�Jd7| �K|!����	t�|��}#n#t�t�f$rd}#YnwxYw| �O|!| jP| jP| jP|�8��}$|j�$��d9kr!|#dkr|j:�;|#��}%nd}%tsj9|j:jQgggd��drH|j:jQ�Rd��sn(tsj9|j:jQgggd��d�H|$�S|%��\}&}'|j5�T|&��|'r|�=d:|'��|$jU�V��|$jW�V��|$jX}(|(r|�=d;|(��dS|�Jd<��dS)=zExecute a CGI script.r'r
rNr\r6zNo such CGI script (%r)z#CGI script is not a plain file (%r)z!CGI script is not executable (%r)�SERVER_SOFTWARE�SERVER_NAMEzCGI/1.1�GATEWAY_INTERFACE�SERVER_PROTOCOL�SERVER_PORT�REQUEST_METHOD�	PATH_INFO�PATH_TRANSLATED�SCRIPT_NAME�QUERY_STRING�REMOTE_ADDR�
authorizationr�	AUTH_TYPE�basic�ascii�:�REMOTE_USERzcontent-type�CONTENT_TYPEzcontent-length�CONTENT_LENGTH�referer�HTTP_REFERER�acceptr�,�HTTP_ACCEPTz
user-agent�HTTP_USER_AGENT�cookiez, �HTTP_COOKIE)r��REMOTE_HOSTr�r�r�r�zScript output follows�+r��=zCGI script exit code r�zw.exe������z-uzcommand: %s)�stdin�stdoutr��env�postz%szCGI script exit status %#xzCGI script exited OK)Yr�r�r2rrrLrrw�existsrHrr(r%�	FORBIDDENr��	have_forkr��copy�deepcopy�environr��serverrrJr>rr:rr rJr�rSrWrB�base64�binasciirXr��decodebytes�decode�Error�UnicodeError�get_content_type�get_allr�r`�
setdefaultr�r5r�r�r�r�rnror��waitpid�selectrQ�read�waitstatus_to_exitcoderq�setuidr*�dup2r,�execve�handle_error�request�_exit�
subprocessr�r�r"r��list2cmdlinerFr3rD�Popen�PIPE�_sock�recv�communicater�r�r7r��
returncode))r�dir�restrL�i�nextdir�nextrest�	scriptdirrrry�script�
scriptname�
scriptfile�ispyr��uqrestr�r�r��lengthr�r��ua�co�
cookie_str�k�
decoded_queryr�r��pid�sts�exitcoder��cmdline�interp�nbytes�p�datar�r��statuss)                                         rr�zCGIHTTPRequestHandler.run_cgis
���M�	��T��S�y�4����I�I�c�3�s�8�8�A�:�&�&���1�f�f��2�A�2�h�G��A�a�C�D�D�z�H��+�+�G�4�4�I��w�}�}�Y�'�'�
�#�X�T���I�I�c�3�s�8�8�A�:�.�.�����1�f�f�����,�,���a��
�I�I�c�N�N����6�6�����8�T�!�"�"�X�D�F�F���D�F��3�Y��'�
��(�(��4�4�
��w�~�~�j�)�)�	��O�O��$�)�J�6�
8�
8�
8�
�F��w�~�~�j�)�)�	��O�O��$�5�
�B�
D�
D�
D�
�F��~�~�j�)�)���>�	��	��%�%�j�1�1�
�����(�7�*�D�F�F�F����m�B�J�'�'��!%�!4�!4�!6�!6����!�[�4��M��#,��� �!%�!6���� ���!8�9�9��M�� $�������%�%�d�+�+��!��K��!%�!4�!4�V�!<�!<����'��M��#��N��!�0��3��M����(�(��9�9�
��	B�)�/�/�1�1�M��=�!�!�Q�&�&�'�'�'�'�'�'�'�'�#0��#3��K� � ��#�)�)�+�+�w�6�6�	B�(5�a�(8�(?�(?��(H�(H�
�(.�(:�(:�=�(I�(I�(.��w���&�
)6�(;�(;�C�(@�(@�
��}�-�-��2�2�1>�q�1A�C�
�.���%�N�L�9�����������<���N�+�+�3�"&�,�"?�"?�"A�"A�C����"&�,�~�">�C�����!�!�"2�3�3���	+�$*�C� �!��,�"�"�9�-�-���	*�")�C�����%�%�h��3�3�� �X�X�f�-�-��M��
�\�
�
�l�
+�
+��
�	(�%'�C�!�"�
�D�$�,�.�.�x��<�<�
=�
=���Y�Y�r�]�]�
��	,�!+�C�
��D�	"�	"�A��N�N�1�b�!�!�!�!����:�=�*A�B�B�B��������
�
�c�3�/�/�
��>�I	9��8�D��-�'�'����M�*�*�*��\�\�F��J�������'�)�)�C��a�x�x��:�c�1�-�-���S��m�T�Z�L�"�b�!�<�<�Q�?���:�?�?�1�-�-����m�T�Z�L�"�b�!�<�<�Q�?���4�S�9�9���G��N�N�#E�8�#E�#E�F�F�F���

���I�f�%�%�%�%�������D��������
�)�)�+�+�Q�/�/�/����
�)�)�+�+�Q�/�/�/��	�*�d�C�0�0�0�0�0��
���(�(���t�7J�K�K�K����
�
�
�
�
�
����
����!�l�G��~�~�j�)�)�
3�����<�<�>�>�*�*�7�3�3�7�#�C�R�C�[�6�"�#�#�;�6�F�!�4�.�7�2���%������u�%�%�%����]�J�,C�,C�G�,L�,L�M�M�M�
��V�������z�*�
�
�
�����
����� � ��'1��(2��(2��'*�	!�#�#�A��|�!�!�#�#�v�-�-�&�1�*�*��z���v�.�.������-���!1� 2�B��A�>�>�q�A�
��z�'�,�,�Q�/�/����-���!1� 2�B��A�>�>�q�A�
��]�]�4�0�0�N�F�F��J���V�$�$�$��
-����t�V�,�,�,�
�H�N�N����
�H�N�N�����\�F��
9����;�V�D�D�D�D�D�� � �!7�8�8�8�8�8sP�
AO�O�O�.Z�\�
Z�
\�Z�A1\�;]�2`�`�`N)rrrr�rkrr��rbufsizer�r
r�r�r�r�r�rrrrr�s������������F�#�#�I��H�0�0�0�<�<�<����4"�8�,�O� � � �/�/�/�
x9�x9�x9�x9�x9rrc��tj|tjtjd��}t	t|����\}}}}}||fS)N)�type�flags)r�getaddrinfo�SOCK_STREAM�
AI_PASSIVE�next�iter)�address�infos�familyr�proto�	canonname�sockaddrs       r�_get_best_familyr�sS����	�
�
���
�
�
�E�
04�D��K�K�/@�/@�,�F�D�%��H��8��rr�i@c��t||��\|_}||_|||��5}|j���dd�\}}d|vrd|�d�n|}td|�d|�d|�d|�d	�	��	|���n3#t$r&td
��tj	d��YnwxYwddd��dS#1swxYwYdS)zmTest the HTTP request handler class.

    This runs an HTTP server on port 8000 (or the port argument).

    Nrr��[�]zServing HTTP on z port z	 (http://z/) ...z&
Keyboard interrupt received, exiting.r)
r�address_familyrJr�getsockname�print�
serve_forever�KeyboardInterruptr��exit)	�HandlerClass�ServerClass�protocolr�bind�addr�httpdr�url_hosts	         r�testr!�sr��(8��d�'C�'C�$�K���$,�L�!�	��T�<�	(�	(��E��\�-�-�/�/����3�
��d�"%��+�+�;�t�;�;�;�;�4��
�
/�t�
/�
/�4�
/�
/��
/�
/�"&�
/�
/�
/�	
�	
�	
�	����!�!�!�!�� �	�	�	��;�<�<�<��H�Q�K�K�K�K�K�	������������������������s6�A
C�:B�C�-B?�<C�>B?�?C�C�C�__main__z--cgi�
store_truezrun as CGI server)�action�helpz-bz--bind�ADDRESSz.bind to this address (default: all interfaces))�metavarr%z-dz--directoryz1serve this directory (default: current directory))�defaultr%z-pz
--protocol�VERSIONz3conform to this HTTP version (default: %(default)s))r'r(r%rr\z(bind to this port (default: %(default)s))r(r�nargsr%c�$��eZdZ�fd�Zd�Z�xZS)�DualStackServerc���tjt��5|j�tjtjd��ddd��n#1swxYwYt�����S)Nr)	�
contextlib�suppress�	Exceptionr�
setsockopt�IPPROTO_IPV6�IPV6_V6ONLYrr)rrs �rrzDualStackServer.server_binds�����$�Y�/�/�
@�
@���&�&��'��);�Q�@�@�@�
@�
@�
@�
@�
@�
@�
@�
@�
@�
@�
@����
@�
@�
@�
@��7�7�&�&�(�(�(s�1A�A�Ac�L�|�|||tj���dS)Nr)�RequestHandlerClassr�r)rr�r�s   r�finish_requestzDualStackServer.finish_requests4���$�$�W�n�d�/3�~�
%�
?�
?�
?�
?�
?r)rrrrr6rtrus@rr,r,sG�������	)�	)�	)�	)�	)�	?�	?�	?�	?�	?�	?�	?rr,)rrrrr)8r�r��__all__r�r.�email.utilsr�r��http.clientrNrNr�rnrr^r�rgrr
r�r��urllib.parserrr�r�rr�ThreadingMixInr�StreamRequestHandlerrrr�r�r�r�rrr!r�argparser.�ArgumentParser�parser�add_argumentrrF�
parse_argsr��cgi�
handler_classr,rrrrrr�<module>rDs�����d������
��������������������	�	�	�	���������	�	�	�	�����
�
�
�
�
�
�
�
�
�
�
�
�����
�
�
�
����������������� 7��	 �	 �	 �	 �	 ��'�	 �	 �	 ������,�5�z����q�q�q�q�q�\�>�q�q�q�h@*�@*�@*�@*�@*�5�@*�@*�@*�J,�,�,�`
��
�
�
� $�$�$�
C9�C9�C9�C9�C9�4�C9�C9�C9�L���-�(��4�d�����.�z����O�O�O�����
$�X�
$�
&�
&�F�
�����0��2�2�2�
����h�	�9��:�:�:�����m�Y�R�Y�[�[�<��=�=�=�����l�I� *�6��7�7�7������3�c�6��7�7�7������D��x�1�-�
�
�0�
�?�?�?�?�?�-�?�?�?�	�D�"�#�
�Y�
�Y���������Q�r