From 51c0b873cc93366ea4d66dc4f3e5939aa3a92726 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sat, 27 Jun 2020 21:59:40 +0100 Subject: [PATCH] Objects: Reduce duplicated code (thanks @atcuno) --- volatility/framework/interfaces/objects.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/volatility/framework/interfaces/objects.py b/volatility/framework/interfaces/objects.py index dc4a3f18c..266231fe6 100644 --- a/volatility/framework/interfaces/objects.py +++ b/volatility/framework/interfaces/objects.py @@ -178,7 +178,11 @@ class ObjectInterface(metaclass = ABCMeta): return False def has_valid_member(self, member_name: str) -> bool: - """Returns whether the dereferenced type has a valid member.""" + """Returns whether the dereferenced type has a valid member. + + Args: + member_name: Name of the member to test access to determine if the member is valid or not + """ if self.has_member(member_name): with contextlib.suppress(Exception): _ = getattr(self, member_name) @@ -191,14 +195,7 @@ class ObjectInterface(metaclass = ABCMeta): Args: member_names: List of names to test as to members with those names validity """ - # Use catch a single error to short circuit failures quickly - with contextlib.suppress(Exception): - for member_name in member_names: - if not self.has_member(member_name): - return False - _ = getattr(self, member_name) - return True - return False + return all([self.has_valid_member(member_name) for member_name in member_names]) class VolTemplateProxy(metaclass = abc.ABCMeta): """A container for proxied methods that the ObjectTemplate of this