f3<dZddlmZmZddlZddlZddlmZddl m Z dZ gdZ de zZ e d zejdzZe d zezZGd d eZGd deZGddeZdZeefdZedkredde5ZejZededdeddddlZejdeddddS#1swxYwYdSdS)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) WSGIServerWSGIRequestHandlerdemo_app make_server WSGIServer// ceZdZeZdZdS) ServerHandlerc |j|jddd|jt j|dS#t j|wxYw)Nr r)request_handler log_requeststatussplit bytes_sentrcloseselfs C !!"233  +$*C !L&&(( # #DAqiiC  &&((AAGGII!CxxqyCGAI#a%'!"GAI r!ctjSr4)sysstderrrs r get_stderrzWSGIRequestHandler.get_stderrps zr!c|jd|_t|jdkr,d|_d|_d|_|ddS|sdSt|j|j | | d}||_ ||jdS)zHandle a single HTTP requestiir*iNF) multithread)rfilereadlineraw_requestlinelen requestlinerKrM send_error parse_requestrwfilerdr`rrunrIr7)rhandlers rhandlezWSGIRequestHandler.handless $z22599 t# $ $u , ,!D #%D DL OOC F!!##  F J DOO$5$5t7G7G7I7I   #' DK''))*****r!N)rrr __version__rLr`rdrqr r!rrrGsL"[0N###J+++++r!rc`ddlm}|}td|t|t|}|D]%\}}t|dt ||&|ddg|dgS) Nr)StringIOz Hello world!)file=z200 OK)z Content-Typeztext/plain; charset=utf-8zutf-8)iortprintsortedrWreprgetvalueencode)environstart_responsertstdouthr^r_s rr r s XZZF .v&&&& vw}}A**! aDGG&)))))N8JKLLL OO   $ $W - - ..r!cL|||f|}|||S)zACreate a new WSGI server listening on `host` and `port` for `app`)r9)r\portapp server_class handler_classrIs rr r s0\4, 6 6F NN3 Mr!__main__r*i@zServing HTTP onrrz...zhttp://localhost:8000/xyz?abc) r: http.serverrrrb urllib.parserOwsgiref.handlersrplatformrrr__all__rLversionr sys_versionrrrrr r rhttpdsocket getsocknamesarx webbrowseropenhandle_requestr r!rrsS  ;::::::: ************ I I I,##%%+ck.?.?.A.A!.DD !C'+5 & & & & &M & & &'''''''':?+?+?+?+?+/?+?+?+F / / /#-