Commits

Rick Copeland committed 0c03319

name change to kajiki complete

Comments (0)

Files changed (10)

-import loader
-from util import expose, flattener
-from template import Template
-
+from .util import expose, flattener
+from .template import Template
+from .loader import MockLoader
+from .text import TextTemplate
+from .xml_template import XMLTemplate
         for block in self.mod_py:
             for  line in block.py():
                 yield line
-        yield self.line('@fpt.Template')
+        yield self.line('@kajiki.Template')
         yield self.line('class template:')
         for child in self.defs:
             for line in child.py():
 
     def py(self):
         yield self.line(
-            'local.__fpt__.import_(%r, %r, globals())' % (
+            'local.__kj__.import_(%r, %r, globals())' % (
                 self.tpl_name, self.alias))
 
 class IncludeNode(Node):
 
     def py(self):
         yield self.line(
-            'yield local.__fpt__.import_(%r, None, {}).__call__()' % (
+            'yield local.__kj__.import_(%r, None, {}).__call__()' % (
                 self.tpl_name))
 
 class ExtendNode(Node):
 
     def py(self):
         yield self.line(
-            'yield local.__fpt__.extend(%r).__call__()' % (
+            'yield local.__kj__.extend(%r).__call__()' % (
                 self.tpl_name))
 
 class DefNode(Node):
-    prefix = '@fpt.expose'
+    prefix = '@kajiki.expose'
 
     def __init__(self, decl, *body):
         super(DefNode, self).__init__()
                 yield line.indent()
 
 class InnerDefNode(DefNode):
-    prefix='@__fpt__.flattener.decorate'
+    prefix='@__kj__.flattener.decorate'
 
 class CallNode(Node):
 
         self.body = tuple(x for x in body if x is not None)
 
     def py(self):
-        yield self.line('@__fpt__.flattener.decorate')
+        yield self.line('@__kj__.flattener.decorate')
         yield self.line('def %s:' % (self.decl))
         for child in self.body:
             for line in child.py():
         self.body = tuple(x for x in body if x is not None)
 
     def py(self):
-        yield self.line('local.__fpt__.push_switch(%s)' % self.decl)
+        yield self.line('local.__kj__.push_switch(%s)' % self.decl)
         for child in self.body:
             for line in child.py():
                 yield line
-        yield self.line('local.__fpt__.pop_switch()')
+        yield self.line('local.__kj__.pop_switch()')
 
 class CaseNode(Node):
 
         self.body = tuple(x for x in body if x is not None)
 
     def py(self):
-        yield self.line('if local.__fpt__.case(%s):' % self.decl)
+        yield self.line('if local.__kj__.case(%s):' % self.decl)
         for child in self.body:
             for line in child.py():
                 yield line.indent()
         self.text = text
 
     def py(self):
-        yield self.line('yield self.__fpt__.escape(%s)' % self.text)
+        yield self.line('yield self.__kj__.escape(%s)' % self.text)
 
 class AttrNode(Node):
 
     def py(self):
         k,v = gen_name(), gen_name()
         def _body():
-            yield self.line('for %s,%s in self.__fpt__.iter_attrs(%s):' % (k, v, self.attrs))
+            yield self.line('for %s,%s in self.__kj__.iter_attrs(%s):' % (k, v, self.attrs))
             yield self.line('    yield \' %%s="%%s"\' %% (%s, %s)' % (k,v))
         if self.guard:
             yield self.line('if %s:' % self.guard)
 
 from webhelpers.html import literal
 
-import fastpt
+import kajiki
 from .util import flattener
 
 class _obj(object):
             self=self,
             literal=literal,
             __builtins__=__builtins__,
-            __fpt__=fastpt.v2)
+            __kj__=kajiki)
         for k,v in self.__methods__:
             v = v.bind_instance(self)
             setattr(self, k, v)
             self.__globals__[k] = v
-        self.__fpt__ = _obj(
+        self.__kj__ = _obj(
             render=self._render,
             extend=self._extend,
             push_switch=self._push_switch,
     return type(ns.__name__,(_Template,), dct)
 
 def from_ir(ir_node):
-    from fastpt import v2 as fpt
     py_text = '\n'.join(map(str, ir_node.py()))
-    dct = dict(fpt=fpt)
+    dct = dict(kajiki=kajiki)
     try:
         exec py_text in dct
     except SyntaxError: # pragma no cover

kajiki/tests/test_ir.py

 from unittest import TestCase, main
 
-from fastpt import v2 as fpt
-from fastpt.v2 import ir 
+import kajiki
+from kajiki import ir
 
 class TestBasic(TestCase):
 
                 ir.TextNode('\n'))])
 
     def test(self):
