Your IP : 18.226.28.97


Current Path : /opt/alt/python39/lib64/python3.9/http/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/http/__pycache__/server.cpython-39.opt-2.pyc

a

R�fg��@s�dZgd�ZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZdZdZGdd�dej�ZGd	d
�d
eje�ZGdd�dej�ZGd
d�de�Zdd�Z da!dd�Z"dd�Z#Gdd�de�Z$dd�Z%eedddfdd�Z&e'dk�r�ddl(Z(ddl)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,de.d-d.d/�e+�/�Z0e0j1�r�e$Z2neZ2Gd0d1�d1e�Z3e&e2e3e0j4e0j5d2�dS)3z0.6)�
HTTPServer�ThreadingHTTPServer�BaseHTTPRequestHandler�SimpleHTTPRequestHandler�CGIHTTPRequestHandler�N)�
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/python39/lib64/python3.9/http/server.pyr�szHTTPServer.server_bindN)�__name__�
__module__�__qualname__Zallow_reuse_addressrrrrrr�src@seZdZdZdS)rTN)rrrZdaemon_threadsrrrrr�src	@s&eZdZdej��dZdeZe	Z
eZdZ
dd�Zdd�Zd	d
�Zdd�Zd4dd�Zd5dd�Zd6dd�Zdd�Zdd�Zdd�Zd7dd�Zdd�Ze�dd �e�ed!�ed"d#��D��Zd$ee d%�<d&d'�Z!d(d)�Z"d8d*d+�Z#d,d-�Z$gd.�Z%gd/�Z&d0d1�Z'd2Z(e)j*j+Z,d3d �e-j.�/�D�Z0d
S)9rzPython/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
fy�|�tjd
|�YdS0|dkr�|jdkr�d|_|dk�r|�tjd|�dS||_dt	|�k�r<dk�sTn|�tjd|�dS|dd�\}}t	|�dk�r�d|_|dk�r�|�tjd|�dS|||_|_|j�
d��r�d	|j�d	�|_ztjj|j|jd�|_Wn~tjj�y }z"|�tjdt|��WYd}~dSd}~0tjj�y^}z"|�tjdt|��WYd}~dSd}~00|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))rrzHTTP/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!r1�errZconntypeZexpectrrr�
parse_requests�


�
��
�
������
z$BaseHTTPRequestHandler.parse_requestcCs|�tj�|��dS�NT)�send_response_onlyrZCONTINUE�end_headers�rrrrr:vs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:tjy�}z |�d|�d|_
WYd}~dSd}~00dS)NiirTZdo_zUnsupported method (%r)zRequest timed out: %r)r5�readliner&r*r(r#r!r/rZREQUEST_URI_TOO_LONGr$r>�hasattr�NOT_IMPLEMENTED�getattr�wfile�flushr
Ztimeout�	log_error)rZmname�method�errr�handle_one_request�s6

