summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-02-04 18:24:07 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:53:54 -0300
commit44998fd471927efb8c7a55e5bd7b81bad9f6e876 (patch)
treeef930c2935faab26d27c5ded94b1876a66880807
parent59c882566be0d58c256f715ce675f10f3181ccc3 (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.xml11
-rw-r--r--tests/QtCore/qbytearray_test.py9
2 files changed, 20 insertions, 0 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 8e292cf1..0cc5b2f4 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 396545f4..fa838c19 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"