From aefecb4e3774f0e004d0b1255a09a37d46f9449e Mon Sep 17 00:00:00 2001 From: stonebig Date: Sat, 1 Aug 2015 18:02:17 +0200 Subject: [PATCH 1/2] update py3compat from spyder to try fix Qt5 --- winpython/py3compat.py | 67 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/winpython/py3compat.py b/winpython/py3compat.py index 3cdfa630..ecd8c4f3 100644 --- a/winpython/py3compat.py +++ b/winpython/py3compat.py @@ -5,12 +5,10 @@ # (see spyderlib/__init__.py for details) """ -winpython.py3compat (exact copy of spyderlib.py3compat) -------------------------------------------------------- - -Transitional module providing compatibility functions intended to help +spyderlib.py3compat +------------------- +Transitional module providing compatibility functions intended to help migrating from Python 2 to Python 3. - This module should be fully compatible with: * Python >=v2.6 * Python 3 @@ -21,13 +19,13 @@ import sys import os -PY2 = sys.version_info[0] == 2 -PY3 = sys.version_info[0] == 3 +PY2 = sys.version[0] == '2' +PY3 = sys.version[0] == '3' -# ============================================================================= +#============================================================================== # Data types -# ============================================================================= +#============================================================================== if PY2: # Python 2 TEXT_TYPES = (str, unicode) @@ -39,9 +37,9 @@ NUMERIC_TYPES = tuple(list(INT_TYPES) + [float, complex]) -# ============================================================================= +#============================================================================== # Renamed/Reorganized modules -# ============================================================================= +#============================================================================== if PY2: # Python 2 import __builtin__ as builtins @@ -60,6 +58,8 @@ except ImportError: import pickle from UserDict import DictMixin as MutableMapping + import thread as _thread + import repr as reprlib else: # Python 3 import builtins @@ -72,11 +72,25 @@ import io import pickle from collections import MutableMapping + import _thread + import reprlib -# ============================================================================= +#============================================================================== # Strings -# ============================================================================= +#============================================================================== +if PY2: + # Python 2 + import codecs + def u(obj): + """Make unicode object""" + return codecs.unicode_escape_decode(obj)[0] +else: + # Python 3 + def u(obj): + """Return string as it is""" + return obj + def is_text_string(obj): """Return True if `obj` is a text string, False if it is anything else, like binary data (Python 3) or QString (Python 2, PyQt API #1)""" @@ -87,7 +101,6 @@ def is_text_string(obj): # Python 3 return isinstance(obj, str) - def is_binary_string(obj): """Return True if `obj` is a binary string, False if it is anything else""" if PY2: @@ -97,13 +110,11 @@ def is_binary_string(obj): # Python 3 return isinstance(obj, bytes) - def is_string(obj): """Return True if `obj` is a text or binary Python string object, False if it is anything else, like a QString (Python 2, PyQt API #1)""" return is_text_string(obj) or is_binary_string(obj) - def is_unicode(obj): """Return True if `obj` is unicode""" if PY2: @@ -113,7 +124,6 @@ def is_unicode(obj): # Python 3 return isinstance(obj, str) - def to_text_string(obj, encoding=None): """Convert `obj` to (unicode) text string""" if PY2: @@ -132,7 +142,6 @@ def to_text_string(obj, encoding=None): else: return str(obj, encoding) - def to_binary_string(obj, encoding=None): """Convert `obj` to binary string (bytes in Python 3, str in Python 2)""" if PY2: @@ -146,9 +155,9 @@ def to_binary_string(obj, encoding=None): return bytes(obj, 'utf-8' if encoding is None else encoding) -# ============================================================================= +#============================================================================== # Function attributes -# ============================================================================= +#============================================================================== def get_func_code(func): """Return function code object""" if PY2: @@ -158,7 +167,6 @@ def get_func_code(func): # Python 3 return func.__code__ - def get_func_name(func): """Return function name""" if PY2: @@ -168,7 +176,6 @@ def get_func_name(func): # Python 3 return func.__name__ - def get_func_defaults(func): """Return function default argument values""" if PY2: @@ -179,9 +186,9 @@ def get_func_defaults(func): return func.__defaults__ -# ============================================================================= +#============================================================================== # Special method attributes -# ============================================================================= +#============================================================================== def get_meth_func(obj): """Return method function object""" if PY2: @@ -191,7 +198,6 @@ def get_meth_func(obj): # Python 3 return obj.__func__ - def get_meth_class_inst(obj): """Return method class instance""" if PY2: @@ -201,7 +207,6 @@ def get_meth_class_inst(obj): # Python 3 return obj.__self__ - def get_meth_class(obj): """Return method class""" if PY2: @@ -212,9 +217,9 @@ def get_meth_class(obj): return obj.__self__.__class__ -# ============================================================================= +#============================================================================== # Misc. -# ============================================================================= +#============================================================================== if PY2: # Python 2 input = raw_input @@ -222,19 +227,19 @@ def get_meth_class(obj): cmp = cmp import string str_lower = string.lower + from itertools import izip_longest as zip_longest else: # Python 3 input = input getcwd = os.getcwd - def cmp(a, b): return (a > b) - (a < b) str_lower = str.lower - + from itertools import zip_longest def qbytearray_to_str(qba): """Convert QByteArray object to str in a way compatible with Python 2/3""" - return str(bytes(qba.toHex()).decode()) + return str(bytes(qba.toHex().data()).decode()) if __name__ == '__main__': From c24ae96693f35729e44f4f6ba353fa7cfb92960f Mon Sep 17 00:00:00 2001 From: stonebig Date: Sat, 1 Aug 2015 18:12:40 +0200 Subject: [PATCH 2/2] minor fix --- winpython/py3compat.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/winpython/py3compat.py b/winpython/py3compat.py index ecd8c4f3..a7f95509 100644 --- a/winpython/py3compat.py +++ b/winpython/py3compat.py @@ -7,8 +7,10 @@ """ spyderlib.py3compat ------------------- + Transitional module providing compatibility functions intended to help migrating from Python 2 to Python 3. + This module should be fully compatible with: * Python >=v2.6 * Python 3