Viewing File: /opt/alt/python35/lib64/python3.5/wsgiref/__pycache__/simple_server.cpython-35.opt-1.pyc



Yf@sdZddlmZmZddlmZddlZddlZddl	m
Z
ddlmZdZ
dd	d
dgZde
Zed
ejjdZedeZGddde
ZGdddeZGdd	d	eZdd
ZeeddZedkreddeZejjZededdeddddlZej dej!ej"dS)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
HTTPServer)BufferedWriterN)
SimpleHandler)python_implementationz0.2
WSGIServerWSGIRequestHandlerdemo_appmake_serverzWSGIServer// c@s"eZdZeZddZdS)
ServerHandlercCsBz-|jj|jjddd|jWdtj|XdS)Nrr)request_handlerZlog_requestZstatussplitZ
bytes_sentrclose)selfr:/opt/alt/python35/lib64/python3.5/wsgiref/simple_server.pyr!s	$zServerHandler.closeN)__name__
__module____qualname__software_versionZserver_softwarerrrrrr
sr
c@sLeZdZdZdZddZddZddZd	d
ZdS)rz7BaseHTTPServer that implements the Python WSGI protocolNcCstj||jdS)z.Override server_bind to store the server name.N)rserver_bind
setup_environ)rrrrr1s
zWSGIServer.server_bindcCsYi}|_|j|d<d|d<t|j|d<d|d<d|d<d|d<dS)	NZSERVER_NAMEzCGI/1.1ZGATEWAY_INTERFACEZSERVER_PORTREMOTE_HOSTCONTENT_LENGTHZSCRIPT_NAME)base_environZserver_namestrZserver_port)renvrrrr6s




zWSGIServer.setup_environcCs|jS)N)application)rrrrget_app@szWSGIServer.get_appcCs
||_dS)N)r!)rr!rrrset_appCszWSGIServer.set_app)	rrr__doc__r!rrr"r#rrrrr+s
c@s>eZdZdeZddZddZddZdS)	rzWSGIServer/cCs|jjj}|j|d<|j|d<|j|d<d|jkrf|jjdd\}}n|jd}}tj	j
|d|d<||d	<|j}||jd
kr||d<|jd
|d<|j
jd
dkr|j
j|d<n|j
d
|d<|j
jd}|r4||d<x|j
jD]v\}}|jddj}|j}||krqDd||kr|d|d|7<qD||d|<qDW|S)NZSERVER_PROTOCOLZSERVER_SOFTWAREZREQUEST_METHOD?rrz
iso-8859-1Z	PATH_INFOZQUERY_STRINGrrZREMOTE_ADDRzcontent-typeZCONTENT_TYPEzcontent-lengthr-_ZHTTP_,)serverrcopyrequest_versionserver_versioncommandpathrurllibparseZunquoteZaddress_stringZclient_addressZheadersgetZget_content_typeitemsreplaceupperstrip)rr r.ZqueryhostZlengthkvrrrget_environLs8





zWSGIRequestHandler.get_environcCstjS)N)sysstderr)rrrr
get_stderrqszWSGIRequestHandler.get_stderrcCs|jjd|_t|jdkrVd|_d|_d|_|jddS|jsfdSt	|j
}zGt|j||j|j
}||_|j|jjWd|jXdS)zHandle a single HTTP requestiiriN)ZrfilereadlineZraw_requestlinelenZrequestliner+r-Z
send_errorZ
parse_requestrZwfiler
r<r9rZrunr)r"detach)rstdoutZhandlerrrrhandlets 			
!	zWSGIRequestHandler.handleN)rrr__version__r,r9r<rArrrrrHs
%cCsddlm}|}tdd|td|t|j}x0|D](\}}t|dt|d|qOW|dd
g|jjd	gS)Nr)StringIOzHello world!file=z200 OKContent-Typetext/plain; charset=utf-8zutf-8)rFrG)iorCprintsortedr2reprgetvalueencode)environZstart_responserCr@hr7r8rrrr	s	
 cCs&|||f|}|j||S)zACreate a new WSGI server listening on `host` and `port` for `app`)r#)r6portZappZserver_classZ
handler_classr)rrrr
s
__main__ri@zServing HTTP onrPrz...zhttp://localhost:8000/xyz?abc)#r$Zhttp.serverrrrHrr:Zurllib.parser/Zwsgiref.handlersrplatformrrB__all__r,versionrsys_versionrr
rrr	r
rZhttpdZsocketZgetsocknameZsarIZ
webbrowseropenZhandle_requestZserver_closerrrr<module>s0
H



Back to Directory File Manager