From 5aa7fb85b6fb1e13651b7f794a864f6d1fc0715b Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 22 Jul 2016 16:10:15 +0200 Subject: [PATCH 1/2] Derive directly rather than using `_injector` - fixes pickling but I'm not entirely sure is a way to go. --- mapnik/__init__.py | 8 ++++---- mapnik/printing.py | 2 +- src/mapnik_color.cpp | 2 +- src/mapnik_envelope.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mapnik/__init__.py b/mapnik/__init__.py index 250970ef8..4903f53f4 100644 --- a/mapnik/__init__.py +++ b/mapnik/__init__.py @@ -103,12 +103,12 @@ def Filter(*args, **kwargs): return Expression(*args, **kwargs) -class Envelope(Box2d): +class Envelope(Box2d_Base): def __init__(self, *args, **kwargs): warnings.warn("'Envelope' is deprecated and will be removed in Mapnik 3.x, use 'Box2d' instead", DeprecationWarning, 2) - Box2d.__init__(self, *args, **kwargs) + Box2d_Base.__init__(self, *args, **kwargs) class _Coord(Coord, _injector()): @@ -186,7 +186,7 @@ def inverse(self, projection): return inverse_(self, projection) -class _Box2d(Box2d, _injector()): +class Box2d(Box2d_Base):#, _injector()): """ Represents a spatial envelope (i.e. bounding box). @@ -294,7 +294,7 @@ def all_features(self, fields=None, variables={}): return self.__iter__(fields, variables) -class _Color(Color, _injector()): +class Color(Color_Base):#, _injector()): def __repr__(self): return "Color(R=%d,G=%d,B=%d,A=%d)" % (self.r, self.g, self.b, self.a) diff --git a/mapnik/printing.py b/mapnik/printing.py index e2f975d92..19d953c32 100644 --- a/mapnik/printing.py +++ b/mapnik/printing.py @@ -21,7 +21,7 @@ import os import tempfile -from . import (Box2d, Coord, Feature, Geometry, Layer, Map, Projection, Style, +from . import (Box2d_Base, Coord, Feature, Geometry, Layer, Map, Projection, Style, render) try: diff --git a/src/mapnik_color.cpp b/src/mapnik_color.cpp index 3799f7734..1f2c0a4fa 100644 --- a/src/mapnik_color.cpp +++ b/src/mapnik_color.cpp @@ -47,7 +47,7 @@ struct color_pickle_suite : boost::python::pickle_suite void export_color () { using namespace boost::python; - class_("Color", init( + class_("Color_Base", init( ( arg("r"), arg("g"), arg("b"), arg("a") ), "Creates a new color from its RGB components\n" "and an alpha value.\n" diff --git a/src/mapnik_envelope.cpp b/src/mapnik_envelope.cpp index 0ea4ded77..504c3896f 100644 --- a/src/mapnik_envelope.cpp +++ b/src/mapnik_envelope.cpp @@ -106,7 +106,7 @@ box2d box2d_deepcopy(box2d & obj, boost::python::dict const&) void export_envelope() { using namespace boost::python; - class_ >("Box2d", + class_ >("Box2d_Base", // class docstring is in mapnik/__init__.py, class _Coord init( (arg("minx"),arg("miny"),arg("maxx"),arg("maxy")), From 27e204786b93d6a7a199da26ff32b4ac875b93f5 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 22 Jul 2016 16:11:28 +0200 Subject: [PATCH 2/2] re-enable pickling tests --- test/python_tests/pickling_test.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/python_tests/pickling_test.py b/test/python_tests/pickling_test.py index 2b21309b0..8a4ee3a6f 100644 --- a/test/python_tests/pickling_test.py +++ b/test/python_tests/pickling_test.py @@ -17,18 +17,17 @@ def setup(): os.chdir(execution_path('.')) -#def test_color_pickle(): -# c = mapnik.Color('blue') -# eq_(pickle.loads(pickle.dumps(c)), c) -# c = mapnik.Color(0, 64, 128) -# eq_(pickle.loads(pickle.dumps(c)), c) -# c = mapnik.Color(0, 64, 128, 192) -# eq_(pickle.loads(pickle.dumps(c)), c) - - -#def test_envelope_pickle(): -# e = mapnik.Box2d(100, 100, 200, 200) -# eq_(pickle.loads(pickle.dumps(e)), e) +def test_color_pickle(): + c = mapnik.Color('blue') + eq_(pickle.loads(pickle.dumps(c)), c) + c = mapnik.Color(0, 64, 128) + eq_(pickle.loads(pickle.dumps(c)), c) + c = mapnik.Color(0, 64, 128, 192) + eq_(pickle.loads(pickle.dumps(c)), c) + +def test_envelope_pickle(): + e = mapnik.Box2d(100, 100, 200, 200) + eq_(pickle.loads(pickle.dumps(e)), e) def test_parameters_pickle():