[Python-modules-commits] [python-kajiki] 01/04: Imported Upstream version 0.5.3

Takaki Taniguchi takaki at moszumanska.debian.org
Tue Feb 2 07:52:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

takaki pushed a commit to annotated tag debian/0.5.3-1
in repository python-kajiki.

commit 76c55fc30cc80d1ca3dc1afaa360ec0718966ab3
Author: TANIGUCHI Takaki <takaki at asis.media-as.org>
Date:   Tue Feb 2 16:17:20 2016 +0900

    Imported Upstream version 0.5.3
---
 CHANGES.rst                  |  6 ++++++
 Kajiki.egg-info/PKG-INFO     |  8 +++++++-
 Kajiki.egg-info/requires.txt |  3 +--
 PKG-INFO                     |  8 +++++++-
 kajiki/ir.py                 | 41 ++++++++++++++++++++++++++---------------
 kajiki/template.py           |  6 ++----
 kajiki/tests/test_xml.py     | 17 +++++++++++++++++
 kajiki/util.py               | 11 +++++++++++
 kajiki/version.py            |  2 +-
 setup.py                     |  2 +-
 10 files changed, 79 insertions(+), 25 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index 6a0ea50..037331a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,12 @@
 CHANGES
 =======
 
+0.5.3 (2016-01-25)
+------------------
+
+* ``py:with`` statement now keeps order of variables, so that variables can depend from each other.
+* Babel is no longer a dependency unless you want to use the message extractor.
+
 0.5.2 (2015-10-13)
 ------------------
 
diff --git a/Kajiki.egg-info/PKG-INFO b/Kajiki.egg-info/PKG-INFO
index 71bcba3..bc5e38d 100644
--- a/Kajiki.egg-info/PKG-INFO
+++ b/Kajiki.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: Kajiki
-Version: 0.5.2
+Version: 0.5.3
 Summary: Fast XML-based template engine with Genshi syntax and Jinja blocks
 Home-page: https://github.com/nandoflorestan/kajiki
 Author: Nando Florestan
@@ -78,6 +78,12 @@ Description: Kajiki provides fast well-formed XML templates
         CHANGES
         =======
         
+        0.5.3 (2016-01-25)
+        ------------------
+        
+        * ``py:with`` statement now keeps order of variables, so that variables can depend from each other.
+        * Babel is no longer a dependency unless you want to use the message extractor.
+        
         0.5.2 (2015-10-13)
         ------------------
         
diff --git a/Kajiki.egg-info/requires.txt b/Kajiki.egg-info/requires.txt
index 23f2f57..211a828 100644
--- a/Kajiki.egg-info/requires.txt
+++ b/Kajiki.egg-info/requires.txt
@@ -1,2 +1 @@
-nine
-babel
\ No newline at end of file
+nine
\ No newline at end of file
diff --git a/PKG-INFO b/PKG-INFO
index 71bcba3..bc5e38d 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: Kajiki
-Version: 0.5.2
+Version: 0.5.3
 Summary: Fast XML-based template engine with Genshi syntax and Jinja blocks
 Home-page: https://github.com/nandoflorestan/kajiki
 Author: Nando Florestan
@@ -78,6 +78,12 @@ Description: Kajiki provides fast well-formed XML templates
         CHANGES
         =======
         
+        0.5.3 (2016-01-25)
+        ------------------
+        
+        * ``py:with`` statement now keeps order of variables, so that variables can depend from each other.
+        * Babel is no longer a dependency unless you want to use the message extractor.
+        
         0.5.2 (2015-10-13)
         ------------------
         
diff --git a/kajiki/ir.py b/kajiki/ir.py
index dc0ba42..7a81e80 100644
--- a/kajiki/ir.py
+++ b/kajiki/ir.py
@@ -2,8 +2,11 @@
 
 from __future__ import (absolute_import, division, print_function,
                         unicode_literals)
-from .util import gen_name, flattener
-from nine import iteritems, nine
+from itertools import chain
+import re
+
+from .util import gen_name, flattener, window
+from nine import nine
 
 
 def generate_python(ir):
@@ -188,35 +191,43 @@ class ForNode(HierNode):
 
 
 class WithNode(HierNode):
+
+    assignment_pattern = re.compile(r'(?:^|;)\s*([^;=]+)=(?!=)', re.M)
+
     class WithTail(Node):
-        def __init__(self, vars):
+        def __init__(self, var_names):
             super(WithNode.WithTail, self).__init__()
-            self.vars = vars
+            self.var_names = var_names
 
         def py(self):
-            gen = gen_name()
-            yield self.line('%s = local.__kj__.pop_with()' % gen)
-            for v in self.vars:
-                yield self.line('%s = %s.get(%r)' % (v, gen, v))
-                # yield self.line('if %s == (): del %s' % (v, v))
+            yield self.line('(%s,) = local.__kj__.pop_with()' %
+                            (','.join(self.var_names),))
+            # yield self.line('if %s == (): del %s' % (v, v))
 
     def __init__(self, vars, *body):
         super(WithNode, self).__init__(body)
