[py3k] print function
authorRémi Cardona <remi.cardona@free.fr>
Thu, 24 Jul 2014 02:26:50 +0200
changeset 749 c6aa72c82081
parent 748 c97f90cd49c5
child 750 e554893cccb6
[py3k] print function Requires python >= 2.6.
analyze.py
parser.g
parser.py
stmts.py
test/unittest_analyze.py
test/unittest_parser.py
test/unittest_stcheck.py
--- a/analyze.py	Tue Jul 22 20:26:12 2014 +0200
+++ b/analyze.py	Thu Jul 24 02:26:50 2014 +0200
@@ -18,9 +18,10 @@
 """Analyze of the RQL syntax tree to get possible types for RQL variables.
 
 """
+from __future__ import print_function
+
 __docformat__ = "restructuredtext en"
 
-
 import os
 from itertools import izip
 
@@ -51,9 +52,9 @@
         self.output = StringIO()
 
     def debug(self):
-        print "Domains:", self.domains
-        print "Constraints:", self.constraints
-        print "Scons:", self.scons
+        print("Domains:", self.domains)
+        print("Constraints:", self.constraints)
+        print("Scons:", self.scons)
 
     def get_output(self):
         return self.output.getvalue()
@@ -170,10 +171,10 @@
         self.ivalues = {}
         for val_name, val_num in self.values.items():
             self.ivalues[val_num] = val_name
-        print "Domains:", self.domains
-        print "Ops:", self.pretty_print_ops(self.op)
-        print "Variables:", self.variables
-        print "Values:", self.values
+        print("Domains:", self.domains)
+        print("Ops:", self.pretty_print_ops(self.op))
+        print("Variables:", self.variables)
+        print("Values:", self.values)
 
 
     def pretty_print_ops(self, ops):
@@ -327,9 +328,9 @@
     def solve(self, node, constraints):
         # debug info
         if self.debug > 1:
-            print "- AN1 -"+'-'*80
-            print node
-            print "CONSTRAINTS:"
+            print("- AN1 -"+'-'*80)
+            print(node)
+            print("CONSTRAINTS:")
             constraints.debug()
 
         sols = constraints.solve()
--- a/parser.g	Tue Jul 22 20:26:12 2014 +0200
+++ b/parser.g	Thu Jul 24 02:26:50 2014 +0200
@@ -44,18 +44,6 @@
 * P -> parent node
 
 """
-
-from warnings import warn
-from rql.stmts import Union, Select, Delete, Insert, Set
-from rql.nodes import *
-
-
-def unquote(string):
-    """Remove quotes from a string."""
-    if string.startswith('"'):
-        return string[1:-1].replace('\\\\', '\\').replace('\\"', '"')
-    elif string.startswith("'"):
-        return string[1:-1].replace('\\\\', '\\').replace("\\'", "'")
 %%
 
 parser Hercule:
@@ -359,4 +347,16 @@
           | INT        {{ return Constant(int(INT), 'Int') }}
           | STRING     {{ return Constant(unquote(STRING), 'String') }}
           | SUBSTITUTE {{ return Constant(SUBSTITUTE[2:-2], 'Substitute') }}
+%%
 
+from warnings import warn
+from rql.stmts import Union, Select, Delete, Insert, Set
+from rql.nodes import *
+
+
+def unquote(string):
+    """Remove quotes from a string."""
+    if string.startswith('"'):
+        return string[1:-1].replace('\\\\', '\\').replace('\\"', '"')
+    elif string.startswith("'"):
+        return string[1:-1].replace('\\\\', '\\').replace("\\'", "'")
--- a/parser.py	Tue Jul 22 20:26:12 2014 +0200
+++ b/parser.py	Thu Jul 24 02:26:50 2014 +0200
@@ -45,19 +45,8 @@
 
 """
 
-from warnings import warn
-from rql.stmts import Union, Select, Delete, Insert, Set
-from rql.nodes import *
-
-
-def unquote(string):
-    """Remove quotes from a string."""
-    if string.startswith('"'):
-        return string[1:-1].replace('\\\\', '\\').replace('\\"', '"')
-    elif string.startswith("'"):
-        return string[1:-1].replace('\\\\', '\\').replace("\\'", "'")
-
 # Begin -- grammar generated by Yapps
+from __future__ import print_function
 import sys, re
 from yapps import runtime
 
@@ -702,13 +691,18 @@
     P = Hercule(HerculeScanner(text))
     return runtime.wrap_error_reporter(P, rule)
 
-if __name__ == '__main__':
-    from sys import argv, stdin
-    if len(argv) >= 2:
-        if len(argv) >= 3:
-            f = open(argv[2],'r')
-        else:
-            f = stdin
-        print parse(argv[1], f.read())
-    else: print >>sys.stderr, 'Args:  <rule> [<filename>]'
 # End -- grammar generated by Yapps
+
+
+
+from warnings import warn
+from rql.stmts import Union, Select, Delete, Insert, Set
+from rql.nodes import *
+
+
+def unquote(string):
+    """Remove quotes from a string."""
+    if string.startswith('"'):
+        return string[1:-1].replace('\\\\', '\\').replace('\\"', '"')
+    elif string.startswith("'"):
+        return string[1:-1].replace('\\\\', '\\').replace("\\'", "'")
--- a/stmts.py	Tue Jul 22 20:26:12 2014 +0200
+++ b/stmts.py	Thu Jul 24 02:26:50 2014 +0200
@@ -21,6 +21,8 @@
 defined in the nodes module
 """
 
+from __future__ import print_function
+
 __docformat__ = "restructuredtext en"
 
 from copy import deepcopy
@@ -155,7 +157,7 @@
         try:
             _check_references(defined, varrefs)
         except:
-            print repr(self)
+            print(repr(self))
             raise
         return True
 
--- a/test/unittest_analyze.py	Tue Jul 22 20:26:12 2014 +0200
+++ b/test/unittest_analyze.py	Thu Jul 24 02:26:50 2014 +0200
@@ -15,6 +15,8 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with rql. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
+
 from logilab.common.testlib import TestCase, unittest_main, mock_object as mock
 
 from rql import RQLHelper, TypeResolverException
@@ -207,7 +209,7 @@
     def test_raise(self):
         for rql in UNRESOLVABLE_QUERIES:
             if DEBUG:
-                print rql
+                print(rql)
             node = self.helper.parse(rql)
             self.assertRaises(TypeResolverException,
                               self.helper.compute_solutions, node, debug=DEBUG)
--- a/test/unittest_parser.py	Tue Jul 22 20:26:12 2014 +0200
+++ b/test/unittest_parser.py	Thu Jul 24 02:26:50 2014 +0200
@@ -16,6 +16,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with rql. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
 
 from logilab.common.testlib import TestCase, unittest_main
 
@@ -180,7 +181,7 @@
             raise
         except Exception as ex:
             if print_errors:
-                print string, ex
+                print(string, ex)
             raise
 
     def test_unicode_constant(self):
--- a/test/unittest_stcheck.py	Tue Jul 22 20:26:12 2014 +0200
+++ b/test/unittest_stcheck.py	Thu Jul 24 02:26:50 2014 +0200
@@ -15,6 +15,8 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with rql. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
+
 from logilab.common.testlib import TestCase, unittest_main
 
 from rql import RQLHelper, BadRQLQuery, stmts, nodes
@@ -96,7 +98,7 @@
         try:
             self.assertRaises(BadRQLQuery, self.parse, rql)
         except:
-            print rql
+            print(rql)
             raise
 
     def test_raise(self):