
    d3                     <   d Z ddlmZmZ ddlZddlZddlmZ ddl	m
Z
 dZg dZdez   Z e
            d	z   ej                                        d         z   Zed
z   ez   Z G d de          Z G d de          Z G d de          Zd ZeefdZedk    r edde          5 Zej                                        Z eded         ded         d           ddlZ ej        d           e                                 ddd           dS # 1 swxY w Y   dS dS )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_implementationz0.2)
WSGIServerWSGIRequestHandlerdemo_appmake_serverWSGIServer// c                       e Zd ZeZd ZdS )ServerHandlerc                     	 | j                             | j                            dd          d         | j                   t          j        |            d S # t          j        |            w xY w)Nr      r   )request_handlerlog_requeststatussplit
bytes_sentr   closeselfs    '  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/wsgiref/simple_server.pyr   zServerHandler.close    sp    	& ,,!!#a((+T_   %%%%%M%%%%s   ?A A-N)__name__
__module____qualname__software_versionserver_softwarer        r   r   r      s(        &O& & & & &r!   r   c                   .    e Zd ZdZdZd Zd Zd Zd ZdS )r   z7BaseHTTPServer that implements the Python WSGI protocolNc                 V    t          j        |            |                                  dS )z.Override server_bind to store the server name.N)r   server_bindsetup_environr   s    r   r$   zWSGIServer.server_bind0   s+    t$$$r!   c                     i x}| _         | j        |d<   d|d<   t          | j                  |d<   d|d<   d|d<   d|d<   d S )	NSERVER_NAMEzCGI/1.1GATEWAY_INTERFACESERVER_PORT REMOTE_HOSTCONTENT_LENGTHSCRIPT_NAME)base_environserver_namestrserver_port)r   envs     r   r%   zWSGIServer.setup_environ5   sa    "$$d!-M#,  !122MM Mr!   c                     | j         S Napplicationr   s    r   get_appzWSGIServer.get_app?   s    r!   c                     || _         d S r4   r5   )r   r6   s     r   set_appzWSGIServer.set_appB   s    &r!   )	r   r   r   __doc__r6   r$   r%   r7   r9   r    r!   r   r   r   *   s[        AAK  
          ' ' ' ' 'r!   r   c                   *    e Zd Zdez   Zd Zd Zd ZdS )r   r   c                    | j         j                                        }| j        |d<   | j        |d<   | j        |d<   d| j        v r| j                            dd          \  }}n	| j        d}}t          j	        
                    |d          |d<   ||d	<   |                                 }|| j        d
         k    r||d<   | j        d
         |d<   | j                            d          | j                                        |d<   n| j        d         |d<   | j                            d          }|r||d<   | j                                        D ]l\  }}|                    dd                                          }|                                }||v rFd|z   |v r|d|z   xx         d|z   z  cc<   d||d|z   <   m|S )NSERVER_PROTOCOLSERVER_SOFTWAREREQUEST_METHOD?r   r*   z
iso-8859-1	PATH_INFOQUERY_STRINGr   r+   REMOTE_ADDRzcontent-typeCONTENT_TYPEzcontent-lengthr,   -_HTTP_,)serverr.   copyrequest_versionserver_versioncommandpathr   urllibparseunquoteaddress_stringclient_addressheadersgetget_content_typeitemsreplaceupperstrip)r   r2   rN   queryhostlengthkvs           r   get_environzWSGIRequestHandler.get_environK   s   k&++--!%!5!%!4 $$)Q//JD2D!<//lCCK#N""$$4&q)))!%C!03M<N++3"&,"?"?"A"AC"&,~">C!!"233 	+$*C !L&&(( 	# 	#DAqiiC  &&((AAGGII!CxxqyCGAI#a%'!"GAI
r!   c                     t           j        S r4   )sysstderrr   s    r   
get_stderrzWSGIRequestHandler.get_stderrp   s
    zr!   c                    | j                             d          | _        t          | j                  dk    r,d| _        d| _        d| _        |                     d           dS |                                 sdS t          | j         | j
        |                                 |                                 d          }| |_        |                    | j                                                   dS )zHandle a single HTTP requesti  i   r*   i  NF)multithread)rfilereadlineraw_requestlinelenrequestlinerK   rM   
send_errorparse_requestr   wfilerd   r`   r   runrI   r7   )r   handlers     r   handlezWSGIRequestHandler.handles   s      $z22599t#$$u,,!D#%D DLOOC   F!!## 	FJ
DOO$5$5t7G7G7I7I
 
 
 #'DK''))*****r!   N)r   r   r   __version__rL   r`   rd   rq   r    r!   r   r   r   G   sL        "[0N# # #J  + + + + +r!   r   c                 `   ddl m}  |            }t          d|           t          |           t          |                                           }|D ]%\  }}t          |dt          |          |           & |ddg           |                                                    d          gS )	Nr   )StringIOzHello world!)file=z200 OK)zContent-Typeztext/plain; charset=utf-8zutf-8)iort   printsortedrW   reprgetvalueencode)environstart_responsert   stdouthr^   r_   s          r   r	   r	      s    XZZF	.v&&&&	vw}}A * *!aDGG&)))))N8JKLLLOO$$W--..r!   c                 L     || |f|          }|                     |           |S )zACreate a new WSGI server listening on `host` and `port` for `app`)r9   )r\   portappserver_classhandler_classrI   s         r   r
   r
      s0     \4,66F
NN3Mr!   __main__r*   i@  zServing HTTP onr   r   z...zhttp://localhost:8000/xyz?abc) r:   http.serverr   r   rb   urllib.parserO   wsgiref.handlersr   platformr   rr   __all__rL   versionr   sys_versionr   r   r   r   r	   r
   r   httpdsocketgetsocknamesarx   
webbrowseropenhandle_requestr    r!   r   <module>r      sS  
 
 ; : : : : : : : 



     * * * * * * * * * * * *
I
I
I ,##%%+ck.?.?.A.A!.DD!C'+5 
& 
& 
& 
& 
&M 
& 
& 
&' ' ' ' ' ' ' ':?+ ?+ ?+ ?+ ?+/ ?+ ?+ ?+F	/ 	/ 	/ #-<N    z	Rx	(	( E\%%''A1u===
7888                  s   %ADDD