-        self.vars = dict(var.split('=', 1) for var in vars.split(';'))
-        self.vars_args = ','.join('%s=%s' % v for v in self.vars.items())
+        assignments = []
+        matches = self.assignment_pattern.finditer(vars)
+        for m1, m2 in window(chain(matches, [None]), 2):
+            lhs = m1.group(1).strip()
+            rhs = vars[m1.end():(m2.start() if m2 else len(vars))]
+            assignments.append((lhs, rhs))
+
+        self.vars = assignments
+        self.var_names = [l for l, _ in assignments]
 
     def py(self):
         yield self.line(
-            'local.__kj__.push_with(locals(), %s)' % self.vars_args
-        )
-        for k, v in iteritems(self.vars):
+            'local.__kj__.push_with(locals(), [%s])' % (
+                ','.join('"%s"' % k for k in self.var_names),))
+        for k, v in self.vars:
             yield self.line('%s = %s' % (k, v))
 
     def __iter__(self):
         yield self
         for x in self.body_iter():
             yield x
-        yield self.WithTail(self.vars)
+        yield self.WithTail(self.var_names)
 
 
 class SwitchNode(HierNode):
diff --git a/kajiki/template.py b/kajiki/template.py
index d3d6ca1..84dd5ae 100644
--- a/kajiki/template.py
+++ b/kajiki/template.py
@@ -80,10 +80,8 @@ class _Template(object):
     def render(self):
         return ''.join(self)
 
-    def _push_with(self, lcls, **kw):
-        d = dict((k, lcls.get(k, ()))
-                 for k in kw)
-        self._with_stack.append(d)
+    def _push_with(self, locals_, vars):
+        self._with_stack.append([locals_.get(k, ()) for k in vars])
 
     def _pop_with(self):
         return self._with_stack.pop()
diff --git a/kajiki/tests/test_xml.py b/kajiki/tests/test_xml.py
index bc286a7..aa620b8 100755
--- a/kajiki/tests/test_xml.py
+++ b/kajiki/tests/test_xml.py
@@ -243,6 +243,23 @@ class TestWith(TestCase):
 <div>foo - 3</div>
 </div>''')
 
+    def test_with_multiple_and_whitespace(self):
+        perform('''<div py:with="a = 'foo';
+                                 b = 3">$a - $b</div>''',
+                '<div>foo - 3</div>')
+
+    def test_with_trailing_semicolon(self):
+        perform('''<div py:with="a = 'foo';">$a</div>''',
+                '<div>foo</div>')
+
+    def test_with_ordered_multiple(self):
+        perform('''<div py:with="a='foo';b=a * 2;c=b[::-1];d=c[:3]">'''
+                '''$a $b $c $d</div>''',
+                '<div>foo foofoo oofoof oof</div>')
+
+    def test_with_multiple_with_embedded_semicolons(self):
+        perform('''<div py:with="a=';';b='-)'">$a$b</div>''',
+                '<div>;-)</div>')
 
 
 class TestFunction(TestCase):
diff --git a/kajiki/util.py b/kajiki/util.py
index 95002bb..7604856 100644
--- a/kajiki/util.py
+++ b/kajiki/util.py
@@ -2,6 +2,7 @@
 
 from __future__ import (absolute_import, division, print_function,
                         unicode_literals)
+from collections import deque
 import sys
 from random import randint
 from threading import local
@@ -108,3 +109,13 @@ class NameGen(object):
 
 def gen_name(hint='_kj_'):
     return NameGen.gen(hint)
+
+
+def window(seq, n=2):
+    """Return a sliding window of size ``n`` over an iterator"""
+    l = deque((next(seq, None) for _ in range(n)), maxlen=n)
+    push = l.append
+    yield l
+    for item in seq:
+        push(item)
+        yield l
diff --git a/kajiki/version.py b/kajiki/version.py
index 5665fa9..68fce99 100644
--- a/kajiki/version.py
+++ b/kajiki/version.py
@@ -3,4 +3,4 @@ from __future__ import (absolute_import, division, print_function,
                         unicode_literals)
 
 __version__ = '0.5'
-__release__ = '0.5.2'
+__release__ = '0.5.3'
diff --git a/setup.py b/setup.py
index c07d35c..1c9f22d 100755
--- a/setup.py
+++ b/setup.py
@@ -58,7 +58,7 @@ setup(name='Kajiki',
       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
       include_package_data=True,
       zip_safe=False,
-      install_requires=['nine', 'babel'],
+      install_requires=['nine'],
       test_suite='kajiki.tests',
       entry_points="""
           [babel.extractors]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-kajiki.git



More information about the Python-modules-commits mailing list