-        tpl = fpt.template.from_ir(self.tpl)
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        tpl = kajiki.template.from_ir(self.tpl)
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == 'Hello, Rick\n', rsp
 
 class TestSwitch(TestCase):
                                 ir.TextNode('odd\n')))))])
             
     def test_basic(self):
-        tpl = fpt.template.from_ir(self.tpl)
-        rsp = tpl(dict()).__fpt__.render() 
+        tpl = kajiki.template.from_ir(self.tpl)
+        rsp = tpl(dict()).__kj__.render() 
         assert rsp == '0 is even\n1 is odd\n', rsp
 
 class TestFunction(TestCase):
                         ir.TextNode('\n')))])
 
     def test_basic(self):
-        tpl = fpt.template.from_ir(self.tpl)
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        tpl = kajiki.template.from_ir(self.tpl)
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '0 is even\n1 is odd\n', rsp
 
 class TestCall(TestCase):
                         ir.ExprNode('n')))])
             
     def test_basic(self):
-        tpl = fpt.template.from_ir(self.tpl)
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        tpl = kajiki.template.from_ir(self.tpl)
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert (
             rsp == 'Quoth the raven, "Nevermore 0."\n'
             'Quoth the raven, "Nevermore 1."\n'), rsp
                         ir.ExprNode('simple_function.evenness(i)'),
                         ir.ExprNode('simple_function.half_evenness(i)'),
                         ir.TextNode('\n')))])
-        loader = fpt.loader.MockLoader({
-            'lib.txt':fpt.template.from_ir(lib),
-            'tpl.txt':fpt.template.from_ir(tpl)})
+        loader = kajiki.loader.MockLoader({
+            'lib.txt':kajiki.template.from_ir(lib),
+            'tpl.txt':kajiki.template.from_ir(tpl)})
         self.tpl = loader.import_('tpl.txt')
 
     def test_import(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert (rsp=='0 is even half of 0 is even\n'
                 '1 is odd half of 1 is even\n'
                 '2 is even half of 2 is odd\n'
                     ir.TextNode('a\n'),
                     ir.IncludeNode('hdr.txt'),
                     ir.TextNode('b\n'))])
-        loader = fpt.loader.MockLoader({
-            'hdr.txt':fpt.template.from_ir(hdr),
-            'tpl.txt':fpt.template.from_ir(tpl)})
+        loader = kajiki.loader.MockLoader({
+            'hdr.txt':kajiki.template.from_ir(hdr),
+            'tpl.txt':kajiki.template.from_ir(tpl)})
         self.tpl = loader.import_('tpl.txt')
 
     def test_include(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a\n# header\nb\n', rsp
 
 class TestExtends(TestCase):
                 ir.DefNode(
                     'id()',
                     ir.TextNode('child'))])
-        loader = fpt.loader.MockLoader({
-            'parent.txt':fpt.template.from_ir(parent_tpl),
-            'mid.txt':fpt.template.from_ir(mid_tpl),
-            'child.txt':fpt.template.from_ir(child_tpl)})
+        loader = kajiki.loader.MockLoader({
+            'parent.txt':kajiki.template.from_ir(parent_tpl),
+            'mid.txt':kajiki.template.from_ir(mid_tpl),
+            'child.txt':kajiki.template.from_ir(child_tpl)})
         self.loader = loader
         self.tpl = loader.import_('child.txt')
         
     def test_extends(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert (rsp == '# Header name=Rick\n'
                 '## Child Body\n'
                 '## Parent Body\n'
                         ir.ExtendNode('parent0.txt')),
                     ir.ElseNode(
                         ir.ExtendNode('parent1.txt')))])
