m o%Gc@s$dZdZeadZdZdkZdkZdkZdk Z dk Z dk Z dk Z dk Z dkZdkZdkZdkZdkZdkZdkZdZdZeaedZeadZd Zd Zd d d dfZhZdfdYZ dfdYZ!dfdYZ"dfdYZ#dfdYZ$dfdYZ%dZ&dZ'dZ(dZ)dZ*d Z+d!Z,d"eeed#Z-d"eeed$Z.eeed%Z/e0d&jo-e1ei2i3ei2i4e5d'd(ndS()s2.1t3cCs#totiid|ndS(Ns%s (t DEBUG_ERRORtsyststderrtwritets(R((t)/home/holguin2/public_html/spyce/spyce.pytDEBUGssy Spyce is a server-side language that supports elegant and efficient Python-based dynamic HTML generation. Spyce allows embedding Python in pages similar to how JSP embeds Java, but Spyce is far more than a JSP clone. Out of the box, Spyce provides development as rapid as other modern frameworks like Rails, but with an cohesive design rather than a morass of special cases. NidicCsJtp?|pdk}|i}ntd|it|ntS(Ns!creating server with config from (t SPYCE_SERVERtconfigt spycePreloadtgetConfigModuleRt__file__t spyceServer(R R ((Rt getServer1s cCstS(N(t SPYCE_GLOBALS(((RtgetServerGlobals<st spyceLoadert SPYCE_ENTRYtrequesttresponsetstdoutterrortspyceServerObjectcBstZdZRS(sserverObject placeholder(t__name__t __module__t__doc__(((RRLs R cBs}tZdZdZdZdZdZdZeedZ deedZ deed Z eed Z RS( sNOne per server, stored in SPYCE_SERVER (above) at processing of first request.c Bsi|ae|_yeie|_Wnd|_nX||_|ii a |ii |_ |i a |ii |_ |ii|_h|_h|_|ii}|ddjo,|d|i|d|ddf}n||_|ii|_|io%eiei|_|ie_n d|_|ii}|djoei|ii }n.|djo h}ne!d e"||i#d }ei%|e&e'||_(e)i*|}xu|ii,D]g}e.|}|i0dy|i1|Wqei2i3ei4d e!d |fqXqWx |iiD]}d|dUqOWdS(NtUNKNOWNitstringiis.pytfiletmemtmemorysUnrecognized cache type t spycecaches sError loading global taglib %ssimport (sfile(RR(6tselfRRt serverobjecttostenvironRtentryR tdebugRtglobalsRtpathtimportst module_cachetmodule_coderefstpageerrortemplatet pageerrort loadModulet errorhandlerRt multithreadedt spyceUtiltThreadedWriterRRtNonetcachet raw_cachet spyceCachet fileCachetcachedirt Exceptiontstrt createLockt cache_lockt semanticCachetspyceCacheValidtspyceCacheGeneratet spyce_cachetspyceTagtspyceTagCheckertcheckert globaltagsttagtupletlisttLtappendtloadLibRRtexceptionStringti( R!R R<RCR5RGRERKR-((Rt__init__Rs\        ,           cCs dtijS(NtspyceWWW(Rtmodules(R!((RtthreadedscCs0|io#|iidjo|iidjS(Ni(R!ROR t minthreadst maxthreads(R!((RR0scCsX|io)|iotiSq6tiSntitii |i i |S(N( R!ROR0t spyceLockt threadLockt dummyLocktfileLockR#R(tjoinR ttmptlockname(R!RX((RR;s   c Cs8|p|d}n|||f}y|i|}|d}Wntj o d}nX|p|o t ii |g|i}n |i}xz|D]r}d}t iit ii||}t ii|o2t i|t io||f|i|<}PqqW|ptd||fq4n|S(s Find (and cache) the path a spyce module given by may be loaded from ("file" argument does not include any path information) rel_file is relevant because the "current directory" is always searched first. s.pyis%unable to find module "%s" in path %sN(Rtnametrel_filetkeyR!R*tpathkeyR(tKeyErrorR3R#tdirnameRGtftrealpathRVtexiststaccesstR_OKt ImportError( R!RYRRZR_R\R[R(RG((Rt _findModules.    !) c si|||}|d} yi|\} }Wn$t j ot d|fnfXi i p|t| jot d||| f| Snx!ti| gD] }|qW| ||d}hd|<}|S(s! Find and load a spyce module, with caching. (I.e., return the class inheriting spyceModule from the python module in the given file -- the actual python module is not returned!) This is also used to load stuff that isn't actually a spyceModule -- spyceTags and defaultErrorTemplate, for instance. Caching is performed at the name/actual filename [not file parameter] level. (This is done so that .spy files in different directories can ask for tags in their directory w/o worrying about name conflicts.) The 2nd level is the necessary one to avoid unnecessary reloads (which can break things that only expect to be loaded once); the first is just an optimization to avoid repeatedly walking the spyce path looking for the right source file. iscache miss for %sscache hit (%d) for %s in %scszt|} ti| oti}ti| i|dt t \}}} } d} x'| D]}ti|gi| qnW| iti} td|| i|| i| idn|}y"ttit|| |}Wnt!i"id||ti#ft!i$}t&i'|d|ddd } yd|| fWqt)i*qXnXy ||_+Wnt,j onX|t-|fi/||f
s'Unexpected exception: (please report!)
s
(/ttimetstartR3tthespycettheErrorR!R@t spyceInfot spycecodeRt newWrappert spyceInitRRRRt spyceProcesst parent_codeRRRRRRR1RJt spyceDestroyt returnWrappert spyceDonet spyceRedirecttetspyceFileHandlerRtKeyboardInterruptt spyceNotFoundtspyceForbiddentspyceSyntaxErrortpythonSyntaxErrort SyntaxErrorRt SystemExitt errorStringtcgiRgtescapet RETURN_OKt returncode(R!RRRRRRRRRRRRR((RRsj          !+      ( RRRRLROR0R;ReR3R.RRR(((RR Ps  G    Nt spyceRequestcBsPtZdZdZedZedZedZedZdZ RS(sUnderlying Spyce request object. All implementations (CGI, Apache...) should subclass and implement the methods marked 'not implemented'.cCsd|_g|_dS(N(R3R!t_int_stack(R!((RRLMs cCs,|o|ii|Sn|iiSdS(N(tlimitR!RRn(R!R((RRnPscCs,|o|ii|Sn|iiSdS(N(RR!Rtreadline(R!R((RRUscCs ddS(Nsnot implemented((R!RY((RtenvZscCs ddS(Nsnot implemented((R!ttype((Rt getHeader\scCs ddS(Nsnot implemented((R!((Rt getServerID^s( RRRRLR3RnRRRR(((RRJs      t spyceResponsecBstZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*hed)<ed*<ed+<ed,<ed-<ed.<e d/<e d0<e d1<e d2<e d3<ed4<ed5<ed6<ed7<ed8<ed9<ed:<ed;<ed<<ed=<ed><ed?<ed@<edA<edB<edC<edD<edE<e dF<e!dG<e"dH<e#dI<e$dJ<e%dK<e&dL<e'dM<e(dN<e)dO<e*dPMaximum stack depth exceeded! (infinite parent template loop?)t_bodytchildR(R!t _hasParentt getModulestpushtspyceProcessSingleRRtpoptresultRtlenRRt MAX_STACKRRt_finishUserModulesterrtsrct childargsRRR1tattrdictRR3(R!RRR7R6R2R8((RR@s.        5cNsei}z|iio;eiei}eiieii|iinhd|i <d|<d|<}d|U|dSWd|e_XdS(s;Process the current Spyce request; no parent tag processingt_spyce_processt _spyce_argst _spyce_kwargss=_spyce_result = _spyce_process(*_spyce_args, **_spyce_kwargs)t _spyce_resultN( RR(R!RR tcopyRHR#R^R*RRR(R!RRRR(((RR0^s )$ cCsz|iix|iD]\}}yt|d|i|Wqti j oqti j o5}yt dWqti |i}qXqtj o qtj oqti |i}qXqWWdg|_X|S(Ns.finishsModules may not perform internal redirects in their start/finish methods. (External redirects are permitted, if you really must do this.)(R!RtreverseRRRtfinishRRRRRR9RRRR(R!RRRR((RR5ls.   cCs|i|p|}d}zz|iixF|iD];\}}yt |d|i |Wq6d}q6Xq6Wd|_ d|_ |onWd|i Xt dt|iidS(s%Cleanup after the request processing.s.finishiNsfinished destroy for %s(R!R5RR3t finishErrorR#R?RRRR@RRt spyceCleanupR:RR(R!RRRAR((RRs&      cCsNg|_h|_x5|iiD]$}||ijo|i|=q"q"WdS(sSweep the Spyce environment.N(R!R#RRRRR(R!R((RRBs  cCs|itiiS(N(R!RRkR't _has_parent(R!((RR-scCs |iiS(sHReturn spyce call stack (includes, parent templates, internal redirects)N(R!RR(R!((RtgetStackscCs |iiS(s Return filename of current SpyceN(R!RR (R!((RR scCs |iiS(s)Return processed Spyce (i.e. Python) codeN(R!RR (R!((RR scCs |iiS(s+Return python-to-Spyce code line referencesN(R!RR (R!((RR scCs |iiS(s.Return list of import references in Spyce codeN(R!RR (R!((RR scCs tiS(s1Return unique (per engine instance) server objectN(RR"(R!((RtgetServerObjectscCs tiS(s#Return server configuration globalsN(RR'(R!((RRscCs |iiS(sReturn unique server identifierN(R!RR(R!((RRscCs tiS(sReturn default page error valueN(RR-(R!((Rt getPageErrorscCs|iS(sReturn internal request objectN(R!R(R!((Rt getRequestscCs|iS(sReturn internal response objectN(R!R(R!((Rt getResponsescCs.||_x|iiD] }|qWdS(sSet internal response objectN(toR!RRRR_(R!RIR_((Rt setResponses  cCsd|i|:s cCs,|\}}hdt<dt<||S(NRR(RR[RaR_(RbRR[((RR?@s cCsUxBtii|o.tiitii|ti|}qWtii|S(N(R#R(tislinktfnameRVR^treadlinktgetmtime(Rd((RRFs/RfcCsGtii|}|ii|t||d||ff|||S(NR( R#R(R`RRRRHt_spyceCommonHandlerRRRRR (RRRRRRR ((RROscCs5|iidt||d||ff|||S(NR( RRRHRgRRpRRRR (RRRpRRRR ((RtspyceStringHandlerTscCst|i|||||S(N(RR RRRRRR(RRRRRR ((RRgXst__main__isrun_spyceCmd.py(6t __version__t __release__tFalseRRRRR#R>RR|RRRRkRRURARRR6R1R4RR3RRRRR~RR"RuRR RRRRR^R_R`RaR>R?RRRhRgRtexecfileR(RVtsplitR (+RRRRRRuRARR"RUR_R?RkRRR R4R`R|RRjRRhRRaRRRkRRR>RR^RR1R~RR6RRRRgR#R>((Rt?sJ  H  o6