Ñò °›—Ic@s¿dZddkZddkZddkZyddklZWn#ej oddklZnXddkZddkl Z ddk Z ddk Z ddddd d d gZ d d dddddddddg Z eieƒZd„Zd-dddd„Zddddd„Zdddd„Zdddddd„Zddddd„Zdefd„ƒYZdefd„ƒYZd efd!„ƒYZdefd"„ƒYZhZxÑeid#ƒD]ÀZ ye i!ƒZ"e"ee i#` -- Routes url generator object - :class:`translator` -- Gettext translator object configured for current locale - :func:`ungettext` -- Unicode capable version of gettext's ngettext function (handles plural translations) - :func:`_` -- Unicode capable gettext translate function - :func:`N_` -- gettext no-op function to mark a string for translation, but doesn't actually translate Configuring the template language --------------------------------- The template engine is created in the projects ``config/environment.py`` and attached to the ``app_globals`` (g) instance. Configuration options can be directly passed into the template engine, and are used by the render functions. .. warning:: Don't change the variable name on :data:`app_globals` that the template loader is attached to if you want to use the render_* functions that :mod:`pylons.templating` comes with. The render_* functions look for the template loader to render the template. Legacy Buffet templating plugin and render functions ==================================================== The Buffet object is styled after the original Buffet module that implements template language neutral rendering for CherryPy. This version of Buffet also contains caching functionality that utilizes `Beaker middleware `_ to provide template language neutral caching functionality. A customized version of `BuffetMyghty `_ is included that provides a template API hook as the ``pylonsmyghty`` engine. This version of BuffetMyghty disregards some of the TurboGears API spec so that traditional Myghty template names can be used with ``/`` and file extensions. The render functions are intended as the primary user-visible rendering commands and hook into Buffet to make rendering content easy. iÿÿÿÿN(tStringIO(tliteraltBuffettMyghtyTemplatePlugintrendert render_genshit render_jinja2t render_makotrender_responsetctconfigtgthtrequesttsessiont translatort ungettextt_tN_cCsMtiiƒ}tiiƒ}|idƒp|d}td|d|d|d|d|d|id ƒp tiiƒd tiiƒd tiiƒd ti iƒd ti iƒdti i dti i dti iƒ }tid}dtiijp$d|jo.|dtiijotiiƒ|d(tdef_nameR.R4(s5/usr/lib/python2.6/site-packages/pylons/templating.pyR@(s   R1R2R3(R8(R.RBR1R2R3R4R@((RBR.R4s5/usr/lib/python2.6/site-packages/pylons/templating.pytrender_mako_defs txhtmlcs@‡‡‡fd†}tˆ|d|d|d|dddˆƒS(sÊRender a template with Genshi Accepts the cache options ``cache_key``, ``cache_type``, and ``cache_expire`` in addition to method which are passed to Genshi's render function. csXˆph}|itƒƒ|diiˆƒ}t|i|idˆddƒƒS(NRtmethodtencoding(R9R"t genshi_loadertloadRtgenerateRR)(R=R>(R?R.RE(s5/usr/lib/python2.6/site-packages/pylons/templating.pyR@Cs  R1R2R3R0RE(R8(R.R?R1R2R3RER@((R.R?REs5/usr/lib/python2.6/site-packages/pylons/templating.pyR9s   c s1‡‡fd†}tˆ|d|d|d|ƒS(s{Render a template with Jinja2 Accepts the cache options ``cache_key``, ``cache_type``, and ``cache_expire``. csFˆph}|itƒƒ|diiˆƒ}t|i|ƒS(NR(R9R"t jinja2_envR;RR(R=R>(R?R.(s5/usr/lib/python2.6/site-packages/pylons/templating.pyR@^s R1R2R3(R8(R.R?R1R2R3R@((R.R?s5/usr/lib/python2.6/site-packages/pylons/templating.pyRUs  t BuffetErrorcBseZdZRS(sBuffet Exception(t__name__t __module__t__doc__(((s5/usr/lib/python2.6/site-packages/pylons/templating.pyRKoscBsMeZdZdddd„Zddd„Zddeddddd„ZRS(sùBuffet style plug-in template rendering Buffet implements template language plug-in support modeled highly on the `Buffet Project `_ from which this class inherits its name. cKsm|djo h}n||_||_||_h|_tidƒ|io|i|||ndS(sSInitialize the Buffet renderer, and optionally set a default engine/optionssInitialized Buffet objectN(R)tdefault_enginet template_roottdefault_optionstenginesRRtprepare(tselfRORPRQR ((s5/usr/lib/python2.6/site-packages/pylons/templating.pyt__init__}s        cKsti|dƒ}|ptd|ƒ‚n|p|}|i|ddƒ}td|d|d|ƒd|ƒ|i|`_ method is called so that the ``template_root`` and options can be set. Template engines can also be aliased if you wish to use multiplate configurations of the same template engines, or prefer a shorter name when rendering a template with the engine of your choice. s9Please install a plugin for "%s" to use its functionalitys.extra_vars_functenginetextra_vars_functoptionstroots/Adding %s template language for use with BuffetN( tavailable_enginesRR)tTemplateEngineMissingtpopRRRRR(RTt engine_nameRPtaliasR tEngineRW((s5/usr/lib/python2.6/site-packages/pylons/templating.pyRS‹s    c su| o|io |i}n|ii|ƒ‰ˆptd|ƒ‚n|‰|djoÔˆdjo h‰nx2dD]*} | ˆjoˆi| ƒˆ| tiiˆd |ƒ‰ˆitiid ƒid ƒ‰ndˆjoˆddjo ˆd=n|dj p|dj p |dj oå|p d}n|p d}n|djo d}n‡‡‡‡fd†} ˆ} ˆidtƒo| d7} nˆidtƒo| ˆd7} ntidˆƒtii| ƒ}|i|d| d|d|ƒ} | Stidˆ|ƒˆdiˆdˆˆS(s™Render a template using a template engine plug-in To use templates it is expected that you will attach data to be used in the template to the ``c`` variable which is available in the controller and the template. When porting code from other projects it is sometimes easier to use an exisitng dictionary which can be specified with ``namespace``. ``engine_name`` The name of the template engine to use, which must be 'prepared' first. ``template_name`` Name of the template to render ``include_pylons_variables`` If a custom namespace is specified this determines whether Pylons variables are included in the namespace or not. Defaults to ``True``. ``namespace`` A custom dictionary of names and values to be substituted in the template. Caching options (uses Beaker caching middleware) ``cache_key`` Key to cache this copy of the template under. ``cache_type`` Valid options are ``dbm``, ``file``, ``memory``, or ``ext:memcached``. ``cache_expire`` Time in seconds to cache this template with this ``cache_key`` for. Or use 'never' to designate that the cache should never expire. The minimum key required to trigger caching is ``cache_expire='never'`` which will cache the template forever seconds with no key. All other keyword options are passed directly to the template engine used. s'No engine with that name configured: %st pylonsmyghtytoutput_encodingtencoding_errorstdisable_unicodet _global_argsRVt allow_globalssIYou must specify ``namespace`` when ``include_pylons_variables`` is FalseRtmakoRYt.tformatR#R$R%cs*tidˆƒˆdiˆdˆˆS(NsCached render running for %sRVR>(RRR((t engine_configR5t full_pathRX(s5/usr/lib/python2.6/site-packages/pylons/templating.pyR7stfragmentt_fragsUsing render cache for %sR'R&R(s$Rendering template %s with engine %sR>N(soutput_encodingsencoding_errorssdisable_unicode(RORRRt ExceptionR)R\R"t interpretert global_argstkeyst init_paramsRKR9t startswithtostpathtseptjointreplacetlstriptFalseRRRR+R,R-R(RTR]R.tinclude_pylons_variablesR5R1R3R2RXtkeytinterpR=R7ttfiletmycache((R5RiRXRjs5/usr/lib/python2.6/site-packages/pylons/templating.pyR£s~.        #     %       N(RLRMRNR)RURStTrueR(((s5/usr/lib/python2.6/site-packages/pylons/templating.pyRts R[cBseZdZRS(s+Exception to toss when an engine is missing(RLRMRN(((s5/usr/lib/python2.6/site-packages/pylons/templating.pyR[%scBsGeZdZdZddd„Zd„Zdeddddd„ZRS(sÓMyghty Template Plugin This Myghty Template Plugin varies from the official BuffetMyghty in that it will properly populate all the default Myghty variables needed and render fragments. tmytcCsŠ|djo h}nh}x<|iƒD].\}}|idƒo|||dRaRbRctbufRot optional_args((s5/usr/lib/python2.6/site-packages/pylons/templating.pyRDs"   N( RLRMRNt extensionR)RUR‰RyR(((s5/usr/lib/python2.6/site-packages/pylons/templating.pyR*s  spython.templating.engines(tDistributionNotFoundiR`tfiles4Unable to load template engine entry point: '%s': %sic Osò|idtƒ}|idd ƒ}t|ƒ}|iƒ}td|idd ƒd|idd ƒd|idd ƒƒ}tid||ƒ|o5|iƒ}tii ||d|d|d||Stii d|d|d|d||S( sRender a template and return it as a string (possibly Unicode) Optionally takes 3 keyword arguments to use caching supplied by Buffet. Examples: .. code-block:: python content = render('/my/template.mako') print content content = render('/my/template2.myt', fragment=True) .. admonition:: Note Not all template languages support the concept of a fragment. In those template languages that do support the fragment option, this usually implies that the template will be rendered without extending or inheriting any site skin. RkRhR3R2R1s.Render called with %s args and %s keyword argsR5R.N( R\RyR)tlistRRRRtbuffetR(targstkargsRkRhR>t cache_argsRV((s5/usr/lib/python2.6/site-packages/pylons/templating.pyRss    cOs»titiitdƒtiiƒ}t||Ž}t |t ƒo ||_ n ||_ |i dƒ}|i dƒ}|o!dtii|f|id|sj        ,<#±2       '