diff --git a/python/selfie-lib/selfie_lib/Snapshot.py b/python/selfie-lib/selfie_lib/Snapshot.py index c4de20ac..60192841 100644 --- a/python/selfie-lib/selfie_lib/Snapshot.py +++ b/python/selfie-lib/selfie_lib/Snapshot.py @@ -51,12 +51,15 @@ def __str__(self): return f"[{self._subject} {self._facet_data}]" @staticmethod - def of(binary): - return Snapshot(SnapshotValue.of(binary), {}) - - @staticmethod - def of(string): - return Snapshot(SnapshotValue.of(string), {}) + def of(data): + if isinstance(data, bytes): + # Handling binary data + return Snapshot(SnapshotValue.of(data), {}) + elif isinstance(data, str): + # Handling string data + return Snapshot(SnapshotValue.of(data), {}) + else: + raise TypeError("Data must be either binary or string") @staticmethod def of_entries(entries): diff --git a/python/selfie-lib/selfie_lib/SnapshotValue.py b/python/selfie-lib/selfie_lib/SnapshotValue.py index 84b7fca9..2776da5a 100644 --- a/python/selfie-lib/selfie_lib/SnapshotValue.py +++ b/python/selfie-lib/selfie_lib/SnapshotValue.py @@ -20,13 +20,15 @@ def value_string(self) -> str: pass @staticmethod - def of(value: Union[bytes, str]) -> "SnapshotValue": - if isinstance(value, bytes): - return SnapshotValueBinary(value) - elif isinstance(value, str): - return SnapshotValueString(unix_newlines(value)) + def of(cls, data): + if isinstance(data, bytes): + return cls(SnapshotValue.of(data), {}) + elif isinstance(data, str): + return cls(SnapshotValue.of(data), {}) + elif isinstance(data, SnapshotValue): + return cls(data, {}) else: - raise TypeError("Value must be either bytes or str") + raise TypeError("Unsupported type for Snapshot creation") class SnapshotValueBinary(SnapshotValue):