;
Πβ"Ic            
   @   sS  d  Z  d d l m Z m Z d d l Z d d l Z d d l m Z d Z	 d d d d	 g Z
 d
 e	 Z d e j j   d Z e d e Z Gd   d e  Z Gd   d e  Z Gd   d e  Z d   Z e e d  Z e d k of e d d e  Z e j j   Z e d e d d e d d  d d l Z e j d  e j   n d S(   u*  BaseHTTPServer that implements the Python WSGI protocol (PEP 333, rev 1.21)

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.
i    (   u   BaseHTTPRequestHandleru
   HTTPServerN(   u   SimpleHandleru   0.1u
   WSGIServeru   WSGIRequestHandleru   demo_appu   make_serveru   WSGIServer/u   Python/u    c             B   s   |  Ee  Z e Z d    Z d S(   c          
   C   sB   z- |  j  j |  j j d d  d |  j  Wd  t j |   Xd  S(   Nu    i   i    (   u   request_handleru   log_requestu   statusu   splitu
   bytes_sentu   SimpleHandleru   close(   u   self(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   close   s    	$N(   u   __name__u
   __module__u   software_versionu   server_softwareu   close(   u
   __locals__(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   ServerHandler   s   
u   ServerHandlerc             B   s>   |  Ee  Z d  Z d Z d   Z d   Z d   Z d   Z d S(   u7   BaseHTTPServer that implements the Python WSGI protocolc             C   s   t  j |   |  j   d S(   u.   Override server_bind to store the server name.N(   u
   HTTPServeru   server_bindu   setup_environ(   u   self(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   server_bind1   s    c             C   sY   i  } |  _  |  j | d <d | d <t |  j  | d <d | d <d | d <d | d <d  S(	   Nu   SERVER_NAMEu   CGI/1.1u   GATEWAY_INTERFACEu   SERVER_PORTu    u   REMOTE_HOSTu   CONTENT_LENGTHu   SCRIPT_NAME(   u   base_environu   server_nameu   stru   server_port(   u   selfu   env(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   setup_environ6   s    


c             C   s   |  j  S(   N(   u   application(   u   self(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   get_app@   s    c             C   s   | |  _  d  S(   N(   u   application(   u   selfu   application(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   set_appC   s    N(	   u   __name__u
   __module__u   __doc__u   Noneu   applicationu   server_bindu   setup_environu   get_appu   set_app(   u
   __locals__(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu
   WSGIServer+   s   
		
	c             B   s3   |  Ee  Z d  e Z d   Z d   Z d   Z d S(   u   WSGIServer/c       	      C   sΥ  |  j  j j   } |  j | d <|  j | d <d |  j k o |  j j d d  \ } } n |  j d } } t j j	 |  | d <| | d <|  j
   } | |  j d k o | | d	 <n |  j d | d
 <|  j j d  d  k o |  j j   | d <n |  j d | d <|  j j d  } | o | | d <n x |  j D] } | j d d  \ } } | j d d  j   } | j   } | | k o q<n d | | k o | d | c d | 7<q<| | d | <q<W| S(   Nu   SERVER_PROTOCOLu   REQUEST_METHODu   ?i   u    u	   PATH_INFOu   QUERY_STRINGi    u   REMOTE_HOSTu   REMOTE_ADDRu   content-typeu   CONTENT_TYPEu   content-lengthu   CONTENT_LENGTHu   :u   -u   _u   HTTP_u   ,(   u   serveru   base_environu   copyu   request_versionu   commandu   pathu   splitu   urllibu   parseu   unquoteu   address_stringu   client_addressu   headersu   getu   Noneu   get_content_typeu   replaceu   upperu   strip(	   u   selfu   envu   pathu   queryu   hostu   lengthu   hu   ku   v(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   get_environX   s:    

  c             C   s   t  j S(   N(   u   sysu   stderr(   u   self(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu
   get_stderr}   s    c             C   sn   |  j  j   |  _ |  j   p d St |  j  |  j |  j   |  j    } |  | _ | j	 |  j
 j    d S(   u   Handle a single HTTP requestN(   u   rfileu   readlineu   raw_requestlineu   parse_requestu   ServerHandleru   wfileu
   get_stderru   get_environu   request_handleru   runu   serveru   get_app(   u   selfu   handler(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   handle   s    $	N(   u   __name__u
   __module__u   __version__u   server_versionu   get_environu
   get_stderru   handle(   u
   __locals__(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   WSGIRequestHandlerT   s   

	%	c             C   s   d d l  m } |   } t d d | t d |  |  j   } | j   x0 | D]( \ } } t | d t |  d | qS W| d d	 g  | j   g S(
   Ni    (   u   StringIOu   Hello world!u   fileu   =u   200 OKu   Content-Typeu
   text/plain(   u   Content-Typeu
   text/plain(   u   iou   StringIOu   printu   itemsu   sortu   repru   getvalue(   u   environu   start_responseu   StringIOu   stdoutu   hu   ku   v(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   demo_app¦   s    	 
  c             C   s&   | |  | f |  } | j  |  | S(   uA   Create a new WSGI server listening on `host` and `port` for `app`(   u   set_app(   u   hostu   portu   appu   server_classu   handler_classu   server(    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   make_server²   s    u   __main__u    i@  u   Serving HTTP onu   porti   u   ...u   http://localhost:8000/xyz?abc(   u   __doc__u   http.serveru   BaseHTTPRequestHandleru
   HTTPServeru   sysu   urllib.parseu   urllibu   wsgiref.handlersu   SimpleHandleru   __version__u   __all__u   server_versionu   versionu   splitu   sys_versionu   software_versionu   ServerHandleru
   WSGIServeru   WSGIRequestHandleru   demo_appu   make_serveru   __name__u   httpdu   socketu   getsocknameu   sau   printu
   webbrowseru   openu   handle_request(    (    (    u2   /mit/python/lib/python3.0/wsgiref/simple_server.pyu   <module>   s*   
)R	