-        loader = fpt.loader.MockLoader({
-            'parent0.txt':fpt.template.from_ir(p0),
-            'parent1.txt':fpt.template.from_ir(p1),
-            'child.txt':fpt.template.from_ir(child)})
+        loader = kajiki.loader.MockLoader({
+            'parent0.txt':kajiki.template.from_ir(p0),
+            'parent1.txt':kajiki.template.from_ir(p1),
+            'child.txt':kajiki.template.from_ir(child)})
         self.loader = loader
         self.tpl = loader.import_('child.txt')
 
     def test_extends(self):
-        rsp = self.tpl(dict(p=0)).__fpt__.render()
+        rsp = self.tpl(dict(p=0)).__kj__.render()
         assert rsp == 'Parent 0', rsp
-        rsp = self.tpl(dict(p=1)).__fpt__.render()
+        rsp = self.tpl(dict(p=1)).__kj__.render()
         assert rsp == 'Parent 1', rsp
 
 if __name__ == '__main__':

kajiki/tests/test_runtime.py

 from unittest import TestCase, main
 
-from fastpt import v2 as fpt
+import kajiki
 
 class TestBasic(TestCase):
 
     def setUp(self):
-        @fpt.Template
+        @kajiki.Template
         class tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 yield 'Hello,'
                 yield name
         self.tpl = tpl
 
     def test_basic(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'Hello,Rick\n', rsp
 
 class TestSwitch(TestCase):
 
     def setUp(self):
-        @fpt.Template
+        @kajiki.Template
         class tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 for i in range(2):
                     yield i
                     yield ' is '
-                    local.__fpt__.push_switch(i % 2)
-                    if local.__fpt__.case(0):
+                    local.__kj__.push_switch(i % 2)
+                    if local.__kj__.case(0):
                         yield 'even\n'
                     else:
                         yield 'odd\n'
         self.tpl = tpl
 
     def test_basic(self):
-        rsp = self.tpl().__fpt__.render()
+        rsp = self.tpl().__kj__.render()
         assert rsp == '0 is even\n1 is odd\n', rsp
 
 class TestFunction(TestCase):
     
     def setUp(self):
-        @fpt.Template
+        @kajiki.Template
         class tpl:
-            @fpt.expose
+            @kajiki.expose
             def evenness(n):
                 if n % 2 == 0: yield 'even'
                 else: yield 'odd'
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 for i in range(2):
                     yield i
         self.tpl = tpl
 
     def test_basic(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '0 is even\n1 is odd\n', rsp
 
 class TestCall(TestCase):
     
     def setUp(self):
-        @fpt.Template
+        @kajiki.Template
         class tpl:
-            @fpt.expose
+            @kajiki.expose
             def quote(caller, speaker):
                 for i in range(2):
                     yield 'Quoth '
                     yield ', "'
                     yield caller(i)
                     yield '."\n'
-            @fpt.expose
+            @kajiki.expose
             def __call__():
-                @__fpt__.flattener.decorate
-                def _fpt_lambda(n):
+                @__kj__.flattener.decorate
+                def _kj_lambda(n):
                     yield 'Nevermore '
                     yield n
-                yield quote(_fpt_lambda, 'the raven')
-                del _fpt_lambda
+                yield quote(_kj_lambda, 'the raven')
+                del _kj_lambda
         self.tpl = tpl
 
     def test_basic(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert (
             rsp == 'Quoth the raven, "Nevermore 0."\n'
             'Quoth the raven, "Nevermore 1."\n'), rsp
 
 class TestImport(TestCase):
     def setUp(self):
-        @fpt.Template
+        @kajiki.Template
         class lib:
-            @fpt.expose
+            @kajiki.expose
             def evenness(n):
                 if n % 2 == 0: yield 'even'
                 else: yield 'odd'
-            @fpt.expose
+            @kajiki.expose
             def half_evenness(n):
                 yield ' half of '
                 yield n
                 yield ' is '
                 yield evenness(n/2)
-        @fpt.Template
+        @kajiki.Template
         class tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 simple_function = lib(dict(globals()))
                 for i in range(4):
         self.tpl = tpl
 
     def test_import(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert (rsp=='0 is even half of 0 is even\n'
                 '1 is odd half of 1 is even\n'
                 '2 is even half of 2 is odd\n'
 
 class TestInclude(TestCase):
     def setUp(self):
-        @fpt.Template
+        @kajiki.Template
         class hdr:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 yield '# header\n'
-        @fpt.Template
+        @kajiki.Template
         class tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 yield 'a\n'
                 yield hdr().__call__()
         self.tpl = tpl
 
     def test_include(self):
-        rsp = self.tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a\n# header\nb\n', rsp
 
 class TestExtends(TestCase):
     def setUp(_self):
-        @fpt.Template
+        @kajiki.Template
         class parent_tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 yield header()
                 yield body()
                 yield footer()
-            @fpt.expose
+            @kajiki.expose
             def header():
                 yield '# Header name='
                 yield name
                 yield '\n'
-            @fpt.expose
+            @kajiki.expose
             def body():
                 yield '## Parent Body\n'
                 yield 'local.id() = '
                 yield 'child.id() = '
                 yield child.id()
                 yield '\n'
-            @fpt.expose
+            @kajiki.expose
             def footer():
                 yield '# Footer'
                 yield '\n'
-            @fpt.expose
+            @kajiki.expose
             def id():
                 yield 'parent'
 
-        @fpt.Template
+        @kajiki.Template
         class mid_tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
-                yield local.__fpt__.extend(parent_tpl).__call__()
-            @fpt.expose
+                yield local.__kj__.extend(parent_tpl).__call__()
+            @kajiki.expose
             def id():
                 yield 'mid'
 
-        @fpt.Template
+        @kajiki.Template
         class child_tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
-                yield local.__fpt__.extend(mid_tpl).__call__()
-            @fpt.expose
+                yield local.__kj__.extend(mid_tpl).__call__()
+            @kajiki.expose
             def body():
                 yield '## Child Body\n'
                 yield parent.body()
-            @fpt.expose
+            @kajiki.expose
             def id():
                 yield 'child'
         _self.parent_tpl = parent_tpl
         _self.child_tpl = child_tpl
 
     def test_extends(self):
-        rsp = self.child_tpl(dict(name='Rick')).__fpt__.render()
+        rsp = self.child_tpl(dict(name='Rick')).__kj__.render()
         assert (rsp == '# Header name=Rick\n'
                 '## Child Body\n'
                 '## Parent Body\n'
 
 class TestDynamicExtends(TestCase):
     def setUp(_self):
-        @fpt.Template
+        @kajiki.Template
         class parent_0:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 yield 'Parent 0'
-        @fpt.Template
+        @kajiki.Template
         class parent_1:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 yield 'Parent 1'
-        @fpt.Template
+        @kajiki.Template
         class child_tpl:
-            @fpt.expose
+            @kajiki.expose
             def __call__():
                 if p == 0:
-                    yield local.__fpt__.extend(parent_0).__call__()
+                    yield local.__kj__.extend(parent_0).__call__()
                 else:
-                    yield local.__fpt__.extend(parent_1).__call__()
+                    yield local.__kj__.extend(parent_1).__call__()
         _self.child_tpl = child_tpl
 
     def test_extends(self):
-        rsp = self.child_tpl(dict(p=0)).__fpt__.render()
+        rsp = self.child_tpl(dict(p=0)).__kj__.render()
         assert rsp == 'Parent 0', rsp
-        rsp = self.child_tpl(dict(p=1)).__fpt__.render()
+        rsp = self.child_tpl(dict(p=1)).__kj__.render()
         assert rsp == 'Parent 1', rsp
 
 if __name__ == '__main__':

kajiki/tests/test_text.py

 from unittest import TestCase, main
 
-from fastpt import v2 as fpt
-from fastpt.v2.text import TextTemplate
+from kajiki import MockLoader, TextTemplate
 
 class TestBasic(TestCase):
 
     def test_auto_escape(self):
         tpl = TextTemplate(source="${'<h1>'}")
-        rsp = tpl().__fpt__.render() 
+        rsp = tpl().__kj__.render() 
         assert rsp == '&lt;h1&gt;', rsp
 
     def test_auto_escape_disable(self):
         tpl = TextTemplate(source="${literal('<h1>')}")
-        rsp = tpl().__fpt__.render() 
+        rsp = tpl().__kj__.render() 
         assert rsp == '<h1>', rsp
 
     def test_expr_brace(self):
         tpl = TextTemplate(source='Hello, ${name}\n')
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == 'Hello, Rick\n', rsp
 
     def test_expr_brace_complex(self):
         tpl = TextTemplate(source="Hello, ${{'name':name}['name']}\n")
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == 'Hello, Rick\n', rsp
 
     def test_expr_name(self):
         tpl = TextTemplate(source='Hello, $name\n')
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == 'Hello, Rick\n', rsp
         tpl = TextTemplate(source='Hello, $obj.name\n')
         class Empty: pass
         Empty.name = 'Rick'
-        rsp = tpl(dict(obj=Empty)).__fpt__.render() 
+        rsp = tpl(dict(obj=Empty)).__kj__.render() 
         assert rsp == 'Hello, Rick\n', rsp
 
 class TestSwitch(TestCase):
         tpl = TextTemplate('''%for i in range(2)
 $i is {%switch i % 2 %}{%case 0%}even\n{%else%}odd\n{%end%}\\
 %end''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == '0 is even\n1 is odd\n', rsp
 
     def test_ljust(self):
         tpl = TextTemplate('''     %for i in range(2)
 $i is {%switch i % 2 %}{%case 0%}even\n{%else%}odd\n{%end%}\\
 %end''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == '0 is even\n1 is odd\n', rsp
         tpl = TextTemplate('''     {%-for i in range(2)%}\\
 $i is {%switch i % 2 %}{%case 0%}even{%else%}odd{%end%}
     {%-end%}''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == '0 is even\n1 is odd\n', rsp
 
     def test_rstrip(self):
         tpl = TextTemplate('''     %for i in range(2)
 $i is {%switch i % 2 %}{%case 0-%}    even\n{%else%}odd\n{%end%}\\
 %end''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == '0 is even\n1 is odd\n', rsp
 
 class TestFunction(TestCase):
 $i is ${evenness(i)}
 %end
 ''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == '0 is even\n1 is odd\n', rsp
 
 class TestCall(TestCase):
 %call(n) quote(%caller ,'the raven')
 Nevermore $n\\
 %end''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert (
             rsp == 'Quoth the raven, "Nevermore 0."\n'
             'Quoth the raven, "Nevermore 1."\n'), rsp
 %for i in range(4)
 $i is ${simple_function.evenness(i)}${simple_function.half_evenness(i)}
 %end''')
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
             'lib.txt':lib,
             'tpl.txt':tpl})
         tpl = loader.import_('tpl.txt')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert (rsp=='0 is even half of 0 is even\n'
                 '1 is odd half of 1 is even\n'
                 '2 is even half of 2 is odd\n'
 %for i in range(4)
 $i is ${lib.evenness(i)}${lib.half_evenness(i)}
 %end''')
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
             'lib.txt':lib,
             'tpl.txt':tpl})
         tpl = loader.import_('tpl.txt')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert (rsp=='0 is even half of 0 is even\n'
                 '1 is odd half of 1 is even\n'
                 '2 is even half of 2 is odd\n'
                 '3 is odd half of 3 is odd\n'), rsp
 
     def test_include(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
                 'hdr.txt': TextTemplate('# header\n'),
                 'tpl.txt': TextTemplate('''a
 %include "hdr.txt"
 b
 ''')})
         tpl = loader.import_('tpl.txt')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a\n# header\nb\n', rsp
 
 class TestExtends(TestCase):
 ${parent.body()}\\
 %end
 ''')
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
             'parent.txt':parent,
             'mid.txt':mid,
             'child.txt':child})
         tpl = loader.import_('child.txt')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert (rsp == '# Header name=Rick\n'
                 '## Child Body\n'
                 '## Parent Body\n'
                 '# Footer\n'), rsp
 
     def test_dynamic(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
                 'parent0.txt':TextTemplate('Parent 0'),
                 'parent1.txt':TextTemplate('Parent 1'),
                 'child.txt':TextTemplate('''%if p == 0
 ''')
                 })
         tpl = loader.import_('child.txt')
-        rsp = tpl(dict(p=0)).__fpt__.render()
+        rsp = tpl(dict(p=0)).__kj__.render()
         assert rsp == 'Parent 0', rsp
-        rsp = tpl(dict(p=1)).__fpt__.render()
+        rsp = tpl(dict(p=1)).__kj__.render()
         assert rsp == 'Parent 1', rsp
 
     def test_block(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
                 'parent.txt':TextTemplate('''%def greet(name)
 Hello, $name!\\
 %end
 %end
 ''')})
         child = loader.import_('child.txt')
-        rsp = child({'to':'Mark', 'from_':'Rick'}).__fpt__.render()
+        rsp = child({'to':'Mark', 'from_':'Rick'}).__kj__.render()
         assert (rsp=='''Dear Mark:
 It was good seeing you last Friday.  Thanks for the gift!
 
 %end
 ${add(5)}
 ''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '15\n', rsp
 
 class TestPython(TestCase):
 import os
 %end
 ${os.path.join('a','b','c')}''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a/b/c'
 
     def test_indent(self):
     import re
 %end
 ${os.path.join('a','b','c')}''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a/b/c'
 
     def test_short(self):
         tpl = TextTemplate('''%py import os
 ${os.path.join('a','b','c')}''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a/b/c'
 
     def test_mod(self):
 ${os.path.join('a','b','c')}\\
 %end
 ${test()}''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a/b/c'
 
 if __name__ == '__main__':

kajiki/tests/test_xml.py

 import xml.dom.minidom
 from unittest import TestCase, main
 
-from fastpt import v2 as fpt
-from fastpt.v2.xml_template import XMLTemplate
+import kajiki
+from kajiki import MockLoader, XMLTemplate
+
 
 DATA = os.path.join(
     os.path.dirname(__file__),
 class TestParser(TestCase):
 
     def test_parser(self):
-        doc = fpt.xml_template._Parser('<string>', '''<?xml version="1.0"?>
+        doc = kajiki.xml_template._Parser('<string>', '''<?xml version="1.0"?>
 <!DOCTYPE div PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <div xmlns="http://www.w3.org/1999/xhtml"
 class TestExpand(TestCase):
 
     def test_expand(self):
-        doc = fpt.xml_template._Parser('<string>', '''<div
+        doc = kajiki.xml_template._Parser('<string>', '''<div
         py:def="def"
         py:call="call"
         py:case="case"
         py:replace="replace"
         py:block="block"
         py:extends="extends">Foo</div>''').parse()
-        fpt.xml_template.expand(doc)
+        kajiki.xml_template.expand(doc)
         node = doc.childNodes[0]
-        for tagname, attr in fpt.markup_template.QDIRECTIVES:
+        for tagname, attr in kajiki.markup_template.QDIRECTIVES:
             if node.tagName == 'div':
                 node = node.childNodes[0]
                 continue
 
     def test_expr_name(self):
         tpl = XMLTemplate(source='<div>Hello, $name</div>')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>Hello, Rick</div>', rsp
 
     def test_expr_braced(self):
         tpl = XMLTemplate(source='<div>Hello, ${name}</div>')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>Hello, Rick</div>', rsp
 
     def test_expr_brace_complex(self):
         tpl = XMLTemplate(source="<div>Hello, ${{'name':name}['name']}</div>")
-        rsp = tpl(dict(name='Rick')).__fpt__.render() 
+        rsp = tpl(dict(name='Rick')).__kj__.render() 
         assert rsp == '<div>Hello, Rick</div>', rsp
 
 class TestSwitch(TestCase):
 <py:case value="0">even</py:case>
 <py:else>odd</py:else>
 </py:switch></div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '''<div>
 0 is even</div><div>
 1 is odd</div>''', rsp
 <py:for each="i in range(2)">$i is ${evenness(i)}
 </py:for
 ></div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '''<div>
 0 is <div>even</div>
 1 is <div>odd</div>
 </ul></py:def
 ><py:call args="n" function="quote(%caller, 'the raven')"
 >Nevermore $n</py:call></div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '''<div><ul>
     <li>Quoth the raven, Nevermore 0</li><li>Quoth the raven, Nevermore 1</li>
 </ul></div>''', rsp
 class TestImport(TestCase):
     
     def test_import(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
             'lib.html':XMLTemplate(source='''<div>
 <span py:def="evenness(n)"
     ><py:if test="n % 2 == 0"
 </div>''')
             })
         tpl = loader.import_('tpl.html')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '''<div>
 <ul>
     <li>
 </div>''', rsp
 
     def test_import_auto(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
             'lib.html':XMLTemplate(source='''<div>
 <span py:def="evenness(n)"
     ><py:if test="n % 2 == 0"
 </div>''')
             })
         tpl = loader.import_('tpl.html')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '''<div>
 <ul>
     <li>
 </div>''', rsp
 
     def test_include(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
                 'hdr.html':XMLTemplate('<h1>Header</h1>\n'),
                 'tpl.html':XMLTemplate('''<html><body>
 <py:include href="hdr.html"/>
 </body></html>''')
                 })
         tpl = loader.import_('tpl.html')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '''<html><body>
 <h1>Header</h1>
 <p>This is the body</p>
 class TestExtends(TestCase):
 
     def test_basic(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
                 'parent.html':XMLTemplate('''<div
 ><h1 py:def="header()">Header name=$name</h1
 ><h6 py:def="footer()">Footer</h6
 ${parent.body()}
 </div></py:extends>''')})
         tpl = loader.import_('child.html')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp=='''<div>
 <h1>Header name=Rick</h1>
 <div>
 </div>''', rsp
 
     def test_dynamic(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
                 'parent0.html':XMLTemplate('<span>Parent 0</span>'),
                 'parent1.html':XMLTemplate('<span>Parent 1</span>'),
                 'child.html':XMLTemplate('''<div
 ''')
                 })
         tpl = loader.import_('child.html')
-        rsp = tpl(dict(p=0)).__fpt__.render()
+        rsp = tpl(dict(p=0)).__kj__.render()
         assert rsp == '<div><span>Parent 0</span></div>', rsp
-        rsp = tpl(dict(p=1)).__fpt__.render()
+        rsp = tpl(dict(p=1)).__kj__.render()
         assert rsp == '<div><span>Parent 1</span></div>', rsp
 
     def test_block(self):
-        loader = fpt.loader.MockLoader({
+        loader = MockLoader({
                 'parent.html':XMLTemplate('''<div
 ><py:def function="greet(name)"
 >Hello, $name!</py:def
 ></py:extends>
 ''')})
         parent = loader.import_('parent.html')
-        rsp = parent({'to':'Mark', 'from_':'Rick'}).__fpt__.render()
+        rsp = parent({'to':'Mark', 'from_':'Rick'}).__kj__.render()
         assert rsp == '''<div>Hello, Mark!
 
 <p>It was good seeing you last Friday.
 Sincerely,<br/><em>Rick</em>
 </div>''', rsp
         child = loader.import_('child.html')
-        rsp = child({'to':'Mark', 'from_':'Rick'}).__fpt__.render()
+        rsp = child({'to':'Mark', 'from_':'Rick'}).__kj__.render()
         assert rsp=='''<div>Dear Mark:
 
 <p>It was good seeing you last Friday.
         >${x+y}</py:def
     >${inner(x*2)}</py:def
 >${add(5)}</div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>15</div>', rsp
 
 class TestPython(TestCase):
 ><?py
 import os
 ?>${os.path.join('a', 'b', 'c')}</div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>a/b/c</div>'
 
     def test_indent(self):
     import os
     import re
 ?>${os.path.join('a','b','c')}</div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>a/b/c</div>'
 
     def test_short(self):
         tpl = XMLTemplate('''<div
 ><?py import os
 ?>${os.path.join('a', 'b', 'c')}</div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>a/b/c</div>'
 
     def test_mod(self):
 ?><py:def function="test()"
 >${os.path.join('a', 'b', 'c')}</py:def
 >${test()}</div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>a/b/c</div>'
 
 class TestComment(TestCase):
 <!-- This comment is preserved. -->
 <!--! This comment is stripped. -->
 </div>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '''<div>
 <!--  This comment is preserved.  -->
 
 
     def test_basic(self):
         tpl = XMLTemplate('''<div id="foo"/>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div id="foo"/>', rsp
         
     def test_content(self):
         tpl = XMLTemplate('''<div py:content="'foo'"/>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div>foo</div>', rsp
         
     def test_replace(self):
         tpl = XMLTemplate('''<div py:replace="'foo'"/>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'foo', rsp
 
     def test_attrs(self):
         tpl = XMLTemplate('''<div py:attrs="dict(a=5, b=6)"/>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div a="5" b="6"/>'
         tpl = XMLTemplate('''<div py:attrs="[('a', 5), ('b', 6)]"/>''')
-        rsp = tpl(dict(name='Rick')).__fpt__.render()
+        rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == '<div a="5" b="6"/>'
 
     def test_strip(self):
         tpl = XMLTemplate('''<div><h1 py:strip="header">Header</h1></div>''')
-        rsp = tpl(dict(header=True)).__fpt__.render()
+        rsp = tpl(dict(header=True)).__kj__.render()
         assert rsp == '<div><h1>Header</h1></div>', rsp
-        rsp = tpl(dict(header=False)).__fpt__.render()
+        rsp = tpl(dict(header=False)).__kj__.render()
         assert rsp == '<div>Header</div>', rsp
 
 if __name__ == '__main__':
 from collections import defaultdict
 from itertools import chain
 
-from fastpt import v2 as fpt
-from fastpt.v2 import ir
+import kajiki
+from . import ir
 
 _pattern = r'''
 \$(?:
         filename = '<string>'
     scanner = _Scanner(filename, source)
     tree = _Parser(scanner).parse()
-    return fpt.template.from_ir(tree)
+    return kajiki.template.from_ir(tree)
 
 class _Scanner(object):
 
             return node
 
     def _parse_block(self, token):
-        fname = '_fpt_block_' + token.body.strip()
+        fname = '_kj_block_' + token.body.strip()
         decl = fname + '()'
         body = list(self._parse_body('end'))[:-1]
         self.functions[decl] = body
         self.names.add(r)
         return r
 
-def gen_name(hint='_fpt_'):
+def gen_name(hint='_kj_'):
     return NameGen.gen(hint)
     

kajiki/xml_template.py

         yield ir.IncludeNode(href)
 
     def _compile_block(self, node):
-        fname = '_fpt_block_' + node.getAttribute('name')
+        fname = '_kj_block_' + node.getAttribute('name')
         decl = fname + '()'
         body = list(self._compile_nop(node))
         self.functions[decl] = body