Ñò ô†³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 cCsüt}|d|d}}|djo|i|d||ƒn¶|djo tƒ‚nœ|djo tƒ‚n‚|djoR|d|d|d }}} |i|||ƒ}|i||| ||ƒn#|d jo!|d} |i| ||ƒnõ|d jo|did ƒ} |i| d||ƒ} x3| dD]'} |i| ||ƒ} | | ƒ} qHW|i|i | |ƒƒni|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}xv|D]n}|d|d}}|djo t}n|i|d||ƒ}|o|i|d||ƒPq q WdS(Niitelseii(R;ROR<( R R?R6R9R>RXR RUR7((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 RTR6RUR>R]Ratetarg0((s7/usr/lib/python2.6/site-packages/paste/util/template.pyROÅs   cBsie}y ||UWnPeiƒ}|d}|i|id|ƒf|_|d||d‚nXdS(Niii(R;R`RaRdR4(R RTR6RUR>RaRe((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;RRRtUnicodeDecodeErrorRcR`RaRdR4Rtdecode_encodingR#tdefault_encodingtUnicodeEncodeErrortencode(R R]RUR>RaRe((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 RU((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRdÿs  N(RRRR0RiRR R)t classmethodR-R8R3R<RBRPRQRORNRSRd(((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(RRVR%Ro((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(RqtsortR*RR=(R t_[1]tktvRqt_[2]((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR-(s 3  (RRR RsRvRxR-(((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@thasattrRRctcgitescapeRk(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(NR€R(RR@RƒRRcRkturllibtquote(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"Rz(RqR{RtendswithRAR†RR=(R5R?R R]((s7/usr/lib/python2.6/site-packages/paste/util/template.pytattrTs    'cBsBeZeiiƒZeiededede ƒƒd„Z RS(RRŒR‰cCs8ti|||ƒ}t|tƒo|St|ƒSdS(N(RRSRRR†(R R]RUtplain((s7/usr/lib/python2.6/site-packages/paste/util/template.pyRSis( RRRR0R1R2RwRRŒR‰RS(((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR`s   cKs.|idƒ}t|d|ƒ}|i|ƒS(NRmR (RnRR8R7(RR5R Ro((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_postmatchRJRURX((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 (Rt 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 tcontextRJRU((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 Csu|d|d\}}}g}|idƒo|d }n|idƒo d||diƒ|f}nT|idƒo d ||d iƒ|f}n$|d jod |d|f}nx¬|ptd d |d|ƒ‚nt|dtƒoM|dddjp-|ddidƒp|ddd jo ||fSt|||ƒ\}}|i|ƒqÅdS(Niit:iÿÿÿÿsif R±iselif R²iR^s No {{endif}}R R Rž( R‹RµR¶RRRR»R°RA(R¦R RºtfirstRURRXRª((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR¼\s,    c CsÅ|d\}}|d}d|}g}|idƒo|d }n|diƒ}ti|ƒ}|p td|d|d |ƒ‚n||iƒ }d |jo td |d|d |ƒ‚ntg}||iƒ id ƒD]$} | iƒo|| iƒqìqì~ƒ}||iƒ} x’|ptd d|d |ƒ‚nt |dtƒo3|dddjod||| |f|dfSt |||ƒ\} }|i | ƒq/dS(NiiRHR¾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‹R´tin_reR¢RR”R»RRR“RR°RA( R¦R RºR¿RURRœRVR|R~RJRª((s7/usr/lib/python2.6/site-packages/paste/util/template.pyR¸vs>    $*cCsþ|d\}}|iddƒd}|iddƒ}t|ƒdjo td|d|d|ƒ‚n|diƒ}d|jotdd|d|ƒ‚nti|ƒp td |d|d|ƒ‚n|diƒ}d |||f|dfS( Niit=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(RRRR/RR´tvar_reR¢(R¦R RºR¿RUR?RZRJ((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 |ƒdjodGHt |ƒGHn|d}|d}h} |io| i|iƒnx|D]y} d| jod| GH|idƒn| iddƒ\} } | idƒo| d } t| ƒ} n| | | RR twb( R`toptparset pkg_resourcestosRtargvtget_distributiont OptionParserRct_fill_command_usaget add_optiont parse_argsR/tdirRÐR2tenvirontexitRRRµR_tstdinR!R R"RÍRRR8RÉtwritetstdout(R4R`RÓRÔRÕtdisttparsertoptionst template_nameRVR]R ttemplate_contentR't TemplateClassttemplateR7((s7/usr/lib/python2.6/site-packages/paste/util/template.pyt fill_command´st0                    t__main__(Ré((0RtreR`R„R‡tpaste.util.looperRt__all__tcompileRRÂtIRÄt ExceptionRRRtobjectRRRRpRwRRR†R‰RŒRRR;RR¡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 ,   "  >