'Construct a Template.
:arg str template_string: the contents of the template file.
:arg str name: the filename from which the template was loaded
(used for error message).
:arg tornado.template.BaseLoader loader: the `~tornado.template.BaseLoader` responsible for this template,
used to resolve ``{% include %}`` and ``{% extend %}``
directives.
:arg bool compress_whitespace: Deprecated since Tornado 4.3.
Equivalent to ``whitespace="single"`` if true and
``whitespace="all"`` if false.
:arg str autoescape: The name of a function in the template
namespace, or ``None`` to disable escaping by default.
:arg str whitespace: A string specifying treatment of whitespace;
see `filter_whitespace` for options.
.. versionchanged:: 4.3
Added ``whitespace`` parameter; deprecated ``compress_whitespace``.'

def __init__(self, template_string, name='<string>', loader=None, compress_whitespace=_UNSET, autoescape=_UNSET, whitespace=None):

    self.name = escape.native_str(name)
    if (compress_whitespace is not _UNSET):
        if (whitespace is not None):
            raise Exception('cannot    set    both    whitespace    and    compress_whitespace')
        whitespace = ('single' if compress_whitespace else 'all')
    if (whitespace is None):
        if (loader and loader.whitespace):
            whitespace = loader.whitespace
        elif (name.endswith('.html') or name.endswith('.js')):
            whitespace = 'single'
        else:
            whitespace = 'all'
    filter_whitespace(whitespace, '')
    if (autoescape is not _UNSET):
        self.autoescape = autoescape
    elif loader:
        self.autoescape = loader.autoescape
    else:
        self.autoescape = _DEFAULT_AUTOESCAPE
    self.namespace = (loader.namespace if loader else {})
    reader = _TemplateReader(name, escape.native_str(template_string), whitespace)
    self.file = _File(self, _parse(reader, self))
    self.code = self._generate_python(loader)
    self.loader = loader
    try:
        self.compiled = compile(escape.to_unicode(self.code), ('%s.generated.py' % self.name.replace('.', '_')), 'exec', dont_inherit=True)
    except Exception:
        formatted_code = _format_code(self.code).rstrip()
        app_log.error('%s    code:\n%s', self.name, formatted_code)
        raise
