def preparse(template_text, lookup=None):
<EOL>template_path = None<EOL>try:<EOL><INDENT>is_file = template_text.startswith("<STR_LIT>")<EOL><DEDENT>except (AttributeError, TypeError):<EOL><INDENT>pass <EOL><DEDENT>else:<EOL><INDENT>if is_file:<EOL><INDENT>template_path = template_text[<NUM_LIT:5>:]<EOL>if template_path.startswith('<STR_LIT:/>'):<EOL><INDENT>template_path = '<STR_LIT:/>' + template_path.lstrip('<STR_LIT:/>')<EOL><DEDENT>elif template_path.startswith('<STR_LIT>'):<EOL><INDENT>template_path = os.path.expanduser(template_path)<EOL><DEDENT>elif lookup:<EOL><INDENT>template_path = lookup(template_path)<EOL><DEDENT>with closing(open(template_path, "<STR_LIT:r>")) as handle:<EOL><INDENT>template_text = handle.read().rstrip()<EOL><DEDENT><DEDENT><DEDENT>if hasattr(template_text, "<STR_LIT>"):<EOL><INDENT>template = template_text<EOL><DEDENT>else:<EOL><INDENT>if template_text.startswith("<STR_LIT>"):<EOL><INDENT>import tempita  <EOL>template = tempita.Template(template_text, name=template_path)<EOL>template.__engine__ = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>template = InterpolationTemplate(template_text)<EOL><DEDENT>template.__file__ = template_path<EOL><DEDENT>template.__text__ = template_text<EOL>return template<EOL>
Do any special processing of a template, including recognizing the templating language
        and resolving file: references, then return an appropriate wrapper object.

        Currently Tempita and Python string interpolation are supported.
        `lookup` is an optional callable that resolves any ambiguous template path.