ó žòœMc@s0dZddlmZddlmZmZmZmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZdefd„ƒYZdefd„ƒYZd efd „ƒYZd efd „ƒYZd „Zd„Zd„Zd„ZdS(s…Provides the Template class, a facade for parsing, generating and executing template strings, as well as template runtime operations.iÿÿÿÿ(tLexer(truntimetutilt exceptionstcodegenNtTemplatecBsÔeZdZdddeddddddddddeeddedded„Zd„Zed„ƒZ ed„ƒZ ed„ƒZ d„Z d„Z d „Zd „Zd „Zd „Zed „ƒZRS(s"Represents a compiled template. :class:`.Template` includes a reference to the original template source (via the ``.source`` attribute) as well as the source code of the generated Python module (i.e. the ``.code`` attribute), as well as a reference to an actual Python module. :class:`.Template` is constructed using either a literal string representing the template text, or a filename representing a filesystem path to a source file. :param text: textual template source. This argument is mutually exclusive versus the "filename" parameter. :param filename: filename of the source template. This argument is mutually exclusive versus the "text" parameter. :param buffer_filters: string list of filters to be applied to the output of %defs which are buffered, cached, or otherwise filtered, after all filters defined with the %def itself have been applied. Allows the creation of default expression filters that let the output of return-valued %defs "opt out" of that filtering via passing special attributes or objects. :param bytestring_passthrough: When True, and output_encoding is set to None, and :meth:`.Template.render` is used to render, the StringIO or cStringIO buffer will be used instead of the default "fast" buffer. This allows raw bytestrings in the output stream, such as in expressions, to pass straight through to the buffer. New in 0.4 to provide the same behavior as that of the previous series. This flag is forced to True if disable_unicode is also configured. :param cache_dir: Filesystem directory where cache files will be placed. See :ref:`caching_toplevel`. :param cache_enabled: Boolean flag which enables caching of this template. See :ref:`caching_toplevel`. :param cache_type: Type of Beaker caching to be applied to the template. See :ref:`caching_toplevel`. :param cache_url: URL of a memcached server with which to use for caching. See :ref:`caching_toplevel`. :param default_filters: List of string filter names that will be applied to all expressions. See :ref:`filtering_default_filters`. :param disable_unicode: Disables all awareness of Python Unicode objects. See :ref:`unicode_disabled`. :param encoding_errors: Error parameter passed to ``encode()`` when string encoding is performed. See :ref:`usage_unicode`. :param error_handler: Python callable which is called whenever compile or runtime exceptions occur. The callable is passed the current context as well as the exception. If the callable returns ``True``, the exception is considered to be handled, else it is re-raised after the function completes. Is used to provide custom error-rendering functions. :param format_exceptions: if ``True``, exceptions which occur during the render phase of this template will be caught and formatted into an HTML error page, which then becomes the rendered result of the :meth:`render` call. Otherwise, runtime exceptions are propagated outwards. :param imports: String list of Python statements, typically individual "import" lines, which will be placed into the module level preamble of all generated Python modules. See the example in :ref:`filtering_default_filters`. :param input_encoding: Encoding of the template's source code. Can be used in lieu of the coding comment. See :ref:`usage_unicode` as well as :ref:`unicode_toplevel` for details on source encoding. :param lookup: a :class:`.TemplateLookup` instance that will be used for all file lookups via the ``<%namespace>``, ``<%include>``, and ``<%inherit>`` tags. See :ref:`usage_templatelookup`. :param module_directory: Filesystem location where generated Python module files will be placed. :param module_filename: Overrides the filename of the generated Python module file. For advanced usage only. :param output_encoding: The encoding to use when :meth:`.render` is called. See :ref:`usage_unicode` as well as :ref:`unicode_toplevel`. :param preprocessor: Python callable which will be passed the full template source before it is parsed. The return result of the callable will be used as the template source code. :param strict_undefined: Replaces the automatic usage of ``UNDEFINED`` for any undeclared variables not located in the :class:`.Context` with an immediate raise of ``NameError``. The advantage is immediate reporting of missing variables which include the name. New in 0.3.6. :param uri: string uri or other identifier for this template. If not provided, the uri is generated from the filesystem path, or from the in-memory identity of a non-file-based template. The primary usage of the uri is to provide a key within :class:`.TemplateLookup`, as well as to generate the file path of the generated Python module file, if ``module_directory`` is specified. tstrictcCs|r*tjdd|ƒ|_||_n‹|rtjdd|ƒ|_tjj|ƒ\}}tjj|ƒjtjj dƒ}||_n%dt t |ƒƒ|_|j|_||_ ||_ ||_||_|pâ||_||_tjr|rtjdƒ‚n|r0|r0tjdƒ‚n|dkrltjsN|jr]dg|_qudg|_n ||_||_||_||_|dk rât|||ƒ\}}||_||_t|d||||ƒn½|dk r| dk r| }nx| dk ru|j}|d dkr5|d }ntjjtjj tjj| ƒtjj|ƒd ƒƒ}nd}|j!||ƒ}ntj"d ƒ‚||_#||_$|j#j%|_&||_'||_(||_)| |_*| |_+| |_,||_-dS( Ns\Wt_t/smemory:s4Mako for Python 3 does not support disabling UnicodesAoutput_encoding must be set to None when disable_unicode is used.tstrtunicodeiis.pys"Template requires text or filename(.tretsubt module_idturitostpatht splitdrivetnormpathtreplacetsepthextidtinput_encodingtoutput_encodingtencoding_errorstdisable_unicodetbytestring_passthroughtstrict_undefinedRtpy3kRtUnsupportedErrortNonetdefault_filterstbuffer_filterstimportst preprocessort _compile_textt_codet_sourcet ModuleInfotabspathtjoint_compile_from_filetRuntimeExceptiontmoduletfilenamet render_bodyt callable_tformat_exceptionst error_handlertlookupt cache_typet cache_dirt cache_urlt cache_enabled(tselfttextR-RR0R1R2RRtmodule_directoryR3R4R5tmodule_filenameRRRR R!RR"R#R6tdriveRtcodeR,tu((s3/usr/lib/python2.7/vendor-packages/mako/template.pyt__init__„sx $                                   cCs”|dk r>tjtjj|ƒƒtj|ƒtj}tjj|ƒ sjtj|ƒtj|krt |t |dƒj ƒ||ƒnt j |j|t |dƒƒ}tj|j=|jtjkr"t |t |dƒj ƒ||ƒt j |j|t |dƒƒ}tj|j=nt||||ddƒnRt|t |dƒj ƒ|ƒ\}}d|_||_t|d|||dƒ|S(Ntrb(RRtverify_directoryRRtdirnametstattST_MTIMEtexistst_compile_module_filetopentreadtimpt load_sourceR tsystmodulest _magic_numberRt MAGIC_NUMBERR'R$R&R%(R7RR-t filemtimeR,R<((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR*ês:  ! !  cCst|jƒjS(s2return the template source code for this Template.(t_get_module_info_from_callableR/tsource(R7((s3/usr/lib/python2.7/vendor-packages/mako/template.pyRP scCst|jƒjS(s/return the module source code for this Template(ROR/R<(R7((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR<scCs |jjS(N(R,t_template_cache(R7((s3/usr/lib/python2.7/vendor-packages/mako/template.pytcachescOstj||j||ƒS(sìRender the output of this template as a string. if the template specifies an output encoding, the string will be encoded accordingly, else the output is raw (raw output uses cStringIO and can't handle multibyte characters). a Context object is created corresponding to the given data. Arguments that are explictly declared by this template's internal rendering method are also pulled from the given \*args, \**data members. (Rt_renderR/(R7targstdata((s3/usr/lib/python2.7/vendor-packages/mako/template.pytrenders cOstj||j||dtƒS(s7render the output of this template as a unicode object.t as_unicode(RRSR/tTrue(R7RTRU((s3/usr/lib/python2.7/vendor-packages/mako/template.pytrender_unicode*s  cOsDt|ddƒdkr$||_ntj||j|||ŽdS(soRender this Template with the given context. the data is written to the context's buffer. t_with_templateN(tgetattrRRZRt_render_contextR/(R7tcontextRTtkwargs((s3/usr/lib/python2.7/vendor-packages/mako/template.pytrender_context3s  cCst|jd|ƒS(Ns render_%s(thasattrR,(R7tname((s3/usr/lib/python2.7/vendor-packages/mako/template.pythas_defAscCst|t|jd|ƒƒS(s9Return a def of this template as a :class:`.DefTemplate`.s render_%s(t DefTemplateR[R,(R7Ra((s3/usr/lib/python2.7/vendor-packages/mako/template.pytget_defDscCst|jd|ƒS(Ns render_%s(R[R,(R7Ra((s3/usr/lib/python2.7/vendor-packages/mako/template.pyt_get_def_callableIscCs |jjS(N(R,t_modified_time(R7((s3/usr/lib/python2.7/vendor-packages/mako/template.pyt last_modifiedLsN((t__name__t __module__t__doc__RtFalseRXR>R*tpropertyRPR<RRRVRYR_RbRdReRg(((s3/usr/lib/python2.7/vendor-packages/mako/template.pyRsDs P "     tModuleTemplatecBsGeZdZdddddddeeeddddded„ZRS(s.A Template which is constructed given an existing Python module. e.g.:: t = Template("this is a template") f = file("mymodule.py", "w") f.write(t.code) f.close() import mymodule t = ModuleTemplate(mymodule) print t.render() RcCstjdd|jƒ|_|j|_|j|_||_||_| |_ | pW| |_ t j r~| r~t jdƒ‚n|rœ| rœt jdƒ‚n||_||_t||||||ƒ|jj|_| |_| |_| |_||_||_||_||_dS(Ns\WRs4Mako for Python 3 does not support disabling UnicodesAoutput_encoding must be set to None when disable_unicode is used.(R R t _template_uriR Rt_source_encodingRRRRRRRRRR,R-R'R.R/R0R1R2R3R4R5R6(R7R,R:ttemplatettemplate_filenamet module_sourcettemplate_sourceRRRRR0R1R2R3R4R5R6((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR>as:                N(RhRiRjRRkRXR>(((s3/usr/lib/python2.7/vendor-packages/mako/template.pyRmPs"RccBs eZdZd„Zd„ZRS(sDa Template which represents a callable def in a parent template.cCsj||_||_|j|_|j|_|j|_|j|_|j|_|j|_|j|_dS(N( tparentR/RR,RR0R1R2R(R7RtR/((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR>šs        cCs|jj|ƒS(N(RtRd(R7Ra((s3/usr/lib/python2.7/vendor-packages/mako/template.pyRd¥s(RhRiRjR>Rd(((s3/usr/lib/python2.7/vendor-packages/mako/template.pyRc–s R'cBsAeZdZejƒZd„Zed„ƒZed„ƒZ RS(s¯Stores information about a module currently loaded into memory, provides reverse lookups of template source, module source code based on a module's identifier. cCs^||_||_||_||_||_||j|j<|_|rZ||j|°s     cCs-|jdk r|jSt|jƒjƒSdS(N(RrRRFR:RG(R7((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR<ÀscCs–|jdk rN|jjrDt|jtƒ rD|jj|jjƒS|jSnD|jjrt|jdƒj ƒj|jjƒSt|jƒj ƒSdS(NR?( RsRR,Rot isinstanceR tdecodeRFRqRG(R7((s3/usr/lib/python2.7/vendor-packages/mako/template.pyRPÇs      ( RhRiRjtweakreftWeakValueDictionaryRuR>RlR<RP(((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR'¨s   c Bsÿ|j}e||d|jd|jd|jƒ}|jƒ}ej||j|d|j d|j d|j d|j d|jd|jd |j ƒ}|}ej rÄe|eƒrÄ|jƒ}nej|ƒ}e||d ƒ} | |j|jU||fS( NRRR#R R!R"tsource_encodingtgenerate_magic_commentRtexec(R RRRR#tparseRtcompileRR R!R"tencodingRRRRwR tencodettypest ModuleTypet__dict__( RpR8R-t identifiertlexertnodeRPtcidR,R<((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR$×s0             c Cs|j}t||d|jd|jd|jƒ}|jƒ}tj||j|d|j d|j d|j d|j dt d|jd |jƒ}tjd tjj|ƒƒ\}} t|tƒrá|j|j pØd ƒ}ntj||ƒtj|ƒtj| |ƒdS( NRRR#R R!R"R{R|Rtdirtascii(R RRRR#R~RRRR R!R"R€RXRttempfiletmkstempRRRARwR Rtwritetclosetshutiltmove( RpR8R-t outputpathR…R†R‡RPtdestRa((s3/usr/lib/python2.7/vendor-packages/mako/template.pyREós.            $ cCst|jdƒS(NRh(t_get_module_infot func_globals(R/((s3/usr/lib/python2.7/vendor-packages/mako/template.pyROscCs tj|S(N(R'Ru(R-((s3/usr/lib/python2.7/vendor-packages/mako/template.pyR“s(Rjt mako.lexerRtmakoRRRRRHRR RRBRJR‹ttimeR‚RytobjectRRmRcR'R$REROR“(((s3/usr/lib/python2.7/vendor-packages/mako/template.pyts"xÿBF/