Your IP : 18.226.34.148


Current Path : /opt/alt/python38/lib64/python3.8/http/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/http/__pycache__/server.cpython-38.opt-2.pyc

U

i�f��@sdZdddddgZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZdd	lmZd
ZdZGdd�dej�ZGd
d�deje�ZGdd�dej �Z!Gdd�de!�Z"dd�Z#da$dd�Z%dd�Z&Gdd�de"�Z'dd�Z(e!edddfdd�Z)e*dk�rddl+Z+e+�,�Z-e-j.ddd d!�e-j.d"d#d$d%d&�e-j.d'd(e�/�d)d*�e-j.d+d,de0d-d.d/�e-�1�Z2e2j3�r�e'Z4nee"e2j5d0�Z4Gd1d2�d2e�Z6e)e4e6e2j7e2j8d3�dS)4z0.6�
HTTPServer�ThreadingHTTPServer�BaseHTTPRequestHandler�SimpleHTTPRequestHandler�CGIHTTPRequestHandler�N)�partial)�
HTTPStatusa�<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;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@seZdZdZdd�ZdS)r�cCs4tj�|�|jdd�\}}t�|�|_||_dS)N�)�socketserver�	TCPServer�server_bindZserver_address�socketZgetfqdn�server_name�server_port)�self�host�port�r�0/opt/alt/python38/lib64/python3.8/http/server.pyr
�szHTTPServer.server_bindN)�__name__�
__module__�__qualname__Zallow_reuse_addressr
rrrrr�sc@seZdZdZdS)rTN)rrrZdaemon_threadsrrrrr�sc
@sFeZdZdej��dZdeZe	Z
eZdZ
dd�Zdd�Zd	d
�Zdd�ZdEdd�ZdFdd�ZdGdd�Zdd�Zdd�Zdd�ZdHdd�Zdd�Ze�dd �e�ed!�ed"d#��D��Zd$ee d%�<d&d'�Z!d(d)�Z"dId*d+�Z#d,d-�Z$d.d/d0d1d2d3d4gZ%d
d5d6d7d8d9d:d;d<d=d>d?d@g
Z&dAdB�Z'dCZ(e)j*j+Z,dDd �e-j.�/�D�Z0d
S)JrzPython/rz	BaseHTTP/�HTTP/0.9c
Cs�d|_|j|_}d|_t|jd�}|�d�}||_|��}t	|�dkrLdSt	|�dk�r&|d}zT|�
d�srt�|�d	d
�d
}|�d�}t	|�dkr�t�t|d�t|d
�f}Wn,tt
fk
r�|�tjd
|�YdSX|dk�r|jdk�rd|_|dk�r |�tjd|�dS||_dt	|�k�rBdk�sZn|�tjd|�dS|dd�\}}t	|�dk�r�d|_|dk�r�|�tjd|�dS|||_|_|j�
d��r�d	|j�d	�|_ztjj|j|jd�|_Wn�tjjk
�r(}z|�tjdt|��WY�dSd}~XYnBtjjk
�rh}z|�tjdt|��WY�dSd}~XYnX|j�dd�}	|	��dk�r�d|_n |	��dk�r�|jdk�r�d|_|j�dd�}
|
��dk�r�|jdk�r�|jdk�r�|� ��s�dSdS)NTz
iso-8859-1z
rF����zHTTP/�/r	�.r
zBad request version (%r))r	r	zHTTP/1.1)r
rzInvalid HTTP version (%s)zBad request syntax (%r)ZGETzBad HTTP/0.9 request type (%r)z//)Z_classz
Line too longzToo many headers�
Connection��close�
keep-aliveZExpectz100-continue)!�command�default_request_version�request_version�close_connection�str�raw_requestline�rstrip�requestline�split�len�
startswith�
ValueError�int�
IndexError�
send_errorrZBAD_REQUEST�protocol_versionZHTTP_VERSION_NOT_SUPPORTED�path�lstrip�http�clientZ
parse_headers�rfile�MessageClass�headersZLineTooLongZREQUEST_HEADER_FIELDS_TOO_LARGEZ
HTTPException�get�lower�handle_expect_100)r�versionr)�wordsZbase_version_numberZversion_numberr"r2�errZconntypeZexpectrrr�
parse_requests�


