Browse Source

deploy-ng: Fix handling of unicode Python files for Python 2

Mitchell Stokes 7 years ago
parent
commit
5b4041bf23
1 changed files with 3 additions and 10 deletions
  1. 3 10
      direct/src/showutil/FreezeTool.py

+ 3 - 10
direct/src/showutil/FreezeTool.py

@@ -752,7 +752,7 @@ class Freezer:
         if self.platform == PandaSystem.getPlatform():
         if self.platform == PandaSystem.getPlatform():
             self.moduleSuffixes = imp.get_suffixes()
             self.moduleSuffixes = imp.get_suffixes()
         else:
         else:
-            self.moduleSuffixes = [('.py', 'r', 1), ('.pyc', 'rb', 2)]
+            self.moduleSuffixes = [('.py', 'rb', 1), ('.pyc', 'rb', 2)]
             if 'linux' in self.platform:
             if 'linux' in self.platform:
                 self.moduleSuffixes += [
                 self.moduleSuffixes += [
                     ('.cpython-{0}{1}m-x86_64-linux-gnu.so'.format(*sys.version_info), 'rb', 3),
                     ('.cpython-{0}{1}m-x86_64-linux-gnu.so'.format(*sys.version_info), 'rb', 3),
@@ -1161,14 +1161,11 @@ class Freezer:
                 stuff = ("", "rb", imp.PY_COMPILED)
                 stuff = ("", "rb", imp.PY_COMPILED)
                 self.mf.load_module(mdef.moduleName, fp, pathname, stuff)
                 self.mf.load_module(mdef.moduleName, fp, pathname, stuff)
             else:
             else:
-                stuff = ("", "r", imp.PY_SOURCE)
+                stuff = ("", "rb", imp.PY_SOURCE)
                 if mdef.text:
                 if mdef.text:
                     fp = io.StringIO(mdef.text)
                     fp = io.StringIO(mdef.text)
-                elif sys.version_info >= (3, 0):
-                    fp = open(pathname, 'rb')
-                    stuff = ("", "rb", imp.PY_SOURCE)
                 else:
                 else:
-                    fp = open(pathname, 'r')
+                    fp = open(pathname, 'rb')
                 self.mf.load_module(mdef.moduleName, fp, pathname, stuff)
                 self.mf.load_module(mdef.moduleName, fp, pathname, stuff)
 
 
             if tempPath:
             if tempPath:
@@ -2224,10 +2221,6 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
         to compile() for PY_SOURCE types. Sending bytes to compile allows it to
         to compile() for PY_SOURCE types. Sending bytes to compile allows it to
         handle file encodings."""
         handle file encodings."""
 
 
-        if sys.version_info < (3, 0):
-            # fallback to original version for Python 2
-            return modulefinder.ModuleFinder.load_module(self, fqname, fp, pathname, file_info)
-
         suffix, mode, type = file_info
         suffix, mode, type = file_info
         self.msgin(2, "load_module", fqname, fp and "fp", pathname)
         self.msgin(2, "load_module", fqname, fp and "fp", pathname)
         if type == imp.PKG_DIRECTORY:
         if type == imp.PKG_DIRECTORY: