diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-04-12 18:56:25 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2011-01-04 14:46:32 +0000 |
commit | 2dd8c01513bde8b30d27faf3a48f07c2e7e95ea7 (patch) | |
tree | 1e7e81c65785e7c6b3afe83220d6c8c57793be12 /bitbake/lib/bb | |
parent | ebe3850beebb233b86bade9b0b93ed23bfd60e04 (diff) | |
download | openembedded-core-2dd8c01513bde8b30d27faf3a48f07c2e7e95ea7.tar.gz openembedded-core-2dd8c01513bde8b30d27faf3a48f07c2e7e95ea7.tar.bz2 openembedded-core-2dd8c01513bde8b30d27faf3a48f07c2e7e95ea7.tar.xz openembedded-core-2dd8c01513bde8b30d27faf3a48f07c2e7e95ea7.zip |
Make DataSmart inherit the MutableMapping ABC
Provide __len__, __iter__, and the getitem/setitem/delitem methods, and its
mixed in versions of keys(), values(), items(), etc will automatically behave,
making the DataSmart act more like a real mapping.
(Bitbake rev: 89b5351c656d263b0ce513cee043bc046d20a01e)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index 30f9cbc2d..22dadec5d 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py @@ -29,6 +29,7 @@ BitBake build tools. # Based on functions from the base bb module, Copyright 2003 Holger Schurig import copy, re, sys +from collections import MutableMapping import bb from bb import utils from bb.COW import COWDictBase @@ -73,7 +74,7 @@ class VariableParse: return str(value) -class DataSmart: +class DataSmart(MutableMapping): def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): self.dict = {} @@ -347,23 +348,28 @@ class DataSmart: return data - # Dictionary Methods - def keys(self): - def _keys(d, mykey): + def __iter__(self): + seen = set() + def _keys(d): if "_data" in d: - _keys(d["_data"], mykey) + for key in _keys(d["_data"]): + yield key - for key in d.keys(): + for key in d: if key != "_data": - mykey[key] = None - keytab = {} - _keys(self.dict, keytab) - return keytab.keys() + if not key in seen: + seen.add(key) + yield key + return _keys(self.dict) + + def __len__(self): + return len(frozenset(self)) def __getitem__(self, item): - #print "Warning deprecated" return self.getVar(item, False) - def __setitem__(self, var, data): - #print "Warning deprecated" - self.setVar(var, data) + def __setitem__(self, var, value): + self.setVar(var, value) + + def __delitem__(self, var): + self.delVar(var) |