From 4670ed61a1ac476cd02980517b939d7b46b5a01e Mon Sep 17 00:00:00 2001 From: jamshale Date: Tue, 2 Jul 2024 17:32:22 +0000 Subject: [PATCH] Better avoid protected keyword Signed-off-by: jamshale --- aries_cloudagent/anoncreds/holder.py | 12 ++++++------ .../anoncreds/tests/test_holder.py | 4 ++-- aries_cloudagent/indy/credx/holder.py | 18 +++++++++++------- aries_cloudagent/indy/holder.py | 14 +++++++++----- .../indy/models/non_rev_interval.py | 16 +++++++++------- .../indy/models/tests/test_non_rev_interval.py | 16 +++++++++------- aries_cloudagent/indy/models/xform.py | 6 +++--- aries_cloudagent/revocation/indy.py | 10 +++++----- aries_cloudagent/revocation/models/indy.py | 16 +++++++++------- .../revocation/models/tests/test_indy.py | 16 +++++++++------- 10 files changed, 72 insertions(+), 56 deletions(-) diff --git a/aries_cloudagent/anoncreds/holder.py b/aries_cloudagent/anoncreds/holder.py index a7863ee93a..85fce82b5c 100644 --- a/aries_cloudagent/anoncreds/holder.py +++ b/aries_cloudagent/anoncreds/holder.py @@ -477,17 +477,17 @@ async def _get_credential(self, credential_id: str) -> Credential: raise AnonCredsHolderError("Error loading requested credential") from err async def credential_revoked( - self, credential_id: str, fro: int = None, to: int = None + self, credential_id: str, timestamp_from: int = None, timestamp_to: int = None ) -> bool: """Check ledger for revocation status of credential by credential id. Args: ledger (BaseLedger): The ledger to check for revocation status. credential_id (str): The ID of the credential to check. - fro (int, optional): The earliest timestamp to consider for revocation status. - Defaults to None. - to (int, optional): The latest timestamp to consider for revocation status. - Defaults to None. + timestamp_from (int, optional): The earliest timestamp to consider for + revocation status. Defaults to None. + timestamp_to (int, optional): The latest timestamp to consider for revocation + status. Defaults to None. Returns: bool: True if the credential is revoked, False otherwise. @@ -498,7 +498,7 @@ async def credential_revoked( anoncreds_registry = self.profile.inject(AnonCredsRegistry) rev_list = ( await anoncreds_registry.get_revocation_list( - self.profile, rev_reg_id, fro, to + self.profile, rev_reg_id, timestamp_from, timestamp_to ) ).revocation_list diff --git a/aries_cloudagent/anoncreds/tests/test_holder.py b/aries_cloudagent/anoncreds/tests/test_holder.py index 3cb6143e93..70a374d998 100644 --- a/aries_cloudagent/anoncreds/tests/test_holder.py +++ b/aries_cloudagent/anoncreds/tests/test_holder.py @@ -403,8 +403,8 @@ async def test_credential_revoked(self, mock_handle): assert ( await self.holder.credential_revoked( credential_id="cred-id", - to=None, - fro=None, + timestamp_to=None, + timestamp_from=None, ) is False ) diff --git a/aries_cloudagent/indy/credx/holder.py b/aries_cloudagent/indy/credx/holder.py index 88d02f14cf..b730a62b62 100644 --- a/aries_cloudagent/indy/credx/holder.py +++ b/aries_cloudagent/indy/credx/holder.py @@ -374,17 +374,21 @@ async def _get_credential(self, credential_id: str) -> Credential: raise IndyHolderError("Error loading requested credential") from err async def credential_revoked( - self, ledger: BaseLedger, credential_id: str, fro: int = None, to: int = None + self, + ledger: BaseLedger, + credential_id: str, + timestamp_from: int = None, + timestamp_to: int = None, ) -> bool: """Check ledger for revocation status of credential by cred id. Args: ledger (BaseLedger): The ledger to check for revocation status. credential_id (str): The ID of the credential to check. - fro (int, optional): The starting sequence number of the revocation registry - delta. Defaults to None. - to (int, optional): The ending sequence number of the revocation registry - delta. Defaults to None. + timestamp_from (int, optional): The starting sequence number of the revocation + registry delta. Defaults to None. + timestamp_to (int, optional): The ending sequence number of the revocation + registry delta. Defaults to None. Returns: bool: True if the credential is revoked, False otherwise. @@ -396,8 +400,8 @@ async def credential_revoked( cred_rev_id = cred.rev_reg_index (rev_reg_delta, _) = await ledger.get_revoc_reg_delta( rev_reg_id, - fro, - to, + timestamp_from, + timestamp_to, ) return cred_rev_id in rev_reg_delta["value"].get("revoked", []) else: diff --git a/aries_cloudagent/indy/holder.py b/aries_cloudagent/indy/holder.py index cab2d70e3f..db1150c4dd 100644 --- a/aries_cloudagent/indy/holder.py +++ b/aries_cloudagent/indy/holder.py @@ -37,17 +37,21 @@ async def get_credential(self, credential_id: str) -> str: @abstractmethod async def credential_revoked( - self, ledger: BaseLedger, credential_id: str, fro: int = None, to: int = None + self, + ledger: BaseLedger, + credential_id: str, + timestamp_from: int = None, + timestamp_to: int = None, ) -> bool: """Check ledger for revocation status of credential by cred id. Args: ledger (BaseLedger): The ledger to check for revocation status. credential_id (str): The ID of the credential to check. - fro (int, optional): The starting time of the revocation status check range. - Defaults to None. - to (int, optional): The ending time of the revocation status check range. - Defaults to None. + timestamp_from (int, optional): The starting time of the revocation status + check range. Defaults to None. + timestamp_to (int, optional): The ending time of the revocation status check + range. Defaults to None. Returns: bool: True if the credential is revoked, False otherwise. diff --git a/aries_cloudagent/indy/models/non_rev_interval.py b/aries_cloudagent/indy/models/non_rev_interval.py index 3951f20a5a..6f7fdb6b69 100644 --- a/aries_cloudagent/indy/models/non_rev_interval.py +++ b/aries_cloudagent/indy/models/non_rev_interval.py @@ -16,18 +16,18 @@ class Meta: schema_class = "IndyNonRevocationIntervalSchema" - def __init__(self, fro: int = None, to: int = None, **kwargs): + def __init__(self, timestamp_from: int = None, timestamp_to: int = None, **kwargs): """Initialize non-revocation interval. Args: - fro: earliest time of interest - to: latest time of interest + timestamp_from: earliest time of interest + timestamp_to: latest time of interest kwargs: additional attributes """ super().__init__(**kwargs) - self.fro = fro - self.to = to + self.timestamp_from = timestamp_from + self.timestamp_to = timestamp_to def covers(self, timestamp: int = None) -> bool: """Whether input timestamp (default now) lies within non-revocation interval. @@ -40,11 +40,13 @@ def covers(self, timestamp: int = None) -> bool: """ timestamp = timestamp or int(time()) - return (self.fro or 0) <= timestamp <= (self.to or timestamp) + return ( + (self.timestamp_from or 0) <= timestamp <= (self.timestamp_to or timestamp) + ) def timestamp(self) -> bool: """Return a timestamp that the non-revocation interval covers.""" - return self.to or self.fro or int(time()) + return self.timestamp_to or self.timestamp_from or int(time()) class IndyNonRevocationIntervalSchema(BaseModelSchema): diff --git a/aries_cloudagent/indy/models/tests/test_non_rev_interval.py b/aries_cloudagent/indy/models/tests/test_non_rev_interval.py index a6f823bd6f..5c692ae19e 100644 --- a/aries_cloudagent/indy/models/tests/test_non_rev_interval.py +++ b/aries_cloudagent/indy/models/tests/test_non_rev_interval.py @@ -1,14 +1,13 @@ from unittest import TestCase - from ..non_rev_interval import IndyNonRevocationInterval FROM = 1000000000 TO = 1234567890 -INTERVAL_FROM = IndyNonRevocationInterval(fro=FROM) -INTERVAL_TO = IndyNonRevocationInterval(to=TO) -INTERVAL = IndyNonRevocationInterval(fro=FROM, to=TO) +INTERVAL_FROM = IndyNonRevocationInterval(timestamp_from=FROM) +INTERVAL_TO = IndyNonRevocationInterval(timestamp_to=TO) +INTERVAL = IndyNonRevocationInterval(timestamp_from=FROM, timestamp_to=TO) class TestInterval(TestCase): @@ -18,11 +17,14 @@ def test_serde(self): """Test serialization and deserialization.""" for interval in (INTERVAL_FROM, INTERVAL_TO, INTERVAL): non_revo_dict = interval.serialize() - assert non_revo_dict.get("from") == interval.fro - assert non_revo_dict.get("to") == interval.to + assert non_revo_dict.get("from") == interval.timestamp_from + assert non_revo_dict.get("to") == interval.timestamp_to model = IndyNonRevocationInterval.deserialize(non_revo_dict) - assert model.fro == interval.fro and model.to == interval.to + assert ( + model.timestamp_from == interval.timestamp_from + and model.timestamp_to == interval.timestamp_to + ) assert model.timestamp() def test_covers(self): diff --git a/aries_cloudagent/indy/models/xform.py b/aries_cloudagent/indy/models/xform.py index ee2e53c2ec..b3870baa6d 100644 --- a/aries_cloudagent/indy/models/xform.py +++ b/aries_cloudagent/indy/models/xform.py @@ -120,9 +120,9 @@ def indy_proof_req2non_revoc_intervals(indy_proof_req: dict): indy_proof_req.get("non_revoked"), ) if interval: - fro = interval.get("from") - to = interval.get("to") - if (to is not None) and fro == to: + timestamp_from = interval.get("from") + timestamp_to = interval.get("to") + if (timestamp_to is not None) and timestamp_from == timestamp_to: interval["from"] = 0 # accommodate indy-sdk verify=False if fro=to non_revoc_intervals[reft] = interval return non_revoc_intervals diff --git a/aries_cloudagent/revocation/indy.py b/aries_cloudagent/revocation/indy.py index 5067713722..c2d46b503f 100644 --- a/aries_cloudagent/revocation/indy.py +++ b/aries_cloudagent/revocation/indy.py @@ -203,15 +203,15 @@ async def list_issuer_registries(self) -> Sequence[IssuerRevRegRecord]: return await IssuerRevRegRecord.query(session) async def get_issuer_rev_reg_delta( - self, rev_reg_id: str, fro: int = None, to: int = None + self, rev_reg_id: str, timestamp_from: int = None, timestamp_to: int = None ) -> dict: """Check ledger for revocation status for a given revocation registry. Args: rev_reg_id (str): ID of the revocation registry - fro (int, optional): The sequence number to start from (exclusive). + timestamp_from (int, optional): The sequence number to start from (exclusive). Defaults to None. - to (int, optional): The sequence number to end at (inclusive). + timestamp_to (int, optional): The sequence number to end at (inclusive). Defaults to None. Returns: @@ -222,8 +222,8 @@ async def get_issuer_rev_reg_delta( async with ledger: (rev_reg_delta, _) = await ledger.get_revoc_reg_delta( rev_reg_id, - fro, - to, + timestamp_from, + timestamp_to, ) return rev_reg_delta diff --git a/aries_cloudagent/revocation/models/indy.py b/aries_cloudagent/revocation/models/indy.py index 9504208468..31053ca9a3 100644 --- a/aries_cloudagent/revocation/models/indy.py +++ b/aries_cloudagent/revocation/models/indy.py @@ -16,18 +16,18 @@ class Meta: schema_class = "NonRevocationIntervalSchema" - def __init__(self, fro: int = None, to: int = None, **kwargs): + def __init__(self, timestamp_from: int = None, timestamp_to: int = None, **kwargs): """Initialize non-revocation interval. Args: - fro: earliest time of interest - to: latest time of interest + timestamp_from: earliest time of interest + timestamp_to: latest time of interest kwargs: additional keyword arguments """ super().__init__(**kwargs) - self.fro = fro - self.to = to + self.timestamp_from = timestamp_from + self.timestamp_to = timestamp_to def covers(self, timestamp: int = None) -> bool: """Whether input timestamp (default now) lies within non-revocation interval. @@ -40,11 +40,13 @@ def covers(self, timestamp: int = None) -> bool: """ timestamp = timestamp or int(time()) - return (self.fro or 0) <= timestamp <= (self.to or timestamp) + return ( + (self.timestamp_from or 0) <= timestamp <= (self.timestamp_to or timestamp) + ) def timestamp(self) -> bool: """Return a timestamp that the non-revocation interval covers.""" - return self.to or self.fro or int(time()) + return self.timestamp_to or self.timestamp_from or int(time()) class NonRevocationIntervalSchema(BaseModelSchema): diff --git a/aries_cloudagent/revocation/models/tests/test_indy.py b/aries_cloudagent/revocation/models/tests/test_indy.py index 79ddc929c9..4e2f7ef8ad 100644 --- a/aries_cloudagent/revocation/models/tests/test_indy.py +++ b/aries_cloudagent/revocation/models/tests/test_indy.py @@ -1,14 +1,13 @@ from unittest import TestCase - from ..indy import NonRevocationInterval FROM = 1000000000 TO = 1234567890 -INTERVAL_FROM = NonRevocationInterval(fro=FROM) -INTERVAL_TO = NonRevocationInterval(to=TO) -INTERVAL = NonRevocationInterval(fro=FROM, to=TO) +INTERVAL_FROM = NonRevocationInterval(timestamp_from=FROM) +INTERVAL_TO = NonRevocationInterval(timestamp_to=TO) +INTERVAL = NonRevocationInterval(timestamp_from=FROM, timestamp_to=TO) class TestInterval(TestCase): @@ -18,11 +17,14 @@ def test_serde(self): """Test serialization and deserialization.""" for interval in (INTERVAL_FROM, INTERVAL_TO, INTERVAL): non_revo_dict = interval.serialize() - assert non_revo_dict.get("from") == interval.fro - assert non_revo_dict.get("to") == interval.to + assert non_revo_dict.get("from") == interval.timestamp_from + assert non_revo_dict.get("to") == interval.timestamp_to model = NonRevocationInterval.deserialize(non_revo_dict) - assert model.fro == interval.fro and model.to == interval.to + assert ( + model.timestamp_from == interval.timestamp_from + and model.timestamp_to == interval.timestamp_to + ) assert model.timestamp() def test_covers(self):