Your IP : 3.149.239.70


Current Path : /opt/alt/python310/lib64/python3.10/http/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/http/__pycache__/server.cpython-310.opt-2.pyc

o

6��fO��@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'dkr�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+�/�Z0e0j1r�e$Z2neZ2Gd0d1�d1e�Z3e&e2e3e0j4e0j5d2�dSdS)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�cCs6	tj�|�|jdd�\}}t�|�|_||_dS)N�)�socketserver�	TCPServer�server_bindZserver_address�socketZgetfqdn�server_name�server_port)�self�host�port�r�2/opt/alt/python310/lib64/python3.10/http/server.pyr�s

zHTTPServer.server_bindN)�__name__�
__module__�__qualname__Zallow_reuse_addressrrrrrr�src@seZdZdZdS)rTN)rrrZdaemon_threadsrrrrr�src	@s(eZdZ	dej��dZdeZe	Z
eZdZ
dd�Zdd�Zd	d
�Zdd�Zd4dd�Zd5dd�Zd5dd�Zdd�Zdd�Zdd�Zd6dd�Zdd�Ze�dd �e�ed!�ed"d#��D��Zd$ee d%�<d&d'�Z!d(d)�Z"d5d*d+�Z#d,d-�Z$gd.�Z%gd/�Z&d0d1�Z'd2Z(e)j*j+Z,d3d �e-j.�/�D�Z0d
S)7rzPython/rz	BaseHTTP/�HTTP/0.9c
Cs�	d|_|j|_}d|_t|jd�}|�d�}||_|��}t	|�dkr'dSt	|�dkr�|d}z*|�
d�s9t�|�d	d
�d
}|�d�}t	|�dkrNt�t|d�t|d
�f}Wntt
fyp|�tjd
|�YdSw|dkr}|jdkr}d|_|dkr�|�tjd|�dS||_dt	|�kr�dks�n|�tjd|�dS|dd�\}}t	|�dkr�d|_|dkr�|�tjd|�dS|||_|_|j�
d�r�d	|j�d	�|_z
tjj|j|jd�|_Wn?tjj�y
}z|�tjdt|��WYd}~dSd}~wtjj�y)}z|�tjdt|��WYd}~dSd}~ww|j�dd�}	|	��dk�r<d|_n|	��dk�rL|jdk�rLd|_|j�dd�}
|
��dk�rm|jdk�rm|jdk�rm|� ��smdSdS)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�	zW|j�d�|_t|j�dkr"d|_d|_d|_|�tj	�WdS|js+d|_
WdS|��s2WdSd|j}t||�sI|�tj
d|j�WdSt||�}|�|j��WdStyt}z|�d|�d|_
WYd}~dSd}~ww)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�flush�TimeoutError�	log_error)rZmname�method�errr�handle_one_request�s<

�
��z)BaseHTTPRequestHandler.handle_one_requestcCs,	d|_|��|js|��|jrdSdSr?)r$rMrBrrr�handle�s�zBaseHTTPRequestHandler.handleNcCs	z	|j|\}}Wn
tyd\}}Ynw|dur|}|dur$|}|�d||�|�||�|�dd�d}|dkrq|tjtjtjfvrq|j	|t
j|dd�t
j|dd�d�}|�d	d
�}|�d|j
�|�dtt|���|��|jd
kr�|r�|j�|�dSdSdS)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*rAr!rG�write)rrSrTrUZshortmsgZlongmsg�bodyZcontentrrrr/�s>����z!BaseHTTPRequestHandler.send_errorcCs<	|�|�|�||�|�d|���|�d|���dS)NZServerZDate)�log_requestr@r[�version_string�date_time_string�rrSrTrrrrZ�s

z$BaseHTTPRequestHandler.send_responsecCsj	|jdkr3|dur||jvr|j|d}nd}t|d�s!g|_|j�d|j||f�dd��dSdS)Nrrr�_headers_bufferz
%s %d %s
�latin-1�strict)r#rXrDrh�appendr0r`rgrrrr@�s 



����z)BaseHTTPRequestHandler.send_response_onlycCsx	|jdkrt|d�sg|_|j�d||f�dd��|��dkr8|��dkr-d|_dS|��d	kr:d
|_dSdSdS)Nrrhz%s: %s
rirjZ
connectionrTr F)r#rDrhrkr`r9r$)r�keyword�valuerrrr[s

�

�z"BaseHTTPRequestHandler.send_headercCs(	|jdkr|j�d�|��dSdS)Nrs
)r#rhrk�
flush_headersrBrrrrAs

