diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-02-04 18:24:07 -0200 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:53:54 -0300 |
commit | 44998fd471927efb8c7a55e5bd7b81bad9f6e876 (patch) | |
tree | ef930c2935faab26d27c5ded94b1876a66880807 | |
parent | 59c882566be0d58c256f715ce675f10f3181ccc3 (diff) |
Fix 666 - "QByteArray does not support slices"
Reviewer: Renato Araújo <renato.filho@openbossa.org>
Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r-- | PySide/QtCore/typesystem_core.xml | 11 | ||||
-rw-r--r-- | tests/QtCore/qbytearray_test.py | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml index 8e292cf18..0cc5b2f4c 100644 --- a/PySide/QtCore/typesystem_core.xml +++ b/PySide/QtCore/typesystem_core.xml @@ -1811,6 +1811,17 @@ return !result ? -1 : 0; </inject-code> </add-function> + <add-function signature="__getslice__"> + <inject-code class="target" position="beginning"> + Py_ssize_t max = %CPPSELF.count(); + _i1 = qBound(Py_ssize_t(0), _i1, max); + _i2 = qBound(Py_ssize_t(0), _i2, max); + + if (_i1 >= _i2) + return %CONVERTTOPYTHON[QByteArray](QByteArray()); + return %CONVERTTOPYTHON[QByteArray](%CPPSELF.mid(_i1, _i2 - _i1)); + </inject-code> + </add-function> </value-type> <value-type name="QTextBoundaryFinder"> <enum-type name="BoundaryReason" flags="QTextBoundaryFinder::BoundaryReasons"/> diff --git a/tests/QtCore/qbytearray_test.py b/tests/QtCore/qbytearray_test.py index 396545f4e..fa838c19f 100644 --- a/tests/QtCore/qbytearray_test.py +++ b/tests/QtCore/qbytearray_test.py @@ -105,6 +105,15 @@ class QByteArrayOnQVariant(unittest.TestCase): a = QSettings().value("some_prop", QByteArray()) self.assertEqual(type(a), QByteArray) +class TestBug666(unittest.TestCase): + '''QByteArray does not support slices''' + def testIt(self): + ba = QByteArray('1234567890') + self.assertEqual(ba[2:4], '34') + self.assertEqual(ba[:4], '1234') + self.assertEqual(ba[4:], '567890') + self.assertEqual(len(ba[4:1]), 0) + class QByteArrayBug514(unittest.TestCase): def testIt(self): data = "foobar" |