ó žòœMc@sqdZddlmZmZddlZddlZddlZdefd„ƒYZde fd„ƒYZ defd „ƒYZ e ƒZ d efd „ƒYZ d efd „ƒYZdefd„ƒYZdefd„ƒYZd„Zd„Zd„Zd„Zd„Zd„Zd„Zdd„Zed„Zd„Zd„Zd„Zddd„Zd„Z dS( sdprovides runtime services for templates, including Context, Namespace, and various helper functions.iÿÿÿÿ(t exceptionstutilNtContextcBs¶eZdZd„Zed„ƒZed„ƒZd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zdd „Zd „Zd„Zd„Zd„Zd„ZRS(s±Provides runtime namespace, output buffer, and various callstacks for templates. See :ref:`runtime_toplevel` for detail on the usage of :class:`.Context`. cKss|g|_||_|jƒ|_d|_d|_i|_tj t |ƒ|jdeZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs d|_dS(N(R t nextcaller(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRœscCs|jƒrtptS(N(t _get_callertTruetFalse(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt __nonzero__žscCs|dS(Niÿÿÿÿ((R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR: scCst|jƒ|ƒS(N(tgetattrR:(RR((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt __getattr__¢scCs#|j|jpdƒd|_dS(N(RR9R (R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt _push_frame¤scCs|jƒ|_dS(N(R"R9(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt _pop_frame§s(R5R6RR=R:R?R@RA(((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR›s      t UndefinedcBs eZdZd„Zd„ZRS(s¨Represents an undefined value in a template. All template modules have a constant value ``UNDEFINED`` present which is an instance of this object. cCstdƒ‚dS(NRB(t NameError(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt__str__³scCstS(N(R<(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR=µs(R5R6R7RDR=(((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRB«s t_NSAttrcBseZd„Zd„ZRS(cCs ||_dS(N(t_NSAttr__parent(RR1((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR»scCsQ|j}x5|r@t|j|ƒr4t|j|ƒS|j}q Wt|ƒ‚dS(N(RFthasattrtmoduleR>tinheritstAttributeError(RRtns((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR?½s    (R5R6RR?(((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyREºs t NamespacecBs­eZdZd d ed d„Zd Zd Zd Zd Z d Z d Z d Z e jd„ƒZd„Zd„Zd„Zed„ƒZd„Zd„Zd „Zd „ZRS( s‡Provides access to collections of rendering methods, which can be local, from other templates, or from imported modules. To access a particular rendering method referenced by a :class:`.Namespace`, use plain attribute access:: ${some_namespace.foo(x, y, z)} :class:`.Namespace` also contains several built-in attributes described here. cCsY||_||_||_|dk rUtg|D]}|j|f^q1ƒ|_ndS(N(tnametcontextRIR tdictt func_namet callables(RRMRNRQRIt populate_selft calling_uriR+((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRÔs     cCs t|ƒS(süAccess module level attributes by name. This accessor allows templates to supply "scalar" attributes which are particularly handy in inheritance relationships. See the example in :ref:`inheritance_toplevel`. (RE(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pytattrs cCsk||f}||jjkr,|jj|St||jjƒd|d|jƒ}||jj|<|SdS(sOReturn a :class:`.Namespace` corresponding to the given uri. If the given uri is a relative uri (i.e. it does not contain ia leading slash ``/``), the uri is adjusted to be relative to the uri of the namespace itself. This method is therefore mostly useful off of the built-in ``local`` namespace, described in :ref:`namespace_local` In most cases, a template wouldn't need this function, and should instead use the ``<%namespace>`` tag to load namespaces. However, since all ``<%namespace>`` tags are evaulated before the body of a template ever runs, this method can be used to locate namespaces using expressions that were generated within the body code of the template, or to conditionally use a particular namespace. t templateuriRSN(RNR tTemplateNamespaceR,t _templateuri(RturiRRK((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt get_namespaces  cCst|j||jƒS(s¯Return a :class:`.Template` from the given uri. The uri resolution is relative to the uri of this :class:`.Namespace` object's :class:`.Template`. (t_lookup_templateRNRW(RRX((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt get_template9scKsÀ|jr­|jjs;|jddƒ}|r4|ƒSdSn|jjr`|jd|jjƒn|jjr…|jd|jjƒn|jjr­|jd|jjƒq­n|jj||S(s”Return a value from the :class:`.Cache` referenced by this :class:`.Namespace` object's :class:`.Template`. The advantage to this method versus direct access to the :class:`.Cache` is that the configuration parameters declared in ``<%page>`` take effect here, thereby calling up the same configured backend as that configured by ``<%page>``. t createfunctdata_dirttypeturlN( ttemplatet cache_enabledR&R t cache_dirt setdefaultt cache_typet cache_urltcache(RRRR\((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt get_cachedBs     cCs |jjS(s„Return the :class:`.Cache` object referenced by this :class:`.Namespace` object's :class:`.Template`. (R`Rf(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRf^scKst|j||j|dS(sInclude a file at the given uriN(t _include_fileRNRW(RRXR((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt include_filegscCs^xW|D]O}|dkrCx:|jƒD]\}}|||(RR/tltidenttktv((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt _populatels   ccs6|jr2x&|jD]}||j|fVqWndS(N(RQ(RR((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRkts cCsj||jkr|j|}n7|jr=t|j|ƒ}ntd|j|fƒ‚t|||ƒ|S(Ns!Namespace '%s' has no member '%s'(RQRIR>RJRMtsetattr(RRtval((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR?ys N((R5R6R7R R;RRQRHR`RNtfilenameRXRWRtmemoized_propertyRTRYR[RgR8RfRiRpRkR?(((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRLÆs&          RVcBsheZdZddddedd„Zed„ƒZed„ƒZed„ƒZ d„Z d„Z RS(s@A :class:`.Namespace` specific to a :class:`.Template` instance.c Csé||_||_||_|dk rUtg|D]} | j| f^q1ƒ|_n|dk r‹t|||ƒ|_|jj j |_ n3|dk r²||_|j j |_ n t dƒ‚|råt ||jd|ƒ\} } ndS(Ns 'template' argument is required.tself_ns(RMRNRIR RORPRQRZR`RHt _template_uriRWt TypeErrort_populate_self_namespace( RRMRNR`RURQRIRRRSR+t lclcallablet lclcontext((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRˆs     .      cCs |jjS(sìThe Python module referenced by this Namespace. If the namespace references a :class:`.Template`, then this module is the equivalent of ``template.module``, i.e. the generated module for the template. (R`RH(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRH s cCs |jjS(s^The path of the filesystem file used for this Namespace's module or template. (R`Rs(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRs«scCs |jjS(s¶The uri for this Namespace's template. I.e. whatever was sent to :meth:`.TemplateLookup.get_template()`. This is the equivalent of :attr:`Template.uri`. (R`RX(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRX²s c#spˆjr2x&ˆjD]}|ˆj|fVqWn‡fd†}x(ˆjjjD]}|||ƒfVqQWdS(Ncs%ˆjj|ƒ}tj|ˆjƒS(N(R`t_get_def_callableRR RN(Rt callable_(R(s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR&Ás(RQR`RHt_exports(RRR&Rn((Rs2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRk½s  cCs¦||jkr|j|}ns|jj|ƒr[|jj|ƒ}tj||jƒ}n7|jryt|j|ƒ}nt d|j |fƒ‚t |||ƒ|S(Ns!Namespace '%s' has no member '%s'( RQR`thas_defR{RR RNRIR>RJRMRq(RRRrR|((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR?Çs N( R5R6R7R R;RR8RHRsRXRkR?(((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRV…s  tModuleNamespacecBsDeZdZddedd„Zed„ƒZd„Zd„Z RS(s;A :class:`.Namespace` specific to a Python module instance.c Cs›||_||_||_|dk rUtg|D]}|j|f^q1ƒ|_nt|ƒ} x*|jdƒdD]} t | | ƒ} quW| |_ dS(Nt.i( RMRNRIR RORPRQt __import__tsplitR>RH( RRMRNRHRQRIRRRSR+tmodttoken((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRÚs    . cCs |jjS(s^The path of the filesystem file used for this Namespace's module or template. (RHt__file__(R((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRsèsc#sƒˆjr2x&ˆjD]}|ˆj|fVqWn‡fd†}x;tˆjƒD]*}|ddkrQ|||ƒfVqQqQWdS(Ncs%tˆj|ƒ}tj|ˆjƒS(N(R>RHRR RN(RR|(R(s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR&ósit_(RQtdirRH(RRR&Rn((Rs2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRkïs cCs¦||jkr|j|}nst|j|ƒr[t|j|ƒ}tj||jƒ}n7|jryt|j|ƒ}ntd|j |fƒ‚t |||ƒ|S(Ns!Namespace '%s' has no member '%s'( RQRGRHR>RR RNRIRJRMRq(RRRrR|((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR?ús N( R5R6R7R R;RR8RsRkR?(((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR×s   cs‡fd†}|S(sŽApply a caller_stack compatibility decorator to a plain Python function. See the example in :ref:`namespaces_python_modules`. cs6|jjƒzˆ|||ŽSWd|jjƒXdS(N(RR@RA(RNtargsR(tfunc(s2/usr/lib/python2.7/vendor-packages/mako/runtime.pytwrap_stackframes ((R‰RŠ((R‰s2/usr/lib/python2.7/vendor-packages/mako/runtime.pytsupports_caller scOsSt|ƒstjdƒ‚n|jƒz|||ŽWd|jƒ}X|jƒS(s‰Execute the given template def, capturing the output into a buffer. See the example in :ref:`namespaces_python_modules`. s[capture() function expects a callable as its argument (i.e. capture(func, *args, **kwargs))N(tcallableRtRuntimeExceptionR$R%tgetvalue(RNR|RˆRR ((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRs    cs‡fd†}|S(Ncs‡‡fd†}|S(NcsP‡‡fd†}yˆjd|_Wntk r9nXˆ|ƒˆ||ŽS(Ncsˆˆ||ŽS(N((Rˆtkw(RNt render_fn(s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyty0si(R5Rw(RNRˆRR‘(tfnR(RNs2/usr/lib/python2.7/vendor-packages/mako/runtime.pytgo/s  ((RR“(R’(Rs2/usr/lib/python2.7/vendor-packages/mako/runtime.pytdecorate_render.s ((R’R”((R’s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt_decorate_toplevel-s cs‡‡fd†}|S(Ncs"ˆ|ƒ‰‡‡fd†}|S(Ncsˆˆ||ŽS(N((RˆR(RNtdec(s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR“>s((RR“(RNR’(R–s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyR”<s ((RNR’R”((RNR’s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt_decorate_inline;scKsMt|||ƒ}t|jƒ|ƒ\}}||t||j|dS(sPlocate the template from the given uri and include it in the current output.N(RZRxR4t_kwargs_for_includeR(RNRXRSRR`R|tctx((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRhCs  c Cs|d krd St|||ƒ}|d}|}x|jd k rP|j}q5W|ji|d6ƒ}td|j|d|dtƒ|_|j|jd<|jdRHR|( RNRXRSR`RutihRzR|trettgen_ns((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyt _inherit_fromMs,        cCs‰|jj}|dkr4tjd|jjƒ‚n|j||ƒ}y|j|ƒSWn+tjk r„}tjt |ƒƒ‚nXdS(Ns.Template '%s' has no TemplateLookup associated( R RR RtTemplateLookupExceptionRXt adjust_uriR[tTopLevelLookupExceptiontstr(RNRXt relativetoRte((s2/usr/lib/python2.7/vendor-packages/mako/runtime.pyRZjs  cCsŠ|dkr1td|j|d|dtƒ}n||jd<|jds0$Ž  ¿R2