[Checkins] SVN: Sandbox/malthe/chameleon.core/ Conditions may now be inverted; fixed issue with omit conditions and multi-part.

Malthe Borch mborch at gmail.com
Sun Nov 16 17:21:19 EST 2008


Log message for revision 93021:
  Conditions may now be inverted; fixed issue with omit conditions and multi-part.
  

Changed:
  U   Sandbox/malthe/chameleon.core/CHANGES.txt
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py

-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-16 21:16:11 UTC (rev 93020)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-16 22:21:19 UTC (rev 93021)
@@ -4,6 +4,9 @@
 HEAD
 ~~~~
 
+- Conditions may now be inverted; this facilitates the bug-fix of an
+  issue where omit conditions were multi-part. [malthe]
+
 - Make sure that arguments passed into the `render`-method are
   introduced in every nested scope. [malthe]
 

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py	2008-11-16 21:16:11 UTC (rev 93020)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py	2008-11-16 22:21:19 UTC (rev 93021)
@@ -378,15 +378,21 @@
 
     """
       
-    def __init__(self, value, clauses=None, finalize=True):
+    def __init__(self, value, clauses=None, finalize=True, invert=False):
         self.assign = Assign(value)
         self.clauses = clauses
         self.finalize = finalize
+        self.invert = False
         
     def begin(self, stream):
         temp = stream.save()
         self.assign.begin(stream, temp)
-        stream.write("if %s:" % temp)
+
+        if self.invert:
+            stream.write("if not (%s):" % temp)
+        else:
+            stream.write("if %s:" % temp)
+            
         stream.indent()
         if self.clauses:
             for clause in self.clauses:

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py	2008-11-16 21:16:11 UTC (rev 93020)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py	2008-11-16 22:21:19 UTC (rev 93021)
@@ -79,7 +79,7 @@
         if isinstance(self.skip, types.expression):
             assert isinstance(self.skip, types.value), \
                    "Dynamic skip condition can't be of type %s." % type(self.skip)
-            condition = clauses.Condition(types.value("not (%s)" % self.skip))
+            condition = clauses.Condition(self.skip, invert=True)
             if len(self.element):
                 condition.begin(self.stream)
         elif self.skip:
@@ -168,12 +168,13 @@
             name = self.symbols.slot + self.define_slot
             if name in itertools.chain(*self.stream.scope):
                 _.append(clauses.Condition(
-                    types.value('not isinstance(%s, basestring)' % name),
+                    types.value('isinstance(%s, basestring)' % name),
                     (clauses.Assign(
                     types.value('%s(%s)' % (
                     name, self.symbols.scope)),
                     name),),
-                    finalize=True))
+                    finalize=True,
+                    invert=True))
                      
                 content = types.value(name)
 
@@ -234,7 +235,7 @@
                 cdata=self.cdata is not None)
             if self.omit:
                 _.append(clauses.Condition(
-                    types.value("not (%s)" % self.omit), [tag], finalize=False))
+                    self.omit, [tag], finalize=False, invert=True))
             else:
                 _.append(tag)
 



More information about the Checkins mailing list