'Create a new template.
If the source parameter (str or buffer) is missing, the name argument
is used to guess a template filename. Subclasses can assume that
self.source and/or self.filename are set. Both are strings.
The lookup, encoding and settings parameters are stored as instance
variables.
The lookup parameter stores a list containing directory paths.
The encoding parameter should be used to decode byte strings or files.
The settings parameter contains a dict for engine-specific settings.'

def __init__(self, source=None, name=None, lookup=None, encoding='utf8', **settings):

    self.name = name
    self.source = (source.read() if hasattr(source, 'read') else source)
    self.filename = (source.filename if hasattr(source, 'filename') else None)
    self.lookup = ([os.path.abspath(x) for x in lookup] if lookup else [])
    self.encoding = encoding
    self.settings = self.settings.copy()
    self.settings.update(settings)
    if ((not self.source) and self.name):
        self.filename = self.search(self.name, self.lookup)
        if (not self.filename):
            raise TemplateError(('Template    %s    not    found.' % repr(name)))
    if ((not self.source) and (not self.filename)):
        raise TemplateError('No    template    specified.')
    self.prepare(**self.settings)
