Ñò ûãtHc@s!dZddkZyeWn#ej oddklZnXddklZlZddk l Z ddk l Z l Z lZlZlZlZddklZlZlZdd d d d d ddddddg ZdZdefd„ƒYZdefd„ƒYZd„Zdefd„ƒYZd efd„ƒYZd efd„ƒYZd efd„ƒYZ d efd„ƒYZ!defd„ƒYZ"defd „ƒYZ#defd!„ƒYZ$d efd"„ƒYZ%defd#„ƒYZ&defd$„ƒYZ'defd%„ƒYZ(dS(&s2Implementation of the various template directives.iÿÿÿÿN(t ImmutableSet(tQNametStream(tPath(tTemplateRuntimeErrortTemplateSyntaxErrortEXPRt_apply_directivest _eval_exprt _exec_suite(t ExpressiontExpressionASTTransformert_parsetAttrsDirectivetChooseDirectivetContentDirectivet DefDirectivet ForDirectivet IfDirectivetMatchDirectivetOtherwiseDirectivetReplaceDirectivetStripDirectivet WhenDirectivet WithDirectivesrestructuredtext ent DirectiveMetacBseZdZd„ZRS(s#Meta class for template directives.cCs2|iƒiddƒ|d(tgetattrtNoneR)tsourcet __class__R%(R+R)((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyt__repr__gsc CsŒy.|ot||i|d|iƒpdSWnWtj oK}|id||if7_t||i|||ipdƒ‚nXdS(spParses the given expression, raising a useful error message when a syntax error is encountered. tlookups% in expression "%s" of "%s" directiveiN( R tfilepathR?R;t SyntaxErrortmsgRRR0(R!R)R-R/R0terr((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR*ms N( R%R&R'Rt __metaclass__t __slots__R;R1R4t classmethodR9R>R*(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR(,s       cs+‡fd†‰ˆ|ƒ‡fd†‰ˆS(sŒTakes the AST representation of an assignment, and returns a function that applies the assignment of a given value to a dictionary. cst|tiitiifƒo/tg}|iD]}|ˆ|ƒq3~ƒSt|tiitiifƒo|i SdS(N( t isinstancetcompilertasttAssTupletTuplettupletnodestAssNametNameR"(tnodet_[1]tchild(t_names(s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRS€s"/"csZt|ƒtjo9x@tt|ƒƒD]}ˆ|||||ƒq&Wn |||>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''''') >>> print tmpl.generate(foo={'class': 'collapse'}) >>> print tmpl.generate(foo=[('class', 'collapse')]) If the value evaluates to ``None`` (or any other non-truth value), no attributes are added: >>> print tmpl.generate(foo=None) c s.‡‡‡‡fd†}t|ƒ|ˆˆS(Nc 3s_ˆiƒ\}\}}}tˆiˆˆ}|oút|tƒo6yt|ƒiƒ}Wqtj o g}qXn!t|tƒp|iƒ}n|g}|D]$\}}|djo ||q«q«~8}|g}|D]<\}}|dj o#|t |ƒt |ƒi ƒfqçqç~O}n|||f|fVxˆD] } | VqLWdS(N( tnextRR)RGRtitert StopIterationtlisttitemsR;Rtunicodetstrip( tkindttagtattribR3tattrsRQR"tvalt_[2]tevent(R8R2R+R7(s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyt _generate­s"< N(R(R+R2R6R7R8Ri((R2R8R+R7s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR9¬s(R%R&R'RER9(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR ŽscBs)eZdZgZd„ZeeƒZRS(sÔImplementation of the ``py:content`` template directive. This directive replaces the content of the element with the result of evaluating the value of the ``py:content`` attribute: >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''''') >>> print tmpl.generate(bar='Bye') cCsmt|ƒtjotd|i|dŒ‚n|i|||dŒ}d|dt||f|dgfS(Ns3The content directive can not be used as an elementiiiÿÿÿÿ(RtdictRR@R*R;R(R!R-R2R,R.R3R)((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4Ós (R%R&R'RER4RF(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRÂs cBs\eZdZdddddgZd ddd„Zd„ZeeƒZd „Zd „Z RS( sImplementation of the ``py:def`` template directive. This directive can be used to create "Named Template Functions", which are template snippets that are not actually output during normal processing, but rather can be expanded from expressions in other places in the template. A named template function can be used just like a normal Python function from template expressions: >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
...

... ${greeting}, ${name}! ...

... ${echo('Hi', name='you')} ...
''') >>> print tmpl.generate(bar='Bye')

Hi, you!

If a function does not require parameters, the parenthesis can be omitted in the definition: >>> tmpl = MarkupTemplate('''
...

