mò "á¸Ec@sdZdklZdkZdkZdklZdklZdkl Z dk Z dk l Z dk l Z dklZd klZd klZd klZlZlZdkZd klZd klZdkZdkZdkZdk Z dk!Z!dk"l#Z#l$Z$eƒZ%de&fd„ƒYZ'dei(fd„ƒYZ)dei*fd„ƒYZ+defd„ƒYZ,dfd„ƒYZ-dS(s Medusa PCGI server. This server functions as the PCGI publisher--it accepts the request from the PCGI wrapper CGI program, services the request, and sends back the response. It should work with both inet and unix domain sockets. Why would you want to use it? Using PCGI to connect to ZServer from another webserver is similar to using the web server as a proxy, with the difference, that the web server gets to control the environment and headers completely. Note that ZServer can operate multiple PCGI servers. (sloggerN(scounter(scompute_timezone_for_log(scompact_traceback(srequestCloseOnExec(shandle(sWakeup(s HTTPResponse(s HTTPRequest(sShutdownProducersLoggingProducersCallbackProducer(sStringIO(s TemporaryFile(s TupleTypes StringTypest ParseErrorcBstZRS(N(t__name__t __module__(((t1/data/zmath/zope/lib/python/ZServer/PCGIServer.pyR6st PCGIChannelcBshtZdZdZd„Zd„Zd„Zd„Zd„Zd„Z dd „Z d „Z d „Z RS( s˜Processes a PCGI request by collecting the env and stdin and then passing them to ZPublisher. The result is wrapped in a producer and sent back.icCsg||_||_tii||ƒt|ƒh|_t ƒ|_ |i dƒd|_ d|_dS(Ni (tservertselftaddrtasynchatt async_chatt__init__tsocktrequestCloseOnExectenvtStringIOtdatatset_terminatortNonetsizetdone(RRR R((RR @s       cCs¤|idjo¾|iidƒti|iiƒƒ|_|i|iƒ|idjo@t i dt |ƒdƒ|idƒt ƒ|_|i ƒq |idjotdƒ|_q t ƒ|_nÓ|ip…d|_|iidƒ|iiƒ}xPti|dƒD]<}y,ti|ddƒ\}}||i|tmethodRttypet TupleTypetloggerR"ttimetstrftimet localtimet tz_for_logt reply_codetbytestgmtime(RRQRRGRFR0RH((Rt log_request“s( : icCs)|ii|ƒ|o|iƒndS(N(Rt producer_fifotpushtproducertsendt initiate_send(RRVRW((RRUÀscCsdt|ƒS(Ns(R#R(R((Rt__repr__ÇscCswd|_xW|ioL|iiƒ}|dj ot|tƒ o|iƒn|ii ƒq Wt i i |ƒdS(Ni( RtclosedRTtfirsttpRt isinstancet StringTypestmoretpoptasyncoret dispatchertclose(RR\((RRcÊs  ( RRt__doc__RZR R5R$R@RARSRURYRc(((RR9s  8   -  t PCGIServerc BsktZdZeZddeeeeeed„Zd„Zd„Zd„Z d„Z d„Z d „Z RS( s÷Accepts PCGI requests and hands them off to the PCGIChannel for handling. PCGIServer can be configured with either a PCGI info file or by directly specifying the module, pid_file, and either port (for inet sockets) or socket_file (for unix domain sockets.) For inet sockets, the ip argument specifies the address from which the server will accept connections, '' indicates all addresses. If you only want to accept connections from the localhost, set ip to '127.0.0.1'.tMains 127.0.0.1c CsL||_tii|ƒtƒ|_|pti t i ƒ}n|oti ||ƒ|_nti|ƒ|_||_||_||_||_|dj o|i|ƒny9t|idƒ} | ittiƒƒƒ| iƒWn#tj o|iddƒnX|iof|it i!t i"ƒ|i#ƒ|i$|i|ifƒ|idt%i&t%i%ƒƒ|ifƒn·yti'|iƒWnti(j onX|it i)t i"ƒ|i#ƒ|i$|iƒyti*|idƒWnti(j onX|idt%i&t%i%ƒƒ|ifƒ|i+dƒdS(NtwsCannot write PID file.terrors/PCGI Server started at %s Inet socket port: %siÿs*PCGI Server started at %s Unix socket: %si(,tipRRaRbR tcountertcountt logger_objectRKt file_loggertsysR6tresolvertresolving_loggertunresolving_loggerR>tporttpid_filet socket_filet pcgi_fileRt read_infotopentfR?tstrtostgetpidRctIOErrortlog_infot create_sockettsockettAF_INETt SOCK_STREAMtset_reuse_addrtbindRLtctimetunlinkRhtAF_UNIXtchmodtlisten( RR>RiRrRtRsRuRoRlRx((RR ãsL         - )cCs'tii|||ƒt|iƒdS(N(RaRbR~RtfamilyRIR R(RR‰RI((RR~"sc Cs|t|ƒiƒ}h}yxz|D]r}ti|ƒ}t|ƒ p|ddjoq"nti |ddƒ\} }ti|ƒ|ti| ƒR0Rztsplitexttext( RRR’R•R“R>R*R0R(R)((RRv&s0$  cCsg|iiƒy|iƒ\}}Wn*tij o|iddƒdSnX|i |||ƒdS(Ns"Server accept() threw an exceptiontwarning( RRkt incrementtaccepttconnRRRhR}t channel_class(RRR™((Rt handle_accept@s  cCs dkl}ttiƒ|jS(N(sCONNECTION_LIMIT(tZServertCONNECTION_LIMITR2Rat socket_map(RR((RRAIs cCsdS(Ni((R((RtwritableMscCsd|_|ii|ƒS(Ni(Rt acceptingRRˆtnum(RR¡((RRˆPs ( RRRdRRšRR R~RvR›RARŸRˆ(((RReÔs !?    R8cBstZd„Zd„ZRS(NcCsjt|ƒtdƒjotdƒ‚n|ip#|iit|ƒƒd|_n|ii|ƒdS(NRCsValue must be a stringi(RIRt TypeErrorRt_wroteR6R?Ry(RR((RR?Xs   cCs3|ii|ƒ|iiƒd|_d|_dS(N(RR6tfinishRcRt_request(R((Rt_finishas  (RRR?R¦(((RR8Vs R9cBs2tZdZd„Zd„Zd„Zd„ZRS(sÛ Formats a HTTP response in PCGI format 10 digits indicating len of STDOUT STDOUT 10 digits indicating len of STDERR STDERR Note that this implementation never sends STDERR cCs"||_tƒ|_d|_dS(Ni(tchannelRt_channelRt_datat _shutdown(RR§((RR ts  cCs|ii|ƒdS(N(RR©R?ttext(RR«((RR?yscCsS|iip0|iiƒ}t|ƒ}ti dt |iƒd|ii |fƒ|ii d||dfdƒ|ii t |i|dƒdƒ|ii tdt |iƒfd„ƒdƒ|ioQy|id}Wn d}nX|t_|ii tƒdƒtd„ƒq=|ii ddƒtƒnd|_d|_dS( NtAs%s %ss %010d%s%010diRStEcCstti|ƒS(N(tapplyR!R"tt(R¯((Rt…scCs tiƒS(N(Rat close_all(((RR°Œs(RR¨RZR©tgetvalueRR2tlR!R"R#RPRUtLoggingProducertCallbackProducerRªtrRœt exit_codetShutdownProducertWakeupR(RR³R¶R((RRc|s*   "'     cCs-|iƒo d|_n|i|i_dS(Ni(R:t_shutdownRequestedRRªtstatusR¨RP(RR:((RR¤“s  (RRRdR R?RcR¤(((RR9is    (.RdtmedusaRKRRatmedusa.counterRjtmedusa.http_servertcompute_timezone_for_logtcompact_tracebackRœR tPubCoreR=tPubCore.ZEventR¹tZPublisher.HTTPResponset HTTPResponsetZPublisher.HTTPRequestR;t ProducersR¸R´RµR!t cStringIORttempfileR%RRRzRnRLttypesRJR^ROt ExceptionRR RRbReR8R9(RRaR¿ReRÀR¹R RR!RµRÄRKR;R=RR´RORRnR^RJR%R¸RRRjRœRLR8RzR9((Rt?s.             - ›‚