Source files now executable even with unicodes in path or filename.

Sun, 23 Aug 2015 11:37:17 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Sun, 23 Aug 2015 11:37:17 +0200
changeset 4385
599681bf149a
parent 4384
04896c4a5a8e
child 4386
510090f78d0a

Source files now executable even with unicodes in path or filename.

DataViews/PyCoverageDialog.py file | annotate | diff | comparison | revisions
DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
DebugClients/Python/coverage/codeunit.py file | annotate | diff | comparison | revisions
DebugClients/Python/coverage/data.py file | annotate | diff | comparison | revisions
DebugClients/Python/coverage/files.py file | annotate | diff | comparison | revisions
DebugClients/Python/coverage/parser.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py file | annotate | diff | comparison | revisions
QScintilla/Editor.py file | annotate | diff | comparison | revisions
--- a/DataViews/PyCoverageDialog.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/DataViews/PyCoverageDialog.py	Sun Aug 23 11:37:17 2015 +0200
@@ -10,6 +10,7 @@
 from __future__ import unicode_literals
 
 import os
+import sys
 
 from PyQt5.QtCore import pyqtSlot, Qt
 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMenu, QHeaderView, \
@@ -22,8 +23,12 @@
 from .Ui_PyCoverageDialog import Ui_PyCoverageDialog
 
 import Utilities
-from DebugClients.Python3.coverage import coverage
-from DebugClients.Python3.coverage.misc import CoverageException
+if sys.version_info[0] == 2:
+    from DebugClients.Python.coverage import coverage
+    from DebugClients.Python.coverage.misc import CoverageException
+else:
+    from DebugClients.Python3.coverage import coverage
+    from DebugClients.Python3.coverage.misc import CoverageException
 
 
 class PyCoverageDialog(QDialog, Ui_PyCoverageDialog):
--- a/DebugClients/Python/DebugClientBase.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/DebugClients/Python/DebugClientBase.py	Sun Aug 23 11:37:17 2015 +0200
@@ -503,6 +503,7 @@
                 self.dircache = []
                 sys.argv = []
                 wd, fn, args, tracePython = arg.split('|')
+                fn = fn.encode(sys.getfilesystemencoding())
                 self.__setCoding(fn)
                 sys.argv.append(fn)
                 sys.argv.extend(eval(args))
@@ -549,6 +550,7 @@
             if cmd == DebugProtocol.RequestRun:
                 sys.argv = []
                 wd, fn, args = arg.split('|')
+                fn = fn.encode(sys.getfilesystemencoding())
                 self.__setCoding(fn)
                 sys.argv.append(fn)
                 sys.argv.extend(eval(args))
@@ -589,6 +591,7 @@
                 from coverage import coverage
                 sys.argv = []
                 wd, fn, args, erase = arg.split('@@')
+                fn = fn.encode(sys.getfilesystemencoding())
                 self.__setCoding(fn)
                 sys.argv.append(fn)
                 sys.argv.extend(eval(args))
@@ -632,6 +635,7 @@
                 import PyProfile
                 sys.argv = []
                 wd, fn, args, erase = arg.split('|')
+                fn = fn.encode(sys.getfilesystemencoding())
                 self.__setCoding(fn)
                 sys.argv.append(fn)
                 sys.argv.extend(eval(args))
@@ -671,6 +675,7 @@
             
             if cmd == DebugProtocol.RequestBreak:
                 fn, line, temporary, set, cond = arg.split('@@')
+                fn = fn.encode(sys.getfilesystemencoding())
                 line = int(line)
                 set = int(set)
                 temporary = int(temporary)
@@ -695,6 +700,7 @@
             
             if cmd == DebugProtocol.RequestBreakEnable:
                 fn, line, enable = arg.split(',')
+                fn = fn.encode(sys.getfilesystemencoding())
                 line = int(line)
                 enable = int(enable)
                 
@@ -709,6 +715,7 @@
             
             if cmd == DebugProtocol.RequestBreakIgnore:
                 fn, line, count = arg.split(',')
+                fn = fn.encode(sys.getfilesystemencoding())
                 line = int(line)
                 count = int(count)
                 
@@ -848,6 +855,7 @@
             
             if cmd == DebugProtocol.RequestUTPrepare:
                 fn, tn, tfn, failed, cov, covname, erase = arg.split('|')
+                fn = fn.encode(sys.getfilesystemencoding())
                 sys.path.insert(0, os.path.dirname(os.path.abspath(fn)))
                 os.chdir(sys.path[0])
                 failed = eval(failed)
--- a/DebugClients/Python/coverage/codeunit.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/DebugClients/Python/coverage/codeunit.py	Sun Aug 23 11:37:17 2015 +0200
@@ -1,6 +1,6 @@
 """Code unit (module) handling for Coverage."""
 
-import glob, os
+import glob, os, sys
 
 from .backward import open_source, string_class, StringIO
 from .misc import CoverageException
@@ -57,6 +57,8 @@
         elif f.endswith('$py.class'): # Jython
             f = f[:-9] + ".py"
         self.filename = self.file_locator.canonical_filename(f)
+        if isinstance(self.filename, unicode):
+            self.filename = self.filename.encode(sys.getfilesystemencoding())
 
         if hasattr(morf, '__name__'):
             n = modname = morf.__name__