�
z)BaseHTTPRequestHandler.handle_one_requestcCs"d|_|��|js|��qdSr?)r$rLrBrrr�handle�szBaseHTTPRequestHandler.handleNcCs
z|j|\}}Wnty,d\}}Yn0|dur:|}|durF|}|�d||�|�||�|�dd�d}|dkr�|tjtjtjfvr�|j	|t
j|dd�t
j|dd�d�}|�d	d
�}|�d|j
�|�dtt|���|��|jd
k�r|�r|j�|�dS)N)�???rNzcode %d, message %srr��F��quote)�code�message�explainzUTF-8�replacezContent-Type�Content-LengthZHEAD)�	responses�KeyErrorrI�
send_response�send_headerrZ
NO_CONTENTZ
RESET_CONTENT�NOT_MODIFIED�error_message_format�html�escape�encode�error_content_typer%r*rAr!rG�write)rrRrSrTZshortmsgZlongmsg�bodyZcontentrrrr/�s:���z!BaseHTTPRequestHandler.send_errorcCs:|�|�|�||�|�d|���|�d|���dS)NZServerZDate)�log_requestr@rZ�version_string�date_time_string�rrRrSrrrrY�s
z$BaseHTTPRequestHandler.send_responsecCsd|jdkr`|dur0||jvr,|j|d}nd}t|d�s@g|_|j�d|j||f�dd��dS)Nrrr�_headers_bufferz
%s %d %s
�latin-1�strict)r#rWrDrg�appendr0r_rfrrrr@�s



��z)BaseHTTPRequestHandler.send_response_onlycCsl|jdkr6t|d�sg|_|j�d||f�dd��|��dkrh|��dkrVd|_n|��d	krhd
|_dS)Nrrgz%s: %s
rhriZ
connectionrTr F)r#rDrgrjr_r9r$)r�keyword�valuerrrrZs

�z"BaseHTTPRequestHandler.send_headercCs"|jdkr|j�d�|��dS)Nrs
)r#rgrj�
flush_headersrBrrrrAs
z"BaseHTTPRequestHandler.end_headerscCs(t|d�r$|j�d�|j��g|_dS)Nrg�)rDrGra�joinrgrBrrrrms
z$BaseHTTPRequestHandler.flush_headers�-cCs.t|t�r|j}|�d|jt|�t|��dS)Nz
"%s" %s %s)�
isinstancerrl�log_messager(r%)rrR�sizerrrrcs

�z"BaseHTTPRequestHandler.log_requestcGs|j|g|�R�dS�N)rr)r�format�argsrrrrI)sz BaseHTTPRequestHandler.log_errorcCsi|]}|d|d���qS)z\xZ02xr)�.0�crrr�
<dictcomp>9rnz!BaseHTTPRequestHandler.<dictcomp>� ��z\\�\cGs2||}tj�d|��|��|�|j�f�dS)Nz%s - - [%s] %s
)�sys�stderrra�address_string�log_date_time_string�	translate�_control_char_table)rrurvrSrrrrr<s
��z"BaseHTTPRequestHandler.log_messagecCs|jd|jS)N� )�server_version�sys_versionrBrrrrdVsz%BaseHTTPRequestHandler.version_stringcCs |durt��}tjj|dd�S)NT)Zusegmt)�time�email�utilsZ
formatdate)rZ	timestamprrrreZsz'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�`s�z+BaseHTTPRequestHandler.log_date_time_string)ZMonZTueZWedZThuZFriZSatZSun)
NZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDeccCs
|jdS�Nr)�client_addressrBrrrr�nsz%BaseHTTPRequestHandler.address_string�HTTP/1.0cCsi|]}||j|jf�qSr)�phraseZdescription)rw�vrrrry}s�)NN)N)N)rprp)N)1rrrr~r;r)r��__version__r��DEFAULT_ERROR_MESSAGEr\�DEFAULT_ERROR_CONTENT_TYPEr`r"r>r:rLrMr/rYr@rZrArmrcrIr%�	maketrans�	itertools�chain�ranger��ordrrrdrer�Zweekdaynamer�r�r0r3r4ZHTTPMessager6r�__members__�valuesrWrrrrr�sBij%
5


�
	�rcsteZdZdeZddddd�ZZdd��fd	d
�
Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Z�ZS)rzSimpleHTTP/zapplication/gzip�application/octet-streamzapplication/x-bzip2zapplication/x-xz)z.gzz.Zz.bz2z.xzN��	directorycs2|durt��}t�|�|_t�j|i|��dSrt)�os�getcwd�fspathr��super�__init__)rr�rv�kwargs��	__class__rrr��sz!SimpleHTTPRequestHandler.__init__cCs6|��}|r2z|�||j�W|��n
|��0dSrt)�	send_head�copyfilerGr�r�frrr�do_GET�s
zSimpleHTTPRequestHandler.do_GETcCs|��}|r|��dSrt)r�rr�rrr�do_HEAD�sz SimpleHTTPRequestHandler.do_HEADcCsf|�|j�}d}tj�|�r�tj�|j�}|j�d�s�|�t	j
�|d|d|dd|d|df}tj�|�}|�d|�|�dd	�|�
�dSd
D]&}tj�||�}tj�|�r�|}q�q�|�|�S|�|�}|�d�r�|�t	jd�dSzt|d�}Wn$t�y&|�t	jd�YdS0�z t�|���}d
|jv�r�d|jv�r�ztj�|jd
�}	Wnttttf�y�Ynz0|	j du�r�|	j!t"j#j$d�}	|	j t"j#j$u�r�t"j"�%|j&t"j#j$�}
|
j!dd�}
|
|	k�r�|�t	j'�|�
�|�(�WdS|�t	j)�|�d|�|�dt*|d��|�d|�+|j&��|�
�|WS|�(��Yn0dS)Nrrrr	r�ZLocationrV�0)z
index.htmlz	index.htmzFile not found�rbzIf-Modified-Sincez
If-None-Match)�tzinfo)Zmicrosecond�Content-type�z
Last-Modified),�translate_pathr1r��isdir�urllib�parseZurlsplit�endswithrYrZMOVED_PERMANENTLYZ
urlunsplitrZrAro�exists�list_directory�
guess_typer/�	NOT_FOUND�open�OSError�fstat�filenor7r�r�Zparsedate_to_datetime�	TypeErrorr.�
OverflowErrorr,r�rU�datetime�timezoneZutcZ
fromtimestamp�st_mtimer[r�OKr%re)rr1r��partsZ	new_partsZnew_url�indexZctypeZfsZimsZ
last_modifrrrr��s~�


��
�

�z"SimpleHTTPRequestHandler.send_headc
	Cs�zt�|�}Wn"ty0|�tjd�YdS0|jdd�d�g}ztjj	|j
dd�}Wn ty|tj�	|j
�}Yn0tj
|dd�}t��}d	|}|�d
�|�d�|�d|�|�d
|�|�d|�|�d�|D]v}tj
�||�}|}	}
tj
�|��r |d}	|d}
tj
�|��r6|d}	|�dtjj|
dd�tj
|	dd�f�q�|�d�d�|��|d�}t��}|�|�|�d�|�tj�|�dd|�|�dtt|���|��|S)NzNo permission to list directorycSs|��Srt)r9)�arrr�<lambda>rnz9SimpleHTTPRequestHandler.list_directory.<locals>.<lambda>)�key�
surrogatepass��errorsFrPzDirectory 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=%srV) r��listdirr�r/rr��sortr�r��unquoter1�UnicodeDecodeErrorr]r^r~�getfilesystemencodingrjror��islinkrQr_�io�BytesIOra�seekrYr�rZr%r*rA)
rr1�list�rZdisplaypath�enc�title�name�fullnameZdisplaynameZlinknameZencodedr�rrrr�sh�
�


�
���


z'SimpleHTTPRequestHandler.list_directorycCs�|�dd�d}|�dd�d}|���d�}ztjj|dd�}Wnty`tj�|�}Yn0t�|�}|�d�}t	d|�}|j
}|D]0}tj�
|�s�|tjtjfvr�q�tj�||�}q�|r�|d7}|S)N�?rr�#rr�r�)r)r'r�r�r�r�r��	posixpath�normpath�filterr�r�r1�dirname�curdir�pardirro)rr1Ztrailing_slashr<Zwordrrrr�?s$	


