Skip to content

Commit 2b33d7f

Browse files
povikmarcan
authored andcommitted
m1n1.adt: Implement 'in' keyword on ADT nodes
So that one can check for children, like: >>> "/arm-io/aic" in u.adt True Signed-off-by: Martin Povišer <[email protected]>
1 parent 0249d04 commit 2b33d7f

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

proxyclient/m1n1/adt.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,20 @@ def __delitem__(self, item):
470470

471471
del self._children[item]
472472

473+
def __contains__(self, item):
474+
if isinstance(item, str):
475+
while item.startswith("/"):
476+
item = item[1:]
477+
if "/" in item:
478+
a, b = item.split("/", 1)
479+
return b in self[a]
480+
for c in self._children:
481+
if c.name == item:
482+
return True
483+
return False
484+
485+
return item in self._children
486+
473487
def __getattr__(self, attr):
474488
attr = attr.replace("_", "-")
475489
attr = attr.replace("--", "_")

proxyclient/m1n1/proxyutils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ def __setitem__(self, item, value):
415415
self._adt[item] = value
416416
def __delitem__(self, item):
417417
del self._adt[item]
418+
def __contains__(self, item):
419+
return item in self._adt
418420
def __getattr__(self, attr):
419421
return getattr(self._adt, attr)
420422
def __setattr__(self, attr, value):

0 commit comments

Comments
 (0)