�z"BaseHTTPRequestHandler.end_headerscCs,t|d�r|j�d�|j��g|_dSdS)Nrh�)rDrGrb�joinrhrBrrrrns

�z$BaseHTTPRequestHandler.flush_headers�-cCs0	t|t�r	|j}|�d|jt|�t|��dS)Nz
"%s" %s %s)�
isinstancerrm�log_messager(r%)rrS�sizerrrrds
�z"BaseHTTPRequestHandler.log_requestcGs	|j|g|�R�dS�N)rs)r�format�argsrrrrJ)sz BaseHTTPRequestHandler.log_errorcCsi|]	}|d|d���qS)z\xZ02xr)�.0�crrr�
<dictcomp>9sz!BaseHTTPRequestHandler.<dictcomp>� ��z\\�\cGs4	||}tj�d|��|��|�|j�f�dS)Nz%s - - [%s] %s
)�sys�stderrrb�address_string�log_date_time_string�	translate�_control_char_table)rrvrwrTrrrrs<s
�
�z"BaseHTTPRequestHandler.log_messagecCs	|jd|jS)N� )�server_version�sys_versionrBrrrreVsz%BaseHTTPRequestHandler.version_stringcCs"	|dur	t��}tjj|dd�S)NT)Zusegmt)�time�email�utilsZ
formatdate)rZ	timestamprrrrfZsz'BaseHTTPRequestHandler.date_time_stringc	CsD	t��}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�ns
z%BaseHTTPRequestHandler.address_string�HTTP/1.0cCsi|]	}||j|jf�qSr)�phrase�description)rx�vrrrrz}s��)NNru)rqrq)1rrrrr;r)r��__version__r��DEFAULT_ERROR_MESSAGEr]�DEFAULT_ERROR_CONTENT_TYPErar"r>r:rMrNr/rZr@r[rArnrdrJr%�	maketrans�	itertools�chain�ranger��ordrsrerfr�Zweekdaynamer�r�r0r3r4ZHTTPMessager6r�__members__�valuesrXrrrrr�sFgj%

5


�
	
�rcsveZdZ	deZddddd�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|��dSru)�os�getcwd�fspathr��super�__init__)rr�rw�kwargs��	__class__rrr��sz!SimpleHTTPRequestHandler.__init__cCs:	|��}|rz|�||j�W|��dS|��wdSru)�	send_head�copyfilerGr�r�frrr�do_GET�s�zSimpleHTTPRequestHandler.do_GETcCs	|��}|r
|��dSdSru)r�rr�rrr�do_HEAD�s
�z SimpleHTTPRequestHandler.do_HEADcCsN	|�|j�}d}tj�|�rhtj�|j�}|j�d�sM|�t	j
�|d|d|dd|d|df}tj�|�}|�d|�|�dd	�|�
�dSd
D]}tj�||�}tj�|�rb|}nqO|�|�S|�|�}|�d�r{|�t	jd�dSzt|d�}Wnty�|�t	jd�YdSwz�t�|���}d
|jvr�d|jvr�ztj�|jd
�}	Wn
ttttfy�Yn:w|	j dur�|	j!t"j#j$d�}	|	j t"j#j$ur�t"j"�%|j&t"j#j$�}
|
j!dd�}
|
|	kr�|�t	j'�|�
�|�(�WdS|�t	j)�|�d|�|�dt*|d��|�d|�+|j&��|�
�|WS|�(��)Nrrrr	r�ZLocationrW�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�endswithrZrZMOVED_PERMANENTLYZ
urlunsplitr[rArp�isfile�list_directory�
guess_typer/�	NOT_FOUND�open�OSError�fstat�filenor7r�r�Zparsedate_to_datetime�	TypeErrorr.�
OverflowErrorr,r�rV�datetime�timezoneZutcZ
fromtimestamp�st_mtimer\r�OKr%rf)rr1r��partsZ	new_partsZnew_url�indexZctypeZfsZimsZ
last_modifrrrr��s�
��


�

��

�
�z"SimpleHTTPRequestHandler.send_headc
	Cs�	zt�|�}Wnty|�tjd�YdSw|jdd�d�g}ztjj	|j
