ó
è¾bc           @   sc  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 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z e e d „ Z e d k r_e d d e ƒ Z e j j ƒ  Z d Ge d Gd Ge d Gd GHd d l Z e j d ƒ e j ƒ  e j ƒ  n  d S(   s*  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ÿÿÿÿ(   t   BaseHTTPRequestHandlert
   HTTPServerN(   t   SimpleHandlers   0.1t
   WSGIServert   WSGIRequestHandlert   demo_appt   make_servers   WSGIServer/s   Python/i    t    t   ServerHandlerc           B   s   e  Z e Z d  „  Z RS(   c         C   sB   z- |  j  j |  j j d d ƒ d |  j ƒ Wd  t j |  ƒ Xd  S(   NR   i   i    (   t   request_handlert   log_requestt   statust   splitt
   bytes_sentR   t   close(   t   self(    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR      s    	$(   t   __name__t
   __module__t   software_versiont   server_softwareR   (    (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR      s   c           B   s8   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z RS(   s7   BaseHTTPServer that implements the Python WSGI protocolc         C   s   t  j |  ƒ |  j ƒ  d S(   s.   Override server_bind to store the server name.N(   R   t   server_bindt   setup_environ(   R   (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR   .   s    c         C   sY   i  } |  _  |  j | d <d | d <t |  j ƒ | d <d | d <d | d <d | d <d  S(	   Nt   SERVER_NAMEs   CGI/1.1t   GATEWAY_INTERFACEt   SERVER_PORTt    t   REMOTE_HOSTt   CONTENT_LENGTHt   SCRIPT_NAME(   t   base_environt   server_namet   strt   server_port(   R   t   env(    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR   3   s    


c         C   s   |  j  S(   N(   t   application(   R   (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyt   get_app=   s    c         C   s   | |  _  d  S(   N(   R"   (   R   R"   (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyt   set_app@   s    N(	   R   R   t   __doc__t   NoneR"   R   R   R#   R$   (    (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR   (   s   		
	c           B   s-   e  Z d  e Z d „  Z d „  Z d „  Z RS(   s   WSGIServer/c   	      C   s¿  |  j  j j ƒ  } |  j | d <|  j | d <d |  j k rY |  j j d d ƒ \ } } n |  j d } } t j | ƒ | d <| | d <|  j	 ƒ  } | |  j
 d k r² | | d	 <n  |  j
 d | d
 <|  j j d  k rè |  j j | d <n |  j j | d <|  j j d ƒ } | r| | d <n  x› |  j j D] } | j d d ƒ \ } } | j d d ƒ j ƒ  } | j ƒ  } | | k r~q*n  d | | k r©| d | c d | 7<q*| | d | <q*W| S(   Nt   SERVER_PROTOCOLt   REQUEST_METHODt   ?i   R   t	   PATH_INFOt   QUERY_STRINGi    R   t   REMOTE_ADDRt   CONTENT_TYPEs   content-lengthR   t   :t   -t   _t   HTTP_t   ,(   t   serverR   t   copyt   request_versiont   commandt   pathR   t   urllibt   unquotet   address_stringt   client_addresst   headerst
   typeheaderR&   t   typet	   getheadert   replacet   uppert   strip(	   R   R!   R7   t   queryt   hostt   lengtht   ht   kt   v(    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyt   get_environI   s8    
 c         C   s   t  j S(   N(   t   syst   stderr(   R   (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyt
   get_stderrn   s    c         C   s°   |  j  j d ƒ |  _ t |  j ƒ d k rV d |  _ d |  _ d |  _ |  j d ƒ d S|  j ƒ  sf d St	 |  j  |  j
 |  j ƒ  |  j ƒ  ƒ } |  | _ | j |  j j ƒ  ƒ d S(   s   Handle a single HTTP requesti  i   R   iž  N(   t   rfilet   readlinet   raw_requestlinet   lent   requestlineR5   R6   t
   send_errort   parse_requestR   t   wfileRL   RI   R	   t   runR3   R#   (   R   t   handler(    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyt   handleq   s    			$	(   R   R   t   __version__t   server_versionRI   RL   RW   (    (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR   E   s   
	%	c         C   s   d d l  m  } | ƒ  } | d IJ| J|  j ƒ  } | j ƒ  x0 | D]( \ } } | | Id It | ƒ IJqD W| d d g ƒ | j ƒ  g S(	   Niÿÿÿÿ(   t   StringIOs   Hello world!t   =s   200 OKs   Content-Types
   text/plain(   s   Content-Types
   text/plain(   RZ   t   itemst   sortt   reprt   getvalue(   t   environt   start_responseRZ   t   stdoutRF   RG   RH   (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR   ‡   s    	
 
 c         C   s&   | |  | f | ƒ } | j  | ƒ | S(   sA   Create a new WSGI server listening on `host` and `port` for `app`(   R$   (   RD   t   portt   appt   server_classt   handler_classR3   (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyR   “   s    t   __main__R   i@  s   Serving HTTP onRc   i   s   ...s   http://localhost:8000/xyz?abc(   R%   t   BaseHTTPServerR    R   R8   RJ   t   wsgiref.handlersR   RX   t   __all__RY   t   versionR   t   sys_versionR   R   R   R   R   R   R   t   httpdt   sockett   getsocknamet   sat
   webbrowsert   opent   handle_requestt   server_close(    (    (    s+   /usr/lib/python2.7/wsgiref/simple_server.pyt   <module>   s*   
B	
