fix several Py3 and import issues in the compiled modules
authorStefan Behnel <scoder@users.berlios.de>
Fri, 26 Nov 2010 14:37:02 +0000 (15:37 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 26 Nov 2010 14:37:02 +0000 (15:37 +0100)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Nodes.py
Cython/Compiler/Optimize.py
Cython/Compiler/ParseTreeTransforms.py

index c11a3ad6e4aad8636c1dc0059c50d170b3bc2401..83883bd792b43dcac80eb37b7beb984b408bbe9e 100755 (executable)
@@ -36,6 +36,11 @@ from Cython.Debugging import print_call_chain
 from DebugFlags import debug_disposal_code, debug_temp_alloc, \
     debug_coercion
 
+try:
+    from __builtin__ import basestring
+except ImportError:
+    basestring = str # Python 3
+
 class NotConstant(object):
     def __repr__(self):
         return "<NOT CONSTANT>"
@@ -2986,7 +2991,7 @@ class SimpleCallNode(CallNode):
             return "<error>"
         formal_args = func_type.args
         arg_list_code = []
-        args = zip(formal_args, self.args)
+        args = list(zip(formal_args, self.args))
         max_nargs = len(func_type.args)
         expected_nargs = max_nargs - func_type.optional_arg_count
         actual_nargs = len(self.args)
@@ -3031,7 +3036,7 @@ class SimpleCallNode(CallNode):
                         self.opt_arg_struct,
                         Naming.pyrex_prefix + "n",
                         len(self.args) - expected_nargs))
-                args = zip(func_type.args, self.args)
+                args = list(zip(func_type.args, self.args))
                 for formal_arg, actual_arg in args[expected_nargs:actual_nargs]:
                     code.putln("%s.%s = %s;" % (
                             self.opt_arg_struct,
index 0b39523c4ae191c5bb913ff97ad1b3326c333120..b453a27b5d8ef02b8bed8a722e8468f57b797c48 100644 (file)
@@ -3,15 +3,17 @@
 #   Pyrex - Parse tree nodes
 #
 
-import sys, os, time, copy
+import cython
+from cython import set
+cython.declare(sys=object, os=object, time=object, copy=object,
+               Builtin=object, error=object, warning=object, Naming=object, PyrexTypes=object,
+               py_object_type=object, ModuleScope=object, LocalScope=object, ClosureScope=object, \
+               StructOrUnionScope=object, PyClassScope=object, CClassScope=object,
+               CppClassScope=object, UtilityCode=object, EncodedString=object,
+               absolute_path_length=cython.Py_ssize_t)
 
-try:
-    set
-except NameError:
-    # Python 2.3
-    from sets import Set as set
+import sys, os, time, copy
 
-import Code
 import Builtin
 from Errors import error, warning, InternalError
 import Naming
@@ -253,7 +255,7 @@ class Node(object):
                 return repr(x)
             
         
-        attrs = [(key, value) for key, value in self.__dict__.iteritems() if key not in filter_out]
+        attrs = [(key, value) for key, value in self.__dict__.items() if key not in filter_out]
         if len(attrs) == 0:
             return "<%s (0x%x)>" % (self.__class__.__name__, id(self))
         else:
@@ -858,7 +860,7 @@ class TemplatedTypeNode(CBaseTypeNode):
             if sys.version_info[0] < 3:
                 # Py 2.x enforces byte strings as keyword arguments ...
                 options = dict([ (name.encode('ASCII'), value)
-                                 for name, value in options.iteritems() ])
+                                 for name, value in options.items() ])
 
             self.type = PyrexTypes.BufferType(base_type, **options)
         
index 807182455f529cdf4499ede2974a630ef25001ee..d95638a518b080ed8fcd44b56c028ff616290752 100644 (file)
@@ -28,6 +28,11 @@ try:
 except ImportError:
     from functools import reduce
 
+try:
+    from __builtin__ import basestring
+except ImportError:
+    basestring = str # Python 3
+
 class FakePythonEnv(object):
     "A fake environment for creating type test nodes etc."
     nogil = False
@@ -751,7 +756,7 @@ class SwitchTransform(Visitor.VisitorTransform):
 
     def extract_in_string_conditions(self, string_literal):
         if isinstance(string_literal, ExprNodes.UnicodeNode):
-            charvals = map(ord, set(string_literal.value))
+            charvals = list(map(ord, set(string_literal.value)))
             charvals.sort()
             return [ ExprNodes.IntNode(string_literal.pos, value=str(charval),
                                        constant_result=charval)
@@ -2937,7 +2942,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
 
         # check if all children are constant
         children = self.visitchildren(node)
-        for child_result in children.itervalues():
+        for child_result in children.values():
             if type(child_result) is list:
                 for child in child_result:
                     if getattr(child, 'constant_result', not_a_constant) is not_a_constant:
index ae8f8ca17c8d75c5ee28256b800891caa957b0c5..a6047d775673d1cf03e794816b489184a9a46423 100644 (file)
@@ -1,3 +1,9 @@
+
+import cython
+from cython import set
+cython.declare(copy=object, ModuleNode=object, TreeFragment=object, TemplateTransform=object,
+               EncodedString=object, error=object, PyrexTypes=object, Naming=object)
+
 from Cython.Compiler.Visitor import VisitorTransform, TreeVisitor
 from Cython.Compiler.Visitor import CythonTransform, EnvTransform, ScopeTrackingTransform
 from Cython.Compiler.ModuleNode import ModuleNode
@@ -7,10 +13,8 @@ from Cython.Compiler.UtilNodes import *
 from Cython.Compiler.TreeFragment import TreeFragment, TemplateTransform
 from Cython.Compiler.StringEncoding import EncodedString
 from Cython.Compiler.Errors import error, CompileError
-try:
-    set
-except NameError:
-    from sets import Set as set
+from Cython.Compiler import PyrexTypes, Naming
+
 import copy
 
 
@@ -572,12 +576,12 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
     
     special_methods = set(['declare', 'union', 'struct', 'typedef', 'sizeof',
                            'cast', 'pointer', 'compiled', 'NULL']
-                          + unop_method_nodes.keys())
+                          + list(unop_method_nodes.keys()))
 
     def __init__(self, context, compilation_directive_defaults):
         super(InterpretCompilerDirectives, self).__init__(context)
         self.compilation_directive_defaults = {}
-        for key, value in compilation_directive_defaults.iteritems():
+        for key, value in compilation_directive_defaults.items():
             self.compilation_directive_defaults[unicode(key)] = value
         self.cython_module_names = set()
         self.directive_names = {}
@@ -593,7 +597,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
         
     # Set up processing and handle the cython: comments.
     def visit_ModuleNode(self, node):
-        for key, value in node.directive_comments.iteritems():
+        for key, value in node.directive_comments.items():
             if not self.check_directive_scope(node.pos, key, 'module'):
                 self.wrong_scope_error(node.pos, key, 'module')
                 del node.directive_comments[key]