�
��
�
������
z$BaseHTTPRequestHandler.parse_requestcCs|�tj�|��dS�NT)�send_response_onlyrZCONTINUE�end_headers�rrrrr;xsz(BaseHTTPRequestHandler.handle_expect_100c
Cs�z�|j�d�|_t|j�dkrBd|_d|_d|_|�tj	�WdS|jsTd|_
WdS|��sbWdSd|j}t||�s�|�tj
d|j�WdSt||�}|�|j��Wn<tjk
r�}z|�d|�d|_
WY�dSd}~XYnXdS)NiirTZdo_zUnsupported method (%r)zRequest timed out: %r)r6�readliner'r+r)r$r"r0rZREQUEST_URI_TOO_LONGr%r?�hasattr�NOT_IMPLEMENTED�getattr�wfile�flushrZtimeout�	log_error)rZmname�method�errr�handle_one_request�s6

�
z)BaseHTTPRequestHandler.handle_one_requestcCs"d|_|��|js|��qdSr@)r%rMrCrrr�handle�szBaseHTTPRequestHandler.handleNcCsz|j|\}}Wntk
r.d\}}YnX|dkr<|}|dkrH|}|�d||�|�||�|�dd�d}|dkr�|tjtjtjfkr�|j	|t
j|dd�t
j|dd�d�}|�d	d
�}|�d|j
�|�dtt|���|��|jd
k�r|�r|j�|�dS)N)�???rOzcode %d, message %srr ��F��quote)�code�message�explainzUTF-8�replacezContent-Type�Content-LengthZHEAD)�	responses�KeyErrorrJ�
send_response�send_headerrZ
NO_CONTENTZ
RESET_CONTENT�NOT_MODIFIED�error_message_format�html�escape�encode�error_content_typer&r+rBr"rH�write)rrSrTrUZshortmsgZlongmsgZbodyZcontentrrrr0�s:���z!BaseHTTPRequestHandler.send_errorcCs:|�|�|�||�|�d|���|�d|���dS)NZServerZDate)�log_requestrAr[�version_string�date_time_string�rrSrTrrrrZ�s
z$BaseHTTPRequestHandler.send_responsecCsd|jdkr`|dkr0||jkr,|j|d}nd}t|d�s@g|_|j�d|j||f�dd��dS)Nrrr�_headers_bufferz
%s %d %s
�latin-1�strict)r$rXrErg�appendr1r`rfrrrrA�s