dd�}Wnty?tj�	|j
�}Ynwtj
|dd�}t��}d	|}|�d
�|�d�|�d|�|�d
|�|�d|�|�d�|D]9}tj
�||�}|}	}
tj
�|�r�|d}	|d}
tj
�|�r�|d}	|�dtjj|
dd�tj
|	dd�f�qu|�d�d�|��|d�}t��}|�|�|�d�|�tj�|�dd|�|�dtt|���|��|S)NzNo permission to list directorycSs|��Sru)r9)�arrr�<lambda>sz9SimpleHTTPRequestHandler.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�r/rr��sortr�r��unquoter1�UnicodeDecodeErrorr^r_r�getfilesystemencodingrkrpr��islinkrRr`�io�BytesIOrb�seekrZr�r[r%r*rA)
rr1�list�rZdisplaypath�enc�title�name�fullnameZdisplaynameZlinknameZencodedr�rrrr�sn��

��

�
���


z'SimpleHTTPRequestHandler.list_directorycCs�	|�dd�d}|�dd�d}|���d�}z
tjj|dd�}Wnty1tj�|�}Ynwt�|�}|�d�}t	d|�}|j
}|D]}tj�
|�sV|tjtjfvrWqFtj�||�}qF|re|d7}|S)N�?rr�#rr�r�)r)r'r�r�r�r�r��	posixpath�normpath�filterr�r�r1�dirname�curdir�pardirrp)rr1Ztrailing_slashr<Zwordrrrr�?s(�


z'SimpleHTTPRequestHandler.translate_pathcCs	t�||�dSru)�shutilZcopyfileobj)r�sourceZ
outputfilerrrr�]s
z!SimpleHTTPRequestHandler.copyfilecCsZ	t�|�\}}||jvr|j|S|��}||jvr |j|St�|�\}}|r+|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]}|dkr'|��q|r2|dkr2|�|�q|rM|��}|rL|dkrF|��d}n	|dkrLd}nd}|rXd�||f�}dd�|�|f}d�|�}|S)Nr�rrz..rr)�	partitionr�r�r�r)�poprkrp)	r1r��query�
path_partsZ
head_parts�partZ	tail_partZ	splitpath�collapsed_pathrrr�_url_collapse_path�s4


��
r�cCsp	trtSzddl}Wn
tyYdSwz
|�d�daWtSty7dtdd�|��D��aYtSw)Nrr�nobodyr	rcss�|]}|dVqdS)r	Nr)rxr�rrr�	<genexpr>�s�znobody_uid.<locals>.<genexpr>)r��pwd�ImportError�getpwnamrY�maxZgetpwall)r�rrr�
nobody_uid�s���rcCs	t�|tj�Sru)r��access�X_OK)r1rrr�
executable�src@sTeZdZ	eed�ZdZdd�Zdd�Zdd�Z	d	d
gZ
dd�Zd
d�Zdd�Z
dS)r�forkrcCs(	|��r|��dS|�tjd�dS)NzCan only POST to CGI scripts)�is_cgi�run_cgir/rrErBrrr�do_POST�s�zCGIHTTPRequestHandler.do_POSTcCs	|��r	|��St�|�Sru)rrrr�rBrrrr��s
zCGIHTTPRequestHandler.send_headcCs�	t|j�}|�dd�}|dkr.|d|�|jvr.|�d|d�}|dkr.|d|�|jvs|dkrH|d|�||dd�}}||f|_dSdS)NrrrTF)r�r1�find�cgi_directories�cgi_info)rr�Zdir_sep�head�tailrrrr�s
�
zCGIHTTPRequestHandler.is_cgiz/cgi-binz/htbincCs
	t|�Sru)r)rr1rrr�
is_executablesz#CGIHTTPRequestHandler.is_executablecCs	tj�|�\}}|��dvS)N)z.pyz.pyw)r�r1r�r9)rr1r
rrrr�	is_pythonszCGIHTTPRequestHandler.is_pythonc)	Cs�	|j\}}|d|}|�dt|�d�}|dkrH|d|�}||dd�}|�|�}tj�|�rC||}}|�dt|�d�}nn|dks|�d�\}}}	|�d�}|dkrg|d|�||d�}
}n|d}
}|d|
}|�|�}tj�|�s�|�	t
jd|�dStj�|�s�|�	t
j
d|�dS|�|�}
|js�|
s�|�|�s�|�	t
j
d|�dSt�tj�}|��|d	<|jj|d
<d|d<|j|d
<t|jj�|d<|j|d<tj�|�}||d<|�|�|d<||d<|	|d<|jd|d<|j� d�}|�rW|�!�}t|�dk�rWddl"}ddl#}|d|d<|d�$�dk�rWz|d�%d�}|�&|��'d�}Wn
|j(t)f�yDYnw|�!d�}t|�dk�rW|d|d<|j� d�du�rh|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��q�|�/t
j0d,�|�1�|	�2d-d.�}|j�rx|
g}d/|v�r�|�3|�t4�}|j5�6�t�7�}|dk�r5t�8|d�\}}t9�9|j:gggd�d�r#|j:�;d��sn
t9�9|j:gggd�d�st�<|�}|�r3|�=d0|���dSz.zt�>|�Wn
t?�yGYnwt�@|j:�A�d�t�@|j5�A�d�t�B|||�WdS|j�C|jD|j�t�Ed1�YdSddlF} |g}!|�|��r�tGjH}"|"�$��Id2��r�|"dd3�|"d4d�}"|"d5g|!}!d/|	v�r�|!�3|	�|�Jd6| �K|!��ztL|�}#WntMtNf�y�d}#Ynw| jO|!| jP| jP| jP|d7�}$|j�$�d8k�r�|#dk�r�|j:�;|#�}%nd}%t9�9|j:jQgggd�d�r|j:jQ�Rd��snt9�9|j:jQgggd�d�s�|$�S|%�\}&}'|j5�T|&�|'�r(|�=d9|'�|$jU�V�|$jW�V�|$jX}(|(�r@|�=d:|(�dS|�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r
r*r�r�r1r�r��existsr/rr�r�Z	FORBIDDENr�	have_forkr�copyZdeepcopy�environreZserverrr0r%rr!r�r�r�r�r7r8r)�base64�binasciir9r`Zdecodebytes�decode�Error�UnicodeErrorZget_content_typeZget_allrpr��
setdefaultrZr�rnrVrkrrGrHr�waitpid�selectr5�read�waitstatus_to_exitcoderJ�setuidr��dup2r��execveZhandle_error�request�_exit�
subprocessrrr�rsZlist2cmdliner-r�r,�Popen�PIPEZ_sockZrecvZcommunicaterbr�rr!�
returncode))r�dir�restr1�iZnextdirZnextrestZ	scriptdirr�r�ZscriptZ
scriptnameZ
scriptfileZispyr"Zuqrestrr'r(ZlengthrrZua�coZ
cookie_str�kZ
decoded_queryrwr��pid�stsZexitcoder6ZcmdlineZinterp�nbytes�p�datar!r�ZstatusrrrrsB


