fix Comparison.as_string to considerer its optional attribute stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 29 Jul 2011 15:10:49 +0200
branchstable
changeset 652 540cf0442346
parent 650 52b945da43ea
child 653 4990981c1826
fix Comparison.as_string to considerer its optional attribute
ChangeLog
nodes.py
--- a/ChangeLog	Wed Jul 27 19:26:55 2011 +0200
+++ b/ChangeLog	Fri Jul 29 15:10:49 2011 +0200
@@ -1,6 +1,9 @@
 ChangeLog for RQL
 =================
 
+	--
+    * fix Comparison.as_string to considerer its optional attribute
+
 2011-07-27  --  0.29.1
     * #70264: remove_group_var renamed into remove_group_term and fixed
       implementation
--- a/nodes.py	Wed Jul 27 19:26:55 2011 +0200
+++ b/nodes.py	Fri Jul 29 15:10:49 2011 +0200
@@ -524,9 +524,14 @@
         if len(self.children) == 0:
             return self.operator
         if len(self.children) == 2:
-            return '%s %s %s' % (self.children[0].as_string(encoding, kwargs),
-                                 self.operator.encode(),
-                                 self.children[1].as_string(encoding, kwargs))
+            lhsopt = rhsopt = ''
+            if self.optional in ('left', 'both'):
+                lhsopt = '?'
+            if self.optional in ('right', 'both'):
+                rhsopt = '?'
+            return '%s%s %s %s%s' % (self.children[0].as_string(encoding, kwargs),
+                                     lhsopt, self.operator.encode(),
+                                     self.children[1].as_string(encoding, kwargs), rhsopt)
         if self.operator == '=':
             return self.children[0].as_string(encoding, kwargs)
         return '%s %s' % (self.operator.encode(),