AlkantarClanX12

Your IP : 18.116.85.102


Current Path : /opt/alt/python34/lib64/python3.4/wsgiref/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/wsgiref/__pycache__/simple_server.cpython-34.pyc

�
i f!�@s�dZddlmZmZddlZddlZddlmZddl	m
Z
dZddd	d
gZdeZ
e
�dejj�dZe
d
eZGdd�de�ZGdd�de�ZGdd�de�Zdd	�Zeedd
�Zedkr}edde�Zejj�Zededdedd�ddlZejd�ej�ej �ndS)a!BaseHTTPServer that implements the Python WSGI protocol (PEP 3333)

This is both an example of how WSGI can be implemented, and a basis for running
simple web applications on a local machine, such as might be done when testing
or debugging an application.  It has not been reviewed for security issues,
however, and we strongly recommend that you use a "real" web server for
production use.

For example usage, see the 'if __name__=="__main__"' block at the end of the
module.  See also the BaseHTTPServer module docs for other API information.
�)�BaseHTTPRequestHandler�
HTTPServerN)�
SimpleHandler)�python_implementationz0.2�
WSGIServer�WSGIRequestHandler�demo_app�make_serverzWSGIServer/�/� c@s"eZdZeZdd�ZdS)�
ServerHandlercCsBz-|jj|jjdd�d|j�Wdtj|�XdS)Nr�r)�request_handlerZlog_requestZstatus�splitZ
bytes_sentr�close)�self�r�:/opt/alt/python34/lib64/python3.4/wsgiref/simple_server.pyr s	$zServerHandler.closeN)�__name__�
__module__�__qualname__�software_versionZserver_softwarerrrrrrsrc@sLeZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)rz7BaseHTTPServer that implements the Python WSGI protocolNcCstj|�|j�dS)z.Override server_bind to store the server name.N)r�server_bind�
setup_environ)rrrrr0s
zWSGIServer.server_bindcCsYi}|_|j|d<d|d<t|j�|d<d|d<d|d<d|d<dS)	NZSERVER_NAMEzCGI/1.1ZGATEWAY_INTERFACEZSERVER_PORT��REMOTE_HOST�CONTENT_LENGTHZSCRIPT_NAME)�base_environZserver_name�strZserver_port)r�envrrrr5s




zWSGIServer.setup_environcCs|jS)N)�application)rrrr�get_app?szWSGIServer.get_appcCs
||_dS)N)r )rr rrr�set_appBszWSGIServer.set_app)	rrr�__doc__r rrr!r"rrrrr*s
c@s>eZdZdeZdd�Zdd�Zdd�ZdS)	rzWSGIServer/cCs�|jjj�}|j|d<|j|d<|j|d<d|jkrf|jjdd�\}}n|jd}}tj	j
|�jd�|d<||d	<|j�}||j
d
kr�||d<n|j
d
|d<|jjd
�dkr
|jj�|d<n|jd
|d<|jjd�}|r@||d<nx�|jj�D]y\}}|jdd�j�}|j�}||kr�qPnd||kr�|d|d|7<qP||d|<qPW|S)NZSERVER_PROTOCOLZSERVER_SOFTWAREZREQUEST_METHOD�?r
rz
iso-8859-1Z	PATH_INFOZQUERY_STRINGrrZREMOTE_ADDRzcontent-typeZCONTENT_TYPEzcontent-lengthr�-�_ZHTTP_�,)�serverr�copy�request_version�server_version�command�pathr�urllib�parseZunquote_to_bytes�decodeZaddress_stringZclient_addressZheaders�getZget_content_type�items�replace�upper�strip)rrr-Zquery�hostZlength�k�vrrr�get_environKs8





zWSGIRequestHandler.get_environcCstjS)N)�sys�stderr)rrrr�
get_stderrpszWSGIRequestHandler.get_stderrcCs�|jjd�|_t|j�dkrVd|_d|_d|_|jd�dS|j�sfdSt	|j|j
|j�|j��}||_
|j|jj��dS)zHandle a single HTTP requestiiri�N)Zrfile�readlineZraw_requestline�lenZrequestliner*r,Z
send_errorZ
parse_requestrZwfiler<r9rZrunr(r!)rZhandlerrrr�handless			
$	zWSGIRequestHandler.handleN)rrr�__version__r+r9r<r?rrrrrGs
%cCs�ddlm}|�}tdd|�td|�t|j��}x0|D](\}}t|dt|�d|�qOW|dd
g�|j�jd	�gS)Nr)�StringIOzHello world!�file�=z200 OK�Content-Type�text/plain; charset=utf-8zutf-8)rDrE)�iorA�print�sortedr2�repr�getvalue�encode)�environZstart_responserA�stdout�hr7r8rrrr�s	
 cCs&|||f|�}|j|�|S)zACreate a new WSGI server listening on `host` and `port` for `app`)r")r6�portZappZserver_classZ
handler_classr(rrrr	�s
�__main__ri@zServing HTTP onrOr
z...zhttp://localhost:8000/xyz?abc)!r#Zhttp.serverrrr:Zurllib.parser.Zwsgiref.handlersr�platformrr@�__all__r+�versionr�sys_versionrrrrrr	rZhttpdZsocketZgetsocknameZsarGZ
webbrowser�openZhandle_requestZserver_closerrrr�<module>s.
B