ha-Kc+@s@dZddkZddkZddkZddklZlZddklZlZl Z l Z l Z ddk Z ddk lZddkZddkZddkZddklZddklZddklZdd klZdd klZhZd Zeid d ZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*e*dZ+dZ,dddfZ-dddddfZ.dd fZ/d!d"d#fZ0d$Z1d%d&d'd(d)d*d+d,d-d.d/f Z2e1fe2Z3d0d1d2d3d4d5d6d7d8f Z4d9d:d;fZ5e,fe-e.e/e0e3e4e5Z6d<d=d>d?d@dAdBdCdDdEd$dFf e2Z7d9dGdHd7dIdJdKdLdMdNdOdPdQd;dRdSdTdUd:dVdWdXdYdZd[d\d8d]fZ8d^Z9d_Z:d^d_d`dadbdcdddedfdgdhdidjdkdldmdndofZ;he9d^6e:d_6e9d`6e:da6e9dd6e:de6e9dh6e:di6e9db6e:dc6e9df6e:dg6e9dl6e:dm6e9dj6e:dk6e9dn6e:do6Z<hd<d=6d@dA6d>d?6Z=hd=d<6dAd@6d?d>6Z>hZ?dpZ@x-e<iAD]\ZBZCe@eBeCe?eBRR(R(tnameR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt namedGroup,scGst|dS(Nt*(R(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytany-scGst|dS(Nt?(R(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmaybe.siiit5abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_t 0123456789s**t+t-t~t/s//t%s>>s<>=s<<=s&=s|=t=s<>tistintandtortnotRRt{t}t[t]t,t.t:t;t`tdeltfortraisetassertteliftfromtlambdatreturntbreaktelsetglobalttrytclasstexcepttiftwhiletcontinuetexectimporttpasstdeftfinallytprints'''s"""sr'''sr"""sR'''sR"""su'''su"""sU'''sU"""sur'''sur"""sUr'''sUr"""suR'''suR"""sUR'''sUR"""cCs?t|}t|}tid|dd|dtiS(Ns(?:s).*?R(RRRR(tstarttend((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmakeTripleQuoteRe{s  s[ \f\t]*s \r\n|\n|\rs|\Zs(?<=\A)s(?Ys cssx|]}|iVqWdS(N(R(Rta((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pys Zs (RtlisttmapRR(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmergeXscCst|iS(N(tstrR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR\s( RRt__doc__RRRRRR(((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRCs     t_LowLevelParsercBseZdZdAZdZedZdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd ZdAdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'e(d#d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d*Z/d+Z0d,Z1d-Z2d.Z3d/Z4d0Z5d1Z6d2Z7d3Z8d4Z9d5Z:d6Z;e<e<d7Z=e<d8Z>d9Z?ged:Z@dAe<d;ZAe<dAdAed<ZBe<dAdAed=ZCd>ZDd?ZEe<e<e<d@ZFRS(BsThis class implements the methods to match or extract ('get*') the basic elements of Cheetah's grammar. It does NOT handle any code generation or state management. cCs ||_dS(N(t_settingsManager(RtsettingsManager((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytsetSettingsManagergscCs8|tjo|ii|S|ii|d|SdS(Ntdefault(R Rtsetting(RtkeyR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRjs cCs|ii||dS(N(Rt setSetting(RRtval((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRpscCs |iiS(N(Rtsettings(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRsscCs|ii|dS(N(RtupdateSettings(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRvscCs|iidS(N(Rt_initializeSettings(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRyscCs|i|i|i|i|idd|idd|idd|idd|idd|_|i|i|i|i |i |i |i g|_ dS(sIs called by the Compiler instance after the parser has had a settingsManager assigned with self.setSettingsManager() tcommentStartTokenitmultiLineCommentStartTokentcheetahVarStartTokentdirectiveStartTokent PSPStartTokenN(t_makeCheetahVarREst_makeCommentREst_makeDirectiveREst _makePspREsRt_possibleNonStrConstantCharstmatchCommentStartTokentmatchMultiLineCommentStartTokentmatchVariablePlaceholderStarttmatchExpressionPlaceholderStarttmatchDirectivetmatchPSPStartTokentmatchEOLSlurpTokent_nonStrConstMatchers(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytconfigureParser|s    CcCsd}d|d|d|d|d|d|d}d d |d d d d dd}t||_dtddd dd}t||_ttdt|iddd|dd|ddd|_d}|id|_ttt|id||_tt|idd|_ ttdt|iddd|ddd|_ |ido2tt|iddd t d|_ n d|_ dS(s*Setup the regexs for Cheetah $var parsing.s[0-9\.]+s (?Pss|sm|sh|sd|sw|Rs(?:s(?P\*s\*)Rs(?P\*)s(?P)s (?Pt!s(?P)s(?PRs(?Ps(?Ps((?P|(?:(?:\{|\(|\[)[ \t\f]*))s (?=[A-Za-z_])s(?=[A-Za-z_\*!\{\(\[])s(?:\{|\(|\[)[ \t\f]*s (?=[^\)\}\]])t EOLSlurpTokens[ \t\f]*Ns(?:(?P(Rt cacheTokenRERtsilentPlaceholderTokenREtescCharLookBehindRtcheetahVarStartRERtcheetahVarStartTokenREt"cheetahVarInExpressionStartTokenREtexpressionPlaceholderStartREtEOLt EOLSlurpRER(RtnumtintervalRtsilentPlaceholderTokentvalidCharsLookAhead((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs06: # ;/cCst|id}tt||_~t|id}t|id}tt||_tt||_dS(s:Construct the regex bits that are used in comment parsing.RRtmultiLineCommentEndTokenN(RRRRtcommentStartTokenREtmultiLineCommentTokenStartREtmultiLineCommentEndTokenRE(Rt startTokenEsct endTokenEsc((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs cCs|id}|id}t|}t|}d}t|g}|ido|idn|i|tdi||_tt||_dS(s8Construct the regexs that are used in directive parsing.RtdirectiveEndTokens(?=[A-Za-z_@])t'allowWhitespaceAfterDirectiveStartTokens[ ]*RN(RRRRRRtdirectiveStartTokenREtdirectiveEndTokenRE(Rt startTokentendTokenRRtvalidSecondCharsLookAheadtreParts((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs    cCs`|id}t|}tt||_|id}t|}tt||_dS(s!Setup the regexs for PSP parsing.Rt PSPEndTokenN(RRRRtPSPStartTokenREt PSPEndTokenRE(RRRRR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs   cCs#|id}|id||S(s;Unescape any escaped Cheetah \$vars in the string. Rs\(Rtreplace(Rt theStringR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt_unescapeCheetahVarsscCs#|id}|id||S(s?Unescape any escaped Cheetah directives in the string. Rs\(RR (RRR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt_unescapeDirectivesscCs |i|S(N(tisLineClearToPos(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytisLineClearToStartTokenscCsMd}|i|ijo-x*|iD]}|}|oPq&q&Wn|S(sReturns the first match found from the following methods: self.matchCommentStartToken self.matchMultiLineCommentStartToken self.matchVariablePlaceholderStart self.matchExpressionPlaceholderStart self.matchDirective self.matchPSPStartToken self.matchEOLSlurpToken Returns None if no match. N(RtpeekRR(Rtmatchtmatcher((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchTopLevelTokens    cCstti|i|i}|oK|itjo8t|ii|i|i}|o|Sn|S(N(RRtsrcRRttripleQuotedStringStartsttripleQuotedStringREs(RRtTQSmatch((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt matchPyToken&s ( cCse|i}|djot|n*|itjot|ddn|i|iS(NRsMalformed triple-quoted string(RRRRRtreadToRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt getPyToken/s   cCs.|io |ii|i|iSdS(N(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR7s cCs<|i}|pt|ddn|i|iS(NRsInvalid EOL slurp token(RRRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetEOLSlurpToken;s cCs|ii|i|iS(N(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRAscCs<|i}|pt|ddn|i|iS(NRs'Invalid single-line comment start token(RRRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetCommentStartTokenDs cCs|ii|i|iS(N(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRJscCs<|i}|pt|ddn|i|iS(NRs&Invalid multi-line comment start token(RRRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetMultiLineCommentStartTokenMs cCs|ii|i|iS(N(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchMultiLineCommentEndTokenSscCs<|i}|pt|ddn|i|iS(NRs$Invalid multi-line comment end token(R!RRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetMultiLineCommentEndTokenVs cCsZt|}g}g}|itjot|nx|i|jo|i}|tjo|i}|i|q>|djoI|id|jo-|idtjo|i|iq0Pq>|djo*|i|idi |g}q>|djo|iq>Pq>W|o|idi |n|S(si Loosely based on getDottedName to pull out comma separated named chunks R9iR8RRs (Rs ( RRt identcharsRRt namecharst getIdentifierRtgetcR(RtsrcLentpiecesRtct nameChunk((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetCommaSeparatedSymbols\s2     -    cCst|}g}|itjot|nx|i|jo|i}|tjo|i}|i|q8|djoI|id|jo-|idtjo|i|iqPq8Pq8Wdi |S(NR9iR( RRR#RRR$R%RR&R(RR'RR)R*((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt getDottedNames      -cCsti|i|iS(N(tidentRERRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchIdentifierscCs<|i}|pt|ddn|i|iS(NRsInvalid identifier(R.RRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR%s cCs4|i}|o|itjo d}n|S(N(RRt operatorsR(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt matchOperators  cCs<|i}|pt|ddn|i|iS(NRsExpected operator(R0RRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt getOperators cCs4|i}|o|itjo d}n|S(N(RRt assignmentOpsR(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchAssignmentOperators  cCs<|i}|pt|ddn|i|iS(NRsExpected assignment operator(R3RRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetAssignmentOperators cCsE|i}|iptS|i|i}|i||S(s<Returns False or the name of the directive matched. (RtmatchDirectiveStartTokentFalsetgetDirectiveStartTokentmatchDirectiveNameR(RtstartPost directiveName((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs     s 0123456789-@c Cs+|i}|ii}d}d}x|ip|i}||joPn||7}|djo0|i o|itjo d}nPng}|D]!}|i|o ||qq~}|pPq*||jo+|ip|i|jo |}Pq*q*W|i ||S(NRRw( Rt_directiveNamesAndParserstkeysRtatEndR&RR#t startswithR( RtdirectiveNameCharsR9tpossibleMatchesRRR)t_[1]tdn((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR8s,      ! 5-  cCs|ii|i|iS(N(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR5scCs<|i}|pt|ddn|i|iS(NRsInvalid directive start token(R5RRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR7s cCs|ii|i|iS(N(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchDirectiveEndTokenscCs<|i}|pt|ddn|i|iS(NRsInvalid directive end token(RCRRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetDirectiveEndTokens cCsz|i oh|idjoU||id|i!}|i}|ptS|ii|otStSntS(NR:i( R=RRtfindEOLRR6RRR(Rt restOfLine((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt)matchColonForSingleLineShortFormDirectives! cCs|ii|i|iS(N(R RRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRscCs|ii|i|iS(N(R RRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchPSPEndTokenscCs<|i}|pt|ddn|i|iS(NRsInvalid psp start token(RRRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetPSPStartTokens cCs<|i}|pt|ddn|i|iS(NRsInvalid psp end token(RHRRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetPSPEndTokens cCs|ii|i|iS(s&includes the enclosure and cache token(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchCheetahVarStart scCs|ii|i|iS(s&includes the enclosure and cache token(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytmatchCheetahVarStartTokenscCs|ii|i|iS(s%no enclosures or cache tokens allowed(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt%matchCheetahVarInExpressionStartTokenscCs|ii|i|iS(s&includes the enclosure and cache token(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRscCs|ii|i|iS(s&includes the enclosure and cache token(RRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRscCs<|i}|pt|ddn|i|iS(s6just the start token, not the enclosure or cache tokenRs!Expected Cheetah $var start token(RLRRRU(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetCheetahVarStartToken s cCsbyB|ii|i|i}|i|i|iSWnt|ddnXdS(NRsExpected cache token(RRRRRRURR(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt getCacheToken(s !cCsbyB|ii|i|i}|i|i|iSWnt|ddnXdS(NRs!Expected silent placeholder token(RRRRRRURR(RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetSilentPlaceholderToken0s !cCsg}x|ip|idjo|iq |idjoPq |ido|iq |idp|idoPq |io5|i|i|i|i |i q |i o|i |i q Pq W|S(Ns s R8sin sin ( R=Rt getWhiteSpaceR>tadvanceRMRNRPRORR,R.(Rtvarnames((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetTargetVarsList:s(       cCs9|p|in|i|i|id|S(sThis is called when parsing inside expressions. Cache tokens are only valid in placeholders so this method discards any cache tokens found. tplain(RNRPROtgetCheetahVarBody(RRUtskipStartToken((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt getCheetahVarQs   cCs|ii|id|S(NRU(t _compilert genCheetahVartgetCheetahVarNameChunks(RRU((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRV[scCsg}x|it|jond}t}|itdjoPnZ|idjoF|idt|jo$|idtjo|iqPn|i}|i o|idjo|idjo|i}n|i dt}t |i dd}|o,|i || |df||d}n|o|ddjo t }qvn|i |||fq W|S(s nameChunks = list of Cheetah $var subcomponents represented as tuples [ (namemapperPart,autoCall,restOfName), ] where: namemapperPart = the dottedName base autocall = where NameMapper should use autocalling on namemapperPart restOfName = any arglist, index, or slice If restOfName contains a call arglist (e.g. '(1234)') then autocall is False, otherwise it defaults to True. EXAMPLE ------------------------------------------------------------------------ if the raw CheetahVar is $a.b.c[1].d().x.y.z nameChunks is the list [ ('a.b.c',True,'[1]'), ('d',False,'()'), ('x.y.z',True,''), ] RR9is([Rtenclosedi(RRRRR#RRR,R=tgetCallArgStringt getExpressiontmaxtrfindRR6(RtchunkstresttautoCallt dottedNametperiod((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR[_s03 !cCs(|tj o#|id}|id|n|onO|idjpt|ddn|i}|id|fg}dg}|i}x\toT|i oS|dd}t |}|i |ddt|dd|d |d n|i} | d jok|pt|n|i} t | }|dd|jo|i |d Pqt|q| d jo||iq|io|i}|i} |i} |i o~|idjok|i} | djo<|i} |i ||idt} |i | n|| | | q|| | q|io|iq|i}|i}|djo |i|idt}n|i||}||qW|tj o|id|ndi|S(sf Get a method/function call argument string. This method understands *arg, and **kw RRRs Expected '('iiis#EOF was reached before a matching 's' was found for the 't's)}]Rs R-RUR4R6R\R(R4RR6(R RRRRRR&RRR=tclosurePairsRevRt closurePairsRRMRXRQRRKt-_raiseErrorAboutInvalidCheetahVarSyntaxInExprtrevR^ttransformTokenR(Rt enclosuresRtuseNameMapper_origR9t argStringBitstaddBittopentcloseR)tcodeFor1stTokentWSt nextTokentendPostbeforeTokenPosR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR]sv                  !          c Cs|idjo|in |i}t}t}|id}|id|xto|iot |dddn|i |joPn|i}|djp |i oPq^|djoPq^|djo&|o|i |n|iq^|d jot}|iq^|d jo|i t}|iq^|i|io"| o|it|iq^|io| o|i|iq^|o|io|i}ns|io|inX|i }|i}|djo |i|id t}n|i||}|i |q^|djoy| oq|i} |idjo| |i7} n|ipt |n| |i7} |i| q^t |q^W|id||iS(s, Get an argument list. Can be used for method/function definition argument lists or for #directive argument lists. Returns a list of tuples in the form (argName, defVal=None) with one tuple for each arg name. These defVals are always strings, so (argName, defVal=None) is safe even with a case like (arg1, arg2=None, arg3=1234*2), which would be returned as [('arg1', None), ('arg2', 'None'), ('arg3', '1234*2'), ] This method understands *arg, and **kw RRRs%EOF was reached before a matching ')'s was found for the '('RR:s R-R8R4R6R\R (R4RR6(RRRRERR6RRRR=RRRCRRR>RRR.RR%RMRXRKRiRRjR^RkR&R( RtexitPosRtargListtonDefValRmR)RRvtvarName((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt getDefArgListst                  cCsv|tj o#|id}|id|n|djo g}nt|}g}xto|io_|oS|dd}t|} |i|ddt |dd| d|dqPn|i } | d jo4|i | |i | |i f|i q\|o | oPq\| d jo|pt |nt| }|dd|jo|i|i | n|dd}t|} |i\} } |i|ddt |dd | d t| d t| d| d|d|i q\| djo|i |iq\|io | oPq\| djow|i d|jo`ti|i|i d} | p |i t |ddn|i| iq\| djo|o|i qLPq\|io|i}|i |q\|io|iq\|i }|i}| o&|o||jo|i|Pn|i||}|i |ti|o|djo,|idt ddg}|i |qL|i |i|i o*|i djo|i |i!qLq\q\W|tj o|id|n|S(s Get a Cheetah expression that includes $CheetahVars and break at directive end tokens, the end of an enclosure, or at a specified pyToken. RiiiRs#EOF was reached before a matching 's' was found for the 'Rfs{([s])}sA 's' was found at line s, col s before a matching 's' was found for the 's s\sLine ending expecteds R>tpyTokensToBreakAtR0RN("R RRRRRR=RgRRRRRRRRhRt getRowColRRQRCtEOLreRRRURMRXRKRiRRkR-R^R6R](RR\RlR|RRmR'texprBitsRpRqR)RRteolMatchtexprRvR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytgetExpressionPartsDs             = $"           !  c Cs+di|id|d|d|d|S(spReturns the output of self.getExpressionParts() as a concatenated string rather than as a list. RR\RlR|R(RR(RR\RlR|R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR^s  c Cs|djo|i ox|idjoe|i}|i}t|}|i}|pdS|itp|ito d}nd}|i ||dg}d}x|i||jow|i p |i oI|o|i t |d}n|i} |i d| dq||i7}qW|i ||o|i t |nd d i|d }n|S( sTakes a token from the expression being parsed and performs and special transformations required by Cheetah. At the moment only Cheetah's c'$placeholder strings' are transformed. R)s'"NiiRsstr(Rs ''.join([R8s])(R=RRtuppertevalRR>tsingle3tdouble3RRKRRtreprtgetPlaceholderR&R( RRRvRtttheStrRut startPosIdxt outputExprststrConsttplaceholderExpr((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRks6.         cCsz|i}|i}|idot|ddn9|idot|ddnt|dddS(NRRsXCache tokens are not valid inside expressions. Use them in top-level $placeholders only.t enclosuresxLong-form placeholders - ${}, $(), $[], etc. are not valid inside expressions. Use them in top-level $placeholders only.s3This form of $placeholder syntax is not valid here.(RKt groupdicttgetR(RRR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRis    c Csx$|idD]}|d|qW|i}|i|}|i}|i}|o t} nt} |o(|i} |ii | i } nh} |i djo5|i} |i } | | fg}|i ng}d}|io |i}|ii|d|}d}|o|i }||7}|ido0|i djo|id|dd !}q|i t| jo|i q|id td|}|d t| jo|d }n||7}n|||i!}nO|id td|}|d t| jo|d }n|||i!}|i|d d |d |}x$|idD]}|d|qW|o|||| || fS|SdS(NtpreparsePlaceholderHookstparsers({[RUtallowPlaceholderFilterArgsR8RliiR\t placeholdertrawExprR9tpostparsePlaceholderHooks(RRR}RNRPRR6RORRRRR&RQRR.R[RYRZR]RgR^t_applyExpressionFilters(RtallowCacheTokensRUtreturnEverythingtcallbackR9tlineColRRtisSilentPlaceholderRtcacheTokenPartsRtenclosureOpenCharRlt filterArgsRRt restOfExprRstrawPlaceholder((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRsd           #  N(GRRRRRRR RRRRRRRRRRRRRRRRRRRRRR R!R"R+R,R.R%R0R1R3R4RR#R8R5R7RCRDRGRRHRIRJRKRLRMRRRNRORPRTR6RXRVR[R]R{RR^RkRiR(((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR_s        E                $                          < QX g $ t_HighLevelParsercBs>eZdZd<d<d<dZdZdZdZdZd<d<dZ dZ d<e dZ d Z d Zd Zd Zd ZdiZdiZhdd6dd6ZdZdZdZe dZedZdZdZdZdZdZ dZ!dZ"dZ#d Z$d!Z%d"Z&d#Z'ed$Z(d%Z)d&Z*d'Z+d(Z,d)Z-d*Z.d+Z/d,Z0d-Z1d.Z2d/Z3d0Z4d1Z5d2Z6d3Z7d4Z8d5Z9d6Z:d7Z;d8Z<d9Z=d:Z>d;Z?RS(=sThis class is a StateMachine for parsing Cheetah source and sending state dependent code generation commands to Cheetah.Compiler.Compiler. cCsPtt|i|d|d||i|||_|i|idS(NRt breakPoint(R\RRRRYt setupStateR(RRRRR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR;s "   cCsh|_h|_g|_dS(N(t_macrost _macroDetailst_openDirectivesStack(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRBs  cCsQ|iix0|iiD]\}}|ii|`qW|iidS(s8Cleanup to remove any possible reference cycles N(RtclearRtitemsttemplatetshutdown(Rt macronamet macroDetails((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytcleanupGs     cCs!tt|i|idS(N(R\RRt_initDirectives(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRPsc sfd}|}ti}idh}|i|ti}idh}|i|h_xG|iD]9\}|tdfjoqn||iRLRRHtcloseableDirectivestmacroDirectivesti18nR(RtcopyRtupdateRR;RR6t_endDirectiveNamesAndHandlerst_closeableDirectivesRR RRRRt eatMacroCall( RRtnormalizeHandlerValR;tcustomNamesAndParsersRtcustomNamesAndHandlersRR:Rt macroNameR((RRs4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRTsN               c CsEx>|idD]-}|d|d|d|d|d|}qW|S(s=Pipes cheetah expressions through a set of optional filter hooks. The filters are functions which may modify the expressions or raise a ForbiddenExpression exception if the expression is not allowed. They are defined in the compiler setting 'expressionFilterHooks'. Some intended use cases: - to implement 'restricted execution' safeguards in cases where you can't trust the author of the template. - to enforce style guidelines filter call signature: (parser, expr, exprType, rawExpr=None, startPos=None) - parser is the Cheetah parser - expr is the expression to filter. In some cases the parser will have already modified it from the original source code form. For example, placeholders will have been translated into namemapper calls. If you need to work with the original source, see rawExpr. - exprType is the name of the directive, 'psp', or 'placeholder'. All lowercase. @@TR: These will eventually be replaced with a set of constants. - rawExpr is the original source string that Cheetah parsed. This might be None in some cases. - startPos is the character position in the source string/file where the parser started parsing the current expression. @@TR: I realize this use of the term 'expression' is a bit wonky as many of the 'expressions' are actually statements, but I haven't thought of a better name yet. Suggestions? texpressionFilterHooksRRtexprTypeRR9(R(RRRRR9R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs cCs|i}||idjp&|ido]||idjoGx*|idD]}|d|d|qXWt|dd|ndS(NtdisabledDirectivestenabledDirectivestdisabledDirectiveHooksRR:RsThis %r directive is disabled(tlowerRR(RR:R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt_filterDisabledDirectivess cCs7|o#|i}|i|t}nx|ip|io|iq-|io|iq-|io|i q-|i o|i q-|i o|i q-|i o|iq-|io|iq-|iq-W|o|in|o|i|ndS(N(Rt setBreakPointR6R=Rt eatCommentRteatMultiLineCommentRteatPlaceholderRRt eatDirectiveRteatPSPRteatEOLSlurpTokent eatPlainTexttassertEmptyOpenDirectivesStack(RRtassertEmptyStacktorigBP((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pytparses2           cCs|i}d}x4|ip&|i}|oPq|iqW|i|id|}|i|}|i|}|ii ||S(NRT( RRR=RRRRRRRYt addStrConst(RR9RR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs   cCsT|i}|o|iin|i|id|}|ii|dS(Ntgobble(RRYthandleWSBeforeDirectiveRt readToEOLt addComment(RRtcomm((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs   cCs|i}|i}|i|i}}d}xto|i}|ioPn|io|i|d7}n&|io|i|d8}n|pPn|i q;W|i |d|}|ip|in|i o|i dov||i|i!}|i p|i d|n|o1|ip|i|jo|iiqn|ii|dS(NiRTt'gobbleWhitespaceAroundMultiLineCommentsR(RRER RRR=RR!R"RRRRRRRYRR(RRtendOfFirstLineRuR9tlevelRRF((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs:           'c Cs\|idtdt\}}}}}}|ii|d|d|d|d|d|dS(NRRRRRRt silentMode(RRRYtaddPlaceholder(RRRRRRR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs ! cCs|idd|i|id}|i}xI|ip;|i|djo|ioPqrn|iq8W|i|id|i }|i |dd|}|i i ||i dS(NR:tpspR iRTR9(RRIRRR=RRHRRRRRRYtaddPSPRJ(RRR9t pspString((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR(s     !s9 else elif for while repeat unless try except finallysc pass continue stop return yield break del assert raise silent echo import fromtaddImportStatementRORBcCs|i}|i|x*|idD]}|d|d|q)W|ii|}|o |n||ijoV|ii|}|pd|i}nt|i |}|i |d|n||i jo|ii|}|pd|i}nt|i |}|d jo t }nt }|i|d|}||nx*|id D]}|d|d|qoWdS( NtpreparseDirectiveHooksRR:taddRRhRgtincludeDirectiveNameInExprtpostparseDirectiveHooks(RhRg(RRRR;Rt_simpleIndentingDirectivest_directiveHandlerNamest capitalizeRRYteatSimpleIndentingDirectivet_simpleExprDirectivesR6RteatSimpleExprDirective(RR:RtdirectiveParsert handlerNameRRR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRBs:      cCst}|ioU|i}|i|ip!|i|t}|iqh|i|n| o|io|i n=|o5|i o'|i djo|i dtn|o1|i p|i|jo|i indS(Ns R(R6RRRRRRRRRCRDR=RRRYR(RRtendOfFirstLinePost foundCommentR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt_eatRestOfDirectiveTages     ('c Cs|i}}}|idd}t}x|ip|i|jo|idjo|i}|i|itd|i |i |oW|i |ot }|i |}n|it||i |i}Pqqn|i|i}}q0W|i|d|}|i||i}|io|in=|o5|i o'|idjo|idt n|o$|i|jo|iin|S(NRiRURTs R(RRR6R=RRR7RRRRQR>RRtfindBOLRRRERCRDRRYR( RR:tfinalPost endRawPosR9t directiveCharRt textEatenR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyt_eatToThisEndDirectivezs>           (cCs|i}|i}|i|p|it|n|i}|ii}|id}|i ||d|}||i jo|i |n|i |||S(NiR9( RRER7RRRRR^RtsplitRRtpushToOpenDirectivesStackR(RR:RRRR9R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs    c Cs|i}|i}|i}|i|dijo|it|n|i}|i|i ddg}|i ||d|}|i o|i|dijo||dt d|n||d||idd |i d |id t|ii|iinm|idjo|in|i|i||||ijo|i|n||d|dS( Ns&else elif for while try except finallyR|R:R9selse elif except finallytdedentRR_iRR(RRER}R7RRRRRRQR^RRGR6RRRYtcommitStrConstRRRRR( RR:RRRRRR9R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs4          cCsJ|i}|i|id|i|i}t}x;|iiD]*}|i|||jo |}PqOqOW|pt |ddn|i }|i |i ||||i jo|i|n|ii|o|i|}|n;|dijo|djo|iiqF|djo|iiqF|djo|iiqF|djo|iiqF|d jo|iiqF|d jo|iiqFnp|d ijo|ii|iin?|d jo1|ii|ii|id |indS(NiRsInvalid end directives,block capture cache call filter errorCatcherRuRpRdRlRfRswhile for if try repeat unlessR{t useSearchList(RR7RRRQRR6RR<tfindRRER^RRtpopFromOpenDirectivesStackRRRYt closeBlocktendCaptureRegiontendCacheRegiont endCallRegiontcloseFilterBlocktturnErrorCatcherOffRRRt_useSearchList_orig(RRRR:RRR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRsR                    cCs|i|idS(sTells the parser to stop parsing at this point and completely ignore everything else. This is a debugging tool. N(RR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRscCsq|i|itd|i|i}|i}|i|dd|}|ii|i dS(NRtshbangR9( R7RRRRQRRRRYt setShBangR(RR9R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR s    cCsq|i|itd|i|i}|i}|i|dd|}|ii|i dS(NRR9( R7RRRRQRRRRYtsetModuleEncodingR(RR9R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs    cCs|i}|i}|i}|i|itd|i|i}|i}|idjo3|i |i |||i |i dS|i|i djo|in t||i }|i}|id||fdd||i ||y|ii||Wnetiidtiidtiid|||!tiidtiid nXdS( NRtresetR-s%s=%rR9sFAn error occurred while processing the following #compiler directive. sG---------------------------------------------------------------------- s%s s,Please check the syntax of these settings. (RRERR7RRRRQR%RR^RRRRRRRYtsetCompilerSettingtsyststderrtwrite(RRRR9t settingNamet valueExprRu((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs@               cCs?|i}|i}|i|itd|i}|i|i||d|jo|ii |i dS|i }|i d}|i |dd|}y|iid|d|Wndtiidtiidtiid |itiidtiid nXdS( Nscompiler-settingsRtcompilerSettingsR9tkeywordst settingsStrsDAn error occurred while processing the following compiler settings. sG---------------------------------------------------------------------- s%s s,Please check the syntax of these settings. (RRER7RRRRTR^RRYRRRRRtsetCompilerSettingsRRRR(RRRRR9R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRLs0          cCs|i}|i}|i}|i|itd|i|i}|io|in|i }|i|i |i }|i |dd|}|i i|||i||dS(NRrR9(RRERR7RRRRQRKRNR%R4R^RRYt addAttributeR(RRRR9t attribNameR((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRqms            cCs|i}|i}|i}|i|i}|i}|i|dd|}|ii||i|||i |i }| p |d jot |ddn|i dS( Nt decoratorR9RQRuR{RwRs5Expected #def, #block, #closure or another @decorator(sdefsblocksclosureRw( RRERR7R^RRYt addDecoratorRRQRRR(RRRR9t decoratorExprR:((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRvs        cCs|iddS(NRQ(t_eatDefOrBlock(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRsscCsL|i}|id\}}h|d6|i|d6|ii|R%t SET_GLOBALt SET_MODULERKRR^R2R6RR4RRtLVALUEtOPtRVALUERYtaddSet( RRRtstyletstartsWithDollarR9R>R?R@RR:texprComponents((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR|Ws>                    cCs?|io|iin|ii|idtdS(NR(RRYRRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR]|s  cCs?|io|iin|ii|idtdS(NR(RRYRRRR(R((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRs  cCs|i}|i}|i|itd|i|io0|i|idd|idt}nK|i djo|in|i|i |||i d}|i i |dS(NR`R_iRR:(RRER7RRRRQRGRR6RRRRYt addRawText(RRRtrawBlock((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyR_s       cCs:|i}|i}|i|itd|id}t}|ido|idt}n|i|idoT|itdd}|i|i djpt |n|in|i }|i }|i |dd|}|i|||ii|||dS( NRbtfileR`itsourceRR-R9(RRER7RRRRQR6R>RRRRR^RRRYt addInclude(RRRt includeFromtisRawR9t sourceExpr((s4/usr/lib64/python2.6/site-packages/Cheetah/Parser.pyRas.          c Cs_|i}|i}|i|itd|i|io|in|i}|i|i djoG|i dt }|i|o |dddjo |d=qng}|i dd'|id(|id)|id*|id+|id,|id-|id.|io@|i|idd|idt }|idtnK|i djo|in|i|i|||id}diddig}|D]+\}}||od||fp|q~d|dg} ddkl} |idd| } |iddh} |iddg} t| } | ih|id 6|d6|id 6| i| dd d!d"| id#| d | }d$d/d%Y}|}||_||_|d&| |_||i |<|ii!|i|<|i"|i#| sT   (             !%         >4