Ñò ûãtHc@sÓdZyddklZWn)ej odefd„ƒYZnXddkZddklZddkZddkl Z l Z l Z l Z l Z lZddklZd d d d d dgZdZeiddfjo d„Zn d„Zd efd„ƒYZd efd„ƒYZdefd„ƒYZd efd„ƒYZd efd„ƒYZd„Zd„Zd„Zdefd„ƒYZ d efd„ƒYZ!e!i"Z"e!i#Z#e!i$Z$e!i%Z%dS(sBasic templating functionality.iÿÿÿÿ(tdequeRcBseZd„Zd„ZRS(cCs|id|ƒdS(Ni(tinsert(tselftx((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt appendleftscCs |idƒS(Ni(tpop(R((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pytpoplefts(t__name__t __module__RR(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRs N(tStringIO(tAttrstStreamtStreamEventKindtSTARTtTEXTt_ensure(t ParseErrortContexttTemplatet TemplateErrortTemplateRuntimeErrortTemplateSyntaxErrortBadDirectiveErrorsrestructuredtext eniicCs |idS(i(tframes(tctxt((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt"scCs|S(((R((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR$scBs eZdZdddd„ZRS(s?Base exception class for errors related to template processing.iÿÿÿÿcCsƒ|djo d}n||_|djp |djod|i||f}nti||ƒ||_||_||_dS(s9Create the exception. :param message: the error message :param filename: the filename of the template :param lineno: the number of line in the template at which the error occurred :param offset: the column number at which the error occurred sis%s (%s, line %d)N(tNonetmsgt Exceptiont__init__tfilenametlinenotoffset(RtmessageRRR ((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR*s     N(RRt__doc__RR(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR'scBs eZdZdddd„ZRS(s|Exception raised when an expression in a template causes a Python syntax error, or the template is not well-formed. iÿÿÿÿcCs]t|tƒo3|idj o#t|ƒid|idƒ}nti||||ƒdS(s8Create the exception :param message: the error message :param filename: the filename of the template :param lineno: the number of line in the template at which the error occurred :param offset: the column number at which the error occurred s (line %d)tN(t isinstancet SyntaxErrorRRtstrtreplaceRR(RR!RRR ((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRCs #N(RRR"RR(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR>scBseZdZddd„ZRS(sñException raised when an unknown directive is encountered when parsing a template. An unknown directive is any attribute using the namespace for directives, with a local name that doesn't match any registered directive. iÿÿÿÿcCsti|d|||ƒdS(søCreate the exception :param name: the name of the directive :param filename: the filename of the template :param lineno: the number of line in the template at which the error occurred sbad directive "%s"N(RR(RtnameRR((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRYsN(RRR"RR(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRQscBseZdZRS(sfException raised when an the evaluation of a Python expression in a template causes an error. (RRR"(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRescBs˜eZdZd„Zd„Zd„ZeZd„Zd„Zd„Z d„Z dd„Z dd „Z d „Zd „Zd „Zd „Zd„ZRS(spContainer for template input data. A context provides a stack of scopes (represented by dictionaries). Template directives such as loops can push a new scope on the stack with data that should only be available inside the loop. When the loop terminates, that scope can get popped off the stack again. >>> ctxt = Context(one='foo', other=1) >>> ctxt.get('one') 'foo' >>> ctxt.get('other') 1 >>> ctxt.push(dict(one='frost')) >>> ctxt.get('one') 'frost' >>> ctxt.get('other') 1 >>> ctxt.pop() {'one': 'frost'} >>> ctxt.get('one') 'foo' c s‡t|gƒˆ_ˆiiˆ_ˆiiˆ_gˆ_gˆ_‡fd†}d‡fd†}|i d|ƒ|i d|ƒdS(sZInitialize the template context with the given keyword arguments as data. cs |ˆjS(s]Return whether a variable with the specified name exists in the expression scope.((R((R(s:/usr/lib64/python2.6/site-packages/genshi/template/base.pytdefinedscsˆi||ƒS(sˆIf a variable of the specified name is defined, return its value. Otherwise, return the provided default value, or ``None``.(tget(R(tdefault(R(s:/usr/lib64/python2.6/site-packages/genshi/template/base.pytvalue_of“sR)R,N( RRRRRtpusht_match_templatest _choice_stackRt setdefault(RtdataR)R,((Rs:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR„s  cCstt|iƒƒS(N(treprtlistR(R((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt__repr__šscCs|i|ƒddj S(suReturn whether a variable exists in any of the scopes. :param key: the name of the variable iN(t_findR(Rtkey((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt __contains__scCs0x)|iD]}||jo ||=q q WdS(saRemove a variable from all scopes. :param key: the name of the variable N(R(RR6tframe((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt __delitem__¥s  cCs6|i|ƒ\}}|djot|ƒ‚n|S(sGet a variables's value, starting at the current scope and going upward. :param key: the name of the variable :return: the variable value :raises KeyError: if the requested variable wasn't found in any scope N(R5RtKeyError(RR6tvalueR8((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt __getitem__®s cCst|iƒƒS(s‰Return the number of distinctly named variables in the context. :return: the number of variables in the context (tlentitems(R((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt__len__»scCs||id|ïscCs|idi|ƒdS(s-Update the context from the mapping provided.iN(Rtupdate(Rtmapping((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRC÷scCsdS(swPush a new scope on the stack. :param data: the data dictionary to push on the context stack. N((RR1((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR-ûscCsdS(s&Pop the top-most scope from the stack.N((R((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRsN(RRR"RR4R7thas_keyR9R<R?R@RR5R*RAR>RCR-R(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRks          cKs2|o'|dt|ƒ|d||}n|S(srApply the given directives to the stream. :param stream: the stream the directives should be applied to :param directives: the list of directives to apply :param ctxt: the `Context` :param vars: additional variables that should be available when Python code is executed :return: the stream with the given directives applied ii(titer(tstreamt directivesRtvars((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt_apply_directivess 'cKs@|o|i|ƒn|i|ƒ}|o|iƒn|S(sEvaluate the given `Expression` object. :param expr: the expression to evaluate :param ctxt: the `Context` :param vars: additional variables that should be available to the expression :return: the result of the evaluation (R-tevaluateR(texprRRItretval((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt _eval_exprs cKsq|o|i|ƒ|ihƒn|it|ƒƒ|o.|iƒ}|iƒ|idi|ƒndS(sÒExecute the given `Suite` object. :param suite: the code suite to execute :param ctxt: the `Context` :param vars: additional variables that should be available to the code iN(R-texecutet _ctxt2dictRRRC(tsuiteRRIttop((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyt _exec_suite#s   t TemplateMetacBseZdZd„ZRS(sMeta class for templates.cCshd|joEt|dƒ|d(t __class__RR(R((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR4†scCs@|i|i|ig|_|io|ii|iƒndS(N(t_flattent_evalt_execRnRdtappendt_include(R((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRg‰s cCs t‚dS(sõParse the template. The parsing stage parses the template and constructs a list of directives that will be executed in the render stage. The input is split up into literal output (text that does not depend on the context data) and directives or expressions. :param source: a file-like object containing the XML source of the template, or an XML event stream :param encoding: the encoding of the `source` N(tNotImplementedError(RRkRl((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRjŽs c cs ddkl}xó|D]ë\}}}|tjo¸g}|d}xW|dD]K\}} } }|i||| | |ƒ\} }| o|i| ƒqNqNW|i|ƒ}|o||t|ƒf|fVqx.|D] } | VqØWq|tjoü|\} }}t| t ƒo°t |i dt ƒ o™yI|i i | d|dd|p|iƒ}x|iD] } | VqgWWq|j o:|djo‚nx!|i|ƒD] } | Vq¬WqXqqô|o"| |t|i|ƒƒf}qôn|||fVqWdS( sŒCall the `attach` method of every directive found in the template. :param stream: the event stream of the template iÿÿÿÿ(tTemplateNotFoundiit auto_reloadt relative_toRZN(tgenshi.template.loaderR{RatattachRxRiR3R`R$RhtgetattrRdtTruetloadRtRGR(RRGR{tkindR1tposRHt substreamRZR;t namespacesR]teventthreftfallbackttmpl((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRiœsL        &cOsh}|o1|d}|djot|}qJ|}n t|}|i}x)|iD]}|t|ƒ||}q]Wt||iƒS(sApply the template to the given context data. Any keyword arguments are made available to the template as context data. Only one positional argument is accepted: if it is provided, it must be an instance of the `Context` class, and keyword arguments are ignored. This calling style is used for internal processing. :return: a markup event stream representing the result of applying the template to the context data. iN(RRRGRnRFR t serializer(RtargstkwargsRIRRGtfilter_((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pytgenerateËs      c ks]|i|if}|i}x;|D]3\}}}|tjo|do |\} } g} x×| D]Ï\} } t| tƒo | }nŽg}xD|i| ||D]-\}}}|tjo|i|ƒq¤q¤Wg}|D]}|dj o ||qàqà~}|pqbn| i| di |ƒfƒqbW|| t | ƒf|fVq"|t joçt |||}|dj oÄt|tƒot||fVqCt|t ttfƒot||ƒ|fVqCt|dƒoIt|ƒ} x |D]}|| ||} qõWx+| D] }|VqWqCtt|ƒ|fVqUq"|||fVq"WdS(sdInternal stream filter that evaluates any expressions in `START` and `TEXT` events. iut__iter__N(RuRvt _number_convR R$RhRRxRtjoinR R_RNtinttfloattlongthasattrRtunicode(RRGRRIRnt number_convRƒR1R„ttagtattrst new_attrsR(R…R;tvaluestsubkindtsubdatatsubposRBRtresultRŽR‡((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRvésP      2     cksCx<|D]4}|dtjot|d||q|VqWdS(s8Internal stream filter that executes Python code blocks.iiN(R^RS(RRGRRIR‡((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRws cksyxr|D]j}|dtjoN|d\}}t||||}x+|i|||D] }|VqYWq|VqWdS(s?Internal stream filter that expands `SUB` events in the stream.iiN(RaRJRu(RRGRRIR‡RHR…((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRu%s   cks°ddkl}x™|D]‘}|dtjou|d\}}}t|tƒpŒg} xD|i|||D]-\} } } | tjo| i| ƒqmqmWdig} | D]}|d j o | |q¯q¯~ ƒ}nyV|i i |d|ddd|p|i ƒ}x|i ||D] }|Vq#WWq¨|j o]|d jo‚nx)|iD]}|t|ƒ||}qbWx|D] }|Vq‹Wq¨Xq|VqWd S( s[Internal stream filter that performs inclusion of external template files. iÿÿÿÿ(R{iiuR}iRZN(R~R{R`R$RhRvRRxR’RRdR‚RtRRnRF(RRGRRIR{R‡RˆRZR‰tpartsRRžRŸRBRRŠRŽ((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyRy3s: ?   N(RRR"RTt __metaclass__R R^R_R`RaRR‹R—R‘RRRrRsR4RgRjRiRRvRwRuRy(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyR@s*     #      /  4  (&R"t collectionsRt ImportErrorR3tosR tsyst genshi.coreR R R R RRt genshi.inputRt__all__t __docformat__t version_infoRPRRRRRtobjectRRJRNRSRXRTRR^R_R`Ra(((s:/usr/lib64/python2.6/site-packages/genshi/template/base.pyts<  .    š    ÿ