z'SimpleHTTPRequestHandler.translate_pathcCst�||�dSrt)�shutilZcopyfileobj)r�sourceZ
outputfilerrrr�]sz!SimpleHTTPRequestHandler.copyfilecCsXt�|�\}}||jvr"|j|S|��}||jvr>|j|St�|�\}}|rT|SdS)Nr�)r��splitext�extensions_mapr9�	mimetypesr�)rr1�baseZextZguess�_rrrr�ms



z#SimpleHTTPRequestHandler.guess_type)rrrr�r�r�Z_encodings_map_defaultr�r�r�r�r�r�r�r��
__classcell__rrr�rr�s
�
	X:rc	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)	r1r��query�
path_partsZ
head_parts�partZ	tail_partZ	splitpath�collapsed_pathrrr�_url_collapse_path�s.


r�cCsntrtSzddl}Wnty(YdS0z|�d�daWn,tyhdtdd�|��D��aYn0tS)Nrr�nobodyr	rcss|]}|dVqdS)r	Nr)rwr�rrr�	<genexpr>�rnznobody_uid.<locals>.<genexpr>)r��pwd�ImportError�getpwnamrX�maxZgetpwall)r�rrr�
nobody_uid�s rcCst�|tj�Srt)r��access�X_OK)r1rrr�
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_cgir/rrErBrrr�do_POST�s
�zCGIHTTPRequestHandler.do_POSTcCs|��r|��St�|�SdSrt)rrrr�rBrrrr��szCGIHTTPRequestHandler.send_headcCszt|j�}|�dd�}|dkrB|d|�|jvrB|�d|d�}q|dkrv|d|�||dd�}}||f|_dSdS)NrrrTF)r�r1�find�cgi_directories�cgi_info)rr�Zdir_sep�head�tailrrrr�s

