'Works like :meth:`get_template` but tries a number of templates
before it fails.  If it cannot find any of the templates, it will
raise a :exc:`TemplatesNotFound` exception.
.. versionadded:: 2.3
.. versionchanged:: 2.4
If `names` contains a :class:`Template` object it is returned
from the function unchanged.'

@internalcode
def select_template(self, names, parent=None, globals=None):

    if (not names):
        raise TemplatesNotFound(message=u'Tried    to    select    from    an    empty    list    of    templates.')
    globals = self.make_globals(globals)
    for name in names:
        if isinstance(name, Template):
            return name
        if (parent is not None):
            name = self.join_path(name, parent)
        try:
            return self._load_template(name, globals)
        except TemplateNotFound:
            pass
    raise TemplatesNotFound(names)
