%PDF- %PDF-
Mini Shell

Mini Shell

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

�

���f����h�dZdZgd�ZddlZddlZddlZddlZddlZ	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddl	mZdZdZGd�d	ej4�ZGd
�dej8e�ZGd�d
ej<�ZGd�de�Z d�Z!da"d�Z#d�Z$Gd�de �Z%d�Z&eedddfd�Z'e(dk(r�ddl)Z)ddl*Z*e)jV�Z,e,j[ddd��e,j[ddd d!�"�e,j[d#d$e
j\�d%�&�e,j[d'd(d)dd*�+�e,j[d,de/d-d.�/�e,ja�Z1e1jdre%Z3ne Z3Gd0�d1e�Z4e'e3e4e1jje1jle1jn�2�yy)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�Zy)r�c��tjj|�|jdd\}}t	j
|�|_||_y)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   �"/usr/lib/python3.12/http/server.pyrzHTTPServer.server_bind�sE�����*�*�4�0��(�(��!�,�
��d�!�>�>�$�/������N)�__name__�
__module__�__qualname__�allow_reuse_addressr�rrrr�s
���� rrc��eZdZdZy)rTN)rrr�daemon_threadsrrrrr�s���Nrrc
�N�eZdZdZdej
j
�dzZdezZ	e
ZeZ
dZd�Zd�Zd�Zd	�Zd"d�Zd#d�Zd#d
�Zd�Zd�Zd�Zd$d�Zd�Zej9ej<ed�edd��D��cic]	}|d|d����c}}�Z de e!d�<d�Z"d�Z#d#d�Z$d�Z%gd�Z&gd�Z'd �Z(d!Z)e*jVjXZ-e.j^ja�D��cic]}||jb|jdf��c}}Z3y
cc}}wcc}}w)%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	|j
d�}|j
d�}||_|j�}t|�dk(ryt|�dk\r�|d}	|jd	�st�|jd
d�d}|jd�}t|�d
k7rt�td�|D��rtd��td�|D��rtd��t|d�t|d�f}|dk\r|j$dk\rd|_|dk\r$|jt j&d|z�y||_d
t|�cxkrdks&n|jt j"d|z�y|dd
\}}t|�d
k(r0d|_|dk7r$|jt j"d|z�y||c|_|_|j(jd�r#d
|j(j+d
�z|_	t,j.j1|j2|j4��|_|j6j?dd�}	|	jA�d k(rd|_n)|	jA�d!k(r|j$dk\rd|_|j6j?d"d�}
|
jA�d#k(r/|j$dk\r |jdk\r|jC�syy#ttf$r&|jt j"d|z�YywxYw#t,j.j8$r4}|jt j:dt	|��Yd}~yd}~wt,j.j<$r4}|jt j:dt	|��Yd}~yd}~wwxYw)$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�|]}|j����y�w�N)�isdigit��.0�	components  r�	<genexpr>z7BaseHTTPRequestHandler.parse_request.<locals>.<genexpr>/s����O�9�9�,�,�.�.�O�s�znon digit in http versionc3�8K�|]}t|�dkD���y�w)�
N)�lenr,s  rr/z7BaseHTTPRequestHandler.parse_request.<locals>.<genexpr>1s����K�y�s�9�~��*�K�s�z 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�E���w� $����$�.�.��=��!�(�(��0��&����!�!�#���u�:��?���u�:��?��B�i�G�
��)�)�'�2�$�$�&-�m�m�C��&;�A�&>�#�!4�!:�!:�3�!?���~�&�!�+�$�$��O��O�O�$�%@�A�A��K�N�K�K�$�%G�H�H�!$�^�A�%6�!7��^�A�=N�9O�!O����'�D�,A�,A�Z�,O�(-��%���'�����9�9�/�2E�E�G��#*�D� ��C��J�#�!�#��O�O��&�&�)�K�7�
9���b�q�	�
����u�:��?�$(�D�!��%������*�*�4�w�>�@��")�4����d�i��9�9����%��d�i�i�.�.�s�3�3�D�I�	��;�;�4�4�T�Z�Z�<@�<M�<M�5�O�D�L� �<�<�#�#�L�"�5���>�>��w�&�$(�D�!��n�n��,�.��#�#�z�1�$)�D�!����!�!�(�B�/���L�L�N�n�,��%�%��3��$�$�
�2��)�)�+����G�
�+�
�����*�*�.��8�:��	
��P�{�{�&�&�	��O�O��:�:���C��
����{�{�(�(�	��O�O��:�:�"��C��
�
��
	�s7�B'L<�:M4�<2M1�0M1�4P�*O� P� *P�Pc�b�|jtj�|j�y)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_100ys'��	
���
� 3� 3�4�����rc�t�	|jjd�|_t|j�dkDr5d|_d|_d|_|jtj�y|jsd|_
y|j�syd|jz}t||�s.|jtjd|jz�yt||�}|�|jj!�y#t"$r#}|j%d|�d|_
Yd}~yd}~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�#%�� �')��$�!������
� ?� ?�@���'�'�(,��%���%�%�'���D�L�L�(�E��4��'�����.�.�-����<�>���T�5�)�F��H��J�J������	��N�N�2�A�6�$(�D�!���		�s1�A,D�/D�D�AD�-D�	D7�D2�2D7c��d|_|j�|js|j�|js�yy)z&Handle multiple requests if necessary.TN)r=rurfs r�handlezBaseHTTPRequestHandler.handle�s6�� $������!��'�'��#�#�%��'�'rNc���	|j|\}}|�|}|�|}|jd||�|j||�|j	dd�d}|dk\r�|t
jt
jt
jfvr�|j|tj|d��tj|d��d	�z}|jd
d�}|j	d|j�|j	d
tt|���|j!�|j"dk7r|r|j$j'|�yyy#t$r	d\}}Y��VwxYw)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��?��G����,�d�G�<����4��)�����w�/�
���C�K���.�.�#�1�1�#�0�0�2�
2�
�0�0���;�;�w�e�<��;�;�w�e�<�4��G�
�>�>�'�9�5�D����^�T�-D�-D�E����-�s�3�t�9�~�>������<�<�6�!�d��J�J���T�"�'+�!��=�	-� ,��H�g�	-�s�E�E+�*E+c���|j|�|j||�|jd|j��|jd|j	��y)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�sT��	
���������g�.�����4�#6�#6�#8�9������!6�!6�!8�9rc�
�|jdk7rt|�#||jvr|j|d}nd}t|d�sg|_|jj	d|j
||fzj
dd��yy)	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�n�T�2�1�5�G� �G��4�!2�3�')��$�� � �'�'���*�*�D�'�:�*;�<B�F�!�8�=-�
.�.rc�>�|jdk7rDt|d�sg|_|jj|�d|�d�j	dd��|j�dk(r7|j�dk(rd	|_y|j�d
k(rd|_yyy)
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�')��$�� � �'�'�!(�%�0�8�8��H�M�
O��=�=�?�l�*��{�{�}��'�(,��%�����,�.�(-��%�/�+rc�z�|jdk7r,|jjd�|j�yy)z,Send the blank line ending the MIME headers.r"s
N)r<r�r��
flush_headersrfs rrez"BaseHTTPRequestHandler.end_headerss5�����:�-�� � �'�'��0���� �.rc��t|d�r<|jjdj|j��g|_yy)Nr�r)rkrnr��joinr�rfs rr�z$BaseHTTPRequestHandler.flush_headerss;���4�*�+��J�J���S�X�X�d�&:�&:�;�<�#%�D� �,rc��t|t�r|j}|jd|jt|�t|��y)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�c�$�i�	Arc�*�|j|g|���y)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��	�����'�$�'r� ��z\x�02xz\\�\c	���||z}tjj|j��d|j	��d|j|j��d��y)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?sR��(�4�-���
�
����-�-�/��3�3�5�!�+�+�D�,D�,D�E�G�	Hrc�:�|jdz|jzS)z*Return the server software version string.� )�server_version�sys_versionrfs rr�z%BaseHTTPRequestHandler.version_stringYs���"�"�S�(�4�+;�+;�;�;rc�p�|�tj�}tjj|d��S)z@Return the current date and time formatted for a message header.T)�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_stringcsX���i�i�k��04���s�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.0)NNr*)�-r�)4rrr�__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__�values�phrase�descriptionr�)r-�c�vs000rrr�sf��d�N�c�k�k�/�/�1�!�4�4�K�
!�;�.�N�0��3��)��l�\�$#�J&�3#�j:�.�.�!�&�
	A�(��-�-�'6�y���u�T�{�E�$�t�DT�'U�V�!�Q�2�a��W�
�
�V�X��%*���D�	�"�H�4<�>��D�K�;�I�&�"���;�;�*�*�L�
�'�'�.�.�0��
�	
�A�H�H�a�m�m�$�$��I��I
W��Hs�D
�6 D!rc�r��eZdZdZdezZdZddddd�xZZd	d
��fd�
Z	d�Z
d
�Zd�Zd�Z
d�Zd�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/)z
index.htmlz	index.htmzapplication/gzip�application/octet-streamzapplication/x-bzip2zapplication/x-xz)z.gzz.Zz.bz2z.xzN��	directoryc���|�tj�}tj|�|_t	�|�|i|��yr*)�os�getcwd�fspathr�super�__init__)rrr��kwargs�	__class__s    �rrz!SimpleHTTPRequestHandler.__init__�s6������	�	��I����9�-���
���$�)�&�)rc��|j�}|r.	|j||j�|j�yy#|j�wxYw)zServe a GET request.N)�	send_head�copyfilernr7�r�fs  r�do_GETzSimpleHTTPRequestHandler.do_GET�sC���N�N����
��
�
�a����,����	�	
�����	�s�A�Ac�J�|j�}|r|j�yy)zServe a HEAD request.N)r
r7rs  r�do_HEADz SimpleHTTPRequestHandler.do_HEAD�s���N�N����
�G�G�I�
rc�.�|j|j�}d}tjj|��r5tj
j
|j�}|jjd�s�|jtj�|d|d|ddz|d|df}tj
j|�}|jd|�|jd	d
�|j�y|jD]E}tjj||�}tjj!|�s�C|}n|j#|�S|j%|�}|jd�r!|j'tj(d�y	t+|d�}	tj.|j1��}d
|j2v�r1d|j2v�r"	t4j6j9|j2d
�}	|	j:�*|	j=t>j@jB��}	|	j:t>j@jBur�t>j>jE|jFt>j@jB�}
|
j=d��}
|
|	kr@|jtjH�|j�|jK�y|jtjT�|jd|�|jd	tW|d��|jd|jY|jF��|j�|S#t,$r#|j'tj(d�YywxYw#tLtNtPtRf$rY��wxYw#|jK��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��0zFile 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�re�index_pagesr��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�sG���"�"�4�9�9�-����
�7�7�=�=����L�L�)�)�$�)�)�4�E��:�:�&�&�s�+��"�"�:�#?�#?�@�"�1�X�u�Q�x��q��C��"�1�X�u�Q�x�1�	� �,�,�1�1�)�<��� � ��W�5�� � �!1�3�7�� � �"���)�)�
1�������T�5�1���7�7�>�>�%�(� �D��	
1��*�*�4�0�0�����%���=�=����O�O�J�0�0�2B�C��	��T�4� �A�
'	����!�(�(�*�%�B�#�t�|�|�3�'�t�|�|�;�(��+�+�;�;����%8�9�;�C��z�z�)�"�k�k��1B�1B�1F�1F�k�G���z�z�X�%6�%6�%:�%:�:�%-�%6�%6�%D�%D��K�K��):�):�)>�)>�&@�
�&0�%7�%7�A�%7�%F�
�%��,� �.�.�z�/F�/F�G� �,�,�.��G�G�I�#'����z�}�}�-����^�U�3����-�s�2�a�5�z�:����_��%�%�b�k�k�2�
4������H��Q�	��O�O�J�0�0�2B�C��	��"�:�}�j�I�����8	�
�G�G�I��sK�7N3�AP�,O"�2C4P�'BP�3)O�O�"O>�;P�=O>�>P�Pc
��	tj|�}|j
d���g}	tjj|jd��}tj|d��}tj�}d	|��}|j!d
�|j!d�|j!d�|j!d
|�d��|j!d|�d��|j!d|�d��|j!d�|D]�}tjj#||�}|x}	}
tjj%|�r
|dz}	|dz}
tjj'|�r|dz}	|j!dtjj)|
d���dtj|	d���d����|j!d�dj#|�j+|d�}t-j.�}|j1|�|j3d�|j5tj6�|j9dd|z�|j9dt;t=|���|j?�|S#t$r#|jtj
d�YywxYw#t$r-tjj|j�}Y���wxYw)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�"�|j�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�r3r�r>r2re)
rrL�list�r�displaypath�enc�title�name�fullname�displayname�linkname�encodedr
s
             rr$z'SimpleHTTPRequestHandler.list_directory	s���	��:�:�d�#�D�	
