Your IP : 18.118.128.17


Current Path : /opt/alt/python35/lib64/python3.5/http/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/http/__pycache__/server.cpython-35.opt-2.pyc



���]ҫ�@s\dZddddgZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZdZd	Zd
d�ZGdd�dej�ZGd
d�dej�ZGdd�de�Zdd�Zdadd�Zdd�ZGdd�de�Z eeddddd�Z!e"dkrXej#�Z$e$j%ddddd �e$j%d!d"d#dd$d%dd&�e$j%d'dd(d#dd)e&d*d+dd,�e$j'�Z(e(j)r3e Z*neZ*e!d-e*d'e(j+d.e(j,�dS)/z0.6�
HTTPServer�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-8cCs(|jdd�jdd�jdd�S)N�&z&amp;�<z&lt;�>z&gt;)�replace)�html�r�+/opt/alt/python35/lib64/python3.5/server.py�_quote_html�src@s"eZdZdZdd�ZdS)r�cCsNtjj|�|jj�dd�\}}tj|�|_||_dS)N�)�socketserver�	TCPServer�server_bind�socket�getsockname�getfqdn�server_name�server_port)�self�host�portrrr
r�szHTTPServer.server_bindN)�__name__�
__module__�__qualname__Zallow_reuse_addressrrrrr
r�sc
@s�eZdZdejj�dZdeZe	Z
eZdZ
dd�Zdd�Zd	d
�Zdd�Zd
d
dd�Zd
dd�Zd
dd�Zdd�Zdd�Zdd�Zdddd�Zdd�Zdd �Zd!d"�Zd
d#d$�Zd%d&�Zd'd(d)d*d+d,d-gZd
d.d/d0d1d2d3d4d5d6d7d8d9g
Zd:d;�Z d<Z!e"j#j$Z%d=d>�e&j'j(�D�Z)d
S)?rzPython/rz	BaseHTTP/zHTTP/0.9cCsyd|_|j|_}d|_t|jd�}|jd�}||_|j�}t	|�dkr�|\}}}|dd�dkr�|j
tjd|�dSya|jd	d
�d
}|jd�}t	|�dkr�t
�t|d
�t|d
�f}Wn3t
tfk
r@|j
tjd|�dSYnX|dkre|jdkred|_|dkr|j
tjd|�dSnvt	|�dkr�|\}}d|_|dkr|j
tjd|�dSn%|s�dS|j
tjd|�dS||||_|_|_y%tjj|jd|j�|_Wnytjjk
rx|j
tjd�dSYnKtjjk
r�}z%|j
tjdt|��dSWYdd}~XnX|jjdd�}	|	j�dkr�d|_n*|	j�dkr |jdkr d|_|jjdd�}
|
j�dkru|jdkru|jdkru|j�sudSdS)NTz
iso-8859-1z
��zHTTP/zBad request version (%r)F�/r�.rrzHTTP/1.1zInvalid HTTP Version (%s)�GETzBad HTTP/0.9 request type (%r)zBad request syntax (%r)Z_classz
Line too longzToo many headers�
Connection��closez
keep-aliveZExpectz100-continue)rr)rr)�command�default_request_version�request_version�close_connection�str�raw_requestline�rstrip�requestline�split�len�
send_errorrZBAD_REQUEST�
ValueError�int�
IndexError�protocol_versionZHTTP_VERSION_NOT_SUPPORTED�path�http�clientZ
parse_headers�rfile�MessageClass�headersZLineTooLongZ
HTTPExceptionZREQUEST_HEADER_FIELDS_TOO_LARGE�get�lower�handle_expect_100)r�versionr.�wordsr'r6Zbase_version_numberZversion_number�errZconntype�expectrrr
�
parse_request	s�			$			
	z$BaseHTTPRequestHandler.parse_requestcCs|jtj�|j�dS)NT)�send_response_onlyrZCONTINUE�end_headers)rrrr
