From 11c06c21c0c241050948dcf55de496b7e0242619 Mon Sep 17 00:00:00 2001 From: jamshale <31809382+jamshale@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:54:52 -0700 Subject: [PATCH] Switch from pytz to dateutil (#3012) * Switch from pytz to dateutil Signed-off-by: jamshale --------- Signed-off-by: jamshale Signed-off-by: EmadAnwer --- .../present_proof/dif/pres_exch_handler.py | 7 +-- .../suites/bbs_bls_signature_2020.py | 11 ++-- .../ld_proofs/suites/linked_data_signature.py | 8 +-- .../vc/vc_ld/models/credential.py | 11 ++-- docs/conf.py | 59 +++++++++---------- poetry.lock | 16 +---- pyproject.toml | 1 - 7 files changed, 49 insertions(+), 64 deletions(-) diff --git a/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py b/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py index 8ccc271fd9..d46415abee 100644 --- a/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py +++ b/aries_cloudagent/protocols/present_proof/dif/pres_exch_handler.py @@ -13,7 +13,7 @@ from datetime import datetime from typing import Dict, List, Optional, Sequence, Tuple, Union -import pytz +from dateutil import tz from dateutil.parser import ParserError from dateutil.parser import parse as dateutil_parser from jsonpath_ng import parse @@ -613,10 +613,9 @@ def string_to_timezone_aware_datetime(self, datetime_str: str) -> datetime: if PYTZ_TIMEZONE_PATTERN.search(datetime_str): result = PYTZ_TIMEZONE_PATTERN.search(datetime_str).group(1) datetime_str = datetime_str.replace(result, "") - return dateutil_parser(datetime_str).replace(tzinfo=pytz.timezone(result)) + return dateutil_parser(datetime_str).replace(tzinfo=tz.gettz(result)) else: - utc = pytz.UTC - return dateutil_parser(datetime_str).replace(tzinfo=utc) + return dateutil_parser(datetime_str).replace(tzinfo=tz.UTC) def validate_patch(self, to_check: any, _filter: Filter) -> bool: """Apply filter on match_value. diff --git a/aries_cloudagent/vc/ld_proofs/suites/bbs_bls_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/bbs_bls_signature_2020.py index 915497c67e..585b1cc970 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/bbs_bls_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/bbs_bls_signature_2020.py @@ -1,17 +1,16 @@ """BbsBlsSignature2020 class.""" -from datetime import datetime, timezone -from pytz import utc +from datetime import datetime from typing import List, Optional, Union -from ....wallet.util import b64_to_bytes, bytes_to_b64 +from dateutil import tz +from ....wallet.util import b64_to_bytes, bytes_to_b64 from ..crypto import _KeyPair as KeyPair from ..document_loader import DocumentLoaderMethod from ..error import LinkedDataProofException from ..purposes import _ProofPurpose as ProofPurpose from ..validation_result import ProofResult - from .bbs_bls_signature_2020_base import BbsBlsSignature2020Base @@ -60,9 +59,9 @@ async def create_proof( # Set created if not already set if not proof.get("created"): # Use class date, or now - date = self.date or datetime.now(timezone.utc) + date = self.date or datetime.now(tz.UTC) if not date.tzinfo: - date = utc.localize(date) + date = date.replace(tzinfo=tz.UTC) proof["created"] = date.isoformat(timespec="seconds") # Allow purpose to update the proof; the `proof` is in the diff --git a/aries_cloudagent/vc/ld_proofs/suites/linked_data_signature.py b/aries_cloudagent/vc/ld_proofs/suites/linked_data_signature.py index 36721f562e..d2a56a514c 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/linked_data_signature.py +++ b/aries_cloudagent/vc/ld_proofs/suites/linked_data_signature.py @@ -1,17 +1,17 @@ """Linked Data Signature class.""" -from abc import abstractmethod, ABCMeta +from abc import ABCMeta, abstractmethod from datetime import datetime, timezone from hashlib import sha256 -from pytz import utc from typing import Optional, Union +from dateutil import tz + from ..constants import SECURITY_CONTEXT_URL from ..document_loader import DocumentLoaderMethod from ..error import LinkedDataProofException from ..purposes import _ProofPurpose as ProofPurpose from ..validation_result import ProofResult - from .linked_data_proof import LinkedDataProof @@ -99,7 +99,7 @@ async def create_proof( # Use class date, or now date = self.date or datetime.now(timezone.utc) if not date.tzinfo: - date = utc.localize(date) + date = date.replace(tzinfo=tz.UTC) proof["created"] = date.isoformat(timespec="seconds") # Allow purpose to update the proof; the `proof` is in the diff --git a/aries_cloudagent/vc/vc_ld/models/credential.py b/aries_cloudagent/vc/vc_ld/models/credential.py index a436f9c84b..8ba27a9a4b 100644 --- a/aries_cloudagent/vc/vc_ld/models/credential.py +++ b/aries_cloudagent/vc/vc_ld/models/credential.py @@ -3,18 +3,17 @@ from datetime import datetime from typing import List, Optional, Union -from pytz import utc - +from dateutil import tz from marshmallow import INCLUDE, ValidationError, fields, post_dump from ....messaging.models.base import BaseModel, BaseModelSchema from ....messaging.valid import ( CREDENTIAL_CONTEXT_EXAMPLE, CREDENTIAL_CONTEXT_VALIDATE, - CREDENTIAL_SUBJECT_EXAMPLE, - CREDENTIAL_SUBJECT_VALIDATE, CREDENTIAL_STATUS_EXAMPLE, CREDENTIAL_STATUS_VALIDATE, + CREDENTIAL_SUBJECT_EXAMPLE, + CREDENTIAL_SUBJECT_VALIDATE, CREDENTIAL_TYPE_EXAMPLE, CREDENTIAL_TYPE_VALIDATE, RFC3339_DATETIME_EXAMPLE, @@ -176,7 +175,7 @@ def issuance_date(self, date: Union[str, datetime]): """Setter for issuance date.""" if isinstance(date, datetime): if not date.tzinfo: - date = utc.localize(date) + date = date.replace(tzinfo=tz.UTC) date = date.isoformat() self._issuance_date = date @@ -191,7 +190,7 @@ def expiration_date(self, date: Union[str, datetime, None]): """Setter for expiration date.""" if isinstance(date, datetime): if not date.tzinfo: - date = utc.localize(date) + date = date.replace(tzinfo=tz.UTC) date = date.isoformat() self._expiration_date = date diff --git a/docs/conf.py b/docs/conf.py index 336d7e620d..c07343c1a2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,48 +18,47 @@ sys.path.insert(0, os.path.abspath("..")) autodoc_mock_imports = [ - "setup", - "nacl", - "indy", + "aiohttp_apispec", "aiohttp_cors", "aiohttp", - "aiohttp_apispec", - "base58", - "msgpack", - "pytest", + "aioredis", + "anoncreds", + "aries_askar", + "async_timeout", "asynctest", - "markdown", - "prompt_toolkit", - "multicodec", + "base58", "configargparse", - "pyld", - "pydid", - "aries_askar", - "indy_vdr", - "aioredis", + "dateutil", "deepmerge", + "did_peer_2", + "did_peer_4", "ecdsa", "indy_credx", - "dateutil", - "packaging", + "indy_vdr", + "indy", "jsonpath_ng", - "unflatten", - "qrcode", - "rlp", - "nest_asyncio", + "jwt", + "markdown", "marshmallow", - "typing_extensions", - "async_timeout", + "msgpack", + "multicodec", + "multiformats", + "nacl", + "nest_asyncio", + "packaging", "portalocker", + "prompt_toolkit", + "pydid", + "pyld", + "pytest", "pythonjsonlogger", - "jwt", - "yaml", - "pytz", - "multiformats", + "qrcode", + "rlp", "sd_jwt", - "anoncreds", - "did_peer_2", - "did_peer_4", + "setup", + "typing_extensions", + "unflatten", + "yaml", ] # "aries_cloudagent.tests.test_conductor", diff --git a/poetry.lock b/poetry.lock index 9a829c3316..750938c778 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "aiohttp" @@ -2237,17 +2237,6 @@ files = [ {file = "python_json_logger-2.0.7-py3-none-any.whl", hash = "sha256:f380b826a991ebbe3de4d897aeec42760035ac760345e57b812938dc8b35e2bd"}, ] -[[package]] -name = "pytz" -version = "2021.1" -description = "World timezone definitions, modern and historical" -optional = false -python-versions = "*" -files = [ - {file = "pytz-2021.1-py2.py3-none-any.whl", hash = "sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798"}, - {file = "pytz-2021.1.tar.gz", hash = "sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da"}, -] - [[package]] name = "pywin32" version = "306" @@ -2296,6 +2285,7 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -2895,4 +2885,4 @@ bbs = ["ursa-bbs-signatures"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "ebf6f9d048937a52695115bf2aa1b2f71521116ccb5d9429f209aee041b91446" +content-hash = "7dbaa13873082c3ccdfdf47d5381b85d30c7c64800884148095e344955f3e27c" diff --git a/pyproject.toml b/pyproject.toml index ec910e97ed..e5b45a51f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,6 @@ pyld="^2.0.4" pynacl="~1.5.0" python-dateutil="~2.8.1" python-json-logger="~2.0.7" -pytz="~2021.1" pyyaml="~6.0.1" qrcode = {version = ">=6.1,<7.0", extras = ["pil"]} requests="~2.31.0"