mirror of
https://git.yoctoproject.org/poky
synced 2026-06-02 01:19:52 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
ebe3850bee
commit
2dd8c01513
@@ -29,6 +29,7 @@ BitBake build tools.
|
|||||||
# Based on functions from the base bb module, Copyright 2003 Holger Schurig
|
# Based on functions from the base bb module, Copyright 2003 Holger Schurig
|
||||||
|
|
||||||
import copy, re, sys
|
import copy, re, sys
|
||||||
|
from collections import MutableMapping
|
||||||
import bb
|
import bb
|
||||||
from bb import utils
|
from bb import utils
|
||||||
from bb.COW import COWDictBase
|
from bb.COW import COWDictBase
|
||||||
@@ -73,7 +74,7 @@ class VariableParse:
|
|||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
class DataSmart:
|
class DataSmart(MutableMapping):
|
||||||
def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ):
|
def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ):
|
||||||
self.dict = {}
|
self.dict = {}
|
||||||
|
|
||||||
@@ -347,23 +348,28 @@ class DataSmart:
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# Dictionary Methods
|
def __iter__(self):
|
||||||
def keys(self):
|
seen = set()
|
||||||
def _keys(d, mykey):
|
def _keys(d):
|
||||||
if "_data" in 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":
|
if key != "_data":
|
||||||
mykey[key] = None
|
if not key in seen:
|
||||||
keytab = {}
|
seen.add(key)
|
||||||
_keys(self.dict, keytab)
|
yield key
|
||||||
return keytab.keys()
|
return _keys(self.dict)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(frozenset(self))
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
#print "Warning deprecated"
|
|
||||||
return self.getVar(item, False)
|
return self.getVar(item, False)
|
||||||
|
|
||||||
def __setitem__(self, var, data):
|
def __setitem__(self, var, value):
|
||||||
#print "Warning deprecated"
|
self.setVar(var, value)
|
||||||
self.setVar(var, data)
|
|
||||||
|
def __delitem__(self, var):
|
||||||
|
self.delVar(var)
|
||||||
|
|||||||
Reference in New Issue
Block a user