;ò
êŒü?c           @   sª   d  Z  d Z d g Z d k Z d k Z d k Z d k Z d k Z d k Z d e i	 f d „  ƒ  YZ
 e a d „  Z d „  Z e
 e i d „ Z e d j o e ƒ  n d S(	   sr  CGI-savvy HTTP Server.

This module builds on SimpleHTTPServer by implementing GET and POST
requests to cgi-bin scripts.

If the os.fork() function is not present (e.g. on Windows),
os.popen2() is used as a fallback, with slightly altered semantics; if
that function is not present either (e.g. on Macintosh), only Python
scripts are supported, and they are executed by the current process.

In all cases, the implementation is intentionally naive -- all
requests are executed sychronously.

SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL
-- it may execute arbitrary Python code or external programs.

s   0.4s   CGIHTTPRequestHandlerNc           B   sƒ   t  Z d  Z e e d ƒ Z e e d ƒ Z e e d ƒ Z d Z d „  Z	 d „  Z
 d „  Z d d	 g Z d
 „  Z d „  Z d „  Z RS(   s­   Complete HTTP server with GET, HEAD and POST commands.

    GET and HEAD also support running CGI scripts.

    The POST command is *only* implemented for CGI scripts.

    s   forks   popen2s   popen3i    c         C   s/   |  i ƒ  o |  i ƒ  n |  i d d ƒ d S(   sR   Serve a POST request.

        This is only implemented for CGI scripts.

        iõ  s   Can only POST to CGI scriptsN(   s   selfs   is_cgis   run_cgis
   send_error(   s   self(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   do_POST3   s     c         C   s/   |  i ƒ  o |  i ƒ  Sn t i i |  ƒ Sd S(   s-   Version of send_head that support CGI scriptsN(   s   selfs   is_cgis   run_cgis   SimpleHTTPServers   SimpleHTTPRequestHandlers	   send_head(   s   self(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys	   send_head?   s     c         C   s‚   |  i } xn |  i D]c } t | ƒ } | |  | j o | | p | | d j o# | |  | | d f |  _ t Sq q Wt Sd S(   s±  Test whether self.path corresponds to a CGI script.

        Return a tuple (dir, rest) if self.path requires running a
        CGI script, None if not.  Note that rest begins with a
        slash if it is not empty.

        The default implementation tests whether the path
        begins with one of the strings in the list
        self.cgi_directories (and the next character is a '/'
        or the end of the string).

        s   /i   N(	   s   selfs   paths   cgi_directoriess   xs   lens   is   cgi_infos   Trues   False(   s   selfs   is   xs   path(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   is_cgiF   s     	
 .s   /cgi-bins   /htbinc         C   s   t  | ƒ Sd S(   s1   Test whether argument path is an executable file.N(   s
   executables   path(   s   selfs   path(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   is_executable_   s     c         C   s2   t  i i | ƒ \ } } | i ƒ  d d f j Sd S(   s.   Test whether argument path is a Python script.s   .pys   .pywN(   s   oss   paths   splitexts   heads   tails   lower(   s   selfs   paths   tails   head(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys	   is_pythonc   s     c   &      C   s	  |  i \ }$ } | i d ƒ } | d j o" | |  | | d f \ } }	 n d }	 | i d ƒ } | d j o | |  | | f \ } } n | d f \ } } |$ d | } |  i
 | ƒ }! t i i |! ƒ o |  i d d | ƒ d Sn t i i |! ƒ o |  i d	 d
 | ƒ d Sn |  i | ƒ } | on |  i p |  i p |  i o |  i d	 d | ƒ d Sn |  i |! ƒ o |  i d	 d | ƒ d Sq£n h  } |  i ƒ  | d <|  i i | d <d | d <|  i | d <t |  i i ƒ | d <|  i | d <t i  | ƒ } | | d <|  i
 | ƒ | d <| | d <|	 o |	 | d <n |  i" ƒ  } | |  i$ d j o | | d <n |  i$ d | d <|  i% i& t' j o |  i% i( | d <n |  i% i& | d <|  i% i) d ƒ }  |  o |  | d <n g  } xY |  i% i, d ƒ D]E } | d  d j o | i. | i/ ƒ  ƒ q| | d i0 d  ƒ } qWd  i1 | ƒ | d! <|  i% i) d" ƒ }# |# o |# | d# <n t3 t' |  i% i4 d$ ƒ ƒ } | o d% i1 | ƒ | d& <n |  i o4 x1 d d d d# d& f D] } | i7 | d ƒ qáWn t i8 i9 | ƒ |  i: d' d( ƒ |	 i; d) d* ƒ } |  i o| g } d+ | j o | i. | ƒ n t> ƒ  } |  i@ iA ƒ  t iB ƒ  } | d j o t iD | d ƒ \ } }" xA tF iF |  iG g g  g  d ƒ d o |  iG iH d ƒ o Pq¬q¬W|" o |  iI d, |" ƒ n d Sn yv y t iJ | ƒ Wn t iK j
 o n Xt iL |  iG iM ƒ  d ƒ t iL |  i@ iM ƒ  d ƒ t iN |! | t i8 ƒ Wq	|  i iO |  iP |  i$ ƒ t iQ d- ƒ q	XnV|  i p |  i oWd kR }
 |  i o t iS } n
 t iU } |! } |  i |! ƒ oI tW iX } | iZ ƒ  i[ d. ƒ o | d/  | d0 } n d1 | | f } n d+ |	 j o
 d2 |	 j o d3 | |	 f } n |  i\ d4 | ƒ y t] |  ƒ } Wn t_ t` f j
 o d } n X| | d5 ƒ } | d } | d } |  i o | d6 }% n |  i iZ ƒ  d7 j o
 | d j o# |  iG iH | ƒ } | if | ƒ n xG tF iF |  iG ig g g  g  d ƒ d o  |  iG ig ih d ƒ o PqJqJW| ii ƒ  |
 ij | |  i@ ƒ |  i o5 |% iH ƒ  } |% ii ƒ  | o |  iI d8 | ƒ qín | ii ƒ  }" |" o |  iI d, |" ƒ q	|  i\ d9 ƒ në tW il } tW in } tW ip } tW ir } y‹ z_ |! g tW _l d+ | j o tW il i. | ƒ n |  i@ tW _p |  iG tW _n tt |! h  d: d; <ƒ Wd | tW _l | tW _n | tW _p | tW _r XWn+ tu j
 o }" |  iI d< t |" ƒ ƒ n X|  i\ d9 ƒ d S(=   s   Execute a CGI script.s   ?i    i   s    s   /i”  s   No such CGI script (%s)Ni“  s#   CGI script is not a plain file (%s)s&   CGI script is not a Python script (%s)s!   CGI script is not executable (%s)s   SERVER_SOFTWAREs   SERVER_NAMEs   CGI/1.1s   GATEWAY_INTERFACEs   SERVER_PROTOCOLs   SERVER_PORTs   REQUEST_METHODs	   PATH_INFOs   PATH_TRANSLATEDs   SCRIPT_NAMEs   QUERY_STRINGs   REMOTE_HOSTs   REMOTE_ADDRs   CONTENT_TYPEs   content-lengths   CONTENT_LENGTHs   accepts   	
 i   s   ,s   HTTP_ACCEPTs
   user-agents   HTTP_USER_AGENTs   cookies   , s   HTTP_COOKIEiÈ   s   Script output followss   +s    s   =s   CGI script exit status %#xi   s   w.exeiûÿÿÿiüÿÿÿs   %s -u %ss   "s   %s "%s"s   command: %ss   bi   s   posts   %ss   CGI script exited OKs   __name__s   __main__s   CGI script exit status %s(v   s   selfs   cgi_infos   dirs   rests   rfinds   is   querys   finds   scripts
   scriptnames   translate_paths
   scriptfiles   oss   paths   existss
   send_errors   isfiles	   is_pythons   ispys	   have_forks   have_popen2s   have_popen3s   is_executables   envs   version_strings   servers   server_names   protocol_versions   strs   server_ports   commands   urllibs   unquotes   uqrests   address_strings   hosts   client_addresss   headerss
   typeheaders   Nones   types	   getheaders   lengths   accepts   getallmatchingheaderss   lines   appends   strips   splits   joins   uas   filters
   getheaderss   cos   ks
   setdefaults   environs   updates   send_responses   replaces   decoded_querys   argss
   nobody_uids   nobodys   wfiles   flushs   forks   pids   waitpids   stss   selects   rfiles   reads	   log_errors   setuids   errors   dup2s   filenos   execves   handle_errors   requests   _exits   shutils   popen3s   popenxs   popen2s   cmdlines   syss
   executables   interps   lowers   endswiths   log_messages   ints   nbytess	   TypeErrors
   ValueErrors   filess   fis   fos   fes   datas   writes   _socks   recvs   closes   copyfileobjs   errorss   argvs	   save_argvs   stdins
   save_stdins   stdouts   save_stdouts   stderrs   save_stderrs   execfiles
   SystemExit(&   s   selfs   save_stdouts   cos	   save_argvs   pids   uqrests   cmdlines
   scriptnames
   save_stdins   querys   shutils   decoded_querys   errorss   scripts   accepts   nbytess   filess   nobodys   ispys   popenxs   interps   argss   hosts   rests   fis   lines   datas   save_stderrs   fos   envs   is   ks   lengths
   scriptfiles   stss   uas   dirs   fe(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   run_cgih   s:    "


  
		 #
	
		


# &



				 			(   s   __name__s
   __module__s   __doc__s   hasattrs   oss	   have_forks   have_popen2s   have_popen3s   rbufsizes   do_POSTs	   send_heads   is_cgis   cgi_directoriess   is_executables	   is_pythons   run_cgi(    (    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   CGIHTTPRequestHandler    s    					c          C   s   t  o t  Sn y d k }  Wn t j
 o d Sn Xy |  i d ƒ d a  Wn5 t j
 o) d t t d „  |  i ƒ  ƒ ƒ a  n Xt  Sd S(   s$   Internal routine to get nobody's uidNiÿÿÿÿs   nobodyi   i   c         C   s   |  d S(   Ni   (   s   x(   s   x(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   <lambda>4  s    (   s   nobodys   pwds   ImportErrors   getpwnams   KeyErrors   maxs   maps   getpwall(   s   pwd(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys
   nobody_uid(  s      	'c         C   sE   y t  i |  ƒ } Wn t  i j
 o t Sn X| i d @d j Sd S(   s   Test for executable file.iI   i    N(   s   oss   stats   paths   sts   errors   Falses   st_mode(   s   paths   st(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys
   executable8  s     	c         C   s   t  i |  | ƒ d  S(   N(   s   SimpleHTTPServers   tests   HandlerClasss   ServerClass(   s   HandlerClasss   ServerClass(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   testA  s    s   __main__(   s   __doc__s   __version__s   __all__s   oss   syss   urllibs   BaseHTTPServers   SimpleHTTPServers   selects   SimpleHTTPRequestHandlers   CGIHTTPRequestHandlers   Nones   nobodys
   nobody_uids
   executables
   HTTPServers   tests   __name__(   s   __all__s   SimpleHTTPServers
   executables   urllibs   CGIHTTPRequestHandlers   syss   tests
   nobody_uids   BaseHTTPServers   __version__s   oss   select(    (    s*   /mit/python/lib/python2.3/CGIHTTPServer.pys   ?   s    							ÿ 			