[PySide] non-ascii chars in python 2 on windows

Joel B. Mohler jmohler at gamry.com
Thu Dec 19 17:20:38 CET 2013


The case correcting code in _utils.py has a bug on windows on python 
2.7.  The easy fix is included in the patch in the post-script.

qt-project grumblings:   I spent more time trying (and failing) to grok 
gerrit and gitorious than I did diagnosing and fixing this bug 
together.  Consider me vexed!  Also https://bugreports.qt-project.org 
doesn't acknowledge version 1.2.1 for PySide.

Joel

Patch:

commit 9ded473872a5617df4b93e93c9db8d7b36f6f642
Author: Joel B. Mohler <jmohler at gamry.com>
Date:   Thu Dec 19 10:55:52 2013 -0500

     use file system encoding instead of assumed 'ascii'

diff --git a/PySide/_utils.py.in b/PySide/_utils.py.in
index b8199fc..2c77ab4 100644
--- a/PySide/_utils.py.in
+++ b/PySide/_utils.py.in
@@ -45,16 +45,20 @@ if sys.platform == 'win32':
      if PY_2:
          def u(x):
              return unicode(x)
+        def u_fs(x):
+            return unicode(x, sys.getfilesystemencoding())
      else:
          def u(x):
              return x
+        def u_fs(x):
+            return x

      def _get_win32_short_name(s):
          """ Returns short name """
          buf_size = MAX_PATH
          for i in range(2):
              buf = create_unicode_buffer(u('\0') * (buf_size + 1))
-            r = GetShortPathNameW(u(s), buf, buf_size)
+            r = GetShortPathNameW(u_fs(s), buf, buf_size)
              if r == 0:
                  raise WinError()
              if r < buf_size:
@@ -69,7 +73,7 @@ if sys.platform == 'win32':
          buf_size = MAX_PATH
          for i in range(2):
              buf = create_unicode_buffer(u('\0') * (buf_size + 1))
-            r = GetLongPathNameW(u(s), buf, buf_size)
+            r = GetLongPathNameW(u_fs(s), buf, buf_size)
              if r == 0:
                  raise WinError()
              if r < buf_size:



More information about the PySide mailing list