zCGIHTTPRequestHandler.is_cgiz/cgi-binz/htbincCst|�Srt)r)rr1rrr�
is_executablesz#CGIHTTPRequestHandler.is_executablecCstj�|�\}}|��dvS)N)z.pyz.pyw)r�r1r�r9)rr1rrrrr�	is_pythonszCGIHTTPRequestHandler.is_pythonc)	Csl|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)f�y�Yn&0|�!d�}t|�dk�r�|d|d<|j� d�du�r�|j�*�|d<n|jd|d<|j� d�}|�r||d<|j� d �}|�r||d!<|j�+d"d#�}d$�,|�|d%<|j� d&�}|�rP||d'<t-d|j�+d(g��}d)�,|�}|�r|||d*<d+D]}|�.|d��q�|�/t
j0d,�|�1�|	�2d-d.�}|j�r�|
g}d/|v�r�|�3|�t4�}|j5�6�t�7�}|dk�r^t�8|d�\}}t9�9|j:gggd�d�r:|j:�;d��s
�q:�q
t�<|�}|�rZ|�=d0|���dSzZzt�>|�Wnt?�y�Yn0t�@|j:�A�d�t�@|j5�A�d�t�B|||�Wn(|j�C|jD|j�t�Ed1�Yn0�n�ddlF} |g}!|�|��r:tGjH}"|"�$��Id2��r.|"dd3�|"d4d�}"|"d5g|!}!d/|	v�rN|!�3|	�|�Jd6| �K|!��ztL|�}#WntMtNf�y�d}#Yn0| jO|!| jP| jP| jP|d7�}$|j�$�d8k�r�|#dk�r�|j:�;|#�}%nd}%t9�9|j:jQgggd�d�r|j:jQ�Rd��sАq�q�|$�S|%�\}&}'|j5�T|&�|'�r0|�=d9|'�|$jU�V�|$jW�V�|$jX}(|(�r^|�=d:|(�n
|�Jd;�dS)<Nrrrr�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�acceptr�,ZHTTP_ACCEPTz
user-agent�HTTP_USER_AGENTZcookiez, �HTTP_COOKIE)rZREMOTE_HOSTrrrrzScript output follows�+r��=zCGI script exit code r{zw.exe������z-uzcommand: %s)�stdin�stdoutr�envZpostz%szCGI script exit status %#xzCGI script exited OK)Yr
rr*r�r�r1r�r�r�r/rr��isfileZ	FORBIDDENr�	have_forkr
�copyZdeepcopy�environrdZserverrr0r%rr!r�r�r�r�r7r8r)�base64�binasciir9r_Zdecodebytes�decode�Error�UnicodeErrorZget_content_typeZget_allror��
setdefaultrYr�rmrUrjrrGrHr�waitpid�selectr5�read�waitstatus_to_exitcoderI�setuidr��dup2r��execveZhandle_error�request�_exit�
subprocessr~rr�rrZlist2cmdliner-r�r,�Popen�PIPEZ_sockZrecvZcommunicaterarrr�
returncode))r�dir�restr1�iZnextdirZnextrestZ	scriptdirr�r�ZscriptZ
scriptnameZ
scriptfileZispyr Zuqrestrr%r&ZlengthrrZua�coZ
cookie_str�kZ
decoded_queryrvr��pid�stsZexitcoder4ZcmdlineZinterp�nbytes�p�datarrZstatusrrrrs6





��
�


�









�

zCGIHTTPRequestHandler.run_cgiN)rrrrDr�r"Zrbufsizerr�rr	r
rrrrrrr�s
rcGs4tj|tjtjd��}tt|��\}}}}}||fS)N)�type�flags)r
ZgetaddrinfoZSOCK_STREAMZ
AI_PASSIVE�next�iter)ZaddressZinfosZfamilyrB�protoZ	canonnameZsockaddrrrr�_get_best_family�s�rGr�i@c	Cs�t||�\|_}||_|||���}|j��dd�\}}d|vrLd|�d�n|}td|�d|�d|�d|�d�	�z|��Wn$ty�td	�t�	d
�Yn0Wd�n1s�0YdS)Nr	r�[�]zServing HTTP on z port z	 (http://z/) ...z&
Keyboard interrupt received, exiting.r)
rGZaddress_familyr0r
Zgetsockname�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-dz8specify alternate directory (default: current directory))�defaultrTrZstorer�z&specify alternate port (default: 8000))rSrVrB�nargsrTcs$eZdZ�fdd�Zdd�Z�ZS)�DualStackServercsHt�t��$|j�tjtjd�Wd�n1s40Yt���Sr�)	�
contextlib�suppress�	Exceptionr
Z
setsockoptZIPPROTO_IPV6ZIPV6_V6ONLYr�rrBr�rrrs

�"zDualStackServer.server_bindcCs|j|||tjd�dS)Nr�)ZRequestHandlerClassrvr�)rr2r�rrr�finish_requests
�zDualStackServer.finish_request)rrrrr\r�rrr�rrXsrX)rMrNrrO)6r��__all__r#r�Zemail.utilsr�r]Zhttp.clientr3r�r�r�r�r�r,r�r
r
r~r�Zurllib.parser�rr�r�rrZThreadingMixInrZStreamRequestHandlerrrr�r�rrrrGrPr�argparserY�ArgumentParser�parser�add_argumentr�r-�
parse_argsrvZcgiZ
handler_classrXrrOrrrr�<module>Ss�s0	
�

�
���
�

?>