[Checkins] SVN: z3c.pt/trunk/ Repeat-clause should not output tail with every iteration.

Malthe Borch mborch at gmail.com
Mon Aug 18 06:04:52 EDT 2008


Log message for revision 89965:
  Repeat-clause should not output tail with every iteration.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/clauses.py
  U   z3c.pt/trunk/src/z3c/pt/translation.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-08-18 09:32:40 UTC (rev 89964)
+++ z3c.pt/trunk/CHANGES.txt	2008-08-18 10:04:51 UTC (rev 89965)
@@ -4,6 +4,8 @@
 Version 1.0dev
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- The repeat-clause should not output tail with every iteration. [malthe]
+
 - UTF-8 encode Unicode attribute literals. [chrism]
 
 - Substantially reduced compiler overhead for lxml CDATA

Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-18 09:32:40 UTC (rev 89964)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-18 10:04:51 UTC (rev 89965)
@@ -581,11 +581,13 @@
 
     Simple repeat loop and repeat data structure:
 
-      >>> stream = CodeIO()
+      >>> from StringIO import StringIO
+      >>> _out = StringIO(); _write = _out.write; stream = CodeIO()
       >>> _repeat = Repeat("i", pyexp("range(5)"))
       >>> _repeat.begin(stream)
       >>> stream.write("r = repeat['i']")
-      >>> stream.write("print (i, r.index, r.start, r.end, r.number(), r.odd(), r.even())")
+      >>> stream.write(
+      ...     "print (i, r.index, r.start, r.end, r.number(), r.odd(), r.even())")
       >>> _repeat.end(stream)
       >>> exec stream.getvalue()
       (0, 0, True, False, 1, False, True)
@@ -665,8 +667,9 @@
     def end(self, stream):
         # cook before leaving loop
         stream.cook()
+        stream.out('\n')
         stream.outdent()
-
+        
         if self.repeatdict:
             stream.outdent()
             stream.write("except StopIteration:")
@@ -860,8 +863,10 @@
     def begin(self, stream):
         if not self.defer:
             stream.out(self.string)
-
+        
     def end(self, stream):
+        stream.cook()
+        
         if self.defer:
             stream.out(self.string)
 

Modified: z3c.pt/trunk/src/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/translation.py	2008-08-18 09:32:40 UTC (rev 89964)
+++ z3c.pt/trunk/src/z3c/pt/translation.py	2008-08-18 10:04:51 UTC (rev 89965)
@@ -106,6 +106,13 @@
                 _.append(clauses.Define(
                     macro.name, types.parts((types.value(self.macro_variable),))))
 
+        # tag tail (deferred)
+        tail = self.tail
+        if tail and not self.node.fill_slot:
+            if isinstance(tail, unicode):
+                tail = tail.encode('utf-8')
+            _.append(clauses.Out(tail, defer=True))
+
         # condition
         if self.node.condition is not None:
             _.append(clauses.Condition(self.node.condition))
@@ -119,13 +126,6 @@
                     "repeat statement.")
             _.append(clauses.Repeat(variables[0], expression))
 
-        # tag tail (deferred)
-        tail = self.tail
-        if tail and not self.node.fill_slot:
-            if isinstance(tail, unicode):
-                tail = tail.encode('utf-8')
-            _.append(clauses.Out(tail, defer=True))
-
         content = self.node.content
 
         # macro slot definition



More information about the Checkins mailing list