Example #1
0
    def test_def_operations(self):
        """test get/list/has def"""

        template = Template("""

            this is the body

            <%def name="a()">
                this is a
            </%def>

            <%def name="b(x, y)">
                this is b, ${x} ${y}
            </%def>

        """)

        assert template.get_def("a")
        assert template.get_def("b")
        assert_raises(AttributeError,
                      template.get_def,
                      ("c")
                      )

        assert template.has_def("a")
        assert template.has_def("b")
        assert not template.has_def("c")

        defs = template.list_defs()
        assert "a" in defs
        assert "b" in defs
        assert "body" in defs
        assert "c" not in defs
Example #2
0
    def test_def_operations(self):
        """test get/list/has def"""

        template = Template("""

            this is the body

            <%def name="a()">
                this is a
            </%def>

            <%def name="b(x, y)">
                this is b, ${x} ${y}
            </%def>

        """)

        assert template.get_def("a")
        assert template.get_def("b")
        assert_raises(AttributeError, template.get_def, ("c"))

        assert template.has_def("a")
        assert template.has_def("b")
        assert not template.has_def("c")

        defs = template.list_defs()
        assert "a" in defs
        assert "b" in defs
        assert "body" in defs
        assert "c" not in defs
Example #3
0
def test_extract_def_source():
    src = """
        <%def name="add(varname)">
        ${varname} + ${num}
        </%def>

        <%def name='sub(varname, kwd=">")'>
        ${varname} - ${num}
        </%def>
    """

    def_src = _extract_def_source(src, 'add')
    template = MakoTemplate(def_src)
    assert 'add' in template.list_defs()
    assert 'sub' not in template.list_defs()

    def_src = _extract_def_source(src, 'sub')
    template = MakoTemplate(def_src)
    assert 'sub' in template.list_defs()
    assert 'add' not in template.list_defs()
Example #4
0
class SampleHtmlParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        print("Encountered start tag:", tag)
        for attr in attrs:
            print(" attr:", attr)

    def handle_endtag(self, tag):
        print("Encountered end tag :", tag )

    def handle_data(self, data):
        print("Encountered some data :",data)

parser = SampleHtmlParser()

with open("Index.html",'r') as my_file:
    html_string = my_file.read().replace('\n','')

# parser.feed(html_string)

sample_template = Template(filename="Index.html")

# print(sample_template.render())

my_lookup = TemplateLookup(directories=['/sample'])

first_def = sample_template.list_defs()

print(sample_template.code)

#named blocks for inheritance between tabs?