Skip to content

Commit

Permalink
Align to be closer to matching the C++ bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
dagardner-nv committed Aug 20, 2024
1 parent aa13a0e commit b449bd4
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions python/morpheus/morpheus/messages/control_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,21 @@ def set_metadata(self, key: str, value: typing.Any):
def has_metadata(self, key: str) -> bool:
return key in self._config["metadata"]

def get_metadata(self, key: str = None, fail_on_nonexist: bool = False) -> typing.Any | None:
def get_metadata(self, key: str = None, default_value: typing.Any = None) -> typing.Any:
"""
Return a given piece of metadata, if `key` is `None` return the entire metadata dictionary.
If `key` is not found, `default_value` is returned.
:param key: The key of the metadata to retrieve, or None for all metadata
:param default_value: The value to return if the key is not found, ignored if `key` is None
:return: The value of the metadata key, or the entire metadata dictionary if `key` is None
"""

# Not using `get` since `None` is a valid value
if key is None:
return self._config["metadata"]

try:
return self._config["metadata"][key]
except KeyError:
if fail_on_nonexist:
raise
return None
return self._config["metadata"].get(key, default_value)

def list_metadata(self) -> list[str]:
return sorted(self._config["metadata"].keys())
Expand Down Expand Up @@ -171,12 +175,7 @@ def get_timestamp(self, key: str, fail_if_nonexist: bool = False) -> datetime |
raise
return None

def filter_timestamp(self, regex_filter: str | re.Pattern) -> dict[str, datetime]:
if isinstance(regex_filter, str):
re_obj = re.compile(regex_filter)
elif isinstance(regex_filter, re.Pattern):
re_obj = regex_filter
else:
raise ValueError("regex_filter must be a string or a compiled regex object")
def filter_timestamp(self, regex_filter: str) -> dict[str, datetime]:
re_obj = re.compile(regex_filter)

return {key: value for key, value in self._timestamps.items() if re_obj.match(key)}

0 comments on commit b449bd4

Please sign in to comment.