‡Æ
¸Mö9c       sÑ     d  Z    d 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
 Z d „  Z "d „  Z +e	 e i d „ Z 0e d j o 1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.4Ns   CGIHTTPRequestHandlerc      s’    d  Z  ' * e e d ƒ Z + e e d ƒ Z / d Z 1 d „  Z = d „  Z D d „  Z [ d d g Z	 ] d	 „  Z
 a d
 „  Z f 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   popen2i    c    s>   1 6 8 |  i ƒ  o 9 |  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   selfs*   /mit/python/lib/python2.0/CGIHTTPServer.pys   do_POST1 s   c    s>   = > ? |  i ƒ  o @ |  i ƒ  Sn B 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   selfs*   /mit/python/lib/python2.0/CGIHTTPServer.pys	   send_head= s   c    s¢   D P R |  i } T x |  i d T ro } U t | ƒ } V | |  | j o | | p | | d j o) W | |  | | d f |  _ X d Sn q! WY d 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).

        i    s   /i   N(   s   selfs   paths   cgi_directoriess   xs   lens   is   cgi_info(   s   selfs   paths   xs   is*   /mit/python/lib/python2.0/CGIHTTPServer.pys   is_cgiD s    	1s   /cgi-bins   /htbinc    s   ] ^ _ t  | ƒ Sd S(   s1   Test whether argument path is an executable file.N(   s
   executables   path(   s   selfs   paths*   /mit/python/lib/python2.0/CGIHTTPServer.pys   is_executable] s   c    s>   a b c t  i i | ƒ \ } } d | 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   heads   tails*   /mit/python/lib/python2.0/CGIHTTPServer.pys	   is_pythona s   c "   s¦	  f g h |  i \ } } i t i | d ƒ } j | d j o% k | |  | | d f \ } } n
 m d } n t i | d ƒ } o | d j o! p | |  | | f \ } } n r | d f \ } } s | d | } t |  i | ƒ } u t i i | ƒ o# v |  i d d | ƒ w d Sn x t i i | ƒ o# y |  i d	 d
 | ƒ { d Sn | |  i | ƒ } } | ov ~ |  i p |  i o#  |  i d	 d | ƒ  d Sn ‚ |  i | ƒ o# ƒ |  i d	 d | ƒ … d Sn 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  } ¥ xp |  i% i, d ƒ d ¥ rW } ¦ | d  t i. j o § | i/ t i0 | ƒ ƒ n © | t i1 | d d ƒ } qžWª t i2 | d ƒ |	 d  <« |  i% i) d! ƒ } ¬ | o ­ | |	 d" <n ® t4 t' |  i% i5 d# ƒ ƒ } ¯ | o ° t i7 | d$ ƒ |	 d% <n ² |  i o? µ x5 d d d d" d% f d µ r } · |	 i9 | d ƒ q³Wn ¹ |  i: d& d' ƒ » t i; | d( d) ƒ } ½ |  i oz¿ | g } À d* | j o Á | i/ | ƒ n Â t> ƒ  } Ã |  i@ iA ƒ  Ä t iB ƒ  } Å | d j oG Ç t iD | d ƒ \ } } È | o É |  iF d+ | ƒ n Ê d Sn Ì yˆ Í y Î t iG | ƒ Wn Ï t iH j
 o
 Ð n XÑ t iI |  iJ iK ƒ  d ƒ Ò t iI |  i@ iK ƒ  d ƒ Ó t iL | | |	 ƒ Wn6 Ô Õ |  i iM |  iN |  i$ ƒ Ö t iO d, ƒ n XnØ |  i oÓÚ d kP } Û t iQ iR |	 ƒ Ü | } Ý |  i | ƒ oW Þ tT iU } ß | iW ƒ  iX d- ƒ o á | d. } | d/ *n â d0 | | f } n ã d* | j o
 d1 | j o ä d2 | | f } n å |  iF d3 | ƒ æ y ç tY | ƒ } Wn è é d } n Xê t i[ | ƒ \ } } ë |  i iW ƒ  d4 j o
 | d j o) ì |  iJ i^ | ƒ } í | i` | ƒ n î | ia ƒ  ï | ib | |  i@ ƒ ð | ia ƒ  } ñ | o ò |  iF d+ | ƒ n ô |  iF d5 ƒ n:ø t iQ iR |	 ƒ ù tT ic } ú tT ie } û tT ig }  ü tT ii }! ý y¯ þ zq ÿ | g tT _c  d* | j o tT ic i/ | ƒ n |  i@ tT _g |  iJ tT _e tk | h  d6 d7 <ƒ Wd | tT _c | tT _e |  tT _g 	|! tT _i XWn1 
tl j
 o" } |  iF d8 t | ƒ ƒ n X|  iF d5 ƒ d S(9   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   accepti   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 %ss   "s   %s "%s"s   command: %ss   posts   CGI script exited OKs   __main__s   __name__s   CGI script exit status %s(m   s   selfs   cgi_infos   dirs   rests   strings   rfinds   is   querys   finds   scripts
   scriptnames   translate_paths
   scriptfiles   oss   paths   existss
   send_errors   isfiles	   is_pythons   ispys	   have_forks   have_popen2s   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
   whitespaces   appends   strips   splits
   joinfieldss   uas   filters
   getheaderss   cos   joins   ks
   setdefaults   send_responses   replaces   decoded_querys   argss
   nobody_uids   nobodys   wfiles   flushs   forks   pids   waitpids   stss	   log_errors   setuids   errors   dup2s   rfiles   filenos   execves   handle_errors   requests   _exits   shutils   environs   updates   cmdlines   syss
   executables   interps   lowers   endswiths   ints   nbytess   popen2s   fis   fos   reads   datas   writes   closes   copyfileobjs   argvs	   save_argvs   stdins
   save_stdins   stdouts   save_stdouts   stderrs   save_stderrs   execfiles
   SystemExit("   s   selfs   dirs   rests   is   querys   scripts
   scriptnames
   scriptfiles   ispys   envs   uqrests   hosts   lengths   accepts   lines   uas   cos   ks   decoded_querys   argss   nobodys   pids   stss   shutils   cmdlines   interps   nbytess   fis   fos   datas	   save_argvs
   save_stdins   save_stdouts   save_stderrs*   /mit/python/lib/python2.0/CGIHTTPServer.pys   run_cgif s  %	!	

	 	!

 	
	&
(   s   __doc__s   hasattrs   oss	   have_forks   have_popen2s   rbufsizes   do_POSTs	   send_heads   is_cgis   cgi_directoriess   is_executables	   is_pythons   run_cgi(    s*   /mit/python/lib/python2.0/CGIHTTPServer.pys   CGIHTTPRequestHandler s   		c     s¸   t  o t  Sn y d k }  Wn t j
 o d Sn Xy |  i d ƒ d a  Wn; t j
 o, d t t d „  |  i ƒ  ƒ ƒ a  n Xt  Sd S(   s$   Internal routine to get nobody's uidNi   s   nobodyi   c    s   |  d S(   Ni   (   s   x(   s   xs*   /mit/python/lib/python2.0/CGIHTTPServer.pys   <lambda>s    (   s   nobodys   pwds   ImportErrors   getpwnams   KeyErrors   maxs   maps   getpwall(   s   pwds*   /mit/python/lib/python2.0/CGIHTTPServer.pys
   nobody_uids   
*c    s[   "#$y %t  i |  ƒ } Wn  &t  i j
 o 'd Sn X(| d d @d j Sd S(   s   Test for executable file.i    iI   N(   s   oss   stats   paths   sts   error(   s   paths   sts*   /mit/python/lib/python2.0/CGIHTTPServer.pys
   executable"s   c    s   +-t  i |  | ƒ d  S(   N(   s   SimpleHTTPServers   tests   HandlerClasss   ServerClass(   s   HandlerClasss   ServerClasss*   /mit/python/lib/python2.0/CGIHTTPServer.pys   test+s   s   __main__(   s   __doc__s   __version__s   oss   syss   strings   urllibs   BaseHTTPServers   SimpleHTTPServers   SimpleHTTPRequestHandlers   CGIHTTPRequestHandlers   Nones   nobodys
   nobody_uids
   executables
   HTTPServers   tests   __name__(    s*   /mit/python/lib/python2.0/CGIHTTPServer.pys   ? s   	ñ		