From ee8e7117c79f6820cb228e0f0da522ce7d3c1dce Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Sun, 20 May 2018 11:04:45 +0800 Subject: Improve the QByteArray implementation The available constructors for QByteArray are now: bytes, bytearray, and QByteArray, unicode is not accepted anymore. Also the concatenation is now possible between QByteArrays. Even though is not possible to initialize a QByteArray with an unicode, we include the possibility to compare it with one (Compatibility with PyQt). The __repr__ and __str__ are now properly working. There seemed to be a confusion regarding data types between Shiboken, Python2 and Python3 related to bytes, so now the structure is based on the flag SBK_BYTES_NAME, which is define as "bytes" for Python3 and "str" for Python2. Many tests were modified to properly handle string, using the `py3kcompat` module. Task-number: PYSIDE-232 Change-Id: I8b671f367c60a0870c72dcbe5662106b3225037d Reviewed-by: Alexandru Croitor --- .../PySide2/QtCore/typesystem_core_common.xml | 147 ++++++++++++++++----- .../pyside2/PySide2/support/signature/mapping.py | 1 + sources/pyside2/tests/QtCore/bug_938.py | 3 +- sources/pyside2/tests/QtCore/deepcopy_test.py | 3 +- .../qbytearray_concatenation_operator_test.py | 31 ++--- .../tests/QtCore/qbytearray_operator_iadd_test.py | 23 ++-- .../tests/QtCore/qbytearray_operator_test.py | 29 ++-- sources/pyside2/tests/QtCore/qbytearray_test.py | 100 ++++++++------ sources/pyside2/tests/QtCore/qdatastream_test.py | 48 +++---- sources/pyside2/tests/QtCore/qfile_test.py | 2 +- sources/pyside2/tests/QtCore/qfileread_test.py | 5 +- .../QtCore/qmessageauthenticationcode_test.py | 3 +- sources/pyside2/tests/QtCore/qtextstream_test.py | 12 +- sources/pyside2/tests/QtCore/qtimezone_test.py | 3 +- sources/pyside2/tests/QtCore/repr_test.py | 3 +- sources/pyside2/tests/QtCore/unicode_test.py | 4 - sources/pyside2/tests/QtGui/bug_660.py | 2 +- .../tests/QtGui/qtextdocumentwriter_test.py | 3 +- sources/pyside2/tests/QtNetwork/bug_1084.py | 2 +- sources/pyside2/tests/QtNetwork/bug_446.py | 5 +- sources/pyside2/tests/QtNetwork/udpsocket_test.py | 3 +- sources/pyside2/tests/QtOpenGL/qglbuffer_test.py | 2 +- .../QtWebEngineCore/web_engine_custom_scheme.py | 7 +- sources/pyside2/tests/QtXml/qdomdocument_test.py | 10 +- sources/pyside2/tests/QtXmlPatterns/import_test.py | 5 +- .../tests/registry/exists_darwin_5_6_4_ci.py | 2 +- .../tests/registry/exists_darwin_5_9_4_ci.py | 2 +- .../tests/registry/exists_linux_5_6_4_ci.py | 2 +- .../tests/registry/exists_linux_5_9_4_ci.py | 2 +- .../tests/registry/exists_win32_5_6_4_ci.py | 2 +- .../tests/registry/exists_win32_5_9_4_ci.py | 2 +- .../shiboken2/generator/shiboken2/cppgenerator.cpp | 6 +- sources/shiboken2/libshiboken/sbkpython.h | 1 - sources/shiboken2/libshiboken/sbkstring.h | 4 +- 34 files changed, 287 insertions(+), 192 deletions(-) diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 63c3d50ea..501f2253f 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -44,6 +44,7 @@ + @@ -2498,14 +2499,16 @@ %out = %OUTTYPE(); - - %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); - #ifdef IS_PY3K %out = %OUTTYPE(PyBytes_AS_STRING(%in), PyBytes_GET_SIZE(%in)); + #else + %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); #endif + + %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); + @@ -2566,47 +2569,108 @@ - + - Shiboken::AutoDecRef str(PyUnicode_AsASCIIString(%PYARG_1)); - if (!str.isNull()) { - QByteArray b(PyBytes_AS_STRING(str.object()), PyBytes_GET_SIZE (str.object())); - b.prepend(*%CPPSELF); - %PYARG_0 = %CONVERTTOPYTHON[QByteArray](b); - } + QByteArray ba = QByteArray(PyBytes_AS_STRING(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)) + *%CPPSELF; + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); - + - Shiboken::AutoDecRef str(PyUnicode_AsASCIIString(%PYARG_1)); - if (!str.isNull()) { - QByteArray b(PyBytes_AS_STRING(str.object()), PyBytes_GET_SIZE(str.object())); - b.append(*%CPPSELF); - %PYARG_0 = %CONVERTTOPYTHON[QByteArray](b); - } + QByteArray ba = QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)) + *%CPPSELF; + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); - + - QByteArray ba = QByteArray(PyBytes_AS_STRING(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)) + *%CPPSELF; + QByteArray ba = *%CPPSELF + QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)); %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); + + + *%CPPSELF += QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)); + + + + + if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF == ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); + } + + + + + if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF != ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); + } + + + + + if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF > ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); + } + + + + + if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF >= ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); + } + + + + + if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF < ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); + } + + + + + if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF <= ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); + } + + - QByteArray b(PepType(Py_TYPE(%PYSELF))->tp_name); - PyObject *aux = Shiboken::String::fromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); - if (PyUnicode_CheckExact(aux)) { - PyObject *tmp = PyUnicode_AsASCIIString(aux); - Py_DECREF(aux); - aux = tmp; + PyObject *aux = PyBytes_FromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); + if (aux == NULL) { + return NULL; } - b += "('"; - b += QByteArray(PyBytes_AS_STRING(aux), PyBytes_GET_SIZE(aux)); - b += "')"; - %PYARG_0 = Shiboken::String::fromStringAndSize(b.constData(), b.size()); + QByteArray b(PepType(Py_TYPE(%PYSELF))->tp_name); + #ifdef IS_PY3K + %PYARG_0 = PyUnicode_FromFormat("%s(%R)", b.constData(), aux); + #else + aux = PyObject_Repr(aux); + b += "("; + b += QByteArray(PyBytes_AS_STRING(aux), PyBytes_GET_SIZE(aux)); + b += ")"; + %PYARG_0 = Shiboken::String::fromStringAndSize(b.constData(), b.size()); + #endif + Py_DECREF(aux); @@ -2623,14 +2687,21 @@ if (PyBytes_Check(%PYARG_1)) { %0 = new QByteArray(PyBytes_AsString(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)); - } else if (PyUnicode_CheckExact(%PYARG_1)) { - Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); - %0 = new QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); } else if (Shiboken::String::check(%PYARG_1)) { %0 = new QByteArray(Shiboken::String::toCString(%PYARG_1), Shiboken::String::len(%PYARG_1)); } + > + + %0 = new QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)); + + + + + %0 = new QByteArray(PyBytes_AS_STRING(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)); + + @@ -2661,6 +2732,7 @@ + @@ -2786,7 +2858,16 @@ - %PYARG_0 = Shiboken::String::fromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); + PyObject *aux = PyBytes_FromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); + if (aux == NULL) { + return NULL; + } + #ifdef IS_PY3K + %PYARG_0 = PyObject_Repr(aux); + Py_DECREF(aux); + #else + %PYARG_0 = aux; + #endif diff --git a/sources/pyside2/PySide2/support/signature/mapping.py b/sources/pyside2/PySide2/support/signature/mapping.py index b8ef3761c..3e05dbcb2 100644 --- a/sources/pyside2/PySide2/support/signature/mapping.py +++ b/sources/pyside2/PySide2/support/signature/mapping.py @@ -238,6 +238,7 @@ def init_QtCore(): "QDir.SortFlags(Name | IgnoreCase)": Instance( "QDir.SortFlags(QDir.Name | QDir.IgnoreCase)"), "PyBytes": bytes, + "PyByteArray": bytearray, "PyUnicode": Text, "signed long": int, "PySide2.QtCore.int": int, diff --git a/sources/pyside2/tests/QtCore/bug_938.py b/sources/pyside2/tests/QtCore/bug_938.py index b23cbe2f2..98b894735 100644 --- a/sources/pyside2/tests/QtCore/bug_938.py +++ b/sources/pyside2/tests/QtCore/bug_938.py @@ -28,13 +28,14 @@ import unittest from PySide2.QtCore import * +import py3kcompat as py3k class TestBug938 (unittest.TestCase): def testIt(self): b = QBuffer() b.open(QBuffer.WriteOnly) - b.write("\x0023\x005") + b.write(py3k.b("\x0023\x005")) b.close() self.assertEqual(b.buffer().size(), 5) diff --git a/sources/pyside2/tests/QtCore/deepcopy_test.py b/sources/pyside2/tests/QtCore/deepcopy_test.py index ed042ce41..a79ccbe15 100644 --- a/sources/pyside2/tests/QtCore/deepcopy_test.py +++ b/sources/pyside2/tests/QtCore/deepcopy_test.py @@ -31,6 +31,7 @@ from copy import deepcopy from PySide2.QtCore import QByteArray, QDate, QDateTime, QTime, QLine, QLineF from PySide2.QtCore import Qt, QSize, QSizeF, QRect, QRectF, QDir, QPoint, QPointF +import py3kcompat as py3k try: from PySide2.QtCore import QUuid HAVE_Q = True @@ -45,7 +46,7 @@ class DeepCopyHelper: class QByteArrayDeepCopy(DeepCopyHelper, unittest.TestCase): def setUp(self): - self.original = QByteArray('the quick brown fox jumps over the lazy dog') + self.original = QByteArray(py3k.b('the quick brown fox jumps over the lazy dog')) class QDateDeepCopy(DeepCopyHelper, unittest.TestCase): diff --git a/sources/pyside2/tests/QtCore/qbytearray_concatenation_operator_test.py b/sources/pyside2/tests/QtCore/qbytearray_concatenation_operator_test.py index 308143d6d..1728c6823 100644 --- a/sources/pyside2/tests/QtCore/qbytearray_concatenation_operator_test.py +++ b/sources/pyside2/tests/QtCore/qbytearray_concatenation_operator_test.py @@ -34,38 +34,25 @@ import unittest from PySide2.QtCore import QByteArray +import py3kcompat as py3k class QByteArrayConcatenationOperatorTest(unittest.TestCase): '''Test cases for QByteArray concatenation with '+' operator''' def testConcatQByteArrayAndPythonString(self): - #Test concatenation of a QByteArray with a Python string, in this order - qba = QByteArray('foo') - result = qba + '\x00bar' + #Test concatenation of a QByteArray with a Python bytes, in this order + qba = QByteArray(py3k.b('foo')) + result = qba + py3k.b('\x00bar') self.assertEqual(type(result), QByteArray) - self.assertEqual(result, 'foo\x00bar') + self.assertEqual(result, py3k.b('foo\x00bar')) def testConcatPythonStringAndQByteArray(self): - #Test concatenation of a Python string with a QByteArray, in this order + #Test concatenation of a Python bytes with a QByteArray, in this order concat_python_string_add_qbytearray_worked = True - qba = QByteArray('foo') - result = 'bar\x00' + qba + qba = QByteArray(py3k.b('foo')) + result = py3k.b('bar\x00') + qba self.assertEqual(type(result), QByteArray) - self.assertEqual(result, 'bar\x00foo') - - # NOTICE: Does not makes sense concat a unicode string with a QByteArray, because the - # user does not know nothing about the internal representation of the unicode string. - #def testConcatPythonUnicodeAndQByteArray(self): - ##Test concatenation of a Python unicode object with a QByteArray, in this order - #concat_python_unicode_add_qbytearray_worked = True - #qba = QByteArray('foo') - #result = None - #try: - #result = u'ümlaut' + qba - #except: - #concat_python_unicode_add_qbytearray_worked = False - #self.assertTrue(concat_python_unicode_add_qbytearray_worked) - #self.assertEqual(result.__class__.__name__, 'unicode') + self.assertEqual(result, py3k.b('bar\x00foo')) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtCore/qbytearray_operator_iadd_test.py b/sources/pyside2/tests/QtCore/qbytearray_operator_iadd_test.py index dd569ac55..a345db514 100644 --- a/sources/pyside2/tests/QtCore/qbytearray_operator_iadd_test.py +++ b/sources/pyside2/tests/QtCore/qbytearray_operator_iadd_test.py @@ -30,6 +30,7 @@ import unittest from PySide2.QtCore import QByteArray from helper.docmodifier import DocModifier +import py3kcompat as py3k class BaseQByteArrayOperatorIAdd(object): '''Base class for QByteArray += operator tests. @@ -41,31 +42,25 @@ class BaseQByteArrayOperatorIAdd(object): __metaclass__ = DocModifier def testSingleString(self): - '''QByteArray += string of size 1''' - s = '0' + '''QByteArray += bytes of size 1''' + s = py3k.b('0') self.obj += s self.assertEqual(self.obj, self.orig_obj + s) self.assertEqual(self.obj.size(), self.orig_obj.size() + len(s)) def testString(self): - '''QByteArray += string of size > 1''' - s = 'dummy' - self.obj += s + '''QByteArray += bytes of size > 1''' + s = bytearray(py3k.b('dummy')) + self.obj += s # XXx iadd support abytearray self.assertEqual(self.obj, self.orig_obj + s) self.assertEqual(self.obj.size(), self.orig_obj.size() + len(s)) def testQByteArray(self): '''QByteArray += QByteArray''' - s = QByteArray('array') + s = QByteArray(py3k.b('array')) self.obj += s self.assertEqual(self.obj, self.orig_obj + s) - def testChar(self): - '''QByteArray += char (number < 256)''' - s = ord('a') - self.obj += s - self.assertEqual(self.obj, self.orig_obj + s) - self.assertEqual(self.obj.size(), self.orig_obj.size() + 1) class NullQByteArrayOperatorIAdd(unittest.TestCase, BaseQByteArrayOperatorIAdd): '''Test case for operator QByteArray += on null QByteArrays''' @@ -85,8 +80,8 @@ class ValidQByteArrayOperatorIAdd(unittest.TestCase, BaseQByteArrayOperatorIAdd) doc_filter = lambda x: x.startswith('test') def setUp(self): - self.obj = QByteArray('some byte array') - self.orig_obj = QByteArray('some byte array') + self.obj = QByteArray(py3k.b('some byte array')) + self.orig_obj = QByteArray(py3k.b('some byte array')) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtCore/qbytearray_operator_test.py b/sources/pyside2/tests/QtCore/qbytearray_operator_test.py index 09b5f24fb..93140d1e0 100644 --- a/sources/pyside2/tests/QtCore/qbytearray_operator_test.py +++ b/sources/pyside2/tests/QtCore/qbytearray_operator_test.py @@ -47,17 +47,12 @@ class QByteArrayOperatorEqual(unittest.TestCase): def testSimple(self): #QByteArray(some_string) == QByteArray(some_string) - string = 'egg snakes' + string = py3k.b('egg snakes') self.assertEqual(QByteArray(string), QByteArray(string)) def testPyString(self): #QByteArray(string) == string - string = 'my test string' - self.assertEqual(QByteArray(string), string) - - def testQString(self): - #QByteArray(string) == string - string = 'another test string' + string = py3k.b('my test string') self.assertEqual(QByteArray(string), string) class QByteArrayOperatorAt(unittest.TestCase): @@ -66,7 +61,7 @@ class QByteArrayOperatorAt(unittest.TestCase): def testInRange(self): #QByteArray[x] where x is a valid index string = 'abcdefgh' - obj = QByteArray(string) + obj = QByteArray(py3k.b(string)) for i in range(len(string)): self.assertEqual(obj[i], py3k.b(string[i])) @@ -74,7 +69,7 @@ class QByteArrayOperatorAt(unittest.TestCase): def testInRangeReverse(self): #QByteArray[x] where x is a valid index (reverse order) string = 'abcdefgh' - obj = QByteArray(string) + obj = QByteArray(py3k.b(string)) for i in range(len(string)-1, 0, -1): self.assertEqual(obj[i], py3k.b(string[i])) @@ -82,12 +77,12 @@ class QByteArrayOperatorAt(unittest.TestCase): def testOutOfRange(self): #QByteArray[x] where x is out of index - string = '1234567' + string = py3k.b('1234567') obj = QByteArray(string) self.assertRaises(IndexError, lambda :obj[len(string)]) def testNullStrings(self): - ba = QByteArray('\x00') + ba = QByteArray(py3k.b('\x00')) self.assertEqual(ba.at(0), '\x00') self.assertEqual(ba[0], py3k.b('\x00')) @@ -97,9 +92,9 @@ class QByteArrayOperatorLen(unittest.TestCase): def testBasic(self): '''QByteArray __len__''' self.assertEqual(len(QByteArray()), 0) - self.assertEqual(len(QByteArray('')), 0) - self.assertEqual(len(QByteArray(' ')), 1) - self.assertEqual(len(QByteArray('yabadaba')), 8) + self.assertEqual(len(QByteArray(py3k.b(''))), 0) + self.assertEqual(len(QByteArray(py3k.b(' '))), 1) + self.assertEqual(len(QByteArray(py3k.b('yabadaba'))), 8) class QByteArrayOperatorStr(unittest.TestCase): @@ -107,9 +102,9 @@ class QByteArrayOperatorStr(unittest.TestCase): def testBasic(self): '''QByteArray __str__''' - self.assertEqual(QByteArray().__str__(), '') - self.assertEqual(QByteArray('').__str__(), '') - self.assertEqual(QByteArray('aaa').__str__(), 'aaa') + self.assertEqual(QByteArray().__str__(), str(b'')) + self.assertEqual(QByteArray(py3k.b('')).__str__(), str(b'')) + self.assertEqual(QByteArray(py3k.b('aaa')).__str__(), str(b'aaa')) if __name__ == '__main__': diff --git a/sources/pyside2/tests/QtCore/qbytearray_test.py b/sources/pyside2/tests/QtCore/qbytearray_test.py index 672472c42..3f7de66fb 100644 --- a/sources/pyside2/tests/QtCore/qbytearray_test.py +++ b/sources/pyside2/tests/QtCore/qbytearray_test.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +# -*- coding:utf-8 -*- +# !/usr/bin/python ############################################################################# ## @@ -35,24 +36,24 @@ import ctypes import pickle import py3kcompat as py3k -from PySide2.QtCore import QByteArray, QSettings, QObject +from PySide2.QtCore import QByteArray, QSettings, QObject, QDataStream, QIODevice class QByteArrayTestToNumber(unittest.TestCase): def testToNumberInt(self): - obj = QByteArray('37') + obj = QByteArray(py3k.b('37')) self.assertEqual((37, True), obj.toInt()) def testToNumberUShort(self): - obj = QByteArray('37') + obj = QByteArray(py3k.b('37')) self.assertEqual((37, True), obj.toUShort()) def testToNumberFloat(self): - obj = QByteArray('37.109') + obj = QByteArray(py3k.b('37.109')) self.assertEqual((ctypes.c_float(37.109).value, True), obj.toFloat()) def testToNumberDouble(self): - obj = QByteArray('37.109') + obj = QByteArray(py3k.b('37.109')) self.assertEqual((ctypes.c_double(37.109).value, True), obj.toDouble()) @@ -69,9 +70,9 @@ class QByteArrayTestToNumber(unittest.TestCase): def testAppend(self): b = QByteArray() - b.append("A") + b.append(py3k.b("A")) self.assertEqual(b.size(), 1) - b.append("AB") + b.append(py3k.b("AB")) self.assertEqual(b.size(), 3) @@ -80,7 +81,7 @@ class QByteArraySplit(unittest.TestCase): def testPathSeparator(self): #QByteArray.split('/') - obj = QByteArray(unittest.__file__) + obj = QByteArray(py3k.b(unittest.__file__)) self.assertEqual(obj.split('/'), unittest.__file__.split('/')) class QByteArrayData(unittest.TestCase): @@ -88,11 +89,11 @@ class QByteArrayData(unittest.TestCase): '''Test case for QByteArray.data''' def testData(self): - url = QByteArray("http://web.openbossa.org/") - self.assertEqual(url.data(), py3k.b("http://web.openbossa.org/")) + url = QByteArray(py3k.b("http://pyside.org")) + self.assertEqual(url.data(), py3k.b("http://pyside.org")) def testDataWithZeros(self): - s1 = "123\000321" + s1 = py3k.b("123\000321") ba = QByteArray(s1) s2 = ba.data() self.assertEqual(py3k.b(s1), s2) @@ -103,21 +104,21 @@ class QByteArrayOperatorAtSetter(unittest.TestCase): def testSetterString(self): '''QByteArray[x] = pythonstring''' - obj = QByteArray('123456') - obj[1] = '0' - self.assertEqual(obj, QByteArray('103456')) + obj = QByteArray(py3k.b('123456')) + obj[1] = py3k.b('0') + self.assertEqual(obj, QByteArray(py3k.b('103456'))) def testSetterStringLarge(self): '''QByteArray[x] = pythonstring (larget than 1 char)''' - obj = QByteArray('123456') - obj[3] = 'abba' - self.assertEqual(obj, QByteArray('123abba56')) + obj = QByteArray(py3k.b('123456')) + obj[3] = py3k.b('abba') + self.assertEqual(obj, QByteArray(py3k.b('123abba56'))) def testSetterQByteArray(self): '''QByteArray[x] = qbytearray''' - obj = QByteArray('123456') - obj[3] = QByteArray('array') - self.assertEqual(obj, QByteArray('123array56')) + obj = QByteArray(py3k.b('123456')) + obj[3] = QByteArray(py3k.b('array')) + self.assertEqual(obj, QByteArray(py3k.b('123array56'))) class QByteArrayOperatorAtSetterNegativeIndex(unittest.TestCase): @@ -125,9 +126,9 @@ class QByteArrayOperatorAtSetterNegativeIndex(unittest.TestCase): def testSetterNegativeIndex(self): '''QByteArray[x] = string - negative index''' - obj = QByteArray('123456') - obj[-3] = 'array' - self.assertEqual(obj, QByteArray('123array56')) + obj = QByteArray(py3k.b('123456')) + obj[-3] = py3k.b('array') + self.assertEqual(obj, QByteArray(py3k.b('123array56'))) class QByteArrayOperatorAtSetterLargeIndex(unittest.TestCase): @@ -136,16 +137,38 @@ class QByteArrayOperatorAtSetterLargeIndex(unittest.TestCase): def testSetterLargeIndexEmpty(self): '''QByteArray[x] = somestring - Overflow index on empty string''' # should pad with spaces if the index is larger - obj = QByteArray('') - obj[2] = 'a' - self.assertEqual(obj, QByteArray(' a')) + obj = QByteArray(py3k.b('')) + obj[2] = py3k.b('a') + self.assertEqual(obj, QByteArray(py3k.b(' a'))) def testSetterLargeIndexNormal(self): '''QByteArray[x] = somestring - Overflow index on normal string''' # should pad with spaces if the index is larger - obj = QByteArray('mystring') - obj[10] = 'normal' - self.assertEqual(obj, QByteArray('mystring normal')) + obj = QByteArray(py3k.b('mystring')) + obj[10] = py3k.b('normal') + self.assertEqual(obj, QByteArray(py3k.b('mystring normal'))) + +class QByteArrayOnQDataStream(unittest.TestCase): + ''' + Bug PYSIDE-232 + ''' + def testIt(self): + a = QByteArray() + b = QDataStream(a, QIODevice.WriteOnly) + b.writeUInt16(5000) + # The __repr__ not suppose to crash anymore + self.assertNotEqual(repr(b), None) + +class TestBug664(unittest.TestCase): + ''' + QByteArray.data() should return correct data + ''' + def testIt(self): + a = QByteArray(py3k.unicode_('hi 猫').encode('utf-8')) + if py3k.IS_PY3K: + self.assertEqual(repr(a), "PySide2.QtCore.QByteArray(b'hi \\xe7\\x8c\\xab')") + else: + self.assertEqual(repr(a), "PySide2.QtCore.QByteArray('hi \\xe7\\x8c\\xab')") class QByteArrayOnQVariant(unittest.TestCase): def testQByteArrayOnQVariant(self): @@ -157,7 +180,7 @@ class TestBug567(unittest.TestCase): QByteArray should support slices ''' def testIt(self): - ba = QByteArray('1234567890') + ba = QByteArray(py3k.b('1234567890')) self.assertEqual(ba[2:4], '34') self.assertEqual(ba[:4], '1234') self.assertEqual(ba[4:], '567890') @@ -176,21 +199,24 @@ class QByteArrayBug514(unittest.TestCase): class TestPickler(unittest.TestCase): def testIt(self): - ba = QByteArray("321\x00123") + ba = QByteArray(py3k.b("321\x00123")) output = pickle.dumps(str(ba)) ba2 = pickle.loads(output) - self.assertEqual(ba, ba2) + self.assertEqual(str(ba), str(ba2)) class QByteArrayBug720(unittest.TestCase): def testIt(self): - ba = QByteArray(b"32\"1\x00123") - self.assertEqual(str(ba), "32\"1\x00123") - self.assertEqual(repr(ba), "PySide2.QtCore.QByteArray('32\"1\x00123')") + ba = QByteArray(py3k.b("32\"1\x00123")) + self.assertEqual(str(ba), str(py3k.b("32\"1\x00123"))) + if py3k.IS_PY3K: + self.assertEqual(repr(ba), "PySide2.QtCore.QByteArray(b'32\"1\\x00123')") + else: + self.assertEqual(repr(ba), "PySide2.QtCore.QByteArray('32\"1\\x00123')") class QByteArrayImplicitConvert(unittest.TestCase): def testString(self): # No implicit conversions from QByteArray to python string - ba = QByteArray("object name") + ba = QByteArray(py3k.b("object name")) obj = QObject() self.assertRaises(TypeError, obj.setObjectName, ba) diff --git a/sources/pyside2/tests/QtCore/qdatastream_test.py b/sources/pyside2/tests/QtCore/qdatastream_test.py index 3e141fbfe..812c2aab5 100644 --- a/sources/pyside2/tests/QtCore/qdatastream_test.py +++ b/sources/pyside2/tests/QtCore/qdatastream_test.py @@ -119,21 +119,21 @@ class QDataStreamShift(unittest.TestCase): def testQByteArrayValid(self): '''QDataStream <<>> QByteArray - valid''' - self.stream << QByteArray("hello") + self.stream << QByteArray(py3k.b("hello")) res = QByteArray() self.read_stream >> res - self.assertEqual(res, QByteArray("hello")) + self.assertEqual(res, QByteArray(py3k.b("hello"))) def testQByteArrayEmpty(self): '''QDataStream <<>> QByteArray - empty''' - self.stream << QByteArray("") + self.stream << QByteArray(py3k.b("")) res = QByteArray() self.read_stream >> res - self.assertEqual(res, QByteArray("")) + self.assertEqual(res, QByteArray(py3k.b(""))) self.assertTrue(res.isEmpty()) self.assertFalse(res.isNull()) @@ -277,29 +277,29 @@ class QDataStreamShiftBitArray(unittest.TestCase): '''QDataStream with valid QBitArray''' data = [] - data.append((QByteArray('\x00\x00\x00\x00'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x00')), QDataStream.Ok, QBitArray())) - data.append((QByteArray('\x00\x00\x00\x01\x00'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x01\x00')), QDataStream.Ok, create_bitarray('0'))) - data.append((QByteArray('\x00\x00\x00\x01\x01'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x01\x01')), QDataStream.Ok, create_bitarray('1'))) - data.append((QByteArray('\x00\x00\x00\x02\x03'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x02\x03')), QDataStream.Ok, create_bitarray('11'))) - data.append((QByteArray('\x00\x00\x00\x03\x07'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x03\x07')), QDataStream.Ok, create_bitarray('111'))) - data.append((QByteArray('\x00\x00\x00\x04\x0f'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x04\x0f')), QDataStream.Ok, create_bitarray('1111'))) - data.append((QByteArray('\x00\x00\x00\x05\x1f'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x05\x1f')), QDataStream.Ok, create_bitarray('11111'))) - data.append((QByteArray('\x00\x00\x00\x06\x3f'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x06\x3f')), QDataStream.Ok, create_bitarray('111111'))) - data.append((QByteArray('\x00\x00\x00\x07\x7f'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x07\x7f')), QDataStream.Ok, create_bitarray('1111111'))) - data.append((QByteArray('\x00\x00\x00\x07\x7e'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x07\x7e')), QDataStream.Ok, create_bitarray('0111111'))) - data.append((QByteArray('\x00\x00\x00\x07\x00'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x07\x00')), QDataStream.Ok, create_bitarray('0000000'))) - data.append((QByteArray('\x00\x00\x00\x07\x39'), QDataStream.Ok, + data.append((QByteArray(py3k.b('\x00\x00\x00\x07\x39')), QDataStream.Ok, create_bitarray('1001110'))) self._check_bitarray(data) @@ -310,19 +310,19 @@ class QDataStreamShiftBitArray(unittest.TestCase): data.append((QByteArray(), QDataStream.ReadPastEnd, QBitArray())) - data.append((QByteArray('\x00'), QDataStream.ReadPastEnd, + data.append((QByteArray(py3k.b('\x00')), QDataStream.ReadPastEnd, QBitArray())) - data.append((QByteArray('\x00\x00'), QDataStream.ReadPastEnd, + data.append((QByteArray(py3k.b('\x00\x00')), QDataStream.ReadPastEnd, QBitArray())) - data.append((QByteArray('\x00\x00\x00'), QDataStream.ReadPastEnd, + data.append((QByteArray(py3k.b('\x00\x00\x00')), QDataStream.ReadPastEnd, QBitArray())) - data.append((QByteArray('\x00\x00\x00\x01'), QDataStream.ReadPastEnd, + data.append((QByteArray(py3k.b('\x00\x00\x00\x01')), QDataStream.ReadPastEnd, QBitArray())) - data.append((QByteArray('\x00\x00\x00\x02'), QDataStream.ReadPastEnd, + data.append((QByteArray(py3k.b('\x00\x00\x00\x02')), QDataStream.ReadPastEnd, QBitArray())) - data.append((QByteArray('\x00\x00\x00\x03'), QDataStream.ReadPastEnd, + data.append((QByteArray(py3k.b('\x00\x00\x00\x03')), QDataStream.ReadPastEnd, QBitArray())) - data.append((QByteArray('\x00\x00\x00\x04'), QDataStream.ReadPastEnd, + data.append((QByteArray(py3k.b('\x00\x00\x00\x04')), QDataStream.ReadPastEnd, QBitArray())) self._check_bitarray(data) @@ -331,7 +331,7 @@ class QDataStreamShiftBitArray(unittest.TestCase): '''QDataStream reading corrupt data''' data = [] - data.append((QByteArray('\x00\x00\x00\x01\x02'), + data.append((QByteArray(py3k.b('\x00\x00\x00\x01\x02')), QDataStream.ReadCorruptData, QBitArray())) diff --git a/sources/pyside2/tests/QtCore/qfile_test.py b/sources/pyside2/tests/QtCore/qfile_test.py index 3dae1aaf0..40f861e4c 100644 --- a/sources/pyside2/tests/QtCore/qfile_test.py +++ b/sources/pyside2/tests/QtCore/qfile_test.py @@ -80,7 +80,7 @@ class GetCharTest(unittest.TestCase): self.assertTrue(dir.isValid()) saveFile = QSaveFile(dir.path() + "/test.dat") self.assertTrue(saveFile.open(QIODevice.WriteOnly)) - saveFile.write("Test") + saveFile.write(py3k.b("Test")) self.assertTrue(saveFile.commit()) self.assertTrue(os.path.exists(QDir.toNativeSeparators(saveFile.fileName()))) diff --git a/sources/pyside2/tests/QtCore/qfileread_test.py b/sources/pyside2/tests/QtCore/qfileread_test.py index d8c17cebd..19e1ea371 100644 --- a/sources/pyside2/tests/QtCore/qfileread_test.py +++ b/sources/pyside2/tests/QtCore/qfileread_test.py @@ -31,6 +31,7 @@ import unittest import os from PySide2.QtCore import QIODevice, QTemporaryFile +import py3kcompat as py3k class FileChild1(QTemporaryFile): pass @@ -48,11 +49,11 @@ class readDataTest(unittest.TestCase): '''Acquire resources''' self.filename1 = FileChild1() self.assertTrue(self.filename1.open()) - self.filename1.write('Test text for testing') + self.filename1.write(py3k.b('Test text for testing')) self.filename2 = FileChild2() self.assertTrue(self.filename2.open()) - self.filename2.write('Test text for testing') + self.filename2.write(py3k.b('Test text for testing')) def tearDown(self): '''release resources''' diff --git a/sources/pyside2/tests/QtCore/qmessageauthenticationcode_test.py b/sources/pyside2/tests/QtCore/qmessageauthenticationcode_test.py index 392e6f052..867862de5 100644 --- a/sources/pyside2/tests/QtCore/qmessageauthenticationcode_test.py +++ b/sources/pyside2/tests/QtCore/qmessageauthenticationcode_test.py @@ -33,10 +33,11 @@ import unittest from PySide2.QtCore import QCryptographicHash, QMessageAuthenticationCode +import py3kcompat as py3k class TestQMessageAuthenticationCode (unittest.TestCase): def test(self): - code = QMessageAuthenticationCode(QCryptographicHash.Sha1, 'bla') + code = QMessageAuthenticationCode(QCryptographicHash.Sha1, py3k.b('bla')) result = code.result() self.assertTrue(result.size() > 0) print(result.toHex()) diff --git a/sources/pyside2/tests/QtCore/qtextstream_test.py b/sources/pyside2/tests/QtCore/qtextstream_test.py index 5cc961aec..6af7f46ba 100644 --- a/sources/pyside2/tests/QtCore/qtextstream_test.py +++ b/sources/pyside2/tests/QtCore/qtextstream_test.py @@ -102,12 +102,12 @@ class QTextStreamReadLinesFromDevice(unittest.TestCase): data = [] data.append((QByteArray(), [])) - data.append((QByteArray('\n'), [''])) - data.append((QByteArray('\r\n'), [''])) - data.append((QByteArray('ole'), ['ole'])) - data.append((QByteArray('ole\n'), ['ole'])) - data.append((QByteArray('ole\r\n'), ['ole'])) - data.append((QByteArray('ole\r\ndole\r\ndoffen'), ['ole', 'dole', 'doffen'])) + data.append((QByteArray(py3k.b('\n')), [''])) + data.append((QByteArray(py3k.b('\r\n')), [''])) + data.append((QByteArray(py3k.b('ole')), ['ole'])) + data.append((QByteArray(py3k.b('ole\n')), ['ole'])) + data.append((QByteArray(py3k.b('ole\r\n')), ['ole'])) + data.append((QByteArray(py3k.b('ole\r\ndole\r\ndoffen')), ['ole', 'dole', 'doffen'])) self._check_data(data) diff --git a/sources/pyside2/tests/QtCore/qtimezone_test.py b/sources/pyside2/tests/QtCore/qtimezone_test.py index fb1326e53..3d5bd1714 100644 --- a/sources/pyside2/tests/QtCore/qtimezone_test.py +++ b/sources/pyside2/tests/QtCore/qtimezone_test.py @@ -29,10 +29,11 @@ import unittest from PySide2.QtCore import QTimeZone +import py3kcompat as py3k class TestQTimeZone (unittest.TestCase): def testTimeZone(self): - id = 'Europe/Berlin' + id = py3k.b('Europe/Berlin') timeZone = QTimeZone(id) self.assertTrue(timeZone.isValid()) self.assertEqual(timeZone.id(), id) diff --git a/sources/pyside2/tests/QtCore/repr_test.py b/sources/pyside2/tests/QtCore/repr_test.py index 343c991ac..0c20c24ec 100644 --- a/sources/pyside2/tests/QtCore/repr_test.py +++ b/sources/pyside2/tests/QtCore/repr_test.py @@ -31,6 +31,7 @@ import unittest from PySide2.QtCore import QByteArray, QDate, QDateTime, QTime, QLine, QLineF from PySide2.QtCore import Qt, QSize, QSizeF, QRect, QRectF, QPoint, QPointF +import py3kcompat as py3k try: from PySide2.QtCore import QUuid HAVE_Q = True @@ -45,7 +46,7 @@ class ReprCopyHelper: class QByteArrayReprCopy(ReprCopyHelper, unittest.TestCase): def setUp(self): - self.original = QByteArray('the quick brown fox jumps over the lazy dog') + self.original = QByteArray(py3k.b('the quick brown fox jumps over the lazy dog')) class QDateReprCopy(ReprCopyHelper, unittest.TestCase): diff --git a/sources/pyside2/tests/QtCore/unicode_test.py b/sources/pyside2/tests/QtCore/unicode_test.py index f44a00c62..6fa169a71 100644 --- a/sources/pyside2/tests/QtCore/unicode_test.py +++ b/sources/pyside2/tests/QtCore/unicode_test.py @@ -58,10 +58,6 @@ class UnicodeConversion(unittest.TestCase): obj.setObjectName(py3k.unicode_('ümlaut')) self.assertEqual(obj.objectName(), py3k.unicode_('ümlaut')) - def testTranslateUnicode(self): - ba = QByteArray(py3k.unicode_('0123456789')) - self.assertEqual(ba.__str__(), py3k.unicode_('0123456789')) - if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtGui/bug_660.py b/sources/pyside2/tests/QtGui/bug_660.py index a5fc5be91..e19835a3a 100644 --- a/sources/pyside2/tests/QtGui/bug_660.py +++ b/sources/pyside2/tests/QtGui/bug_660.py @@ -42,7 +42,7 @@ class MyItemModel(QStandardItemModel): def mimeData(self,indexes): self.__mimedata = super(MyItemModel,self).mimeData(indexes) - self.__mimedata.setData(py3k.unicode_('application/my-form'), 'hi') + self.__mimedata.setData(py3k.unicode_('application/my-form'), py3k.b('hi')) return self.__mimedata class TestBug660(unittest.TestCase): diff --git a/sources/pyside2/tests/QtGui/qtextdocumentwriter_test.py b/sources/pyside2/tests/QtGui/qtextdocumentwriter_test.py index c5166ca18..b9d87ff2b 100644 --- a/sources/pyside2/tests/QtGui/qtextdocumentwriter_test.py +++ b/sources/pyside2/tests/QtGui/qtextdocumentwriter_test.py @@ -30,6 +30,7 @@ import unittest from PySide2.QtGui import QTextDocumentWriter, QTextDocument from PySide2.QtCore import QBuffer +import py3kcompat as py3k class QTextDocumentWriterTest(unittest.TestCase): @@ -38,7 +39,7 @@ class QTextDocumentWriterTest(unittest.TestCase): doc = QTextDocument(text) b = QBuffer() b.open(QBuffer.ReadWrite) - writer = QTextDocumentWriter(b, "plaintext"); + writer = QTextDocumentWriter(b, py3k.b("plaintext")); writer.write(doc); b.close() self.assertEqual(b.buffer(), text) diff --git a/sources/pyside2/tests/QtNetwork/bug_1084.py b/sources/pyside2/tests/QtNetwork/bug_1084.py index b9dfd009a..e9d31eae9 100644 --- a/sources/pyside2/tests/QtNetwork/bug_1084.py +++ b/sources/pyside2/tests/QtNetwork/bug_1084.py @@ -38,7 +38,7 @@ class QTcpSocketTestCase(unittest.TestCase): self.sock.connectToHost('127.0.0.1', 25) def testIt(self): - self.sock.write(py3k.unicode_('quit')) + self.sock.write(py3k.b('quit')) if __name__ == "__main__": unittest.main() diff --git a/sources/pyside2/tests/QtNetwork/bug_446.py b/sources/pyside2/tests/QtNetwork/bug_446.py index da4e27d42..4fcda65b7 100644 --- a/sources/pyside2/tests/QtNetwork/bug_446.py +++ b/sources/pyside2/tests/QtNetwork/bug_446.py @@ -32,10 +32,11 @@ from PySide2.QtCore import * from PySide2.QtNetwork import * from helper import UsesQCoreApplication +import py3kcompat as py3k class HttpSignalsCase(UsesQCoreApplication): '''Test case for launching QHttp signals''' - DATA = "PySide rocks" + DATA = py3k.b("PySide rocks") def onError(self): self.assertTrue(False) @@ -48,7 +49,7 @@ class HttpSignalsCase(UsesQCoreApplication): def onReadReady(self): data = self.client.read(100) - self.assertEqual(data.size(), len(HttpSignalsCase.DATA)) + self.assertEqual(len(data), len(HttpSignalsCase.DATA)) self.assertEqual(data, HttpSignalsCase.DATA) self.done() diff --git a/sources/pyside2/tests/QtNetwork/udpsocket_test.py b/sources/pyside2/tests/QtNetwork/udpsocket_test.py index b20ef134a..ea4f5c8f6 100644 --- a/sources/pyside2/tests/QtNetwork/udpsocket_test.py +++ b/sources/pyside2/tests/QtNetwork/udpsocket_test.py @@ -32,6 +32,7 @@ import unittest from PySide2.QtCore import QUrl, QObject, SIGNAL, QCoreApplication, QTimer from PySide2.QtNetwork import QUdpSocket, QHostAddress +import py3kcompat as py3k class HttpSignalsCase(unittest.TestCase): '''Test case for bug #124 - readDatagram signature @@ -57,7 +58,7 @@ class HttpSignalsCase(unittest.TestCase): def sendPackage(self): addr = QHostAddress(QHostAddress.LocalHost) - self.socket.writeDatagram('datagram', addr, 45454) + self.socket.writeDatagram(py3k.b('datagram'), addr, 45454) def callback(self): while self.server.hasPendingDatagrams(): diff --git a/sources/pyside2/tests/QtOpenGL/qglbuffer_test.py b/sources/pyside2/tests/QtOpenGL/qglbuffer_test.py index 1ec033471..07e028eff 100644 --- a/sources/pyside2/tests/QtOpenGL/qglbuffer_test.py +++ b/sources/pyside2/tests/QtOpenGL/qglbuffer_test.py @@ -49,7 +49,7 @@ class QGLBufferTest(UsesQApplication): self.assertTrue(b.bufferId() != 0) self.assertTrue(b.bind()) - data = QByteArray("12345") + data = QByteArray(py3k.b("12345")) b.allocate(data) self.assertEqual(b.size(), data.size()) diff --git a/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py b/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py index 2a110742a..8da2b45f8 100644 --- a/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py +++ b/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py @@ -34,6 +34,7 @@ from PySide2.QtCore import QBuffer, QTimer from PySide2.QtWidgets import QApplication from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile from PySide2.QtWebEngineCore import QWebEngineUrlSchemeHandler +import py3kcompat as py3k class TestSchemeHandler(QWebEngineUrlSchemeHandler): def requestStarted(self, request): @@ -42,16 +43,16 @@ class TestSchemeHandler(QWebEngineUrlSchemeHandler): return self.buffer = QBuffer() - self.buffer.setData("Really nice goodbye text.") + self.buffer.setData(py3k.b("Really nice goodbye text.")) self.buffer.aboutToClose.connect(self.buffer.deleteLater) - request.reply("text/plain;charset=utf-8", self.buffer) + request.reply(py3k.b("text/plain;charset=utf-8"), self.buffer) class MainTest(unittest.TestCase): def test_SchemeHandlerRedirect(self): app = QApplication([]) handler = TestSchemeHandler() profile = QWebEngineProfile.defaultProfile() - profile.installUrlSchemeHandler("testpy", handler) + profile.installUrlSchemeHandler(py3k.b("testpy"), handler) view = QWebEngineView() view.loadFinished.connect(app.quit) QTimer.singleShot(5000, app.quit) diff --git a/sources/pyside2/tests/QtXml/qdomdocument_test.py b/sources/pyside2/tests/QtXml/qdomdocument_test.py index 2af37b01a..63f9fd430 100644 --- a/sources/pyside2/tests/QtXml/qdomdocument_test.py +++ b/sources/pyside2/tests/QtXml/qdomdocument_test.py @@ -29,26 +29,28 @@ ############################################################################# import unittest + from PySide2.QtCore import QByteArray from PySide2.QtXml import QDomDocument, QDomElement +import py3kcompat as py3k class QDomDocumentTest(unittest.TestCase): def setUp(self): self.dom = QDomDocument() - self.goodXmlData = QByteArray(''' + self.goodXmlData = QByteArray(py3k.b(''' - ''') + ''')) - self.badXmlData = QByteArray(''' + self.badXmlData = QByteArray(py3k.b(''' - ''') + ''')) def tearDown(self): del self.dom diff --git a/sources/pyside2/tests/QtXmlPatterns/import_test.py b/sources/pyside2/tests/QtXmlPatterns/import_test.py index 26f740368..bbbb7da07 100644 --- a/sources/pyside2/tests/QtXmlPatterns/import_test.py +++ b/sources/pyside2/tests/QtXmlPatterns/import_test.py @@ -32,18 +32,19 @@ import unittest from PySide2.QtCore import * from PySide2.QtXmlPatterns import QXmlSchema from helper import UsesQCoreApplication +import py3kcompat as py3k class QXmlPatternsTest(UsesQCoreApplication): def testSchema(self): - data = QByteArray(''' + data = QByteArray(py3k.b(''' - ''') + ''')) buf = QBuffer(data) buf.open(QIODevice.ReadOnly) diff --git a/sources/pyside2/tests/registry/exists_darwin_5_6_4_ci.py b/sources/pyside2/tests/registry/exists_darwin_5_6_4_ci.py index d49f08de1..a43dc38af 100644 --- a/sources/pyside2/tests/registry/exists_darwin_5_6_4_ci.py +++ b/sources/pyside2/tests/registry/exists_darwin_5_6_4_ci.py @@ -302,7 +302,7 @@ if "PySide2.QtCore" in sys.modules: "QBuffer.writeData": ('str', 'int'), # class PySide2.QtCore.QByteArray: - "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'PySide2.support.signature.typing.Union[str, int]')], + "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'PySide2.support.signature.typing.Union[str, int]'), ('bytes',), ('bytearray',)], "QByteArray.__copy__": (), "QByteArray.__reduce__": (), "QByteArray.append": [('PySide2.QtCore.QByteArray',), ('PySide2.support.signature.typing.Union[str, int]',)], diff --git a/sources/pyside2/tests/registry/exists_darwin_5_9_4_ci.py b/sources/pyside2/tests/registry/exists_darwin_5_9_4_ci.py index 63a74ff07..45bee7944 100644 --- a/sources/pyside2/tests/registry/exists_darwin_5_9_4_ci.py +++ b/sources/pyside2/tests/registry/exists_darwin_5_9_4_ci.py @@ -308,7 +308,7 @@ if "PySide2.QtCore" in sys.modules: "QBuffer.writeData": ('str', 'int'), # class PySide2.QtCore.QByteArray: - "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'Union[str, int]')], + "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'Union[str, int]'), ('bytes',), ('bytearray',)], "QByteArray.__copy__": (), "QByteArray.__reduce__": (), "QByteArray.append": [('PySide2.QtCore.QByteArray',), ('Union[str, int]',), ('int', 'Union[str, int]')], diff --git a/sources/pyside2/tests/registry/exists_linux_5_6_4_ci.py b/sources/pyside2/tests/registry/exists_linux_5_6_4_ci.py index 7c1188b21..2addd0611 100644 --- a/sources/pyside2/tests/registry/exists_linux_5_6_4_ci.py +++ b/sources/pyside2/tests/registry/exists_linux_5_6_4_ci.py @@ -302,7 +302,7 @@ if "PySide2.QtCore" in sys.modules: "QBuffer.writeData": ('str', 'int'), # class PySide2.QtCore.QByteArray: - "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'PySide2.support.signature.typing.Union[str, int]')], + "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'PySide2.support.signature.typing.Union[str, int]'), ('bytes',), ('bytearray',)], "QByteArray.__copy__": (), "QByteArray.__reduce__": (), "QByteArray.append": [('PySide2.QtCore.QByteArray',), ('PySide2.support.signature.typing.Union[str, int]',)], diff --git a/sources/pyside2/tests/registry/exists_linux_5_9_4_ci.py b/sources/pyside2/tests/registry/exists_linux_5_9_4_ci.py index c552e21f0..636c88a7e 100644 --- a/sources/pyside2/tests/registry/exists_linux_5_9_4_ci.py +++ b/sources/pyside2/tests/registry/exists_linux_5_9_4_ci.py @@ -308,7 +308,7 @@ if "PySide2.QtCore" in sys.modules: "QBuffer.writeData": ('str', 'int'), # class PySide2.QtCore.QByteArray: - "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'Union[str, int]')], + "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'Union[str, int]'), ('bytes',), ('bytearray',)], "QByteArray.__copy__": (), "QByteArray.__reduce__": (), "QByteArray.append": [('PySide2.QtCore.QByteArray',), ('Union[str, int]',), ('int', 'Union[str, int]')], diff --git a/sources/pyside2/tests/registry/exists_win32_5_6_4_ci.py b/sources/pyside2/tests/registry/exists_win32_5_6_4_ci.py index dbf8e59c4..3b4c7441b 100644 --- a/sources/pyside2/tests/registry/exists_win32_5_6_4_ci.py +++ b/sources/pyside2/tests/registry/exists_win32_5_6_4_ci.py @@ -304,7 +304,7 @@ if "PySide2.QtCore" in sys.modules: "QBuffer.writeData": ('str', 'int'), # class PySide2.QtCore.QByteArray: - "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'PySide2.support.signature.typing.Union[str, int]')], + "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'PySide2.support.signature.typing.Union[str, int]'), ('bytes',), ('bytearray',)], "QByteArray.__copy__": (), "QByteArray.__reduce__": (), "QByteArray.append": [('PySide2.QtCore.QByteArray',), ('PySide2.support.signature.typing.Union[str, int]',)], diff --git a/sources/pyside2/tests/registry/exists_win32_5_9_4_ci.py b/sources/pyside2/tests/registry/exists_win32_5_9_4_ci.py index 01e572e21..adf853850 100644 --- a/sources/pyside2/tests/registry/exists_win32_5_9_4_ci.py +++ b/sources/pyside2/tests/registry/exists_win32_5_9_4_ci.py @@ -310,7 +310,7 @@ if "PySide2.QtCore" in sys.modules: "QBuffer.writeData": ('str', 'int'), # class PySide2.QtCore.QByteArray: - "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'Union[str, int]')], + "QByteArray.__init__": [(), ('PySide2.QtCore.QByteArray',), ('int', 'Union[str, int]'), ('bytes',), ('bytearray',)], "QByteArray.__copy__": (), "QByteArray.__reduce__": (), "QByteArray.append": [('PySide2.QtCore.QByteArray',), ('Union[str, int]',), ('int', 'Union[str, int]')], diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index bd654f17c..badb6a4cd 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1988,7 +1988,7 @@ void CppGenerator::writeErrorSection(QTextStream& s, OverloadData& overloadData) QString strArg; AbstractMetaType* argType = arg->type(); if (isCString(argType)) { - strArg = QLatin1String("\" SBK_STR_NAME \""); + strArg = QLatin1String("\" SBK_BYTES_NAME \""); } else if (argType->isPrimitive()) { const PrimitiveTypeEntry* ptp = reinterpret_cast(argType->typeEntry()); while (ptp->referencedTypeEntry()) @@ -2025,7 +2025,9 @@ void CppGenerator::writeErrorSection(QTextStream& s, OverloadData& overloadData) else if (strArg == QLatin1String("PyString")) strArg = QLatin1String("str"); else if (strArg == QLatin1String("PyBytes")) - strArg = QLatin1String("\" SBK_STR_NAME \""); + strArg = QLatin1String("\" SBK_BYTES_NAME \""); + else if (strArg == QLatin1String("PyByteArray")) + strArg = QLatin1String("bytearray"); else if (strArg == QLatin1String("PySequence")) strArg = QLatin1String("list"); else if (strArg == QLatin1String("PyTuple")) diff --git a/sources/shiboken2/libshiboken/sbkpython.h b/sources/shiboken2/libshiboken/sbkpython.h index 5fe364a29..a26c318d1 100644 --- a/sources/shiboken2/libshiboken/sbkpython.h +++ b/sources/shiboken2/libshiboken/sbkpython.h @@ -76,7 +76,6 @@ #define SbkNumber_Check(X) \ (PyNumber_Check(X) && (!PyInstance_Check(X) || PyObject_HasAttrString(X, "__trunc__"))) #define SBK_NB_BOOL(x) (x).nb_nonzero - #define SBK_STR_NAME "str" #define SBK_PyMethod_New(X, Y) PyMethod_New(X, Y, reinterpret_cast(Py_TYPE(Y))) #define Py_hash_t long diff --git a/sources/shiboken2/libshiboken/sbkstring.h b/sources/shiboken2/libshiboken/sbkstring.h index d437f1c77..a6b5fbeed 100644 --- a/sources/shiboken2/libshiboken/sbkstring.h +++ b/sources/shiboken2/libshiboken/sbkstring.h @@ -44,9 +44,9 @@ #include "shibokenmacros.h" #if PY_MAJOR_VERSION >= 3 - #define SBK_STR_NAME "unicode" + #define SBK_BYTES_NAME "bytes" #else - #define SBK_STR_NAME "str" + #define SBK_BYTES_NAME "str" #endif namespace Shiboken -- cgit v1.2.3