pystache.loader module

This module provides a Loader class for locating and reading templates.

class pystache.loader.Loader(file_encoding=None, extension=None, to_unicode=None, search_dirs=None)[source]

Bases: object

Loads the template associated to a name or user-defined object.

All load_*() methods return the template as a unicode string.

load_file(file_name)[source]

Find and return the template with the given file name.

Arguments:

file_name: the file name of the template.

load_name(name)[source]

Find and return the template with the given template name.

Arguments:

name: the name of the template.

load_object(obj)[source]

Find and return the template associated to the given object.

Arguments:

obj: an instance of a user-defined class.

search_dirs: the list of directories in which to search.

read(path, encoding=None)[source]

Read the template at the given path, and return it as a unicode string.

str(s, encoding=None)[source]

Convert a string to unicode using the given encoding, and return it.

This function uses the underlying to_unicode attribute.

Arguments:

s: a basestring instance to convert to unicode. Unlike Python’s

built-in unicode() function, it is okay to pass unicode strings to this function. (Passing a unicode string to Python’s unicode() with the encoding argument throws the error, “TypeError: decoding Unicode is not supported.”)

encoding: the encoding to pass to the to_unicode attribute.

Defaults to None.