@@ -64,6 +66,8 @@
         else:
             n = os.path.splitext(morf)[0]
             rel = self.file_locator.relative_filename(n)
+            if isinstance(rel, unicode):
+                rel = rel.encode(sys.getfilesystemencoding())
             if os.path.isabs(n):
                 self.relative = (rel != n)
             else:
--- a/DebugClients/Python/coverage/data.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/DebugClients/Python/coverage/data.py	Sun Aug 23 11:37:17 2015 +0200
@@ -1,6 +1,7 @@
 """Coverage data for Coverage."""
 
 import os
+import sys
 
 from .backward import iitems, pickle, sorted    # pylint: disable=W0622
 from .files import PathAliases
@@ -101,13 +102,15 @@
     def line_data(self):
         """Return the map from filenames to lists of line numbers executed."""
         return dict(
-            [(f, sorted(lmap.keys())) for f, lmap in iitems(self.lines)]
+            [(f.decode(sys.getfilesystemencoding()), sorted(lmap.keys()))
+                for f, lmap in iitems(self.lines)]
             )
 
     def arc_data(self):
         """Return the map from filenames to lists of line number pairs."""
         return dict(
-            [(f, sorted(amap.keys())) for f, amap in iitems(self.arcs)]
+            [(f.decode(sys.getfilesystemencoding()), sorted(amap.keys()))
+                for f, amap in iitems(self.arcs)]
             )
 
     def write_file(self, filename):
@@ -163,12 +166,14 @@
             if isinstance(data, dict):
                 # Unpack the 'lines' item.
                 lines = dict([
-                    (f, dict.fromkeys(linenos, None))
+                    (f.encode(sys.getfilesystemencoding()),
+                        dict.fromkeys(linenos, None))
                         for f, linenos in iitems(data.get('lines', {}))
                     ])
                 # Unpack the 'arcs' item.
                 arcs = dict([
-                    (f, dict.fromkeys(arcpairs, None))
+                    (f.encode(sys.getfilesystemencoding()),
+                        dict.fromkeys(arcpairs, None))
                         for f, arcpairs in iitems(data.get('arcs', {}))
                     ])
         except Exception:
--- a/DebugClients/Python/coverage/files.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/DebugClients/Python/coverage/files.py	Sun Aug 23 11:37:17 2015 +0200
@@ -11,6 +11,8 @@
     def __init__(self):
         # The absolute path to our current directory.
         self.relative_dir = os.path.normcase(abs_file(os.curdir) + os.sep)
+        if isinstance(self.relative_dir, str):
+            self.relative_dir = self.relative_dir.decode(sys.getfilesystemencoding())
 
         # Cache of results of calling the canonical_filename() method, to
         # avoid duplicating work.
@@ -23,6 +25,8 @@
         `FileLocator` was constructed.
 
         """
+        if isinstance(filename, str):
+            filename = filename.decode(sys.getfilesystemencoding())
         fnorm = os.path.normcase(filename)
         if fnorm.startswith(self.relative_dir):
             filename = filename[len(self.relative_dir):]
--- a/DebugClients/Python/coverage/parser.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/DebugClients/Python/coverage/parser.py	Sun Aug 23 11:37:17 2015 +0200
@@ -346,7 +346,11 @@
             try:
                 # Python 2.3 and 2.4 don't like partial last lines, so be sure
                 # the text ends nicely for them.
-                self.code = compile(text + '\n', filename, "exec")
+                if sys.version_info[0] == 2 and isinstance(filename, unicode):
+                    filenameEnc = filename.encode('utf-8')
+                else:
+                    filenameEnc = filename
+                self.code = compile(text + '\n', filenameEnc, "exec")
             except SyntaxError:
                 _, synerr, _ = sys.exc_info()
                 raise NotPython(
--- a/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Sun Aug 23 11:37:17 2015 +0200
@@ -228,7 +228,7 @@
         if sys.version_info[0] == 2:
             lines = [x.decode(sys.getfilesystemencoding()) for x in lines]
         match = re.match('\s*File "(.+)", line (\d+)',
-                         lines[0].replace('<string>', '{0}'.format(filename)))
+                         lines[0].replace('<string>', filename))
         if match is not None:
             fn, line = match.group(1, 2)
             if lines[1].startswith('SyntaxError:'):
--- a/QScintilla/Editor.py	Sun Aug 23 11:31:11 2015 +0200
+++ b/QScintilla/Editor.py	Sun Aug 23 11:37:17 2015 +0200
@@ -15,6 +15,7 @@
 
 import os
 import re
+import sys
 import difflib
 
 from PyQt5.QtCore import QDir, QTimer, QModelIndex, QFileInfo, pyqtSignal, \
@@ -5468,7 +5469,10 @@
         
         fn = self.__getCodeCoverageFile()
         if fn:
-            from DebugClients.Python3.coverage import coverage
+            if sys.version_info[0] == 2:
+                from DebugClients.Python.coverage import coverage
+            else:
+                from DebugClients.Python3.coverage import coverage
             cover = coverage(data_file=fn)
             cover.use_cache(True)
             cover.load()

eric ide

mercurial