mς %άGc@smdklZdklZdklZdZdefd„ƒYZdfd„ƒYZdfd „ƒYZd S( (s spyceModule(s NoCloseOut(sStringIOs…Sets the thread-safe server stdout to the response object for convenience of using print statements, and supports output redirection.tstdoutcBsDtZd„Zdd„Zdd„Zd„Zd„Zd„ZRS(NcCs}g|_|iiƒ|_|iit|ƒƒy|iiƒi|_ Wn,t j o h|_ |iiƒ_nXdS(N( tselft outputStackt_apit getStdoutRt setStdouttmyResponseWrappertgetServerObjecttmemoizedt memoizeCachetAttributeError(R((t2/home/holguin2/public_html/spyce/modules/stdout.pytstarts cCs3x|io|iƒqW|ii|iƒdS(N(RRtpopRRR(RttheError((R tfinishs cCs•|iiƒ}|iidƒ}t|ƒ}|ii|ƒ|ii ddƒ|iƒ}|ii d|ƒ|i ƒ|i i|||fƒdS(sRedirect stdout to buffertresponses response.pyN(RRt getResponset old_responset getModuletold_response_modtspyceCaptureResponset new_responset setResponset spyceModuletnew_response_modt setModuleR Rtappendtfile(RRRRRR((R tpush!s  cCsή|iidƒiƒ|iiƒiƒ}|iiƒ\}}}|ii d|ƒ|ii |ƒ|omtiitii|iiƒƒ|ƒ}d}z t|dƒ}|i|ƒWd|o|iƒnXn|S(s/Return buffer value, and possible write to fileRtwN(RRRRRtgetCapturedOutputtbufferRR RRRRRtostpathtjointdirnamet getFilenametNonetouttopentwritetclose(RRR RRR'((R R +s *cOs8|}|iƒt|||ƒ}|iƒ}||fS(s-Capture the output side-effects of a functionN( t_spyceReservedtfRRtapplytargstkwargstrR ts(RR+R.R/R,R1R0((R tcapture;s   cCs-t|dƒodt|iƒSndSdS(NRsstdout depth: %ssstdout not started(thasattrRtlenR(R((R t__repr__Bs( t__name__t __module__R R&RRR R2R5(((R Rs    RcBs#tZd„Zd„Zd„ZRS(NcCs*||_|ii|iƒ|iƒdS(N(tmodRt_modRtregisterModuleCallbackt syncResponse(RR8((R t__init__Is cCs=|iiidƒ}|i|_|i|_|i|_dS(NR(RR9RRRR)twritelntflush(RR((R R;Ms  cCs d‚dS(Nsmethod not allowed((R((R R*Ss(R6R7R<R;R*(((R RHs  RcBsbtZdZd„Zd„Zd„Zd„Zd„Zdd„Zd„Z d „Z d „Z RS( s0Capture output, and let everything else through.cCs||_tƒ|_dS(N(RRt _old_responsetStringIOt_buf(RR((R R<Xs cCs|ii|ƒdS(N(RRAR)R1(RR1((R R)[scCs d‚dS(Ns*cannot close output while capturing output((R((R R*]scCstƒ|_dS(N(R@RRA(R((R tclear_scCs d‚dS(Ns*cannot sendHeaders while capturing output!((R((R t sendHeadersasicCsdS(N((RtstopFlag((R R>cscCs d‚dS(Ns.cannot unbuffer output while capturing output!((R((R tunbufferescCstd|ƒS(Nsself._old_response.%s(tevaltname(RRG((R t __getattr__gscCs |iiƒS(N(RRAtgetvalue(R((R Ris( R6R7t__doc__R<R)R*RBRCR>RERHR(((R RVs         N( Rt spyceUtilt NoCloseOutt cStringIOR@RJRRR(RR@RRRLRRJ((R t? s   8