[Pyshapelib-commits] r2894 - trunk/thuban/libraries/pyshapelib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu May 27 22:52:50 CEST 2010
Author: bramz
Date: 2010-05-27 22:52:47 +0200 (Thu, 27 May 2010)
New Revision: 2894
Modified:
trunk/thuban/libraries/pyshapelib/ChangeLog
trunk/thuban/libraries/pyshapelib/setup.py
trunk/thuban/libraries/pyshapelib/shapelibmodule.c
Log:
hapelibmodule.c: implementing __reduce__ for SHPObject, so that it can be pickled/unpickled properly, and be copy.deepcopy-ed.
Modified: trunk/thuban/libraries/pyshapelib/ChangeLog
===================================================================
--- trunk/thuban/libraries/pyshapelib/ChangeLog 2009-12-16 19:33:56 UTC (rev 2893)
+++ trunk/thuban/libraries/pyshapelib/ChangeLog 2010-05-27 20:52:47 UTC (rev 2894)
@@ -1,3 +1,8 @@
+2010-05-27 Bram de Greve <bram.degreve at bramz.net>
+
+ * shapelibmodule.c: implementing __reduce__ for SHPObject, so that it
+ can be pickled/unpickled properly, and be copy.deepcopy-ed.
+
2009-09-26 Bram de Greve <bram.degreve at bramz.net>
reintegrating WIP-pyshapelib-Unicode branch (r2888) in trunk
Modified: trunk/thuban/libraries/pyshapelib/setup.py
===================================================================
--- trunk/thuban/libraries/pyshapelib/setup.py 2009-12-16 19:33:56 UTC (rev 2893)
+++ trunk/thuban/libraries/pyshapelib/setup.py 2010-05-27 20:52:47 UTC (rev 2894)
@@ -109,7 +109,7 @@
setup(name = "pyshapelib",
- version = "0.4",
+ version = "0.4.1",
description = "Python bindings for shapelib",
author = "Bernhard Herzog, Bram de Greve",
author_email = "bh at intevation.de, bram.degreve at bramz.net",
Modified: trunk/thuban/libraries/pyshapelib/shapelibmodule.c
===================================================================
--- trunk/thuban/libraries/pyshapelib/shapelibmodule.c 2009-12-16 19:33:56 UTC (rev 2893)
+++ trunk/thuban/libraries/pyshapelib/shapelibmodule.c 2010-05-27 20:52:47 UTC (rev 2894)
@@ -135,7 +135,6 @@
/* parts and part_types have to have the same lengths */
if (part_type_list == Py_None)
{
- Py_DECREF(part_type_list);
part_type_list = NULL;
}
if (part_type_list)
@@ -468,6 +467,32 @@
+static PyObject* getstate(SHPObjectObject* self)
+{
+ /* shpobject_vertices doesn't really return a good parts list,
+ * as the outer layer of the onion is stripped in case of point shapes (when nParts == 0).
+ * put that layer back!
+ */
+ PyObject* parts = NULL;
+ parts = shpobject_vertices(self);
+ if (parts && self->shpObject->nParts == 0)
+ {
+ parts = Py_BuildValue("[N]", parts);
+ }
+ if (!parts)
+ {
+ return NULL;
+ }
+
+ return Py_BuildValue("iiNN",
+ self->shpObject->nSHPType,
+ self->shpObject->nShapeId,
+ parts,
+ shpobject_part_types(self));
+}
+
+
+
/* return a string that can be feeded to eval() to reconstruct the object,
* assuming a proper context
*/
@@ -480,11 +505,7 @@
format = PyString_FromString("shapelib.SHPObject(%i, %i, %s, %s)");
if (!format) return NULL;
- args = Py_BuildValue("iiNN",
- self->shpObject->nSHPType,
- self->shpObject->nShapeId,
- shpobject_vertices(self),
- shpobject_part_types(self));
+ args = getstate(self);
if (!args)
{
Py_DECREF(format);
@@ -499,6 +520,15 @@
+static PyObject* shpobject_reduce(SHPObjectObject* self)
+{
+ return Py_BuildValue("ON",
+ self->ob_type,
+ getstate(self));
+}
+
+
+
static struct PyMethodDef shpobject_methods[] =
{
{"extents", (PyCFunction)shpobject_extents, METH_NOARGS,
@@ -512,6 +542,8 @@
"part_types() -> tuple\n\n"
"returns a tuple of integers, each integer indicating the type of the "
"corresponding part in vertices()"},
+ {"__reduce__", (PyCFunction)shpobject_reduce, METH_NOARGS,
+ "__reduce__() -> (cls, state)"},
{NULL}
};
More information about the Pyshapelib-commits
mailing list