��z)BaseHTTPRequestHandler.send_response_onlycCsl|jdkr6t|d�sg|_|j�d||f�dd��|��dkrh|��dkrVd|_n|��d	krhd
|_dS)Nrrgz%s: %s
rhriZ
connectionr Tr!F)r$rErgrjr`r:r%)r�keyword�valuerrrr[s

�z"BaseHTTPRequestHandler.send_headercCs"|jdkr|j�d�|��dS)Nrs
)r$rgrj�
flush_headersrCrrrrBs
z"BaseHTTPRequestHandler.end_headerscCs(t|d�r$|j�d�|j��g|_dS)Nrg�)rErHrb�joinrgrCrrrrms
z$BaseHTTPRequestHandler.flush_headers�-cCs.t|t�r|j}|�d|jt|�t|��dS)Nz
"%s" %s %s)�
isinstancerrl�log_messager)r&)rrS�sizerrrrc s
�z"BaseHTTPRequestHandler.log_requestcGs|j|f|��dS�N)rr)r�format�argsrrrrJ+sz BaseHTTPRequestHandler.log_errorcCsi|]}|d|d���qS)z\xZ02xr)�.0�crrr�
<dictcomp>;sz!BaseHTTPRequestHandler.<dictcomp>� ��z\\�\cGs2||}tj�d|��|��|�|j�f�dS)Nz%s - - [%s] %s
)�sys�stderrrb�address_string�log_date_time_string�	translate�_control_char_table)rrurvrTrrrrr>s
��z"BaseHTTPRequestHandler.log_messagecCs|jd|jS)N� )�server_version�sys_versionrCrrrrdXsz%BaseHTTPRequestHandler.version_stringcCs |dkrt��}tjj|dd�S)NT)Zusegmt)�time�email�utilsZ
formatdate)rZ	timestamprrrre\sz'BaseHTTPRequestHandler.date_time_stringc	CsBt��}t�|�\	}}}}}}}}	}
d||j|||||f}|S)Nz%02d/%3s/%04d %02d:%02d:%02d)r��	localtime�	monthname)rZnowZyearZmonthZdayZhhZmmZss�x�y�z�srrrr�bs�z+BaseHTTPRequestHandler.log_date_time_stringZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDeccCs
|jdS�Nr)�client_addressrCrrrr�psz%BaseHTTPRequestHandler.address_string�HTTP/1.0cCsi|]}||j|jf�qSr)�phraseZdescription)rw�vrrrrys�)NN)N)N)rprp)N)1rrrr~r<r*r��__version__r��DEFAULT_ERROR_MESSAGEr]�DEFAULT_ERROR_CONTENT_TYPErar#r?r;rMrNr0rZrAr[rBrmrcrJr&�	maketrans�	itertools�chain�ranger��ordrrrdrer�Zweekdaynamer�r�r1r4r5ZHTTPMessager7r�__members__�valuesrXrrrrr�s\ij%
5


�
�	�cs�eZdZdeZdd��fdd�
Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
jshe
��e
j��Ze�ddddd���ZS)rzSimpleHTTP/N��	directorycs(|dkrt��}||_t�j||�dSrt)�os�getcwdr��super�__init__)rr�rv�kwargs��	__class__rrr��sz!SimpleHTTPRequestHandler.__init__cCs.|��}|r*z|�||j�W5|��XdSrt)�	send_headr �copyfilerH�r�frrr�do_GET�s
zSimpleHTTPRequestHandler.do_GETcCs|��}|r|��dSrt)r�r r�rrr�do_HEAD�sz SimpleHTTPRequestHandler.do_HEADcCs^|�|j�}d}tj�|�r�tj�|j�}|j�d�s�|�t	j
�|d|d|dd|d|df}tj�|�}|�d|�|�
�dSdD]&}tj�||�}tj�|�r�|}q�q�|�|�S|�|�}|�d�r�|�t	jd	�dSzt|d
�}Wn&tk
�r|�t	jd	�YdSX�z"t�|���}d|jk�r�d|jk�r�ztj�|jd�}	Wnttttfk
�r|YnzX|	j dk�r�|	j!t"j#j$d
�}	|	j t"j#j$k�r�t"j"�%|j&t"j#j$�}
|
j!dd�}
|
|	k�r�|�t	j'�|�
�|�(�WdS|�t	j)�|�d|�|�dt*|d��|�d|�+|j&��|�
�|WS|�(��YnXdS)Nrrr	r
r�ZLocation)z
index.htmlz	index.htmzFile not found�rbzIf-Modified-Sincez
If-None-Match)�tzinfo)Zmicrosecond�Content-typerW�z
Last-Modified),�translate_pathr2r��isdir�urllib�parseZurlsplit�endswithrZrZMOVED_PERMANENTLYZ
urlunsplitr[rBro�exists�list_directory�
guess_typer0�	NOT_FOUND�open�OSError�fstat�filenor8r�r�Zparsedate_to_datetime�	TypeErrorr/�
OverflowErrorr-r�rV�datetime�timezoneZutcZ
fromtimestamp�st_mtimer\r �OKr&re)rr2r��partsZ	new_partsZnew_url�indexZctypeZfsZimsZ
last_modifrrrr��s��


���

�z"SimpleHTTPRequestHandler.send_headc
	Cs�zt�|�}Wn$tk
r2|�tjd�YdSX|jdd�d�g}ztjj	|j
dd�}Wn"tk
r�tj�	|j
�}YnXtj
|dd�}t��}d	|}|�d
�|�d�|�d|�|�d
|�|�d|�|�d�|D]v}tj
�||�}|}	}
tj
�|��r$|d}	|d}
tj
�|��r:|d}	|�dtjj|
dd�tj
|	dd�f�q�|�d�d�|��|d�}t��}|�|�|�d�|�tj�|�dd|�|�dtt|���|��|S)NzNo permission to list directorycSs|��Srt)r:)�arrr�<lambda>rnz9SimpleHTTPRequestHandler.list_directory.<locals>.<lambda>)�key�
surrogatepass��errorsFrQzDirectory listing for %szZ<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">z
<html>
<head>z@<meta http-equiv="Content-Type" content="text/html; charset=%s">z<title>%s</title>
</head>z<body>
<h1>%s</h1>z	<hr>
<ul>r�@z<li><a href="%s">%s</a></li>z</ul>
<hr>
</body>
</html>
�
�surrogateescaperr�ztext/html; charset=%srW) r��listdirr�r0rr��sortr�r��unquoter2�UnicodeDecodeErrorr^r_r~�getfilesystemencodingrjror��islinkrRr`�io�BytesIOrb�seekrZr�r[r&r+rB)
rr2�list�rZdisplaypath�enc�title�name�fullnameZdisplaynameZlinknameZencodedr�rrrr�sh�
�


�
���


z'SimpleHTTPRequestHandler.list_directorycCs�|�dd�d}|�dd�d}|���d�}ztjj|dd�}Wn tk
rbtj�|�}YnXt�|�}|�d�}t	d|�}|j
}|D]0}tj�
|�s�|tjtjfkr�q�tj�||�}q�|r�|d7}|S)N�?r	r�#rr�r�)r*r(r�r�r�r�r��	posixpath�normpath�filterr�r�r2�dirname�curdir�pardirro)rr2Ztrailing_slashr=Zwordrrrr�:s$	


z'SimpleHTTPRequestHandler.translate_pathcCst�||�dSrt)�shutilZcopyfileobj)r�sourceZ
outputfilerrrr�Xsz!SimpleHTTPRequestHandler.copyfilecCsLt�|�\}}||jkr"|j|S|��}||jkr>|j|S|jdSdS)Nr)r��splitext�extensions_mapr:)rr2�baseZextrrrr�hs



z#SimpleHTTPRequestHandler.guess_typezapplication/octet-streamz
text/plain)r�.pyz.cz.h)rrrr�r�r�r�r�r�r�r�r�r��	mimetypesZinitedZinitZ	types_map�copyr��update�
__classcell__rrr�rr�s$
	W:
�c	Cs�|�d�\}}}tj�|�}|�d�}g}|dd�D],}|dkrL|��q6|r6|dkr6|�|�q6|r�|��}|r�|dkr�|��d}q�|dkr�d}nd}|r�d�||f�}dd�|�|f}d�|�}|S)Nr�rrz..rr)�	partitionr�r�r�r*�poprjro)	r2�_�query�
path_partsZ
head_parts�partZ	tail_partZ	splitpath�collapsed_pathrrr�_url_collapse_path�s.


