ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ ]c@s?dZddlZddlZddlZddlZddlmZdddddd d gZejd Z ejd Z ejd ej Z de fdYZde fdYZde fdYZdefdYZdZddZd efdYZd efdYZdZdZdZdefdYZdZdedZejdZ dd d!d"gZ!ejd#Z"ejd$Z#d%Z$d&Z%dd'Z&d1d(Z'd)Z(d*Z)d+Z*d,Z+d-Z,dd.Z-e.d/kr;dd0l/m-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. iN(tloopert TemplateErrortTemplatetsubt HTMLTemplatetsub_htmlthtmltbunchs \{\{|\}\}s\s+in\s+s^[a-z_][a-z0-9_]*$cBs#eZdZddZdZRS(s.Exception raised while parsing a template cCs||_||_||_dS(N(tmessagetpositiontname(tselfRR R ((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__init__2s  cCsEd|j|jd|jdf}|jrA|d|j7}n|S(Ns%s at line %s column %siis in %s(RR R (R tmsg((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__str__7s ! N(t__name__t __module__t__doc__tNoneR R(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR.s t_TemplateContinuecBseZRS((RR(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR>st_TemplateBreakcBseZRS((RR(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRAscBseZidd6dd6ed6ZdZdddZdddZeeZdZ d Z d Z d Z d Z d ZdZdZdZdZdZRS(s{{t start_bracess}}t end_bracesRtutf8cCs[||_t|t|_||_t|d||_|dkrNi}n||_dS(NR ( tcontentt isinstancetunicodet_unicodeR tparset_parsedRt namespace(R RR R((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR Ns    cCsVt|d}|j}|j|r=|j|}n|d|d|d|S(NtrbRR R(topentreadtclosetdecode(tclstfilenameRtencodingtftc((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt from_filenameWs   cCs*d|jjtt|d|jfS(Ns<%s %s name=%r>i(t __class__RthextidR (R ((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__repr__as cOs|rI|rtdnt|dkr<tdn|d}n|jj}|j|j|j||j|}|S(Ns3You can only give positional *or* keyword argumentsis(You can only give on positional argumenti(t TypeErrortlentdefault_namespacetcopytupdateRt _interpret(R targstkwtnstresult((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt substitutefs    cCs2t}g}|j|j|d|dj|S(Ntoutt(tTruet_interpret_codesRtjoin(R R6t__traceback_hide__tparts((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR3uscCsMt}x@|D]8}t|tr2|j|q |j|||q WdS(N(R;Rt basestringtappendt_interpret_code(R tcodesR6R9R>titem((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR<{s  cCst}|d|d}}|dkrA|j|d||n|dkrYtn|dkrqtn|dkr|d|d|d }}} |j|||}|j||| ||n.|d kr|d} |j| ||n|d kr|djd } |j| d||} x3| dD]'} |j| ||} | | } q=W|j|j | |nx|d kr|d|d}}||kr|j|||}|||R tpostvarsRJRR?tbasetparttfunctvarR7((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRBs<             c Cst}x|D]}t|dkr6|||dRDR tvalue((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRPs    c Cst}x|D]}t|t s)t|d|d}}|dkrSt}n|j|d||}|r |j|d||Pq q WdS(Niitelseii(R;RR@RTROR<( R R?R6R9R>RYR RVR7((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRQs   c Cst}yt||}|SWnttj}|d}t|drX|jd}n t|}|j||f|_|d||dnXdS(NiR4ii(R;tevaltsystexc_infotgetattrR4tstrt_add_line_info( R RUR6RVR>R^Rbtetarg0((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyROs   cBsie}y ||UWnPej}|d}|j|jd|f|_|d||dnXdS(Niii(R;RaRbReR4(R RUR6RVR>RbRf((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRNs   cCsPt}y\|dkrdS|jrUyt|}Wqatk rQt|}qaXn t|}WnPtj}|d}|j|j d|f|_ |d||dnX|jrt |tr|j std|n|j |j }nJ|j rHt |trH|j s3td|n|j|j }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((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRSs8         cCs<d||d|df}|jr8|d|j7}n|S(Ns%s at line %s column %siis in file %s(R (R R RV((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRes  N(RRRR0RjRR R)t classmethodR-R8R3R<RBRPRQRORNRSRe(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRDs&        !    !cKs.|jd}t|d|}|j|S(Nt__nameR (tgetRR8R7(RR5R ttmpl((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRs cCst|d|}|j|S(NR (RR8(RRWR%Rp((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytpaste_script_template_renderer scBs5eZdZdZdZdZdZRS(cKs1x*|jD]\}}t|||q WdS(N(titemstsetattr(R R5R R^((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR scCs|||t s%s=%r(RrtsortR*RR=(R tktvRr((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR-(s +  (RRR RtRwRyR-(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRs     cBs#eZdZdZdZRS(cCs ||_dS(N(R^(R R^((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR 5scCs|jS(N(R^(R ((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR7scCsd|jj|jfS(Ns<%s %r>(R*RR^(R ((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR-9s(RRR RR-(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR4s  cCs|dkrdSt|tsLt|dr=t|}qLt|}ntj|d}t|tr|jdd}n|S(NR:t __unicode__itasciitxmlcharrefreplace( RRR@thasattrRRdtcgitescapeRl(R^((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt html_quote=s cCsjt|ts<t|dr-t|}q<t|}nt|tr]|jd}ntj|S(NRR(RR@RRRdRlturllibtquote(R~((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyturlJscKs|j}|jg}xe|D]]\}}|dkrAq#n|jdr]|d }n|jdt|t|fq#Wtdj|S(Nt_is%s="%s"R{(RrR|RtendswithRARRR=(R5R?R R^((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytattrTs    'cBsBeZejjZejededede dZ RS(RRRcCs6tj|||}t|tr(|St|SdS(N(RRSRRR(R R^RVtplain((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRSis( RRRR0R1R2RxRRRRS(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR`s   cKs.|jd}t|d|}|j|S(NRnR (RoRR8R7(RR5R Rp((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRps c Cst}g}d}d }x tj|D]}|jd}t||j} |dkr|rtdd| d|n.|dkr| rtdd| d|n|dkr|||j!} | r|j| nt }n&|j|||j!|ft}|j}| }q(W|rHtd d|d|n||} | rh|j| n|r}t |}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((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytlex{s>         s^(?:if |elif |else |for |py:)tendiftendforRFRGs \n[\t ]*$s ^[\t ]*\ncCsxxtt|D]d}||}t||tr<qn|d}tj| rh|tkrhqn|swd}n||d}|dt|krd}n||d}t|t st|t rqn| stj|r| stj|r|r>tj|}||j 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_reRR(ttokenstitcurrentRDtprevtnexttm((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRs6     cCs.|| j}t|t|ddfS(s/Given a string and index, return (line, column)ii(t splitlinesR/(tstringtindextleading((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRscCsKt|d|}g}x,|rFt||\}}|j|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(RR RR7R((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRs 2 cCsHt|dtr%|d|dfS|d\}}|j}|jdr|djd}|jdr|d}n'd|krtdd|d |nd ||f|dfS|dkrd |krtdd|d |n||f|dfS|jdr#t|||S|jds>|dkrgtd|jdd|d |n|dkrtd|d|d |n|d krtd|d|d |nl|jdrt|||S|jdrt |||S|jdr)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 expressionRRs Unexpected %ssfor sdefault t#RMRJ(RFRG(RRRH(RR( RR@tstript startswithtlstripRt parse_condRRt parse_fort parse_default(RR tcontextRJRV((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR!sR          cCs|dd}g}|d }x|sBtdd|d|nt|dtr|dddkrd|ft||dfSt|||\}}|j|q!WdS( NiiRsMissing {{endif}}R R RRI(R(RRttupletparse_one_condRA(RR RRtpiecesR((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRMs cCs|d|d\}}}g}|jdr=|d }n|jdrkd||dj|f}nk|jdrd ||d j|f}n=|d krd |d|f}ndstd ||fx|std d|d|nt|dtrV|dddksL|ddjdsL|ddd krV||fSt|||\}}|j |qWdS(Niit:isif Riselif RiR_sUnexpected token %r at %ss No {{endif}}R R R( RRRRRTRRRRRA(RR RtfirstRVRRYR((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR\s.   c Cs|d\}}|d}d|}g}|jds?t|jdr[|d }n|dj}tj|}|std|d |d |n||j }d |krtd |d |d |ntg||j j d D]}|jr|j^q}||j } x|sRtdd |d |nt |dtr|dddkrd||| |f|dfSt |||\} }|j | q1WdS(NiiRHsfor RiisBad 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(RH(RRTRRtin_reRRRRRRRRRRA( RR RRRVRRRWR~RJR((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRvs@      !cCs |d\}}|jds%t|jddd}|jdd}t|dkr~td|d|d|n|dj}d|krtd d|d|ntj|std |d|d|n|dj}d |||f|dfS( Nisdefault it=s:Expression must be {{default var=value}}; no = found in %rR R Rs'{{default x, y = ...}} is not supporteds-Not a valid variable name for {{default}}: %rRL( RRTRRRR/RRtvar_reR(RR RRRVR?R[RJ((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRs&  sn%prog [OPTIONS] TEMPLATE arg=value Use py:arg=value to set a Python value; otherwise all values are strings. c Csddl}ddl}ddl}ddl}|dkrL|jd}n|jd}|jdt|dt }|j dddd d d d d |j dddddd d|j dddddd d|j |\}}t |dkrdGHt |GHdstn|d}|d}i} |jrU| j|jnx}|D]u} d| krd| GH|jdn| jdd\} } | jdr| d } t| } n| | | RR twb(!Ratoptparset pkg_resourcestosRtargvtget_distributiont OptionParserRdt_fill_command_usaget add_optiont parse_argsR/tdirRTRR2tenvirontexitRRRR`tstdinR!R R"RRRR8Rtwritetstdout(R4RaRRRtdisttparsertoptionst template_nameRWR^R ttemplate_contentR't TemplateClassttemplateR7((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt fill_commandsr0                      t__main__(R((0RtreRaRRtpaste.util.looperRt__all__tcompileRRtIRt ExceptionRRRtobjectRRRRqRxRRRRRRRR;RRRRRRRRRRRRRRRRtpaste.util.template(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytsR       $  7 ,  9 ,   "  >