Ñò ô†³Kc @sAdZddkZddkZddkZddkZddklZdddddd d gZeid ƒZ eid ƒZ eid ei ƒZ de fd„ƒYZde fd„ƒYZde fd„ƒYZdefd„ƒYZd„Zdd„Zd efd„ƒYZd efd„ƒYZd„Zd„Zd„Zdefd„ƒYZd„Zded„ZeidƒZ dd d!d"gZ!eid#ƒZ"eid$ƒZ#d%„Z$d&„Z%dd'„Z&d1d(„Z'd)„Z(d*„Z)d+„Z*d,„Z+d-Z,dd.„Z-e.d/jodd0k/l-Z-e-ƒndS(2sð A small templating language This implements a small templating language for use internally in Paste and Paste Script. This language implements if/elif/else, for/continue/break, expressions, and blocks of Python code. The syntax is:: {{any expression (function calls etc)}} {{any expression | filter}} {{for x in y}}...{{endfor}} {{if x}}x{{elif y}}y{{else}}z{{endif}} {{py:x=1}} {{py: def foo(bar): return 'baz' }} {{default var = default_value}} {{# comment}} You use this with the ``Template`` class or the ``sub`` shortcut. The ``Template`` class takes the template string and the name of the template (for errors) and a default namespace. Then (like ``string.Template``) you can call the ``tmpl.substitute(**kw)`` method to make a substitution (or ``tmpl.substitute(a_dict)``). ``sub(content, **kw)`` substitutes the template immediately. You can use ``__name='tmpl.html'`` to set the name of the template. If there are syntax errors ``TemplateError`` will be raised. iÿÿÿÿN(tloopert TemplateErrortTemplatetsubt HTMLTemplatetsub_htmlthtmltbunchs \{\{|\}\}s\s+in\s+s^[a-z_][a-z0-9_]*$cBs#eZdZdd„Zd„ZRS(s.Exception raised while parsing a template cCs||_||_||_dS(N(tmessagetpositiontname(tselfRR R ((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt__init__2s  cCsGd|i|id|idf}|io|d|i7}n|S(Ns%s at line %s column %siis in %s(RR R (R tmsg((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt__str__7s ! N(t__name__t __module__t__doc__tNoneR R(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR.s t_TemplateContinuecBseZRS((RR(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR>st_TemplateBreakcBseZRS((RR(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRAscBs¶eZhdd6dd6ed6ZdZddd„Zddd„ZeeƒZd„Z d „Z d „Z d „Z d „Z d „Zd„Zd„Zd„Zd„Zd„ZRS(s{{t start_bracess}}t end_bracesRtutf8cCs]||_t|tƒ|_||_t|d|ƒ|_|djo h}n||_dS(NR ( tcontentt isinstancetunicodet_unicodeR tparset_parsedRt namespace(R RR R((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR Ns    cCsXt|dƒ}|iƒ}|iƒ|o|i|ƒ}n|d|d|d|ƒS(NtrbRR R(topentreadtclosetdecode(tclstfilenameRtencodingtftc((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt from_filenameWs   cCs*d|iitt|ƒƒd|ifS(Ns<%s %s name=%r>i(t __class__RthextidR (R ((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt__repr__as cOsŽ|oH|otdƒ‚nt|ƒdjotdƒ‚n|d}n|iiƒ}|i|iƒ|i|ƒ|i|ƒ}|S(Ns3You can only give positional *or* keyword argumentsis(You can only give on positional argumenti(t TypeErrortlentdefault_namespacetcopytupdateRt _interpret(R targstkwtnstresult((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt substitutefs   cCs2t}g}|i|i|d|ƒdi|ƒS(Ntoutt(tTruet_interpret_codesRtjoin(R R6t__traceback_hide__tparts((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR3uscCsOt}xB|D]:}t|tƒo|i|ƒq |i|||ƒq WdS(N(R;Rt basestringtappendt_interpret_code(R tcodesR6R9R>titem((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR<{s cCst}|d|d}}|djo|i|d||ƒnË|djo tƒ‚n±|djo tƒ‚n—|djoR|d|d|d }}} |i|||ƒ}|i||| ||ƒn8|d jo!|d} |i| ||ƒn |d jo|did ƒ} |i| d||ƒ} x3| dD]'} |i| ||ƒ} | | ƒ} qHW|i|i | |ƒƒn~|d joI|d|d}}||jo#|i|||ƒ}|||R tpostvarsRJRR?tbasetparttfunctvarR7((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRBƒs>              c Csìt}xß|D]×}t|ƒdjo|||dRDR tvalue((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRP¤s$  c Cs›t}xŽ|D]†}t|tƒ pt‚|d|d}}|djo t}n|i|d||ƒ}|o|i|d||ƒPq q WdS(Niitelseii(R;RR@RTROR<( R R?R6R9R>RYR RVR7((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRQ·s  c Csšt}yt||ƒ}|SWnvtiƒ}|d}t|dƒo|id}n t|ƒ}|i||ƒf|_|d||d‚nXdS(NiR4ii(R;tevaltsystexc_infotgetattrR4tstrt_add_line_info( R RUR6RVR>R^Rbtetarg0((s7/usr/lib/python2.6/site-packages/paste/util/template.pyROÅs   cBsie}y ||UWnPeiƒ}|d}|i|id|ƒf|_|d||d‚nXdS(Niii(R;RaRbReR4(R RUR6RVR>RbRf((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRNÔs   c Cs`t}yb|djodS|io6yt|ƒ}Wqgtj ot|ƒ}qgXn t|ƒ}WnPtiƒ}|d}|i|i d|ƒf|_ |d||d‚n¢X|ioDt |tƒo4|i ptd|ƒ‚n|i |i ƒ}nP|i oDt |tƒo4|i ptd|ƒ‚n|i|i ƒ}n|SdS(NR:iiisFCannot decode str value %r into unicode (no default_encoding provided)sFCannot encode unicode value %r into str (no default_encoding provided)(R;RRRtUnicodeDecodeErrorRdRaRbReR4Rtdecode_encodingR#tdefault_encodingtUnicodeEncodeErrortencode(R R^RVR>RbRf((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRSÞs8      cCs>d||d|df}|io|d|i7}n|S(Ns%s at line %s column %siis in file %s(R (R R RV((s7/usr/lib/python2.6/site-packages/paste/util/template.pyReÿs  N(RRRR0RjRR R)t classmethodR-R8R3R<RBRPRQRORNRSRe(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRDs&        !    !cKs.|idƒ}t|d|ƒ}|i|ƒS(Nt__nameR (tgetRR8R7(RR5R ttmpl((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRs cCst|d|ƒ}|i|ƒS(NR (RR8(RRWR%Rp((s7/usr/lib/python2.6/site-packages/paste/util/template.pytpaste_script_template_renderer scBs5eZd„Zd„Zd„Zd„Zd„ZRS(cKs1x*|iƒD]\}}t|||ƒq WdS(N(titemstsetattr(R R5R R^((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR s cCs|||t s%s=%r(RrtsortR*RR=(R t_[1]tktvRrt_[2]((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR-(s 3  (RRR RtRwRyR-(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRs     cBs#eZd„Zd„Zd„ZRS(cCs ||_dS(N(R^(R R^((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR 5scCs|iS(N(R^(R ((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR7scCsd|ii|ifS(Ns<%s %r>(R*RR^(R ((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR-9s(RRR RR-(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR4s  cCsŽ|djodSt|tƒp0t|dƒot|ƒ}qRt|ƒ}nti|dƒ}t|tƒo|iddƒ}n|S(NR:t __unicode__itasciitxmlcharrefreplace( RRR@thasattrRRdtcgitescapeRl(R^((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt html_quote=s cCspt|tƒp0t|dƒot|ƒ}q@t|ƒ}nt|tƒo|idƒ}nti|ƒS(NRR(RR@R„RRdRlturllibtquote(R((s7/usr/lib/python2.6/site-packages/paste/util/template.pyturlJscKs›|iƒ}|iƒg}xi|D]a\}}|djoq#n|idƒo|d }n|idt|ƒt|ƒfƒq#Wtdi|ƒƒS(Nt_iÿÿÿÿs%s="%s"R{(RrR|RtendswithRAR‡RR=(R5R?R R^((s7/usr/lib/python2.6/site-packages/paste/util/template.pytattrTs    'cBsBeZeiiƒZeiededede ƒƒd„Z RS(RRRŠcCs8ti|||ƒ}t|tƒo|St|ƒSdS(N(RRSRRR‡(R R^RVtplain((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRSis( RRRR0R1R2RxRRRŠRS(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR`s   cKs.|idƒ}t|d|ƒ}|i|ƒS(NRnR (RoRR8R7(RR5R Rp((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRps c Cs‘t}g}d}d }xti|ƒD]}|idƒ}t||iƒƒ} |djo#|otdd| d|ƒ‚n2|djo$| otdd| d|ƒ‚n|djo5|||iƒ!} | o|i| ƒnt }n'|i|||iƒ!|fƒt}|iƒ}| }q(W|otd d|d|ƒ‚n||} | o|i| ƒn|ot |ƒ}n|S( sY Lex a string into chunks: >>> lex('hey') ['hey'] >>> lex('hey {{you}}') ['hey ', ('you', (1, 7))] >>> lex('hey {{') Traceback (most recent call last): ... TemplateError: No }} to finish last expression at line 1 column 7 >>> lex('hey }}') Traceback (most recent call last): ... TemplateError: }} outside expression at line 1 column 7 >>> lex('hey {{ {{') Traceback (most recent call last): ... TemplateError: {{ inside expression at line 1 column 10 iis{{s{{ inside expressionR R s}}s}} outside expressionsNo }} to finish last expression(ii( tFalsettoken_retfinditertgroupt find_positiontendRtstartRAR;ttrim_lex( tsR ttrim_whitespacetin_exprtchunkstlasttlast_postmatchRJRVRY((s7/usr/lib/python2.6/site-packages/paste/util/template.pytlex{s@         s^(?:if |elif |else |for |py:)tendiftendforRFRGs \n[\t ]*$s ^[\t ]*\ncCs”xtt|ƒƒD]y}||}t||tƒoqn|d}ti|ƒ o|tjoqn|p d}n||d}|dt|ƒjo d}n||d}t|tƒ pt|tƒ oqn| pti|ƒo| pti|ƒox|o5ti|ƒ}||i ƒd }|||d>> tokens = lex('{{if x}}\nx\n{{endif}}\ny', trim_whitespace=False) >>> tokens [('if x', (1, 3)), '\nx\n', ('endif', (3, 3)), '\ny'] >>> trim_lex(tokens) [('if x', (1, 3)), 'x\n', ('endif', (3, 3)), 'y'] iR:i( trangeR/RR@t statement_retsearchtsingle_statementsttrail_whitespace_retlead_whitespace_reR•R”(ttokenstitcurrentRDtprevtnexttm((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR–·s8     cCs.|| iƒ}t|ƒt|dƒdfS(s/Given a string and index, return (line, column)iÿÿÿÿi(t splitlinesR/(tstringtindextleading((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR“ãscCsMt|d|ƒ}g}x.|o&t||ƒ\}}|i|ƒqW|S(s« Parses a string into a kind of AST >>> parse('{{x}}') [('expr', (1, 3), 'x')] >>> parse('foo') ['foo'] >>> parse('{{if x}}test{{endif}}') [('cond', (1, 3), ('if', (1, 3), 'x', ['test']))] >>> parse('series->{{for x in y}}x={{x}}{{endfor}}') ['series->', ('for', (1, 11), ('x',), 'y', ['x=', ('expr', (1, 27), 'x')])] >>> parse('{{for x, y in z:}}{{continue}}{{endfor}}') [('for', (1, 3), ('x', 'y'), 'z', [('continue', (1, 21))])] >>> parse('{{py:x=1}}') [('py', (1, 3), 'x=1')] >>> parse('{{if x}}a{{elif y}}b{{else}}c{{endif}}') [('cond', (1, 3), ('if', (1, 3), 'x', ['a']), ('elif', (1, 12), 'y', ['b']), ('else', (1, 23), None, ['c']))] Some exceptions:: >>> parse('{{continue}}') Traceback (most recent call last): ... TemplateError: continue outside of for loop at line 1 column 3 >>> parse('{{if x}}foo') Traceback (most recent call last): ... TemplateError: No {{endif}} at line 1 column 3 >>> parse('{{else}}') Traceback (most recent call last): ... TemplateError: else outside of an if block at line 1 column 3 >>> parse('{{if x}}{{for x in y}}{{endif}}{{endfor}}') Traceback (most recent call last): ... TemplateError: Unexpected endif at line 1 column 25 >>> parse('{{if}}{{endif}}') Traceback (most recent call last): ... TemplateError: if with no expression at line 1 column 3 >>> parse('{{for x y}}{{endfor}}') Traceback (most recent call last): ... TemplateError: Bad for (no "in") in 'x y' at line 1 column 3 >>> parse('{{py:x=1\ny=2}}') Traceback (most recent call last): ... TemplateError: Multi-line py blocks must start with a newline at line 1 column 3 R (Ržt parse_exprRA(R—R R§R7R«((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRès2cCsct|dtƒo|d|dfS|d\}}|iƒ}|idƒor|didƒ}|idƒo|d}n*d|jotdd|d |ƒ‚nd ||f|dfS|djo>d |jotdd|d |ƒ‚n||f|dfS|idƒot|||ƒS|idƒp |djo*td|iƒdd|d |ƒ‚nÍ|djo td|d|d |ƒ‚n |d jo td|d|d |ƒ‚ns|idƒot|||ƒS|idƒot |||ƒS|idƒo d||ddf|dfSd||ddf|dfS(!Niispy:is s s.Multi-line py blocks must start with a newlineR R RERFRGRHscontinue outside of for loopsif selif R_s%s outside of an if blocktiftelifs%s with no expressionRŸR s Unexpected %ssfor sdefault t#RMRJ(scontinuesbreak(R²R³sfor(RŸR ( RR@tstript startswithtlstripRt parse_condRRt parse_fort parse_default(R§R tcontextRJRV((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR±!sR          cCs¸|dd}g}|d }x“|ptdd|d|ƒ‚nt|dtƒo4|dddjod|ft|ƒ|dfSt|||ƒ\}}|i|ƒq!dS( NiiR²sMissing {{endif}}R R RŸRI(sif(RRttupletparse_one_condRA(R§R R»R•tpiecesR«((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR¸Ms c Cs|d|d\}}}g}|idƒo|d }n|idƒo d||diƒ|f}no|idƒo d ||d iƒ|f}n?|d jod |d|f}ndptd ||f‚x¬|ptd d|d|ƒ‚nt|dtƒoM|dddjp-|ddidƒp|ddd jo ||fSt|||ƒ\}}|i |ƒqàdS(Niit:iÿÿÿÿsif R²iselif R³iR_sUnexpected token %r at %ss No {{endif}}R R RŸ( RŒR¶R·RRTRRR¼R±RA(R§R R»tfirstRVRRYR«((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR½\s.    c CsÜ|d\}}|d}d|}g}|idƒpt‚|idƒo|d }n|diƒ}ti|ƒ}|p td|d |d |ƒ‚n||iƒ }d |jo td |d |d |ƒ‚ntg}||iƒ i d ƒD]$} | iƒo|| iƒqq~ƒ}||i ƒ} x’|ptdd |d |ƒ‚nt |dtƒo3|dddjod||| |f|dfSt |||ƒ\} }|i | ƒqFdS(NiiRHsfor R¿iÿÿÿÿisBad for (no "in") in %rR R t(s=You cannot have () in the variable section of a for loop (%r)t,s No {{endfor}}R (sfor(R¶RTRŒRµtin_reR£RR•R¼RRR”RR±RA( R§R R»RÀRVRRRWR}RRJR«((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR¹vs@    $*cCs|d\}}|idƒpt‚|iddƒd}|iddƒ}t|ƒdjo td|d|d|ƒ‚n|diƒ}d|jotd d|d|ƒ‚nti|ƒp td |d|d|ƒ‚n|diƒ}d |||f|dfS( Nisdefault it=s:Expression must be {{default var=value}}; no = found in %rR R RÂs'{{default x, y = ...}} is not supporteds-Not a valid variable name for {{default}}: %rRL( R¶RTRRRR/RRµtvar_reR£(R§R R»RÀRVR?R[RJ((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRº˜s&  sn%prog [OPTIONS] TEMPLATE arg=value Use py:arg=value to set a Python value; otherwise all values are strings. cCs²ddk}ddk}ddk}ddk}|djo|id}n|idƒ}|idt|ƒdt ƒ}|i dddd d d d d ƒ|i dddddd dƒ|i dddddd dƒ|i |ƒ\}}t |ƒdjo"dGHt |ƒGHdpt‚n|d}|d}h} |io| i|iƒnx|D]y} d| jod| GH|idƒn| iddƒ\} } | idƒo| d } t| ƒ} n| | | RR twb(!Ratoptparset pkg_resourcestosRtargvtget_distributiont OptionParserRdt_fill_command_usaget add_optiont parse_argsR/tdirRTRÑR2tenvirontexitRRR¶R`tstdinR!R R"RÎRRR8RÊtwritetstdout(R4RaRÔRÕRÖtdisttparsertoptionst template_nameRWR^R ttemplate_contentR't TemplateClassttemplateR7((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt fill_command´st0                    t__main__(Rê((0RtreRaR…Rˆtpaste.util.looperRt__all__tcompileRRÃtIRÅt ExceptionRRRtobjectRRRRqRxRRR‡RŠRRRR;RžR¢R¤R¥R¦R–R“RR±R¸R½R¹RºRÚRêRtpaste.util.template(((s7/usr/lib/python2.6/site-packages/paste/util/template.pytsR       $  7 ,  9 ,   "  >