r�cCsrtrtSzddl}Wntk
r*YdSXz|�d�daWn.tk
rldtdd�|��D��aYnXtS)Nrr�nobodyr
r	css|]}|dVqdS)r
Nr)rwr�rrr�	<genexpr>�sznobody_uid.<locals>.<genexpr>)r��pwd�ImportError�getpwnamrY�maxZgetpwall)r�rrr�
nobody_uid�s rcCst�|tj�Srt)r��access�X_OK)r2rrr�
executable�src@sReZdZeed�ZdZdd�Zdd�Zdd�Z	d	d
gZ
dd�Zd
d�Zdd�Z
dS)r�forkrcCs$|��r|��n|�tjd�dS)NzCan only POST to CGI scripts)�is_cgi�run_cgir0rrFrCrrr�do_POST�s
�zCGIHTTPRequestHandler.do_POSTcCs|��r|��St�|�SdSrt)rrrr�rCrrrr��szCGIHTTPRequestHandler.send_headcCsPt|j�}|�dd�}|d|�||dd�}}||jkrL||f|_dSdS)Nrr	TF)r�r2�find�cgi_directories�cgi_info)rr�Zdir_sep�head�tailrrrr�s


zCGIHTTPRequestHandler.is_cgiz/cgi-binz/htbincCst|�Srt)r)rr2rrr�
is_executablesz#CGIHTTPRequestHandler.is_executablecCstj�|�\}}|��dkS)N)r�z.pyw)r�r2r�r:)rr2rrrrr�	is_pythonszCGIHTTPRequestHandler.is_pythonc)	Cs�|j\}}|d|}|�dt|�d�}|dkr�|d|�}||dd�}|�|�}tj�|�r�||}}|�dt|�d�}q*q�q*|�d�\}}}	|�d�}|dkr�|d|�||d�}
}n
|d}
}|d|
}|�|�}tj�|��s
|�	t
jd|�dStj�|��s.|�	t
j
d|�dS|�|�}
|j�sF|
�sh|�|��sh|�	t
j
d|�dSt�tj�}|��|d	<|jj|d
<d|d<|j|d
<t|jj�|d<|j|d<tj�|�}||d<|�|�|d<||d<|	�r�|	|d<|jd|d<|j� d�}|�r�|�!�}t|�dk�r�ddl"}ddl#}|d|d<|d�$�dk�r�z"|d�%d�}|�&|��'d�}Wn|j(t)fk
�r�Yn&X|�!d�}t|�dk�r�|d|d<|j� d�dk�r�|j�*�|d<n|jd|d<|j� d�}|�r||d<|j� d �}|�r||d!<g}|j�+d"�D]>}|dd�d#k�rR|�,|�-��n||d$d��!d%�}�q,d%�.|�|d&<|j� d'�}|�r�||d(<t/d|j�0d)g��}d*�.|�}|�r�||d+<d,D]}|�1|d��q�|�2t
j3d-�|�4�|	�5d.d/�}|j�r|
g}d0|k�r|�,|�t6�}|j7�8�t�9�}|dk�r�t�:|d�\}}t;�;|j<gggd�d�r~|j<�=d��sN�q~�qN|�r�|�>d1|�dSz\zt�?|�Wnt@k
�r�YnXt�A|j<�B�d�t�A|j7�B�d�t�C|||�Wn(|j�D|jE|j�t�Fd2�YnX�n�ddlG} |g}!|�|��rrtHjI}"|"�$��Jd3��rf|"dd4�|"d5d�}"|"d6g|!}!d0|	k�r�|!�,|	�|�Kd7| �L|!��ztM|�}#WntNtOfk
�r�d}#YnX| jP|!| jQ| jQ| jQ|d8�}$|j�$�d9k�r|#dk�r|j<�=|#�}%nd}%t;�;|j<jRgggd�d�r>|j<jR�Sd��s
�q>�q
|$�T|%�\}&}'|j7�U|&�|'�rj|�>d:|'�|$jV�W�|$jX�W�|$jY}(|(�r�|�>d1|(�n
|�Kd;�dS)<Nrr	rr�rzNo such CGI script (%r)z#CGI script is not a plain file (%r)z!CGI script is not executable (%r)ZSERVER_SOFTWAREZSERVER_NAMEzCGI/1.1ZGATEWAY_INTERFACEZSERVER_PROTOCOLZSERVER_PORTZREQUEST_METHODZ	PATH_INFOZPATH_TRANSLATEDZSCRIPT_NAME�QUERY_STRINGZREMOTE_ADDR�
authorizationr
Z	AUTH_TYPEZbasic�ascii�:ZREMOTE_USERzcontent-typeZCONTENT_TYPEzcontent-length�CONTENT_LENGTH�referer�HTTP_REFERER�acceptz	

 ��,ZHTTP_ACCEPTz
