From e8a4929a5a26cea4b4f931a07101d21cb9621eb4 Mon Sep 17 00:00:00 2001 From: Alberto Valverde Date: Thu, 11 Mar 2010 19:59:40 +0000 Subject: [PATCH] added a proxy to the deprecated Feature.properties interface in the python bindings --- bindings/python/mapnik/__init__.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index bb6837946..ec2dc8acb 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -234,13 +234,30 @@ class _Datasource(Datasource,_injector): query.add_property_name(fld) return self.features(query).features +class _DeprecatedFeatureProperties(object): + def __init__(self, feature): + self._feature = feature + + def __getitem__(self, name): + from warnings import warn + warn("indexing feature.properties is deprecated, index the " + "feature object itself for the same effect", DeprecationWarning, 2) + return self._feature[name] + + def __iter__(self): + from warnings import warn + warn("iterating feature.properties is deprecated, iterate the " + "feature object itself for the same effect", DeprecationWarning, 2) + return iter(self._feature) + class _Feature(Feature,_injector): + @property + def properties(self): + return _DeprecatedFeatureProperties(self) + @property def attributes(self): - attr = {} - for prop in self.properties: - attr[prop[0]] = prop[1] - return attr + return dict(self) class _Symbolizer(Symbolizer,_injector): def symbol(self):