# Path: mako/lookup.py
# class TemplateCollection(object):
# class TemplateLookup(TemplateCollection):
#     def has_template(self, uri):
#     def get_template(self, uri, relativeto=None):
#     def filename_to_uri(self, uri, filename):
#     def adjust_uri(self, uri, filename):
#     def __init__(self, 
#                         directories=None, 
#                         module_directory=None, 
#                         filesystem_checks=True, 
#                         collection_size=-1, 
#                         format_exceptions=False, 
#                         error_handler=None, 
#                         disable_unicode=False, 
#                         output_encoding=None, 
#                         encoding_errors='strict', 
#                         cache_type=None, 
#                         cache_dir=None, cache_url=None,
#                         cache_enabled=True, 
#                         modulename_callable=None, 
#                         default_filters=None, 
#                         buffer_filters=(), 
#                         imports=None, 
#                         input_encoding=None, 
#                         preprocessor=None):
#     def get_template(self, uri):
#     def adjust_uri(self, uri, relativeto):
#     def filename_to_uri(self, filename):
#     def _relativeize(self, filename):
#     def _load(self, filename, uri):
#     def _check(self, uri, template):
#     def put_string(self, uri, text):
#     def put_template(self, uri, template):
# 
# Path: mako/exceptions.py
# class MakoException(Exception):
# class RuntimeException(MakoException):
# class CompileException(MakoException):
# class SyntaxException(MakoException):
# class TemplateLookupException(MakoException):
# class TopLevelLookupException(TemplateLookupException):
# class RichTraceback(object):
# def _format_filepos(lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, traceback=None):
#     def init_message(self):
#     def _get_reformatted_records(self, records):
#     def _init(self, trcback):
# def text_error_template(lookup=None):
# def html_error_template():


from mako.template import Template
from mako import lookup, exceptions
from util import flatten_result, result_lines
import unittest
import os
tl = lookup.TemplateLookup(directories=['./test_htdocs'])
class LookupTest(unittest.TestCase):
    def test_basic(self):
        t = tl.get_template('index.html')
        assert result_lines(t.render()) == [
            "this is index"
        ]
    def test_subdir(self):
        t = tl.get_template('/subdir/index.html')
        assert result_lines(t.render()) == [
            "this is sub index",
            "this is include 2"

        ]

        assert tl.get_template('/subdir/index.html').module_id == '_subdir_index_html'
    
    def test_updir(self):
        t = tl.get_template('/subdir/foo/../bar/../index.html')
        assert result_lines(t.render()) == [
            "this is sub index",
            "this is include 2"

        ]
        
    def test_no_lookup(self):
        t = Template("hi <%include file='foo.html'/>")
        try:
            t.render()
            assert False

# Path: mako/lookup.py
# class TemplateCollection(object):
# class TemplateLookup(TemplateCollection):
#     def has_template(self, uri):
#     def get_template(self, uri, relativeto=None):
#     def filename_to_uri(self, uri, filename):
#     def adjust_uri(self, uri, filename):
#     def __init__(self, 
#                         directories=None, 
#                         module_directory=None, 
#                         filesystem_checks=True, 
#                         collection_size=-1, 
#                         format_exceptions=False, 
#                         error_handler=None, 
#                         disable_unicode=False, 
#                         output_encoding=None, 
#                         encoding_errors='strict', 
#                         cache_type=None, 
#                         cache_dir=None, cache_url=None,
#                         cache_enabled=True, 
#                         modulename_callable=None, 
#                         default_filters=None, 
#                         buffer_filters=(), 
#                         imports=None, 
#                         input_encoding=None, 
#                         preprocessor=None):
#     def get_template(self, uri):
#     def adjust_uri(self, uri, relativeto):
#     def filename_to_uri(self, filename):
#     def _relativeize(self, filename):
#     def _load(self, filename, uri):
#     def _check(self, uri, template):
#     def put_string(self, uri, text):
#     def put_template(self, uri, template):
# 
# Path: mako/exceptions.py
# class MakoException(Exception):
# class RuntimeException(MakoException):
# class CompileException(MakoException):
# class SyntaxException(MakoException):
# class TemplateLookupException(MakoException):
# class TopLevelLookupException(TemplateLookupException):
# class RichTraceback(object):
# def _format_filepos(lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, traceback=None):
#     def init_message(self):
#     def _get_reformatted_records(self, records):
#     def _init(self, trcback):
# def text_error_template(lookup=None):
# def html_error_template():


# Path: test/test_lookup.py
from mako.template import Template
from mako import lookup, exceptions
from util import flatten_result, result_lines
import unittest
import os

tl = lookup.TemplateLookup(directories=['./test_htdocs'])
class LookupTest(unittest.TestCase):
    def test_basic(self):
        t = tl.get_template('index.html')
        assert result_lines(t.render()) == [
            "this is index"
        ]
    def test_subdir(self):
        t = tl.get_template('/subdir/index.html')
        assert result_lines(t.render()) == [
            "this is sub index",
            "this is include 2"

        ]

        assert tl.get_template('/subdir/index.html').module_id == '_subdir_index_html'
    
    def test_updir(self):
        t = tl.get_template('/subdir/foo/../bar/../index.html')
        assert result_lines(t.render()) == [
            "this is sub index",
            "this is include 2"

        ]
        
    def test_no_lookup(self):
        t = Template("hi <%include file='foo.html'/>")
        try:
            t.render()
            assert False

        except exceptions.TemplateLookupException, e: