a  ze3@s2dZddlmZmZddlZddlZddlmZddl m Z dZ gdZ de Z e d ejdZe d eZGd d d eZGd ddeZGdddeZddZeefddZedkr.eddeLZejZededdeddddlZedeWdn1s$0YdS)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// c@seZdZeZddZdS) ServerHandlerc Cs>z,|j|jddd|jWt|n t|0dS)Nr r)request_handlerZ log_requeststatussplitZ bytes_sentrcloseselfrI/opt/bitninja-python-dojo/embedded/lib/python3.9/wsgiref/simple_server.pyr s zServerHandler.closeN)__name__ __module__ __qualname__software_versionZserver_softwarerrrrrr sr c@s4eZdZdZdZddZddZddZd d ZdS) rz7BaseHTTPServer that implements the Python WSGI protocolNcCst||dS)z.Override server_bind to store the server name.N)r server_bind setup_environrrrrr0s 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|jSN applicationrrrrget_app?szWSGIServer.get_appcCs ||_dSr#r$)rr%rrrset_appBszWSGIServer.set_app) rrr__doc__r%rrr&r'rrrrr*s  rc@s,eZdZdeZddZddZddZdS) rr cCsP|jj}|j|d<|j|d<|j|d<d|jvrH|jdd\}}n |jd}}tj |d|d<||d <| }||j d kr||d <|j d |d <|j d dur|j |d<n|j d |d<|j d}|r||d<|j D]`\}}|dd}|}||vrqd||vr>|d|d|7<q||d|<q|S)NZSERVER_PROTOCOLZSERVER_SOFTWAREZREQUEST_METHOD?rrz iso-8859-1Z PATH_INFOZ QUERY_STRINGrrZ REMOTE_ADDRz content-typeZ CONTENT_TYPEzcontent-lengthr-_ZHTTP_,)serverr copyrequest_versionserver_versioncommandpathrurllibparseunquoteZaddress_stringZclient_addressZheadersgetZget_content_typeitemsreplaceupperstrip)rr"r2queryhostlengthkvrrr get_environKs6        zWSGIRequestHandler.get_environcCstjSr#)sysstderrrrrr get_stderrpszWSGIRequestHandler.get_stderrcCs|jd|_t|jdkrr?rrrrs      rcCs|||f|}|||S)zACreate a new WSGI server listening on `host` and `port` for `app`)r')r<portZappZ server_classZ handler_classr-rrrr s r __main__ri@zServing HTTP onrVrz...zhttp://localhost:8000/xyz?abc) r(Z http.serverrrrA urllib.parser3Zwsgiref.handlersrplatformrrI__all__r0versionr sys_versionrr rrrr rZhttpdsocket getsocknamesarNZ webbrowseropenZhandle_requestrrrrs.    C