Objects: Add in the ability to test for member validity

This commit is contained in:
Mike Auty
2020-07-01 20:24:30 +01:00
committed by ikelos
parent 826102c0b5
commit 6f1001f290
@@ -176,6 +176,32 @@ class ObjectInterface(metaclass = ABCMeta):
"""
return False
def has_valid_member(self, member_name: str) -> bool:
"""Returns whether the dereferenced type has a valid member."""
if self.has_member(member_name):
try:
_ = getattr(self, member_name)
return True
finally:
return False
return False
def has_valid_members(self, member_names: List[str]) -> bool:
"""Returns whether the object has all of the members listed in member_names
Args:
member_names: List of names to test as to members with those names validity
"""
# Use only a single try/except for efficiency
try:
for member_name in member_names:
if not self.has_member(member_name):
return False
_ = getattr(self, member_name)
return True
finally:
return False
class VolTemplateProxy(metaclass = abc.ABCMeta):
"""A container for proxied methods that the ObjectTemplate of this
object will call. This is primarily to keep methods together for easy