�	�	�)�	�*���	:� �,�,�.�.�t�y�y�6E�/�G�K��k�k�+�U�;���'�'�)��(��
�6��	���"�#�	���#�$�	�����	���?�3�%�r�*�+�	���7�5�'�!2�3�4�	���<��w�e�,�-�	������
	?�D��w�w�|�|�D�$�/�H�%)�)�K�(��w�w�}�}�X�&�"�S�j���#�:���w�w�~�~�h�'�"�S�j��
�H�H��|�|�)�)�(�1@�*�B��{�{�;�e�<�>�
?�
	?�	
���2�3��)�)�A�,�%�%�c�+<�=���J�J�L��	�����	���q�	����:�=�=�)�����)@�3�)F�G����)�3�s�7�|�+<�=��������[�	��O�O��$�$�1�
3��		��"�	:� �,�,�.�.�t�y�y�9�K�	:�s"�J!�+K�!)K
�K
�2L�Lc��|jdd�d}|jdd�d}|j�jd�}	tjj|d��}tj|�}|jd�}td|�}|j}|D]d}tjj|�s"|tjtjfvr�Etjj!||�}�f|r|dz
}|S#t$r"tjj|�}Y��wxYw)	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'rArBN)rBr@rrrrHrI�	posixpath�normpath�filterrrrL�dirname�curdir�pardirr�)rrL�trailing_slashr[�words     rrz'SimpleHTTPRequestHandler.translate_pathBs���z�z�#�a� ��#���z�z�#�a� ��#������/�/��4��	.��<�<�'�'��_�'�E�D��!�!�$�'���
�
�3����t�U�#���~�~���	,�D��w�w���t�$�����B�I�I�0F�(F���7�7�<�<��d�+�D�		,�
��C�K�D����"�	.��<�<�'�'��-�D�	.�s�!D�(E�Ec�0�tj||�y)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|j�}||jvr|j|St	j
|�\}}|r|Sy)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_typeps����&�&�t�,�	��c��$�%�%�%��&�&�s�+�+��i�i�k���$�%�%�%��&�&�s�+�+��'�'��-���q���L�)r)rrrr�r�r�r"rk�_encodings_map_defaultrrrr
r$rrr%�
__classcell__�rs@rrr�sd���	�#�[�0�N�-�K�!�(�%�!�	/��N�+�)-�*���V�p7�r�</� *rrc���|jd�\}}}tjj|�}|j	d�}g}|ddD]2}|dk(r|j��|s�|dk7s�"|j
|��4|r2|j�}|r"|dk(r|j�d}n
|dk(rd}nd}|rdj||f�}ddj|�z|f}dj|�}|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.

    rZr'Nr&z..r(r6)�	partitionrrrHrB�popr�r�)	rLrp�query�
path_parts�
head_parts�part�	tail_part�	splitpath�collapsed_paths	         r�_url_collapse_pathr~�s����^�^�C�(�N�D�!�U��<�<����%�D����C��J��J��3�B��&���4�<��N�N��
�d�c�k����t�%�	&�
��N�N�$�	���D� ���� ��	��c�!��	��	���H�H�i��/�0�	��s�x�x�
�+�+�Y�7�I��X�X�i�(�N��rc���trtS	ddl}	|jd�datS#t$rYywxYw#t$r+dtd�|j
�D��zaYtSwxYw)z$Internal routine to get nobody's uidrNr&�nobodyrr
c3�&K�|]	}|d���y�w)rNr)r-r�s  rr/znobody_uid.<locals>.<genexpr>�s����6�!��1��6�s�)r��pwd�ImportError�getpwnamr��max�getpwall)r�s r�
nobody_uidr��sw����
���7����h�'��*���M��
������7��S�6�s�|�|�~�6�6�6���M�7�s�-�<�	9�9�,A0�/A0c�J�tj|tj�S)zTest for executable file.)r�access�X_OK)rLs r�
executabler��s��
�9�9�T�2�7�7�#�#rc�R�eZdZdZeed�ZdZd�Zd�Z	d�Z
ddgZd	�Zd
�Z
d�Zy)
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��|j�r|j�y|jtjd�y)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�s.���;�;�=��L�L�N��O�O��*�*�.�
0rc�l�|j�r|j�Stj|�S)z-Version of send_head that support CGI scripts)r�r�rr
rfs rr
zCGIHTTPRequestHandler.send_head�s(���;�;�=��<�<�>�!�+�5�5�d�;�;rc��t|j�}|jdd�}|dkDr=|d||jvr,|jd|dz�}|dkDr|d||jvr�,|dkDr|d|||dzd}}||f|_yy)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�I�6�� �%�%�c�1�-����k�.��'�":�d�>R�>R�"R�$�)�)�#�w�q�y�9�G���k�.��'�":�d�>R�>R�"R��Q�;�'���1�>�'�!�)�*�3M�$�D� �$�J�D�M��rz/cgi-binz/htbinc��t|�S)z1Test whether argument path is an executable file.)r�)rrLs  r�
is_executablez#CGIHTTPRequestHandler.is_executables
���$��rc�j�tjj|�\}}|j�dvS)z.Test whether argument path is a Python script.)z.pyz.pyw)rrLrjrX)rrLr�r�s    r�	is_pythonzCGIHTTPRequestHandler.is_pythons+���W�W�%�%�d�+�
��d��z�z�|��.�.rc��|j\}}|dz|z}|jdt|�dz�}|dk\rg|d|}||dzd}|j|�}tj
j
|�r#||}}|jdt|�dz�}nn|dk\r�g|jd�\}}}	|jd�}|dk\r|d|||d}}
n|d}}
|dz|
z}|j|�}tj
j|�s$|jtjd|z�ytj
j|�s$|jtjd|z�y|j|�}
|js|
s5|j!|�s$|jtjd	|z�yt#j$tj&�}|j)�|d
<|j*j,|d<d|d
<|j.|d<t1|j*j2�|d<|j4|d<t6j8j;|�}||d<|j|�|d<||d<|	|d<|j<d|d<|j>jAd�}|r�|jC�}t|�dk(r�ddl"}ddl#}|d|d<|djI�dk(r]	|djKd�}|jM|�jOd�}|jCd�}t|�dk(r	|d|d<	|j>jAd��|j>jU�|d<n|j>d|d<|j>jAd�}|r||d <|j>jAd!�}|r||d"<|j>jWd#d$�}d%jY|�|d&<|j>jAd'�}|r||d(<t[d|j>jWd)g��}d*jY|�}|r||d+<d,D]}|j]|d��|j_tj`d-�|jc�|	jed.d/�}|j�r�|
g}d0|vr|jg|�ti�}|jjjm�t	jn�}|dk7r�t	jp|d�\}}tsjr|jtgggd�drC|jtjwd�sn'tsjr|jtgggd�dr�Ct	jx|�}|r|j{d1|���y		t	j||�t	j�|jtj��d�t	j�|jjj��d�t	j�|||�yddlF} |g}!|j|�rAt�j�}"|"jI�j�d3�r|"dd4|"d5dz}"|"d6g|!z}!d0|	vr|!jg|	�|j�d7| j�|!��	t�|�}#| j�|!| j�| j�| j�|�8�}$|j4jI�d9k(r!|#dkDr|jtjw|#�}%nd}%tsjr|jtj�gggd�drW|jtj�j�d�sn1tsjr|jtj�gggd�dr�W|$j�|%�\}&}'|jjj�|&�|'r|j{d:|'�|$j�j��|$j�j��|$j�}(|(r|j{d;|(�y|j�d<�y#|jPtRf$rY��mwxYw#t~$rY���wxYw#|j*j�|j�|j<�t	j�d2�YyxYw#t�t�f$rd}#Y��1wxYw)=zExecute a CGI script.r'r
rNrZr6zNo 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�r2rrrLrru�existsrHrr&r#�	FORBIDDENr��	have_forkr��copy�deepcopy�environr��serverrrJr>rr:rrrHr�rSrWrB�base64�binasciirXr��decodebytes�decode�Error�UnicodeError�get_content_type�get_allr�r^�
setdefaultr�r3r�r�r�r�rnror��waitpid�selectrQ�read�waitstatus_to_exitcoderq�setuidr(�dup2r*�execve�handle_error�request�_exit�
subprocessr�r�rr��list2cmdlinerFr1rD�Popen�PIPE�_sock�recv�communicater�r�r7r��
returncode))r�dir�restrL�i�nextdir�nextrest�	scriptdirrprw�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�M�	��T��S�y�4����I�I�c�3�s�8�A�:�&���1�f��2�A�h�G��A�a�C�D�z�H��+�+�G�4�I��w�w�}�}�Y�'�#�X�T���I�I�c�3�s�8�A�:�.����1�f�����,���a��
�I�I�c�N����6����8�T�!�"�X�D�F���D�F��3�Y��'�
��(�(��4�
��w�w�~�~�j�)��O�O��$�$�)�J�6�
8�
��w�w�~�~�j�)��O�O��$�$�5�
�B�
D�
��~�~�j�)���>�>���%�%�j�1�����(�(�7�*�D�F���m�m�B�J�J�'��!%�!4�!4�!6����!�[�[�4�4��M��#,��� �!%�!6�!6���� ����!8�!8�9��M�� $���������%�%�d�+��!��K��!%�!4�!4�V�!<����'��M��#��N��!�0�0��3��M�����(�(��9�
��)�/�/�1�M��=�!�Q�&�'�#0��#3��K� � ��#�)�)�+�w�6�	B�(5�a�(8�(?�(?��(H�
�(.�(:�(:�=�(I�(.��w��&�
)6�(;�(;�C�(@�
��}�-��2�1>�q�1A�C�
�.��<�<���N�+�3�"&�,�,�"?�"?�"A�C���"&�,�,�~�">�C������!�!�"2�3���$*�C� �!��,�,�"�"�9�-���")�C������%�%�h��3�� �X�X�f�-��M��
�\�\�
�
�l�
+��
�%'�C�!�"�
�D�$�,�,�.�.�x��<�
=���Y�Y�r�]�
��!+�C�
��D�	"�A��N�N�1�b�!�	"�	
���:�=�=�*A�B������
�
�c�3�/�
��>�>��8�D��-�'����M�*��\�F��J�J�����'�'�)�C��a�x��:�:�c�1�-���S��m�m�T�Z�Z�L�"�b�!�<�Q�?��:�:�?�?�1�-���m�m�T�Z�Z�L�"�b�!�<�Q�?��4�4�S�9����N�N�%:�8�*�#E�F��

���I�I�f�%�����
�
�)�)�+�Q�/�����
�
�)�)�+�Q�/��	�	�*�d�C�0�
�!�l�G��~�~�j�)������<�<�>�*�*�7�3�#�C�R�[�6�"�#�;�6�F�!�4�.�7�2���%�����u�%����]�J�,C�,C�G�,L�M�
��V���� � ��'1���(2���(2���'*�	!�#�A��|�|�!�!�#�v�-�&�1�*��z�z���v�.�����-�-����!1�!1� 2�B��A�>�q�A��z�z�'�'�,�,�Q�/���-�-����!1�!1� 2�B��A�>�q�A��]�]�4�0�N�F�F��J�J���V�$�����t�V�,�
�H�H�N�N��
�H�H�N�N���\�\�F�����;�V�D�� � �!7�8��_%�N�N�L�9�����z�����

����(�(����t�7J�7J�K�����
��"�z�*�
���
�sP�4c
�c&�A3c6�e�
c#�"c#�&	c3�/c6�2c3�3c6�6Ad?�e�eN)rrrr�rkrr��rbufsizer�r
r�r�r�r�r�rrrrr�sG�����F�#�I��H�0�<��4"�8�,�O� �/�
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�sM�����	�
�
�
����
�E�
04�D��K�/@�,�F�D�%��H��8��rr�i@c�~�t||�\|_}||_|||�5}|jj	�dd\}}d|vrd|�d�n|}td|�d|�d|�d|�d	�	�	|j
�ddd�y#t$r#td
�tjd�Y�4wxYw#1swYyxYw)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�s���(8��d�'C�$�K���$,�L�!�	�T�<�	(��E��\�\�-�-�/���3�
��d�"%��+�Q�t�f�A�;�4��
��t�f�F�4�&�1��j��$��v�
/�	
�	����!����!�	��;�<��H�H�Q�K�	����s*�AB3�+B�)B0�-B3�/B0�0B3�3B<�__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#rrZz(bind to this port (default: %(default)s))r&r�nargsr#c�$��eZdZ�fd�Zd�Z�xZS)�DualStackServerc����tjt�5|jj	tj
tjd�ddd�t�|�!�S#1swY�xYw)Nr)	�
contextlib�suppress�	Exceptionr�
setsockopt�IPPROTO_IPV6�IPV6_V6ONLYrr)rrs �rrzDualStackServer.server_binds`����$�$�Y�/�
@����&�&��'�'��);�);�Q�@�
@��7�&�(�(�
@�
@�s�:A+�+A4c�J�|j|||tj��y)Nr�)�RequestHandlerClassr�r)rr�r�s   r�finish_requestzDualStackServer.finish_requests"���$�$�W�n�d�/3�~�~�
%�
?r)rrrrr4rrrss@rr*r*s
���	)�	?rr*)rrrrr)8r�r��__all__r�r,�email.utilsr�r��http.clientrNrLr�rlrr\r�rerr
r�r��urllib.parserrr�r�rr�ThreadingMixInr�StreamRequestHandlerrrr~r�r�r�rrrr�argparser,�ArgumentParser�parser�add_argumentrrF�
parse_argsr��cgi�
handler_classr*rrrrrr�<module>rBs
���d����
�����	���	��
�
�
��
������ 7��	 ��'�'�	 ��,�5�5�z��q�\�>�>�q�hA*�5�A*�L,�`
��
� $�
C9�4�C9�L�-�(��4�d��.�z����
$�X�
$�
$�
&�F�
�����0��2�
����h�	�9��:�����m�Y�R�Y�Y�[�<��=�����l�I� *�6��7������3�c�6��7�����D��x�x�-�
�0�
�?�-�?�	�"�#�
�Y�Y�
�Y�Y�����Qr

Zerion Mini Shell 1.0