r>ks
z(BaseHTTPRequestHandler.handle_expect_100cCs,y�|jjd�|_t|j�dkr\d|_d|_d|_|jtj	�dS|jsrd|_
dS|j�s�dSd|j}t||�s�|jtj
d|j�dSt||�}|�|jj�WnEtjk
r'}z"|jd|�d|_
dSWYdd}~XnXdS)Niir%TZdo_zUnsupported method (%r)zRequest timed out: %r)r9�readliner,r0r.r)r'r1rZREQUEST_URI_TOO_LONGr*rC�hasattr�NOT_IMPLEMENTED�getattr�wfile�flushr�timeout�	log_error)rZmname�method�errr
�handle_one_request}s4					
	z)BaseHTTPRequestHandler.handle_one_requestcCs1d|_|j�x|js,|j�qWdS)NT)r*rP)rrrr
�handle�s	
zBaseHTTPRequestHandler.handleNcCs^y|j|\}}Wntk
r7d\}}YnX|dkrJ|}|dkr\|}|jd||�|j||�|jdd�d}|dkr+|tjtjtjfkr+|j	d|dt
|�dt
|�i}|jd	d
�}|jd|j�|jdt
t|���|j�|jd
krZ|rZ|jj|�dS)N�???zcode %d, message %sr$r&���code�message�explainzUTF-8r
zContent-TypezContent-LengthZHEAD)rRrR)�	responses�KeyErrorrM�
send_response�send_headerrZ
NO_CONTENTZ
RESET_CONTENTZNOT_MODIFIED�error_message_formatr�encode�error_content_typer3r0rEr'rJ�write)rrTrUrVZshortmsgZlongmsgZbodyZcontentrrr
r1�s4
	
z!BaseHTTPRequestHandler.send_errorcCsM|j|�|j||�|jd|j��|jd|j��dS)NZServerZDate)�log_requestrDrZ�version_string�date_time_string)rrTrUrrr
rY�s
z$BaseHTTPRequestHandler.send_responsecCs�|dkr5||jkr/|j|d}nd}|jdkr�t|d�s\g|_|jjd|j||fjdd��dS)Nrr%zHTTP/0.9�_headers_bufferz
%s %d %s
zlatin-1�strict)rWr)rGrb�appendr5r\)rrTrUrrr
rD�s	z)BaseHTTPRequestHandler.send_response_onlycCs�|jdkrMt|d�s'g|_|jjd||fjdd��|j�dkr�|j�dkr}d|_n|j�d	kr�d
|_dS)NzHTTP/0.9rbz%s: %s
zlatin-1rc�
connectionr&Tz
keep-aliveF)r)rGrbrdr\r=r*)r�keyword�valuerrr
rZ�s		z"BaseHTTPRequestHandler.send_headercCs-|jdkr)|jjd�|j�dS)NzHTTP/0.9s
)r)rbrd�
flush_headers)rrrr
rEsz"BaseHTTPRequestHandler.end_headerscCs8t|d�r4|jjdj|j��g|_dS)Nrb�)rGrJr^�joinrb)rrrr
rhsz$BaseHTTPRequestHandler.flush_headers�-cCsAt|t�r|j}|jd|jt|�t|��dS)Nz
"%s" %s %s)�
isinstancerrg�log_messager.r+)rrT�sizerrr
r_s		z"BaseHTTPRequestHandler.log_requestcGs|j||�dS)N)rm)r�format�argsrrr
rMsz BaseHTTPRequestHandler.log_errorcGs1tjjd|j�|j�||f�dS)Nz%s - - [%s] %s
)�sys�stderrr^�address_string�log_date_time_string)rrorprrr
rm,s		z"BaseHTTPRequestHandler.log_messagecCs|jd|jS)N� )�server_version�sys_version)rrrr
r`Bsz%BaseHTTPRequestHandler.version_stringc	Css|dkrtj�}tj|�\	}}}}}}}}	}
d|j|||j|||||f}|S)Nz#%s, %02d %3s %4d %02d:%02d:%02d GMT)�time�gmtime�weekdayname�	monthname)rZ	timestamp�year�month�day�hh�mm�ssZwd�y�z�srrr
raFs*
z'BaseHTTPRequestHandler.date_time_stringc	Cs]tj�}tj|�\	}}}}}}}}	}
d||j|||||f}|S)Nz%02d/%3s/%04d %02d:%02d:%02d)rx�	localtimer{)rZnowr|r}r~rr�r��xr�r�r�rrr
rtQs
* z+BaseHTTPRequestHandler.log_date_time_stringZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDeccCs|jdS)Nr)�client_address)rrrr
rs_sz%BaseHTTPRequestHandler.address_stringzHTTP/1.0cCs%i|]}|j|jf|�qSr)�phrase�description)�.0�vrrr
�
<dictcomp>ns	z!BaseHTTPRequestHandler.<dictcomp>)*rrrrqr?r/rw�__version__rv�DEFAULT_ERROR_MESSAGEr[�DEFAULT_ERROR_CONTENT_TYPEr]r(rCr>rPrQr1rYrDrZrErhr_rMrmr`rartrzr{rsr5r7r8ZHTTPMessager:r�__members__�valuesrWrrrr
r�s<i
b%5
		c	@s�eZdZdeZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zej
s}ej�ejj�Zejddddddddi�dS)rzSimpleHTTP/c
Cs;|j�}|r7z|j||j�Wd|j�XdS)N)�	send_head�copyfilerJr&)r�frrr
�do_GET�s
zSimpleHTTPRequestHandler.do_GETcCs |j�}|r|j�dS)N)r�r&)rr�rrr
�do_HEAD�sz SimpleHTTPRequestHandler.do_HEADc	Cs�|j|j�}d}tjj|�r
tjj|j�}|jjd�s�|jt	j
�|d|d|dd|d|df}tjj|�}|jd|�|j
�dSxIdD]4}tjj||�}tjj|�r�|}Pq�W|j|�S|j|�}yt|d
�}Wn)tk
rW|jt	jd�dSYnXy}|jt	j�|jd|�tj|j��}|jd
t|d��|jd|j|j��|j
�|SWn|j��YnXdS)Nr!rrrr�ZLocation�
index.html�	index.htm�rbzFile not foundzContent-typezContent-Length�z
Last-Modified)r�r�)�translate_pathr6�os�isdir�urllib�parseZurlsplit�endswithrYrZMOVED_PERMANENTLYZ
urlunsplitrZrErj�exists�list_directory�
guess_type�open�OSErrorr1�	NOT_FOUND�OK�fstat�filenor+ra�st_mtimer&)	rr6r��partsZ	new_partsZnew_url�indexZctype�fsrrr
r��sF



	

