Commits

Anthony Tuininga committed 7d055cb

Adding support for Python 3.x.

  • Participants
  • Parent commits a67c6c9

Comments (0)

Files changed (5)

File cx_Freeze/__init__.py

-version = "4.0.1"
+version = "4.1"
 
 import sys
-from dist import *
+from cx_Freeze.dist import *
 if sys.platform == "win32" and sys.version_info[:2] >= (2, 5):
-    from windist import *
-from finder import *
-from freezer import *
-from main import *
+    from cx_Freeze.windist import *
+from cx_Freeze.finder import *
+from cx_Freeze.freezer import *
+from cx_Freeze.main import *
 
 del dist
 del finder

File cx_Freeze/dist.py

         value = getattr(self, attrName)
         if value is None:
             normalizedValue = []
-        elif isinstance(value, basestring):
+        elif isinstance(value, str):
             normalizedValue = value.split()
         else:
             normalizedValue = list(value)

File cx_Freeze/finder.py

 import dis
 import imp
 import marshal
-import new
 import opcode
 import os
 import sys
+import types
 import zipfile
 
 import cx_Freeze.hooks
                         self._InternalImportModule(subModuleName,
                                 deferredImports)
                 if returnError and subModule is None:
-                    raise ImportError, "No module named %s" % subModuleName
+                    raise ImportError("No module named %s" % subModuleName)
                 module.globalNames[name] = None
                 if subModule.path and recursive:
                     self._ImportAllSubModules(subModule, deferredImports,
         # if module not found, track that fact
         if module is None:
             if caller is None:
-                raise ImportError, "No module named %s" % name
+                raise ImportError("No module named %s" % name)
             self._RunHook("missing", name, caller)
             if returnError and name not in caller.ignoreNames:
                 callers = self._badModules.setdefault(name, {})
             else:
                 magic = fp.read(4)
             if magic != imp.get_magic():
-                raise ImportError, "Bad magic number in %s" % path
+                raise ImportError("Bad magic number in %s" % path)
             if isinstance(fp, str):
                 module.code = marshal.loads(fp[8:])
                 module.inZipFile = True
         for i, value in enumerate(constants):
             if isinstance(value, type(co)):
                 constants[i] = self._ReplacePathsInCode(topLevelModule, value)
-        return new.code(co.co_argcount, co.co_nlocals, co.co_stacksize,
+        return types.CodeType(co.co_argcount, co.co_nlocals, co.co_stacksize,
                 co.co_flags, co.co_code, tuple(constants), co.co_names,
                 co.co_varnames, newFileName, co.co_name, co.co_firstlineno,
                 co.co_lnotab, co.co_freevars, co.co_cellvars)
         arguments = []
         code = co.co_code
         numOps = len(code)
+        is3 = sys.version_info[0] >= 3
         while opIndex < numOps:
-            op = ord(code[opIndex])
+            if is3:
+                op = code[opIndex]
+            else:
+                op = ord(code[opIndex])
             opIndex += 1
             if op >= dis.HAVE_ARGUMENT:
-                opArg = ord(code[opIndex]) + ord(code[opIndex + 1]) * 256
+                if is3:
+                    opArg = code[opIndex] + code[opIndex + 1] * 256
+                else:
+                    opArg = ord(code[opIndex]) + ord(code[opIndex + 1]) * 256
                 opIndex += 2
             if op == LOAD_CONST:
                 arguments.append(co.co_consts[opArg])
             moduleName = name
         info = (ext, "r", imp.PY_SOURCE)
         deferredImports = []
-        module = self._LoadModule(moduleName, file(path, "U"), path, info,
+        module = self._LoadModule(moduleName, open(path, "U"), path, info,
                 deferredImports)
         self._ImportDeferredImports(deferredImports)
         return module
     def ReportMissingModules(self):
         if self._badModules:
             sys.stdout.write("Missing modules:\n")
-            names = self._badModules.keys()
+            names = list(self._badModules.keys())
             names.sort()
             for name in names:
-                callers = self._badModules[name].keys()
+                callers = list(self._badModules[name].keys())
                 callers.sort()
                 sys.stdout.write("? %s imported from %s\n" % \
                         (name, ", ".join(callers)))

File cx_Freeze/freezer.py

                 name = "Console"
             else:
                 name = "ConsoleKeepPath"
+            if sys.version_info[0] >= 3:
+                name += "3"
         argsSource.initScript = self._GetFileName("initscripts", name)
         if argsSource.initScript is None:
             raise ConfigError("no initscript named %s", name)
 
     def _RemoveFile(self, path):
         if os.path.exists(path):
-            os.chmod(path, 0777)
+            os.chmod(path, stat.S_IWRITE)
             os.remove(path)
 
     def _ShouldCopyFile(self, path):
                 sourceTimestamp.strftime(self.timeFormat)
         module = finder._AddModule(self.moduleName)
         sourceParts = []
-        names = self.values.keys()
+        names = list(self.values.keys())
         names.sort()
         for name in names:
             value = self.values[name]

File cx_Freeze/windist.py

 # different "products" very well
 sequence = msilib.sequence.InstallExecuteSequence
 for index, info in enumerate(sequence):
-    if info[0] == u'RemoveExistingProducts':
+    if info[0] == 'RemoveExistingProducts':
         sequence[index] = (info[0], info[1], 1450)