user-agent�HTTP_USER_AGENTZcookiez, �HTTP_COOKIE)rZREMOTE_HOSTrrrrzScript output follows�+r��=zCGI script exit status %#xr{zw.exe������z-uzcommand: %s)�stdin�stdoutr�envZpostz%szCGI script exited OK)Zr
rr+r�r�r2r�r�r�r0rr��isfileZ	FORBIDDENr�	have_forkr
r�Zdeepcopy�environrdZserverrr1r&rr"r�r�r�r�r8r9r*�base64�binasciir:r`Zdecodebytes�decode�Error�UnicodeErrorZget_content_typeZgetallmatchingheadersrj�stripror�Zget_all�
setdefaultrZr�rmrVrrHrIr�waitpid�selectr6�readrJ�setuidr��dup2r��execveZhandle_errorZrequest�_exit�
subprocessr~rr�rrZlist2cmdliner.r�r-�Popen�PIPEZ_sockZrecvZcommunicaterbrr r �
returncode))r�dir�restr2�iZnextdirZnextrestZ	scriptdirr�r�ZscriptZ
scriptnameZ
scriptfileZispyr!Zuqrestrr%r&Zlengthrr�lineZua�coZ
cookie_str�kZ
decoded_queryrvr��pid�stsr3ZcmdlineZinterp�nbytes�p�datar rZstatusrrrrs<





��
�


�








�

zCGIHTTPRequestHandler.run_cgiN)rrrrEr�r#Zrbufsizerr�rr	r
rrrrrrr�s
cGs4tj|tjtjd��}tt|��\}}}}}||fS)N)�type�flags)rZgetaddrinfoZSOCK_STREAMZ
AI_PASSIVE�next�iter)ZaddressZinfosZfamilyrB�protoZ	canonnameZsockaddrrrr�_get_best_family�s�rGr�i@c	Cs�t||�\|_}||_|||���}|j��dd�\}}d|krLd|�d�n|}td|�d|�d|�d|�d�	�z|��Wn&tk
r�td	�t�	d
�YnXW5QRXdS)Nr
r�[�]zServing HTTP on z port z	 (http://z/) ...z&
Keyboard interrupt received, exiting.r)
rGZaddress_familyr1rZgetsockname�printZ
serve_forever�KeyboardInterruptr~�exit)	�HandlerClass�ServerClassZprotocolr�bindZaddrZhttpdrZurl_hostrrr�test�s�rP�__main__z--cgi�
store_truezRun as CGI Server)�action�helpz--bindz-bZADDRESSz8Specify alternate bind address [default: all interfaces])�metavarrTz--directoryz-dz9Specify alternative directory [default:current directory])�defaultrTrZstorer�z&Specify alternate port [default: 8000])rSrVrB�nargsrTr�cseZdZ�fdd�Z�ZS)�DualStackServerc	s4t�t��|j�tjtjd�W5QRXt���Sr�)	�
contextlib�suppress�	ExceptionrZ
setsockoptZIPPROTO_IPV6ZIPV6_V6ONLYr�r
rCr�rrr
s�zDualStackServer.server_bind)rrrr
r�rrr�rrXsrX)rMrNrrO)9r��__all__r�r�Zemail.utilsr�r^Zhttp.clientr4r�r�r�r�r�r-r�rrr~r�Zurllib.parser�rY�	functoolsrrr�r�rrZThreadingMixInrZStreamRequestHandlerrrr�r�rrrrGrPr�argparse�ArgumentParser�parser�add_argumentr�r.�
parse_argsrvZcgiZ
handler_classr�rXrrOrrrr�<module>Ss��s
0
�

�
�����

?>