commit python-QtPy for openSUSE:Factory
Hello community, here is the log from the commit of package python-QtPy for openSUSE:Factory checked in at 2019-05-24 11:32:25 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-QtPy (Old) and /work/SRC/openSUSE:Factory/.python-QtPy.new.5148 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-QtPy" Fri May 24 11:32:25 2019 rev:9 rq:704981 version:1.7.1 Changes: -------- --- /work/SRC/openSUSE:Factory/python-QtPy/python-QtPy.changes 2019-03-20 13:20:47.989321869 +0100 +++ /work/SRC/openSUSE:Factory/.python-QtPy.new.5148/python-QtPy.changes 2019-05-24 11:32:27.101388191 +0200 @@ -1,0 +2,8 @@ +Thu May 23 10:34:57 UTC 2019 - pgajdos@suse.com + +- version update to 1.7.1 + * Skip testing PyQt4 and PySide in Python 3.5 + * Trivial maintenance tweaks + * Avoid deprecated "from collections import MutableMapping" + +------------------------------------------------------------------- Old: ---- QtPy-1.7.0.tar.gz New: ---- QtPy-1.7.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-QtPy.spec ++++++ --- /var/tmp/diff_new_pack.9XuiNc/_old 2019-05-24 11:32:27.713387956 +0200 +++ /var/tmp/diff_new_pack.9XuiNc/_new 2019-05-24 11:32:27.713387956 +0200 @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-QtPy -Version: 1.7.0 +Version: 1.7.1 Release: 0 Summary: Abstraction layer on top of Qt bindings License: MIT ++++++ QtPy-1.7.0.tar.gz -> QtPy-1.7.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/QtPy-1.7.0/CHANGELOG.md new/QtPy-1.7.1/CHANGELOG.md --- old/QtPy-1.7.0/CHANGELOG.md 2019-03-16 11:43:01.000000000 +0100 +++ new/QtPy-1.7.1/CHANGELOG.md 2019-05-05 09:51:49.000000000 +0200 @@ -1,5 +1,20 @@ # History of changes +## Version 1.7.1 (2019-05-05) + + +### Pull Requests Merged + +* [PR 189](https://github.com/spyder-ide/qtpy/pull/189) - PR: Skip testing PyQt4 and PySide in Python 3.5 +* [PR 188](https://github.com/spyder-ide/qtpy/pull/188) - PR: Trivial maintenance tweaks +* [PR 187](https://github.com/spyder-ide/qtpy/pull/187) - PR: Avoid deprecated "from collections import MutableMapping" + +In this release 3 pull requests were closed. + + +---- + + ## Version 1.7.0 (2019-03-16) ### New features diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/QtPy-1.7.0/PKG-INFO new/QtPy-1.7.1/PKG-INFO --- old/QtPy-1.7.0/PKG-INFO 2019-03-16 11:45:49.000000000 +0100 +++ new/QtPy-1.7.1/PKG-INFO 2019-05-05 09:54:16.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: QtPy -Version: 1.7.0 +Version: 1.7.1 Summary: Provides an abstraction layer on top of the various Qt bindings (PyQt5, PyQt4 and PySide) and additional custom QWidgets. Home-page: https://github.com/spyder-ide/qtpy Author: Colin Duquesnoy, The Spyder Development Team diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/QtPy-1.7.0/QtPy.egg-info/PKG-INFO new/QtPy-1.7.1/QtPy.egg-info/PKG-INFO --- old/QtPy-1.7.0/QtPy.egg-info/PKG-INFO 2019-03-16 11:45:48.000000000 +0100 +++ new/QtPy-1.7.1/QtPy.egg-info/PKG-INFO 2019-05-05 09:54:15.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: QtPy -Version: 1.7.0 +Version: 1.7.1 Summary: Provides an abstraction layer on top of the various Qt bindings (PyQt5, PyQt4 and PySide) and additional custom QWidgets. Home-page: https://github.com/spyder-ide/qtpy Author: Colin Duquesnoy, The Spyder Development Team diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/QtPy-1.7.0/qtpy/_version.py new/QtPy-1.7.1/qtpy/_version.py --- old/QtPy-1.7.0/qtpy/_version.py 2019-03-16 11:44:31.000000000 +0100 +++ new/QtPy-1.7.1/qtpy/_version.py 2019-05-05 09:53:12.000000000 +0200 @@ -1,2 +1,2 @@ -version_info = (1, 7, 0) +version_info = (1, 7, 1) __version__ = '.'.join(map(str, version_info)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/QtPy-1.7.0/qtpy/compat.py new/QtPy-1.7.1/qtpy/compat.py --- old/QtPy-1.7.0/qtpy/compat.py 2017-01-02 21:13:51.000000000 +0100 +++ new/QtPy-1.7.1/qtpy/compat.py 2019-05-05 09:50:01.000000000 +0200 @@ -1,196 +1,196 @@ -# -*- coding: utf-8 -*- -# -# Copyright © 2009- The Spyder Development Team -# Licensed under the terms of the MIT License - -""" -Compatibility functions -""" - -from __future__ import print_function -import sys -import collections - -from . import PYQT4 -from .QtWidgets import QFileDialog -from .py3compat import is_text_string, to_text_string, TEXT_TYPES - - -# ============================================================================= -# QVariant conversion utilities -# ============================================================================= -PYQT_API_1 = False -if PYQT4: - import sip - try: - PYQT_API_1 = sip.getapi('QVariant') == 1 # PyQt API #1 - except AttributeError: - # PyQt <v4.6 - PYQT_API_1 = True - - def to_qvariant(pyobj=None): - """Convert Python object to QVariant - This is a transitional function from PyQt API #1 (QVariant exist) - to PyQt API #2 and Pyside (QVariant does not exist)""" - if PYQT_API_1: - # PyQt API #1 - from PyQt4.QtCore import QVariant - return QVariant(pyobj) - else: - # PyQt API #2 - return pyobj - - def from_qvariant(qobj=None, convfunc=None): - """Convert QVariant object to Python object - This is a transitional function from PyQt API #1 (QVariant exist) - to PyQt API #2 and Pyside (QVariant does not exist)""" - if PYQT_API_1: - # PyQt API #1 - assert isinstance(convfunc, collections.Callable) - if convfunc in TEXT_TYPES or convfunc is to_text_string: - return convfunc(qobj.toString()) - elif convfunc is bool: - return qobj.toBool() - elif convfunc is int: - return qobj.toInt()[0] - elif convfunc is float: - return qobj.toDouble()[0] - else: - return convfunc(qobj) - else: - # PyQt API #2 - return qobj -else: - def to_qvariant(obj=None): # analysis:ignore - """Convert Python object to QVariant - This is a transitional function from PyQt API#1 (QVariant exist) - to PyQt API#2 and Pyside (QVariant does not exist)""" - return obj - - def from_qvariant(qobj=None, pytype=None): # analysis:ignore - """Convert QVariant object to Python object - This is a transitional function from PyQt API #1 (QVariant exist) - to PyQt API #2 and Pyside (QVariant does not exist)""" - return qobj - - -# ============================================================================= -# Wrappers around QFileDialog static methods -# ============================================================================= -def getexistingdirectory(parent=None, caption='', basedir='', - options=QFileDialog.ShowDirsOnly): - """Wrapper around QtGui.QFileDialog.getExistingDirectory static method - Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" - # Calling QFileDialog static method - if sys.platform == "win32": - # On Windows platforms: redirect standard outputs - _temp1, _temp2 = sys.stdout, sys.stderr - sys.stdout, sys.stderr = None, None - try: - result = QFileDialog.getExistingDirectory(parent, caption, basedir, - options) - finally: - if sys.platform == "win32": - # On Windows platforms: restore standard outputs - sys.stdout, sys.stderr = _temp1, _temp2 - if not is_text_string(result): - # PyQt API #1 - result = to_text_string(result) - return result - - -def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='', - filters='', selectedfilter='', options=None): - if options is None: - options = QFileDialog.Options(0) - try: - # PyQt <v4.6 (API #1) - from .QtCore import QString - except ImportError: - # PySide or PyQt >=v4.6 - QString = None # analysis:ignore - tuple_returned = True - try: - # PyQt >=v4.6 - func = getattr(QFileDialog, attr+'AndFilter') - except AttributeError: - # PySide or PyQt <v4.6 - func = getattr(QFileDialog, attr) - if QString is not None: - selectedfilter = QString() - tuple_returned = False - - # Calling QFileDialog static method - if sys.platform == "win32": - # On Windows platforms: redirect standard outputs - _temp1, _temp2 = sys.stdout, sys.stderr - sys.stdout, sys.stderr = None, None - try: - result = func(parent, caption, basedir, - filters, selectedfilter, options) - except TypeError: - # The selectedfilter option (`initialFilter` in Qt) has only been - # introduced in Jan. 2010 for PyQt v4.7, that's why we handle here - # the TypeError exception which will be raised with PyQt v4.6 - # (see Issue 960 for more details) - result = func(parent, caption, basedir, filters, options) - finally: - if sys.platform == "win32": - # On Windows platforms: restore standard outputs - sys.stdout, sys.stderr = _temp1, _temp2 - - # Processing output - if tuple_returned: - # PySide or PyQt >=v4.6 - output, selectedfilter = result - else: - # PyQt <v4.6 (API #1) - output = result - if QString is not None: - # PyQt API #1: conversions needed from QString/QStringList - selectedfilter = to_text_string(selectedfilter) - if isinstance(output, QString): - # Single filename - output = to_text_string(output) - else: - # List of filenames - output = [to_text_string(fname) for fname in output] - - # Always returns the tuple (output, selectedfilter) - return output, selectedfilter - - -def getopenfilename(parent=None, caption='', basedir='', filters='', - selectedfilter='', options=None): - """Wrapper around QtGui.QFileDialog.getOpenFileName static method - Returns a tuple (filename, selectedfilter) -- when dialog box is canceled, - returns a tuple of empty strings - Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" - return _qfiledialog_wrapper('getOpenFileName', parent=parent, - caption=caption, basedir=basedir, - filters=filters, selectedfilter=selectedfilter, - options=options) - - -def getopenfilenames(parent=None, caption='', basedir='', filters='', - selectedfilter='', options=None): - """Wrapper around QtGui.QFileDialog.getOpenFileNames static method - Returns a tuple (filenames, selectedfilter) -- when dialog box is canceled, - returns a tuple (empty list, empty string) - Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" - return _qfiledialog_wrapper('getOpenFileNames', parent=parent, - caption=caption, basedir=basedir, - filters=filters, selectedfilter=selectedfilter, - options=options) - - -def getsavefilename(parent=None, caption='', basedir='', filters='', - selectedfilter='', options=None): - """Wrapper around QtGui.QFileDialog.getSaveFileName static method - Returns a tuple (filename, selectedfilter) -- when dialog box is canceled, - returns a tuple of empty strings - Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" - return _qfiledialog_wrapper('getSaveFileName', parent=parent, - caption=caption, basedir=basedir, - filters=filters, selectedfilter=selectedfilter, - options=options) +# -*- coding: utf-8 -*- +# +# Copyright © 2009- The Spyder Development Team +# Licensed under the terms of the MIT License + +""" +Compatibility functions +""" + +from __future__ import print_function +import sys +import collections + +from . import PYQT4 +from .QtWidgets import QFileDialog +from .py3compat import is_text_string, to_text_string, TEXT_TYPES + + +# ============================================================================= +# QVariant conversion utilities +# ============================================================================= +PYQT_API_1 = False +if PYQT4: + import sip + try: + PYQT_API_1 = sip.getapi('QVariant') == 1 # PyQt API #1 + except AttributeError: + # PyQt <v4.6 + PYQT_API_1 = True + + def to_qvariant(pyobj=None): + """Convert Python object to QVariant + This is a transitional function from PyQt API #1 (QVariant exist) + to PyQt API #2 and Pyside (QVariant does not exist)""" + if PYQT_API_1: + # PyQt API #1 + from PyQt4.QtCore import QVariant + return QVariant(pyobj) + else: + # PyQt API #2 + return pyobj + + def from_qvariant(qobj=None, convfunc=None): + """Convert QVariant object to Python object + This is a transitional function from PyQt API #1 (QVariant exist) + to PyQt API #2 and Pyside (QVariant does not exist)""" + if PYQT_API_1: + # PyQt API #1 + assert isinstance(convfunc, collections.Callable) + if convfunc in TEXT_TYPES or convfunc is to_text_string: + return convfunc(qobj.toString()) + elif convfunc is bool: + return qobj.toBool() + elif convfunc is int: + return qobj.toInt()[0] + elif convfunc is float: + return qobj.toDouble()[0] + else: + return convfunc(qobj) + else: + # PyQt API #2 + return qobj +else: + def to_qvariant(obj=None): # analysis:ignore + """Convert Python object to QVariant + This is a transitional function from PyQt API#1 (QVariant exist) + to PyQt API#2 and Pyside (QVariant does not exist)""" + return obj + + def from_qvariant(qobj=None, pytype=None): # analysis:ignore + """Convert QVariant object to Python object + This is a transitional function from PyQt API #1 (QVariant exist) + to PyQt API #2 and Pyside (QVariant does not exist)""" + return qobj + + +# ============================================================================= +# Wrappers around QFileDialog static methods +# ============================================================================= +def getexistingdirectory(parent=None, caption='', basedir='', + options=QFileDialog.ShowDirsOnly): + """Wrapper around QtGui.QFileDialog.getExistingDirectory static method + Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" + # Calling QFileDialog static method + if sys.platform == "win32": + # On Windows platforms: redirect standard outputs + _temp1, _temp2 = sys.stdout, sys.stderr + sys.stdout, sys.stderr = None, None + try: + result = QFileDialog.getExistingDirectory(parent, caption, basedir, + options) + finally: + if sys.platform == "win32": + # On Windows platforms: restore standard outputs + sys.stdout, sys.stderr = _temp1, _temp2 + if not is_text_string(result): + # PyQt API #1 + result = to_text_string(result) + return result + + +def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='', + filters='', selectedfilter='', options=None): + if options is None: + options = QFileDialog.Options(0) + try: + # PyQt <v4.6 (API #1) + from .QtCore import QString + except ImportError: + # PySide or PyQt >=v4.6 + QString = None # analysis:ignore + tuple_returned = True + try: + # PyQt >=v4.6 + func = getattr(QFileDialog, attr+'AndFilter') + except AttributeError: + # PySide or PyQt <v4.6 + func = getattr(QFileDialog, attr) + if QString is not None: + selectedfilter = QString() + tuple_returned = False + + # Calling QFileDialog static method + if sys.platform == "win32": + # On Windows platforms: redirect standard outputs + _temp1, _temp2 = sys.stdout, sys.stderr + sys.stdout, sys.stderr = None, None + try: + result = func(parent, caption, basedir, + filters, selectedfilter, options) + except TypeError: + # The selectedfilter option (`initialFilter` in Qt) has only been + # introduced in Jan. 2010 for PyQt v4.7, that's why we handle here + # the TypeError exception which will be raised with PyQt v4.6 + # (see Issue 960 for more details) + result = func(parent, caption, basedir, filters, options) + finally: + if sys.platform == "win32": + # On Windows platforms: restore standard outputs + sys.stdout, sys.stderr = _temp1, _temp2 + + # Processing output + if tuple_returned: + # PySide or PyQt >=v4.6 + output, selectedfilter = result + else: + # PyQt <v4.6 (API #1) + output = result + if QString is not None: + # PyQt API #1: conversions needed from QString/QStringList + selectedfilter = to_text_string(selectedfilter) + if isinstance(output, QString): + # Single filename + output = to_text_string(output) + else: + # List of filenames + output = [to_text_string(fname) for fname in output] + + # Always returns the tuple (output, selectedfilter) + return output, selectedfilter + + +def getopenfilename(parent=None, caption='', basedir='', filters='', + selectedfilter='', options=None): + """Wrapper around QtGui.QFileDialog.getOpenFileName static method + Returns a tuple (filename, selectedfilter) -- when dialog box is canceled, + returns a tuple of empty strings + Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" + return _qfiledialog_wrapper('getOpenFileName', parent=parent, + caption=caption, basedir=basedir, + filters=filters, selectedfilter=selectedfilter, + options=options) + + +def getopenfilenames(parent=None, caption='', basedir='', filters='', + selectedfilter='', options=None): + """Wrapper around QtGui.QFileDialog.getOpenFileNames static method + Returns a tuple (filenames, selectedfilter) -- when dialog box is canceled, + returns a tuple (empty list, empty string) + Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" + return _qfiledialog_wrapper('getOpenFileNames', parent=parent, + caption=caption, basedir=basedir, + filters=filters, selectedfilter=selectedfilter, + options=options) + + +def getsavefilename(parent=None, caption='', basedir='', filters='', + selectedfilter='', options=None): + """Wrapper around QtGui.QFileDialog.getSaveFileName static method + Returns a tuple (filename, selectedfilter) -- when dialog box is canceled, + returns a tuple of empty strings + Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0""" + return _qfiledialog_wrapper('getSaveFileName', parent=parent, + caption=caption, basedir=basedir, + filters=filters, selectedfilter=selectedfilter, + options=options) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/QtPy-1.7.0/qtpy/py3compat.py new/QtPy-1.7.1/qtpy/py3compat.py --- old/QtPy-1.7.0/qtpy/py3compat.py 2016-01-14 20:29:48.000000000 +0100 +++ new/QtPy-1.7.1/qtpy/py3compat.py 2019-05-05 09:50:01.000000000 +0200 @@ -1,261 +1,261 @@ -# -*- coding: utf-8 -*- -# -# Copyright © 2012-2013 Pierre Raybaut -# Licensed under the terms of the MIT License -# (see spyderlib/__init__.py for details) - -""" -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 -""" - -from __future__ import print_function - -import sys -import os - -PY2 = sys.version[0] == '2' -PY3 = sys.version[0] == '3' - - -# ============================================================================= -# Data types -# ============================================================================= -if PY2: - # Python 2 - TEXT_TYPES = (str, unicode) - INT_TYPES = (int, long) -else: - # Python 3 - TEXT_TYPES = (str,) - INT_TYPES = (int,) -NUMERIC_TYPES = tuple(list(INT_TYPES) + [float, complex]) - - -# ============================================================================= -# Renamed/Reorganized modules -# ============================================================================= -if PY2: - # Python 2 - import __builtin__ as builtins - import ConfigParser as configparser - try: - import _winreg as winreg - except ImportError: - pass - from sys import maxint as maxsize - try: - import CStringIO as io - except ImportError: - import StringIO as io - try: - import cPickle as pickle - except ImportError: - import pickle - from UserDict import DictMixin as MutableMapping - import thread as _thread - import repr as reprlib -else: - # Python 3 - import builtins - import configparser - try: - import winreg - except ImportError: - pass - from sys import maxsize - 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)""" - if PY2: - # Python 2 - return isinstance(obj, basestring) - else: - # 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: - # Python 2 - return isinstance(obj, str) - else: - # 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: - # Python 2 - return isinstance(obj, unicode) - else: - # Python 3 - return isinstance(obj, str) - - -def to_text_string(obj, encoding=None): - """Convert `obj` to (unicode) text string""" - if PY2: - # Python 2 - if encoding is None: - return unicode(obj) - else: - return unicode(obj, encoding) - else: - # Python 3 - if encoding is None: - return str(obj) - elif isinstance(obj, str): - # In case this function is not used properly, this could happen - return obj - 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: - # Python 2 - if encoding is None: - return str(obj) - else: - return obj.encode(encoding) - else: - # Python 3 - return bytes(obj, 'utf-8' if encoding is None else encoding) - - -# ============================================================================= -# Function attributes -# ============================================================================= -def get_func_code(func): - """Return function code object""" - if PY2: - # Python 2 - return func.func_code - else: - # Python 3 - return func.__code__ - - -def get_func_name(func): - """Return function name""" - if PY2: - # Python 2 - return func.func_name - else: - # Python 3 - return func.__name__ - - -def get_func_defaults(func): - """Return function default argument values""" - if PY2: - # Python 2 - return func.func_defaults - else: - # Python 3 - return func.__defaults__ - - -# ============================================================================= -# Special method attributes -# ============================================================================= -def get_meth_func(obj): - """Return method function object""" - if PY2: - # Python 2 - return obj.im_func - else: - # Python 3 - return obj.__func__ - - -def get_meth_class_inst(obj): - """Return method class instance""" - if PY2: - # Python 2 - return obj.im_self - else: - # Python 3 - return obj.__self__ - - -def get_meth_class(obj): - """Return method class""" - if PY2: - # Python 2 - return obj.im_class - else: - # Python 3 - return obj.__self__.__class__ - - -# ============================================================================= -# Misc. -# ============================================================================= -if PY2: - # Python 2 - input = raw_input - getcwd = os.getcwdu - 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().data()).decode()) - - -if __name__ == '__main__': - pass +# -*- coding: utf-8 -*- +# +# Copyright © 2012-2013 Pierre Raybaut +# Licensed under the terms of the MIT License +# (see spyderlib/__init__.py for details) + +""" +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 +""" + +from __future__ import print_function + +import sys +import os + +PY2 = sys.version_info[0] == 2 +PY3 = sys.version_info[0] == 3 +PY33 = PY3 and sys.version_info[1] >= 3 + + +# ============================================================================= +# Data types +# ============================================================================= +if PY2: + # Python 2 + TEXT_TYPES = (str, unicode) + INT_TYPES = (int, long) +else: + # Python 3 + TEXT_TYPES = (str,) + INT_TYPES = (int,) +NUMERIC_TYPES = tuple(list(INT_TYPES) + [float, complex]) + + +# ============================================================================= +# Renamed/Reorganized modules +# ============================================================================= +if PY2: + # Python 2 + import __builtin__ as builtins + import ConfigParser as configparser + try: + import _winreg as winreg + except ImportError: + pass + from sys import maxint as maxsize + try: + import CStringIO as io + except ImportError: + import StringIO as io + try: + import cPickle as pickle + except ImportError: + import pickle + from UserDict import DictMixin as MutableMapping + import thread as _thread + import repr as reprlib +else: + # Python 3 + import builtins + import configparser + try: + import winreg + except ImportError: + pass + from sys import maxsize + import io + import pickle + if PY33: + from collections.abc import MutableMapping + else: + 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)""" + if PY2: + # Python 2 + return isinstance(obj, basestring) + else: + # 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: + # Python 2 + return isinstance(obj, str) + else: + # 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: + # Python 2 + return isinstance(obj, unicode) + else: + # Python 3 + return isinstance(obj, str) + + +def to_text_string(obj, encoding=None): + """Convert `obj` to (unicode) text string""" + if PY2: + # Python 2 + if encoding is None: + return unicode(obj) + else: + return unicode(obj, encoding) + else: + # Python 3 + if encoding is None: + return str(obj) + elif isinstance(obj, str): + # In case this function is not used properly, this could happen + return obj + 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: + # Python 2 + if encoding is None: + return str(obj) + else: + return obj.encode(encoding) + else: + # Python 3 + return bytes(obj, 'utf-8' if encoding is None else encoding) + + +# ============================================================================= +# Function attributes +# ============================================================================= +def get_func_code(func): + """Return function code object""" + if PY2: + # Python 2 + return func.func_code + else: + # Python 3 + return func.__code__ + + +def get_func_name(func): + """Return function name""" + if PY2: + # Python 2 + return func.func_name + else: + # Python 3 + return func.__name__ + + +def get_func_defaults(func): + """Return function default argument values""" + if PY2: + # Python 2 + return func.func_defaults + else: + # Python 3 + return func.__defaults__ + + +# ============================================================================= +# Special method attributes +# ============================================================================= +def get_meth_func(obj): + """Return method function object""" + if PY2: + # Python 2 + return obj.im_func + else: + # Python 3 + return obj.__func__ + + +def get_meth_class_inst(obj): + """Return method class instance""" + if PY2: + # Python 2 + return obj.im_self + else: + # Python 3 + return obj.__self__ + + +def get_meth_class(obj): + """Return method class""" + if PY2: + # Python 2 + return obj.im_class + else: + # Python 3 + return obj.__self__.__class__ + + +# ============================================================================= +# Misc. +# ============================================================================= +if PY2: + # Python 2 + input = raw_input + getcwd = os.getcwdu + 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().data()).decode())
participants (1)
-
root