Ñò ûãtHc @sÊdZddkZyddkZWnej oddkZnXddklZddklZddddd gZ d Z defd „ƒYZ de fd „ƒYZ e iZe iZe iZdS( sTemplate loading and caching.iÿÿÿÿN(t TemplateError(tLRUCachetTemplateLoadertTemplateNotFoundt directorytpackagetprefixedsrestructuredtext encBseZdZd„ZRS(sBException raised when a specific template file could not be found.cCs!ti|d|ƒ||_dS(s¡Create the exception. :param name: the filename of the template :param search_path: the search path used to lookup the template sTemplate "%s" not foundN(Rt__init__t search_path(tselftnameR((s</usr/lib64/python2.6/site-packages/genshi/template/loader.pyR!s(t__name__t __module__t__doc__R(((s</usr/lib64/python2.6/site-packages/genshi/template/loader.pyRsc BsŒeZdZd ed dd ded d„Zd d d d„Zd d„Zd„Z e e ƒZ d„Z e e ƒZ d„Z e e ƒZ RS( s Responsible for loading templates from files on the specified search path. >>> import tempfile >>> fd, path = tempfile.mkstemp(suffix='.html', prefix='template') >>> os.write(fd, '

$var

') 11 >>> os.close(fd) The template loader accepts a list of directory paths that are then used when searching for template files, in the given order: >>> loader = TemplateLoader([os.path.dirname(path)]) The `load()` method first checks the template cache whether the requested template has already been loaded. If not, it attempts to locate the template file, and returns the corresponding `Template` object: >>> from genshi.template import MarkupTemplate >>> template = loader.load(os.path.basename(path)) >>> isinstance(template, MarkupTemplate) True Template instances are cached: requesting a template with the same name results in the same instance being returned: >>> loader.load(os.path.basename(path)) is template True The `auto_reload` option can be used to control whether a template should be automatically reloaded when the file it was loaded from has been changed. Disable this automatic reloading to improve performance. >>> os.remove(path) itstrictc Csõddkl} ||_|idjo g|_n-t|ittfƒp|ig|_n||_||_|p| |_ ||_ ||_ |dj ot |ƒ ot dƒ‚n||_t|ƒ|_h|_tiƒ|_dS(sáCreate the template laoder. :param search_path: a list of absolute path names that should be searched for template files, or a string containing a single absolute path; alternatively, any item on the list may be a ''load function'' that is passed a filename and returns a file-like object and some metadata :param auto_reload: whether to check the last modification time of template files, and reload them if they have changed :param default_encoding: the default encoding to assume when loading templates; defaults to UTF-8 :param max_cache_size: the maximum number of templates to keep in the cache :param default_class: the default `Template` subclass to use when instantiating templates :param variable_lookup: the variable lookup mechanism; either "strict" (the default), "lenient", or a custom lookup class :param allow_exec: whether to allow Python code blocks in templates :param callback: (optional) a callback function that is invoked after a template was initialized by this loader; the function is passed the template object as only argument. This callback can be used for example to add any desired filters to the template :see: `LenientLookup`, `StrictLookup` :note: Changed in 0.5: Added the `allow_exec` argument iÿÿÿÿ(tMarkupTemplates-The "callback" parameter needs to be callableN(tgenshi.template.markupRRtNonet isinstancetlistttuplet auto_reloadtdefault_encodingt default_classtvariable_lookupt allow_exectcallablet TypeErrortcallbackRt_cachet _uptodatet threadingtRLockt_lock( R RRRtmax_cache_sizeRRRRR((s</usr/lib64/python2.6/site-packages/genshi/template/loader.pyROs"         cCsº|djo |i}n|i}|oA| ptii|ƒ o%tiitii|ƒ|ƒ}ntii|ƒ}|}|i i ƒzyI|i |}|i p|S|i |}|dj o|ƒo|SWnttfj onXt} tii|ƒotii|ƒg}t} nr|oStii|ƒo@tii|ƒ} | |jot|ƒ| g}nt} n|ptdƒ‚nxñ|D]é} t| tƒot| ƒ} ny| |ƒ\} }} }Wntj o q¨q¨Xzh| o | }n|i|| | |d|ƒ}|io|i|ƒn||i |<||i |>> load = prefixed( ... app1 = lambda filename: ('app1', filename, None, None), ... app2 = lambda filename: ('app2', filename, None, None) ... ) >>> print load('app1/foo.html') ('app1', 'app1/foo.html', None, None) >>> print load('app2/bar.html') ('app2', 'app2/bar.html', None, None) :param delegates: mapping of path prefixes to loader functions :return: the loader function :rtype: ``function`` cs¢x†ˆiƒD]x\}}|i|ƒo\t|tƒot|ƒ}n||t|ƒidƒƒ\}}}}||||fSq Wt|ˆiƒƒ‚dS(Ns/\( titemst startswithRR0RtlentlstripRtkeys(R5tprefixtdelegateR<t_R=R:(t delegates(s</usr/lib64/python2.6/site-packages/genshi/template/loader.pyt_dispatch_by_prefix?s (((RQRR((RQs</usr/lib64/python2.6/site-packages/genshi/template/loader.pyR+s N( R R R RR.R/RR>R2Rt staticmethodRR(((s</usr/lib64/python2.6/site-packages/genshi/template/loader.pyR+s# 5l     (R R%Rt ImportErrortdummy_threadingtgenshi.template.baseRt genshi.utilRt__all__t __docformat__RtobjectRRRR(((s</usr/lib64/python2.6/site-packages/genshi/template/loader.pyts     ÿ"