Server : Apache System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64 User : dh_edsupp ( 6597262) PHP Version : 8.2.26 Disable Function : NONE Directory : /lib/python3/dist-packages/genshi/template/__pycache__/ |
Upload File : |
o !�b�9 � @ s� d Z ddlZzddlZW n ey ddlZY nw ddlZddlmZ ddlm Z g d�Z dZG dd� de�ZG d d � d e �ZejZejZejZdS )zTemplate loading and caching.� N)� TemplateError)�LRUCache)�TemplateLoader�TemplateNotFound� directory�package�prefixedzrestructuredtext enc @ s e Zd ZdZdd� ZdS )r zBException raised when a specific template file could not be found.c C s t �| d| � || _dS )z�Create the exception. :param name: the filename of the template :param search_path: the search path used to lookup the template zTemplate "%s" not foundN)r �__init__�search_path)�self�namer � r �8/usr/lib/python3/dist-packages/genshi/template/loader.pyr # s zTemplateNotFound.__init__N)�__name__� __module__�__qualname__�__doc__r r r r r r s r c @ sh e Zd ZdZ ddd�Zd d � Zdd� Zdd d�Zddd�Ze dd� �Z e dd� �Ze dd� �ZdS )r a Responsible for loading templates from files on the specified search path. >>> import tempfile >>> fd, path = tempfile.mkstemp(suffix='.html', prefix='template') >>> os.write(fd, u'<p>$var</p>'.encode('utf-8')) 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) NF� �strictTc C s� ddl m} || _| jdu rg | _n t| jttf�s| jg| _|| _ || _|p)| | _|| _ || _ |dur>t|d�s>td��|| _ t|�| _i | _t�� | _dS )a� 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 r )�MarkupTemplateN�__call__z-The "callback" parameter needs to be callable)�genshi.template.markupr r � isinstance�list�tuple�auto_reload�default_encoding� default_class�variable_lookup� allow_exec�hasattr� TypeError�callbackr �_cache� _uptodate� threading�RLock�_lock) r r r r �max_cache_sizer r r r"