summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-01-13 17:51:14 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:51:46 -0300
commitb57192c596230ef8fb6a9cb1fe51d3a72e719e4f (patch)
treebea1eb3f14e3b76101529cffc48683de9b352de9
parentd9940e55a41b83d30ce41e8002f614bfe16d54bf (diff)
Fix bug#584 - "python pickle module can't treat QByteArray object of PySide"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Lauro Moura <lauro.neto@openbossa.org>
-rw-r--r--PySide/QtCore/typesystem_core.xml36
-rw-r--r--PySide/QtGui/typesystem_gui_common.xml6
-rw-r--r--PySide/typesystem_templates.xml5
-rw-r--r--tests/QtCore/qbytearray_test.py11
4 files changed, 33 insertions, 25 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 031244bc..24ce91f7 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -433,7 +433,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x1(), %CPPSELF.y1(), %CPPSELF.x2(), %CPPSELF.y2()" />
</insert-template>
</inject-code>
@@ -451,7 +451,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dddd)" />
+ <replace from="%REDUCE_FORMAT" to="dddd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x1(), %CPPSELF.y1(), %CPPSELF.x2(), %CPPSELF.y2()" />
</insert-template>
</inject-code>
@@ -504,7 +504,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iii)" />
+ <replace from="%REDUCE_FORMAT" to="iii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()" />
</insert-template>
</inject-code>
@@ -562,7 +562,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiiiiiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiiiiiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.date().year(), %CPPSELF.date().month(), %CPPSELF.date().day(), %CPPSELF.time().hour(), %CPPSELF.time().minute(), %CPPSELF.time().second(), %CPPSELF.time().msec(), (int)%CPPSELF.timeSpec()" />
</insert-template>
</inject-code>
@@ -574,7 +574,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.path())" />
</insert-template>
</inject-code>
@@ -586,7 +586,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(ii)" />
+ <replace from="%REDUCE_FORMAT" to="ii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" />
</insert-template>
</inject-code>
@@ -605,7 +605,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dd)" />
+ <replace from="%REDUCE_FORMAT" to="dd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" />
</insert-template>
</inject-code>
@@ -617,7 +617,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -682,7 +682,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dddd)" />
+ <replace from="%REDUCE_FORMAT" to="dddd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -736,7 +736,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(ii)" />
+ <replace from="%REDUCE_FORMAT" to="ii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -755,7 +755,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dd)" />
+ <replace from="%REDUCE_FORMAT" to="dd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -768,7 +768,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()" />
</insert-template>
</inject-code>
@@ -788,7 +788,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.toString())" />
</insert-template>
</inject-code>
@@ -1217,7 +1217,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.toString())" />
</insert-template>
</inject-code>
@@ -1232,7 +1232,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(sii)" />
+ <replace from="%REDUCE_FORMAT" to="sii" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.pattern()), (int)%CPPSELF.caseSensitivity(), (int)%CPPSELF.patternSyntax()" />
</insert-template>
</inject-code>
@@ -1281,7 +1281,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.filePath())" />
</insert-template>
</inject-code>
@@ -1294,8 +1294,8 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
- <replace from="%REDUCE_ARGS" to="%CPPSELF.constData()" />
+ <replace from="%REDUCE_FORMAT" to="N" />
+ <replace from="%REDUCE_ARGS" to="PyString_FromStringAndSize(%CPPSELF.constData(), %CPPSELF.size())" />
</insert-template>
</inject-code>
</add-function>
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml
index e6dabc40..50247c3d 100644
--- a/PySide/QtGui/typesystem_gui_common.xml
+++ b/PySide/QtGui/typesystem_gui_common.xml
@@ -499,14 +499,14 @@
</extra-includes>
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
- PyObject *points = PyList_New(%CPPSELF.count());
- for (int i = 0; i &lt; %CPPSELF.count(); ++i){
+ PyObject* points = PyList_New(%CPPSELF.count());
+ for (int i = 0, max = %CPPSELF.count(); i &lt; max; ++i){
int x, y;
%CPPSELF.point(i, &amp;x, &amp;y);
PyList_SET_ITEM(points, i, %CONVERTTOPYTHON[QPoint](QPoint(x, y)));
}
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(N)" />
+ <replace from="%REDUCE_FORMAT" to="N" />
<replace from="%REDUCE_ARGS" to="points" />
</insert-template>
</inject-code>
diff --git a/PySide/typesystem_templates.xml b/PySide/typesystem_templates.xml
index 4604fda9..dd07459a 100644
--- a/PySide/typesystem_templates.xml
+++ b/PySide/typesystem_templates.xml
@@ -188,10 +188,7 @@
</template>
<!-- templates for __reduce__ -->
<template name="reduce_code">
- PyObject *type = PyObject_Type(%PYSELF);
- PyObject *args = NULL;
- args = Py_BuildValue("%REDUCE_FORMAT", %REDUCE_ARGS);
- %PYARG_0 = Py_BuildValue("(NN)", type, args);
+ %PYARG_0 = Py_BuildValue("(N(%REDUCE_FORMAT))", PyObject_Type(%PYSELF), %REDUCE_ARGS);
</template>
<template name="reduce_code_matrix">
QList&lt; %MATRIX_TYPE &gt; cppArgs;
diff --git a/tests/QtCore/qbytearray_test.py b/tests/QtCore/qbytearray_test.py
index 34dc42f5..f031332d 100644
--- a/tests/QtCore/qbytearray_test.py
+++ b/tests/QtCore/qbytearray_test.py
@@ -4,6 +4,8 @@
import unittest
import ctypes
import sys
+import pickle
+import cStringIO
from PySide.QtCore import *
@@ -109,5 +111,14 @@ class QByteArrayBug514(unittest.TestCase):
self.assertEqual(type(a), QByteArray)
self.assertEqual(a.data(), data)
+class TestPickler(unittest.TestCase):
+ def testIt(self):
+ ba = QByteArray("321\x00123")
+ output = cStringIO.StringIO()
+ pickle.dump(ba, output)
+ ba2 = pickle.loads(output.getvalue())
+ self.assertEqual(ba, ba2)
+
+
if __name__ == '__main__':
unittest.main()