class documentation

class TemplateLookup(TemplateCollection):

View In Hierarchy

Represent a collection of templates that locates template source files from the local filesystem.

The primary argument is the directories argument, the list of directories to search:

lookup = TemplateLookup(["/path/to/templates"])
some_template = lookup.get_template("/index.html")

The .TemplateLookup can also be given .Template objects programatically using .put_string or .put_template:

lookup = TemplateLookup()
lookup.put_string("base.html", '''
    <html><body>${self.next()}</body></html>
''')
lookup.put_string("hello.html", '''
    <%include file='base.html'/>

    Hello, world !
''')

All other keyword parameters available for .Template are mirrored here. When new .Template objects are created, the keywords established with this .TemplateLookup are passed on to each new .Template.

Parameters
directoriesA list of directory names which will be searched for a particular template URI. The URI is appended to each directory and the filesystem checked.
collection​_sizeApproximate size of the collection used to store templates. If left at its default of -1, the size is unbounded, and a plain Python dictionary is used to relate URI strings to .Template instances. Otherwise, a least-recently-used cache object is used which will maintain the size of the collection approximately to the number given.
filesystem​_checksWhen at its default value of True, each call to .TemplateLookup.get_template() will compare the filesystem last modified time to the time in which an existing .Template object was created. This allows the .TemplateLookup to regenerate a new .Template whenever the original source has been updated. Set this to False for a very minor performance increase.
modulename​_callableA callable which, when present, is passed the path of the source file as well as the requested URI, and then returns the full path of the generated Python module file. This is used to inject alternate schemes for Python module location. If left at its default of None, the built in system of generation based on module_directory plus uri is used.
Method adjust​_uri Adjust the given uri based on the given relative URI.
Method filename​_to​_uri Convert the given filename to a URI relative to this .TemplateCollection.
Method get​_template Return a .Template object corresponding to the given uri.
Method put​_string Place a new .Template object into this .TemplateLookup, based on the given string of text.
Method put​_template Place a new .Template object into this .TemplateLookup, based on the given .Template object.
Method __init__ Undocumented
Method ​_check Undocumented
Method ​_load Undocumented
Method ​_relativeize Return the portion of a filename that is 'relative' to the directories in this lookup.
Instance Variable ​_collection Undocumented
Instance Variable ​_mutex Undocumented
Instance Variable ​_uri​_cache Undocumented
Instance Variable collection​_size Undocumented
Instance Variable directories Undocumented
Instance Variable filesystem​_checks Undocumented
Instance Variable module​_directory Undocumented
Instance Variable modulename​_callable Undocumented
Instance Variable template​_args Undocumented

Inherited from TemplateCollection:

Method has​_template Return True if this .TemplateLookup is capable of returning a .Template object for the given uri.
def adjust_uri(self, uri, relativeto):
Adjust the given uri based on the given relative URI.
def filename_to_uri(self, filename):
Convert the given filename to a URI relative to this .TemplateCollection.
def get_template(self, uri):

Return a .Template object corresponding to the given uri.

Note

The relativeto argument is not supported here at the moment.

def put_string(self, uri, text):
Place a new .Template object into this .TemplateLookup, based on the given string of text.
def put_template(self, uri, template):
Place a new .Template object into this .TemplateLookup, based on the given .Template object.
def __init__(self, directories=None, module_directory=None, filesystem_checks=True, collection_size=-1, format_exceptions=False, error_handler=None, disable_unicode=False, bytestring_passthrough=False, output_encoding=None, encoding_errors='strict', cache_args=None, cache_impl='beaker', cache_enabled=True, cache_type=None, cache_dir=None, cache_url=None, modulename_callable=None, module_writer=None, default_filters=None, buffer_filters=(), strict_undefined=False, imports=None, future_imports=None, enable_loop=True, input_encoding=None, preprocessor=None, lexer_cls=None, include_error_handler=None):

Undocumented

def _check(self, uri, template):

Undocumented

def _load(self, filename, uri):

Undocumented

def _relativeize(self, filename):
Return the portion of a filename that is 'relative' to the directories in this lookup.
_collection: dict =

Undocumented

_mutex =

Undocumented

_uri_cache: dict =

Undocumented

collection_size =

Undocumented

directories =

Undocumented

filesystem_checks =

Undocumented

module_directory =

Undocumented

modulename_callable =

Undocumented

template_args =

Undocumented