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/data_smart.py | |
| parent | ebe3850beebb233b86bade9b0b93ed23bfd60e04 (diff) | |
| download | poky-2dd8c01513bde8b30d27faf3a48f07c2e7e95ea7.tar.gz | |
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/data_smart.py')
| -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 30f9cbc2d4..22dadec5de 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
| @@ -29,6 +29,7 @@ BitBake build tools. | |||
| 29 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | 29 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | 
| 30 | 30 | ||
| 31 | import copy, re, sys | 31 | import copy, re, sys | 
| 32 | from collections import MutableMapping | ||
| 32 | import bb | 33 | import bb | 
| 33 | from bb import utils | 34 | from bb import utils | 
| 34 | from bb.COW import COWDictBase | 35 | from bb.COW import COWDictBase | 
| @@ -73,7 +74,7 @@ class VariableParse: | |||
| 73 | return str(value) | 74 | return str(value) | 
| 74 | 75 | ||
| 75 | 76 | ||
| 76 | class DataSmart: | 77 | class DataSmart(MutableMapping): | 
| 77 | def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): | 78 | def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): | 
| 78 | self.dict = {} | 79 | self.dict = {} | 
| 79 | 80 | ||
| @@ -347,23 +348,28 @@ class DataSmart: | |||
| 347 | 348 | ||
| 348 | return data | 349 | return data | 
| 349 | 350 | ||
| 350 | # Dictionary Methods | 351 | def __iter__(self): | 
| 351 | def keys(self): | 352 | seen = set() | 
| 352 | def _keys(d, mykey): | 353 | def _keys(d): | 
| 353 | if "_data" in d: | 354 | if "_data" in d: | 
| 354 | _keys(d["_data"], mykey) | 355 | for key in _keys(d["_data"]): | 
| 356 | yield key | ||
| 355 | 357 | ||
| 356 | for key in d.keys(): | 358 | for key in d: | 
| 357 | if key != "_data": | 359 | if key != "_data": | 
| 358 | mykey[key] = None | 360 | if not key in seen: | 
| 359 | keytab = {} | 361 | seen.add(key) | 
| 360 | _keys(self.dict, keytab) | 362 | yield key | 
| 361 | return keytab.keys() | 363 | return _keys(self.dict) | 
| 364 | |||
| 365 | def __len__(self): | ||
| 366 | return len(frozenset(self)) | ||
| 362 | 367 | ||
| 363 | def __getitem__(self, item): | 368 | def __getitem__(self, item): | 
| 364 | #print "Warning deprecated" | ||
| 365 | return self.getVar(item, False) | 369 | return self.getVar(item, False) | 
| 366 | 370 | ||
| 367 | def __setitem__(self, var, data): | 371 | def __setitem__(self, var, value): | 
| 368 | #print "Warning deprecated" | 372 | self.setVar(var, value) | 
| 369 | self.setVar(var, data) | 373 | |
| 374 | def __delitem__(self, var): | ||
| 375 | self.delVar(var) | ||
