Skip to content

Commit c549631

Browse files
committed
add function to get attributes by prefix
Signed-off-by: Roman Reinert <roman.reinert@gematik.de>
1 parent 97b44f6 commit c549631

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

aries_cloudagent/messaging/models/base_record.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,24 @@ def __eq__(self, other: Any) -> bool:
498498
return self.value == other.value and self.tags == other.tags
499499
return False
500500

501+
@classmethod
502+
def get_attributes_by_prefix(cls, prefix: str, walk_mro: bool = True):
503+
"""
504+
List all values for attributes with common prefix.
505+
506+
Args:
507+
prefix: Common prefix to look for
508+
walk_mro: Walk MRO to find attributes inherited from superclasses
509+
"""
510+
511+
bases = cls.__mro__ if walk_mro else [cls]
512+
return [
513+
vars(base)[name]
514+
for base in bases
515+
for name in vars(base)
516+
if name.startswith(prefix)
517+
]
518+
501519

502520
class BaseExchangeRecord(BaseRecord):
503521
"""Represents a base record with event tracing capability."""

0 commit comments

Comments
 (0)