3 \ @sddlmZmZddlZddlZddlmZddlm Z dZ dddd gZ d e Z e d ej jdZe d eZGd ddeZGdddeZGdddeZddZeefdd ZedkreddeBZejjZededdeddddlZejdejWdQRXdS))BaseHTTPRequestHandler HTTPServerN) SimpleHandler)python_implementationz0.2 WSGIServerWSGIRequestHandlerdemo_app make_serverz WSGIServer// c@seZdZeZddZdS) ServerHandlerc Cs4z"|jj|jjddd|jWdtj|XdS)Nr r)request_handlerZ log_requestZstatussplitZ bytes_sentrclose)selfr-/usr/lib64/python3.6/wsgiref/simple_server.pyr szServerHandler.closeN)__name__ __module__ __qualname__software_versionZserver_softwarerrrrrr sr c@s0eZdZdZddZddZddZdd ZdS) rNcCstj||jdS)N)r server_bind setup_environ)rrrrr0s zWSGIServer.server_bindcCsFi}|_|j|d<d|d<t|j|d<d|d<d|d<d|d<dS) NZ SERVER_NAMEzCGI/1.1ZGATEWAY_INTERFACEZ SERVER_PORT REMOTE_HOSTCONTENT_LENGTHZ SCRIPT_NAME) base_environZ server_namestrZ server_port)renvrrrr5s  zWSGIServer.setup_environcCs|jS)N) application)rrrrget_app?szWSGIServer.get_appcCs ||_dS)N)r )rr rrrset_appBszWSGIServer.set_app)rrrr rrr!r"rrrrr*s  c@s,eZdZdeZddZddZddZdS) rz WSGIServer/cCsT|jjj}|j|d<|j|d<|j|d<d|jkrH|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}|r||d<xn|j jD]`\}}|jddj}|j}||krqd||kr@|d|d|7<q||d|<qW|S)NZSERVER_PROTOCOLZSERVER_SOFTWAREZREQUEST_METHOD?r rz iso-8859-1Z PATH_INFOZ QUERY_STRINGrrZ REMOTE_ADDRz content-typeZ CONTENT_TYPEzcontent-lengthr-_ZHTTP_,)serverrcopyrequest_versionserver_versioncommandpathrurllibparseZunquoteZaddress_stringZclient_addressZheadersgetZget_content_typeitemsreplaceupperstrip)rrr,ZqueryhostZlengthkvrrr get_environKs8        zWSGIRequestHandler.get_environcCstjS)N)sysstderr)rrrr get_stderrpszWSGIRequestHandler.get_stderrcCs||jjd|_t|jdkr__all__r*versionr sys_versionrr rrrr rZhttpdZsocketZ getsocknameZsarEZ webbrowseropenZhandle_requestrrrr s*    B