�


��


�

��





�
�

���

zCGIHTTPRequestHandler.run_cgiN)rrrrDr�r$Zrbufsizer	r�rrrrrrrrrr�s
	rcGs4tj|tjtjd��}tt|��\}}}}}||fS)N)�type�flags)r
ZgetaddrinfoZSOCK_STREAMZ
AI_PASSIVE�next�iter)ZaddressZinfosZfamilyrD�protoZ	canonnameZsockaddrrrr�_get_best_family�s�rIr�i@c	Cs�	t||�\|_}||_|||��R}|j��dd�\}}d|vr'd|�d�n|}td|�d|�d|�d|�d�	�z|��WntyRtd	�t�	d
�Yn	wWd�dSWd�dS1sfwYdS)Nr	r�[�]zServing HTTP on z port z	 (http://z/) ...z&
Keyboard interrupt received, exiting.r)
rIZaddress_familyr0r
Zgetsockname�printZ
serve_forever�KeyboardInterruptr�exit)	�HandlerClass�ServerClassZprotocolr�bindZaddrZhttpdrZurl_hostrrr�test�s.������"�rR�__main__z--cgi�
store_truezrun as CGI server)�action�helpz--bindz-bZADDRESSz8specify alternate bind address (default: all interfaces))�metavarrVz--directoryz-dz8specify alternate directory (default: current directory))�defaultrVrZstorer�z&specify alternate port (default: 8000))rUrXrD�nargsrVcs$eZdZ�fdd�Zdd�Z�ZS)�DualStackServercsHt�t��|j�tjtjd�Wd�n1swYt���Sr�)	�
contextlib�suppress�	Exceptionr
Z
setsockoptZIPPROTO_IPV6ZIPV6_V6ONLYr�rrBr�rrrs
��
zDualStackServer.server_bindcCs|j|||tjd�dS)Nr�)ZRequestHandlerClassrwr�)rr4r�rrr�finish_requests

�zDualStackServer.finish_request)rrrrr^r�rrr�rrZsrZ)rOrPrrQ)6r��__all__r%r�Zemail.utilsr�r^Zhttp.clientr3r�r�r�r�r�r.r�r
r
rr�Zurllib.parser�rr�r�rrZThreadingMixInrZStreamRequestHandlerrrr�r�rrrrIrRr�argparser[�ArgumentParser�parser�add_argumentr�r-�
parse_argsrwZcgiZ
handler_classrZrrQrrrr�<module>s�Rs0

��
���

��

?>