mò %U²Ic@sªdZdZdgZdkZdkZdkZdkZdkZdkZdei fd„ƒYZ e a d„Z d„Ze eid„Zedjo eƒndS( srCGI-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. s0.4tCGIHTTPRequestHandlerNcBsƒtZdZeedƒZeedƒZeedƒZdZd„Z d„Z d„Z dd gZ d „Z d „Zd „ZRS( 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. tforktpopen2tpopen3icCs/|iƒo|iƒn|iddƒdS(sRServe a POST request. This is only implemented for CGI scripts. iõsCan only POST to CGI scriptsN(tselftis_cgitrun_cgit send_error(R((t*/data/zmath/lib/python2.4/CGIHTTPServer.pytdo_POST3s cCs/|iƒo|iƒSntii|ƒSdS(s-Version of send_head that support CGI scriptsN(RRRtSimpleHTTPServertSimpleHTTPRequestHandlert send_head(R((RR ?s cCs~|i}xn|iD]c}t|ƒ}|| |jo@|| p||djo#|| ||df|_tSqqWtS(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). t/iN( Rtpathtcgi_directoriestxtlentitcgi_infotTruetFalse(RRRR((RRFs    . s/cgi-bins/htbincCs t|ƒS(s1Test whether argument path is an executable file.N(t executableR(RR((Rt is_executable_scCs(tii|ƒ\}}|iƒdjS(s.Test whether argument path is a Python script.s.pys.pywN(s.pys.pyw(tosRtsplitexttheadttailtlower(RRRR((Rt is_pythoncsc*CsÓ |i\}(} | idƒ}"|"djo| |" | |"d} } nd} | idƒ}"|"djo| |" | |"}} n| d}} |(d|}|i |ƒ}&t i i|&ƒp|idd|ƒdSnt i i|&ƒp|id d |ƒdSn|i|ƒ}|pj|ip|ip|ip|id d |ƒdSn|i|&ƒp|id d |ƒdSq‹nh}|iƒ|d <|ii|d|$dƒqŽWt i?i@|ƒ|iAd-d.ƒ| iBd/d0ƒ} |io~|g}d1| jo|i6| ƒntEƒ}|iGiHƒt iIƒ}|djo~t iK|dƒ\}}'x@tMiM|iNgggdƒdo|iNiOdƒpPqUqUW|'o|iPd2|'ƒndSnyvyt iQ|ƒWnt iRj onXt iS|iNiTƒdƒt iS|iGiTƒdƒt iU|&|t i?ƒWqÏ |iiV|iW|i$ƒt iXd3ƒqÏ Xnn|ip |ioVdkY} |io t iZ}n t i\}|&}|i|&ƒoIt^i_}|i,ƒiad4ƒo|d5 |d6}nd7||f}nd1| jo!d8| jod9|| f}n|ibd:|ƒytc|%ƒ}Wntetffj o d}nX||d;ƒ}|d}|d}!|io|d})n|ii,ƒd<jo0|djo#|iNiO|ƒ}|il|ƒnxFtMiM|iNimgggdƒdo|iNimindƒpPqòqòW|ioƒ| ip|!|iGƒ|io5|)iOƒ} |)ioƒ| o|iPd=| ƒq”n|!ioƒ}'|'o|iPd2|'ƒqÏ |ibd>ƒnt^ir}t^it}t^iv}t^ix} y¤t izƒ}z_|&gt^_rd1| jot^iri6| ƒn|iGt^_v|iNt^_tt||&hd?d@<ƒWd|t^_r|t^_t|t^_v| t^_xt i}|ƒXWn+t~j o}'|iPdAt|'ƒƒnX|ibd>ƒdS(CsExecute a CGI script.t?iitR i”sNo such CGI script (%r)Ni“s#CGI script is not a plain file (%r)s&CGI script is not a Python script (%r)s!CGI script is not executable (%r)tSERVER_SOFTWAREt SERVER_NAMEsCGI/1.1tGATEWAY_INTERFACEtSERVER_PROTOCOLt SERVER_PORTtREQUEST_METHODt PATH_INFOtPATH_TRANSLATEDt SCRIPT_NAMEt QUERY_STRINGt REMOTE_HOSTt REMOTE_ADDRt authorizationit AUTH_TYPEtbasict:t REMOTE_USERt CONTENT_TYPEscontent-lengthtCONTENT_LENGTHtaccepts it,t HTTP_ACCEPTs user-agenttHTTP_USER_AGENTtcookies, t HTTP_COOKIEiÈsScript output followst+t t=sCGI script exit status %#xisw.exeiûÿÿÿiüÿÿÿs%s -u %st"s%s "%s"s command: %stbtposts%ssCGI script exited OKt__name__t__main__sCGI script exit status %s(R)R*R2R6R8(RRtdirtresttrfindRtquerytfindtscriptt scriptnamettranslate_patht scriptfileRRtexistsRtisfileRtispyt have_forkt have_popen2t have_popen3Rtenvtversion_stringtservert server_nametprotocol_versiontstrt server_porttcommandturllibtunquotetuqresttaddress_stringthosttclient_addresstheaderst getheaderR,tsplitRtbase64tbinasciiRt decodestringtErrort typeheadertNonettypetlengthR3tgetallmatchingheaderstlinetappendtstriptjointuatfiltert getheaderstcotkt setdefaulttenvirontupdatet send_responsetreplacet decoded_querytargst nobody_uidtnobodytwfiletflushRtpidtwaitpidtststselecttrfiletreadt log_errortsetuidterrortdup2tfilenotexecvet handle_errortrequestt_exittshutilRtpopenxRtcmdlinetsysRtinterptendswitht log_messagetinttnbytest TypeErrort ValueErrortfilestfitfotfetdatatwritet_socktrecvtcloset copyfileobjterrorstargvt save_argvtstdint save_stdintstdoutt save_stdouttstderrt save_stderrtgetcwdtsave_cwdtexecfiletchdirt SystemExit(*RR¨RqR¤R~R3RRGR¦RDRBRRxR¢RFRaRbRPR,R•R˜R{R¬RLRŽR‘RyR\RZR™RjRœRªRšRRnRrRhRIR€RAR›((RRhsX                  #          #&                   (R?t __module__t__doc__thasattrRRMRNROtrbufsizeR R RRRRR(((RR s      cCs‰totSny dk}Wntj o dSnXy|idƒdaWn5tj o)dttd„|iƒƒƒanXtS(s$Internal routine to get nobody's uidNiÿÿÿÿR{iicCs|dS(Ni(R(R((RtBs(R{tpwdt ImportErrortgetpwnamtKeyErrortmaxtmaptgetpwall(Rµ((RRz6s  'cCsAyti|ƒ}Wntij o tSnX|id@djS(sTest for executable file.iIiN(RtstatRtstR†Rtst_mode(RR½((RRFs  cCsti||ƒdS(N(R ttestt HandlerClasst ServerClass(RÀRÁ((RR¿OsR@(R±t __version__t__all__RRRXtBaseHTTPServerR RR RRfR{RzRt HTTPServerR¿R?( RÃR RRXRRR¿RzRÄRÂRR((RRs        ÿ