z"SimpleHTTPRequestHandler.send_headc
Cs`ytj|�}Wn)tk
r>|jtjd�dSYnX|jddd��g}ytjj	|j
dd�}Wn$tk
r�tjj	|�}YnXtj
|�}tj�}d|}|jd�|jd	�|jd
|�|jd|�|jd|�|jd
�x�|D]�}tj
j||�}|}	}
tj
j|�rr|d}	|d}
tj
j|�r�|d}	|jdtjj|
dd�tj
|	�f�q'W|jd�dj|�j|d�}tj�}|j|�|jd�|jtj�|jdd|�|jdtt|���|j�|S)NzNo permission to list directory�keycSs
|j�S)N)r=)�arrr
�<lambda>�sz9SimpleHTTPRequestHandler.list_directory.<locals>.<lambda>�errors�
surrogatepasszDirectory 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>
�
�surrogateescaperzContent-typeztext/html; charset=%szContent-Length) r��listdirr�r1rr��sortr�r��unquoter6�UnicodeDecodeErrorr�escaperq�getfilesystemencodingrdrjr��islink�quoter\�io�BytesIOr^�seekrYr�rZr+r0rE)
rr6�list�rZdisplaypath�enc�title�name�fullnameZdisplaynameZlinkname�encodedr�rrr
r��s\
	




	





	



z'SimpleHTTPRequestHandler.list_directorycCs$|jdd�d}|jdd�d}|j�jd�}ytjj|dd�}Wn$tk
r�tjj|�}YnXtj|�}|jd�}t	d|�}t
j�}xP|D]H}t
jj
|�s�|t
jt
jfkr�q�t
jj||�}q�W|r |d7}|S)N�?rr�#r!r�r�)r/r-r�r�r�r�r��	posixpath�normpath�filterr��getcwdr6�dirname�curdir�pardirrj)rr6Ztrailing_slashr@Zwordrrr
r��s$	

*
z'SimpleHTTPRequestHandler.translate_pathcCstj||�dS)N)�shutil�copyfileobj)r�sourceZ
outputfilerrr
r�sz!SimpleHTTPRequestHandler.copyfilecCsdtj|�\}}||jkr/|j|S|j�}||jkrU|j|S|jdSdS)Nr%)r��splitext�extensions_mapr=)rr6�base�extrrr
r�+sz#SimpleHTTPRequestHandler.guess_typer%zapplication/octet-streamz.pyz
text/plainz.cz.hN)rrrr�rvr�r�r�r�r�r�r��	mimetypesZinitedZinitZ	types_map�copyr��updaterrrr
rts 
	1:	
c	Cs+|jd�\}}}tjj|�}|jd�}g}xP|dd�D]>}|dkro|j�qP|rP|dkrP|j|�qPW|r�|j�}|r�|dkr�|j�d}q�|dkr�d}nd}|r�dj||f�}ddj|�|f}dj|�}|S)Nr�r!rz..r"r%���)�	partitionr�r�r�r/�poprdrj)	r6�_�query�
path_partsZ
head_parts�partZ	tail_partZ	splitpath�collapsed_pathrrr
�_url_collapse_pathPs.

		r�cCs�tr
tSyddl}Wntk
r2dSYnXy|jd�daWn5tk
r�dtdd�|j�D��aYnXtS)Nrr�nobodyrcss|]}|dVqdS)rNr)r�r�rrr
�	<genexpr>�sznobody_uid.<locals>.<genexpr>r�)r��pwd�ImportError�getpwnamrX�max�getpwall)r�rrr
�
nobody_uid�s
	
(r�cCstj|tj�S)N)r��access�X_OK)r6rrr
�
executable�sr�c@syeZdZeed�ZdZdd�Zdd�Zdd�Z	d	d
gZ
dd�Zd
d�Zdd�Z
dS)r�forkrcCs0|j�r|j�n|jtjd�dS)NzCan only POST to CGI scripts)�is_cgi�run_cgir1rrH)rrrr
�do_POST�s

zCGIHTTPRequestHandler.do_POSTcCs'|j�r|j�Stj|�SdS)N)r�r�rr�)rrrr
r��s
zCGIHTTPRequestHandler.send_headcCslt|j�}|jdd�}|d|�||dd�}}||jkrh||f|_dSdS)Nr!rTF)r�r6�find�cgi_directories�cgi_info)rr�Zdir_sep�head�tailrrr
r��s%zCGIHTTPRequestHandler.is_cgiz/cgi-binz/htbincCs
t|�S)N)r�)rr6rrr
�
is_executable�sz#CGIHTTPRequestHandler.is_executablecCs(tjj|�\}}|j�dkS)N�.py�.pyw)r�r�)r�r6r�r=)rr6r�r�rrr
�	is_python�szCGIHTTPRequestHandler.is_pythonc)Cs�|j\}}|d|}|jdt|�d�}x�|dkr�|d|�}||dd�}|j|�}tjj|�r�||}}|jdt|�d�}q<Pq<W|jd�\}}}	|jd�}|dkr|d|�||d�}
}n
|d}
}|d|
}|j|�}tjj|�sl|j	t
jd|�dStjj|�s�|j	t
j
d|�dS|j|�}
|js�|
r�|j|�s�|j	t
j
d|�dStjtj�}|j�|d	<|jj|d
<d|d<|j|d
<t|jj�|d<|j|d<tjj|�}||d<|j|�|d<||d<|	r�|	|d<|jd|d<|jj d�}|r�|j!�}t|�dkr�ddl"}ddl#}|d|d<|dj$�dkr�y/|dj%d�}|j&|�j'd�}Wn|j(t)fk
rfYn0X|j!d�}t|�dkr�|d|d<|jj d�dkr�|jj*�|d<n|jd|d<|jj d�}|r�||d<|jj d �}|r||d!<g}xc|jj+d"�D]O}|dd�d#krd|j,|j-��q2||d$d�j!d%�}q2Wd%j.|�|d&<|jj d'�}|r�||d(<t/d|jj0d)g��}d*j.|�}|r�||d+<xd?D]}|j1|d�q�W|j2t
j3d-�|j4�|	j5d.d/�}|jr�|
g}d0|krr|j,|�t6�}|j7j8�tj9�}|dkrtj:|d�\}}x9t;j;|j<gggd�dr�|j<j=d�s�Pq�W|r
|j>d1|�dSyoytj?|�Wnt@k
r6YnXtjA|j<jB�d�tjA|j7jB�d�tjC|||�Wq�|jjD|jE|j�tjFd2�Yq�XnddlG} |g}!|j|�r!tHjI}"|"j$�jJd3�r|"dd@�|"dAd�}"|"d6g|!}!d0|	kr:|!j,|	�|jKd7| jL|!��ytM|�}#WntNtOfk
r�d}#YnX| jP|!d8| jQd9| jQd:| jQd;|�}$|jj$�d<kr�|#dkr�|j<j=|#�}%nd}%x?t;j;|j<jRgggd�dr1|j<jRjSd�s�Pq�W|$jT|%�\}&}'|j7jU|&�|'rm|j>d=|'�|$jVjW�|$jXjW�|$jY}(|(r�|j>d1|(�n
|jKd>�dS)BNr!rrr�r%zNo 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�
authorizationrZ	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�REMOTE_HOSTzScript output follows�+ru�=zCGI script exit status %#x�zw.exer r�z-uzcommand: %s�stdin�stdoutrr�envZpostz%szCGI script exited OK)r�r	rrrr������)Zr�r�r0r�r�r6r�r�r�r1rr��isfileZ	FORBIDDENr��	have_forkr�r��deepcopy�environr`Zserverrr5r+rr'r�r�r�r�r;r<r/�base64�binasciir=r\Zdecodebytes�decode�Error�UnicodeErrorZget_content_typeZgetallmatchingheadersrd�striprjr�Zget_all�
setdefaultrYr�rhr
r�rJrKr��waitpid�selectr9�readrM�setuidr��dup2r��execveZhandle_errorZrequest�_exit�
subprocessrqr�r�rm�list2cmdliner3�	TypeErrorr2�Popen�PIPE�_sock�recv�communicater^rrr&r�
returncode))r�dir�restr6�iZnextdirZnextrestZ	scriptdirr�r�ZscriptZ
scriptnameZ
scriptfileZispyrZuqrestr�rr�lengthrr�lineZua�coZ
cookie_str�kZ
decoded_queryrpr��pid�stsr$ZcmdlineZinterp�nbytes�p�datarrr�statusrrr
r��s4
$









!



		
	
%
		
				!(

	zCGIHTTPRequestHandler.run_cgiN)rrrrGr�rZrbufsizer�r�r�r�r�r�r�rrrr
r�szHTTP/1.0i@r%cCs�||f}||_|||�}|jj�}td|dd|dd�y|j�Wn3tk
r�td�|j�tjd�YnXdS)NzServing HTTP onrrrz...z&
Keyboard interrupt received, exiting.)	r5rr�printZ
serve_forever�KeyboardInterruptZserver_closerq�exit)�HandlerClassZServerClass�protocolr�bindZserver_addressZhttpd�sarrr
�test�s	


rA�__main__z--cgi�action�
store_true�helpzRun as CGI Serverz--bindz-b�default�metavarZADDRESSz8Specify alternate bind address [default: all interfaces]r�store�type�nargsr�z&Specify alternate port [default: 8000]r=r?)-r��__all__rZhttp.clientr7r�r�r�r�rr�rrrqrxZurllib.parser�r��argparserr�r�rrrZStreamRequestHandlerrrr�r�r�r�rrAr�ArgumentParser�parser�add_argumentr3�
parse_argsrpZcgiZ
handler_classrr?rrrr
�<module>Ss`���0�
		

?>