Changeset 1678

Show
Ignore:
Timestamp:
03/11/10 14:59:40 (5 months ago)
Author:
alberto
Message:

added a proxy to the deprecated Feature.properties interface in the python bindings

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/bindings/python/mapnik/__init__.py

    r1665 r1678  
    235235        return self.features(query).features 
    236236 
     237class _DeprecatedFeatureProperties(object): 
     238    def __init__(self, feature): 
     239        self._feature = feature 
     240 
     241    def __getitem__(self, name): 
     242        from warnings import warn 
     243        warn("indexing feature.properties is deprecated, index the " 
     244             "feature object itself for the same effect", DeprecationWarning, 2) 
     245        return self._feature[name] 
     246 
     247    def __iter__(self): 
     248        from warnings import warn 
     249        warn("iterating feature.properties is deprecated, iterate the " 
     250             "feature object itself for the same effect", DeprecationWarning, 2) 
     251        return iter(self._feature) 
     252 
    237253class _Feature(Feature,_injector): 
    238254    @property 
     255    def properties(self): 
     256        return _DeprecatedFeatureProperties(self) 
     257 
     258    @property 
    239259    def attributes(self): 
    240         attr = {} 
    241         for prop in self.properties: 
    242             attr[prop[0]] = prop[1] 
    243         return attr 
     260        return dict(self) 
    244261 
    245262class _Symbolizer(Symbolizer,_injector):