... Hello, world! ...

... ${helloworld()} ...
''') >>> print tmpl.generate(bar='Bye')

Hello, world!

R"targst star_argst dstar_argstdefaultsiÿÿÿÿcCsAti|d||||ƒt|ƒi}g|_d|_d|_h|_t |t i i ƒoÌ|ii |_ x||iD]q}t |t i iƒoB|ii|i ƒt|i|i|d|iƒ|i|i (R=R%R"(R+((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR>LsN( R%R&R'RER;R1R4RFR9R>(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRÝs(   $cBsSeZdZddgZdddd„Zd„ZeeƒZd„Zd„Z RS( s­Implementation of the ``py:for`` template directive for repeating an element based on an iterable in the context data. >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
    ...
  • ${item}
  • ...
''') >>> print tmpl.generate(items=[1, 2, 3])
  • 1
  • 2
  • 3
tassigntfilenameiÿÿÿÿcCs¨d|jotd|i||ƒ‚n|iddƒ\}}t|dƒ}d|iƒ}t|iidiƒ|_ |i|_ t i ||||||ƒdS(Ns in s'"in" keyword missing in "for" directiveitexecsiter(%s)i( RR@tsplitR RaRZRPRMR)R|R}R(R1(R+R,R-R.R/R0R|RI((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR1_s  cCsHt|ƒtjo|idƒ}ntt|ƒi|||||ƒS(Nteach(RRjRtRuRR4(R!R-R2R,R.R3((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4jsc ks t|i||}|djodS|i}h}t|ƒ}xW|D]O}|||ƒ|i|ƒx"t||||D] } | VqW|iƒqIWdS(N(RR)R;R|R^RwRRv( R+R2R6R7R8titerableR|RytitemRh((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR9qs      cCsd|iiS(Ns<%s>(R=R%(R+((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR>€sN( R%R&R'RER;R1R4RFR9R>(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRPs     cBs2eZdZgZd„ZeeƒZd„ZRS(s‹Implementation of the ``py:if`` template directive for conditionally excluding elements from being output. >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
... ${bar} ...
''') >>> print tmpl.generate(foo=True, bar='Hello')
Hello
cCsHt|ƒtjo|idƒ}ntt|ƒi|||||ƒS(Nttest(RRjRtRuRR4(R!R-R2R,R.R3((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4“scKs4t|i||}|ot||||SgS(N(RR)R(R+R2R6R7R8R,((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR9šs(R%R&R'RER4RFR9(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR„s    cBsYeZdZdddgZd d ddd„Zd„ZeeƒZd„Zd„Z RS( s°Implementation of the ``py:match`` template directive. >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
... ... Hello ${select('@name')} ... ... ...
''') >>> print tmpl.generate()
Hello Dude
tpathR.thintsiÿÿÿÿcCsXti|d||||ƒt||i|ƒ|_|ph|_|pd|_dS(N((R(R1R;RR@R„R.R…(R+R,R-R…R.R/R0((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR1´scCsâg}t|ƒtjo£|iddƒiƒdjo|idƒn|iddƒiƒdjo|idƒn|iddƒiƒdjo|id ƒn|id ƒ}n|||t|ƒ||d Œ|fS( NtbufferRtfalset not_bufferedtoncettruet match_oncet recursivet not_recursiveR„i(RRjRtRRqt frozenset(R!R-R2R,R.R3R…((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4»scKsD|ii|iidtƒ|it|ƒ|i|i|fƒgS(Ntignore_context(t_match_templatesRqR„RƒtTrueR^R…R.(R+R2R6R7R8((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR9ÉscCsd|ii|iifS(Ns <%s "%s">(R=R%R„R<(R+((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR>ÏsN( R%R&R'RER;R1R4RFR9R>(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR¡s  cBs)eZdZgZd„ZeeƒZRS(s;Implementation of the ``py:replace`` template directive. This directive replaces the element with the result of evaluating the value of the ``py:replace`` attribute: >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
... Hello ...
''') >>> print tmpl.generate(bar='Bye')
Bye
This directive is equivalent to ``py:content`` combined with ``py:strip``, providing a less verbose way to achieve the same effect: >>> tmpl = MarkupTemplate('''
... Hello ...
''') >>> print tmpl.generate(bar='Bye')
Bye
cCsyt|ƒtjo|idƒ}n|ptd|i|dŒ‚n|i|||dŒ}dt||fgfS(NR,s%missing value for "replace" directivei(RRjRtRR@R*R;R(R!R-R2R,R.R3R)((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4ïs(R%R&R'RER4RF(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRÓs cBs2eZdZgZd„Zd„ZeeƒZRS(s¾Implementation of the ``py:strip`` template directive. When the value of the ``py:strip`` attribute evaluates to ``True``, the element is stripped from the output >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
...
foo
...
''') >>> print tmpl.generate()
foo
Leaving the attribute value empty is equivalent to a truth value. This directive is particulary interesting for named template functions or match templates that do not generate a top-level element: >>> tmpl = MarkupTemplate('''
...
... ${what} ...
... ${echo('foo')} ...
''') >>> print tmpl.generate()
foo
c s.‡‡‡‡fd†}t|ƒ|ˆˆS(Nc3sftˆiˆˆo6ˆiƒˆiƒ}x3ˆD]}|V|}q3WnxˆD] }|VqSWdS(N(RR)R[(tpreviousRh(R8R2R+R7(s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRis  (R(R+R2R6R7R8Ri((R2R8R+R7s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR9s cCs;|pd|dd!fStt|ƒi|||||ƒS(Niiÿÿÿÿ(R;RuRR4(R!R-R2R,R.R3((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4(s(R%R&R'RER9R4RF(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRús  cBs8eZdZddgZd„ZeeƒZd„ZRS(sŒImplementation of the ``py:choose`` directive for conditionally selecting one of several body elements to display. If the ``py:choose`` expression is empty the expressions of nested ``py:when`` directives are tested for truth. The first true ``py:when`` body is output. If no ``py:when`` directive is matched then the fallback directive ``py:otherwise`` will be used. >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
... 0 ... 1 ... 2 ...
''') >>> print tmpl.generate()
1
If the ``py:choose`` directive contains an expression, the nested ``py:when`` directives are tested for equality to the ``py:choose`` expression: >>> tmpl = MarkupTemplate('''
... 1 ... 2 ...
''') >>> print tmpl.generate()
2
Behavior is undefined if a ``py:choose`` block contains content outside a ``py:when`` or ``py:otherwise`` block. Behavior is also undefined if a ``py:otherwise`` occurs before ``py:when`` blocks. tmatchedR,cCsHt|ƒtjo|idƒ}ntt|ƒi|||||ƒS(NRƒ(RRjRtRuRR4(R!R-R2R,R.R3((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4Yscks…tt|iƒdg}|iot|i|||d"when" directives can only be used inside a "choose" directiveiiis?either "choose" or "when" directive must have a test expression(R–RR}R[R)RR•R(R+R2R6R7R8R—R,R“((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR9}s&! !    N( R%R&R'RER;R1R4RFR9(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyRjs    cBs2eZdZdgZdddd„Zd„ZRS(s²Implementation of the ``py:otherwise`` directive for nesting in a parent with the ``py:choose`` directive. See the documentation of `ChooseDirective` for usage. R}iÿÿÿÿcCs,ti|d||||ƒ|i|_dS(N(R(R1R;R@R}(R+R,R-R.R/R0((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR1 scKsr|io |id}|p'td|i|iƒddŒ‚n|dogSt|d>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('''
... $x $y $z ...
''') >>> print tmpl.generate(x=42)
42 7 52
R8iÿÿÿÿc Cs]ti|d||||ƒg|_|iƒ}yÎt|dƒi}xµ|iD]ª}t|t i i ƒoqPn3t|t i i ƒpt d|i||ƒ‚n|iig}|iD]} |t| ƒq¼~t|i|i|d|iƒfƒqPWWnWtj oK} | id||if7_t | |i||| ipdƒ‚nXdS(NR~s8only assignment allowed in value of the "with" directiveR?s% in expression "%s" of "%s" directivei(R(R1R;R8RaR RPRMRGRHRItDiscardtAssignRR@RqRZR R)R?RARBRR0( R+R,R-R.R/R0RIRPRQtnRC((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR1Às(   0 cCsHt|ƒtjo|idƒ}ntt|ƒi|||||ƒS(NR8(RRjRtRuRR4(R!R-R2R,R.R3((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR4Ösc ksh}|i|ƒxG|iD]<\}}t|||}x|D]} | ||ƒqBWqWx"t||||D] } | VqsW|iƒdS(N(RwR8RRRv( R+R2R6R7R8tframettargetsR)R,R|Rh((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR9Ýs   cCsd|iiS(Ns<%s>(R=R%(R+((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR>èsN( R%R&R'RER;R1R4RFR9R>(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyR±s     ()R'RHRŽt NameErrortsetsRt genshi.coreRRt genshi.pathRtgenshi.template.baseRRRRRR tgenshi.template.evalR R R t__all__t __docformat__RRtobjectR(RZR RRRRRRRRRRR(((s@/usr/lib64/python2.6/site-packages/genshi/template/directives.pyts: .    P 4s42'6:.