diff --git a/hcloud/_compat.py b/hcloud/_compat.py deleted file mode 100644 index 6eb552d..0000000 --- a/hcloud/_compat.py +++ /dev/null @@ -1,11 +0,0 @@ -from datetime import datetime - - -def isoparse(value: str) -> datetime: - # Python <3.11 doesn't fully support parsing ISO8601 datetime strings. This - # workaround replaces the ending `Z` or `z` with `+00:00` and allows - # `datetime.fromisoformat` to parse the datetime string. - if value[-1] in "Zz": - value = value[:-1] + "+00:00" - - return datetime.fromisoformat(value) diff --git a/hcloud/actions/domain.py b/hcloud/actions/domain.py index 865a405..0d91eac 100644 --- a/hcloud/actions/domain.py +++ b/hcloud/actions/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from .._exceptions import HCloudException from ..core.domain import BaseDomain diff --git a/hcloud/certificates/domain.py b/hcloud/certificates/domain.py index afe44ed..f05173b 100644 --- a/hcloud/certificates/domain.py +++ b/hcloud/certificates/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain, DomainIdentityMixin diff --git a/hcloud/deprecation/domain.py b/hcloud/deprecation/domain.py index 705016d..8da63b9 100644 --- a/hcloud/deprecation/domain.py +++ b/hcloud/deprecation/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/firewalls/domain.py b/hcloud/firewalls/domain.py index ea431b5..861b40e 100644 --- a/hcloud/firewalls/domain.py +++ b/hcloud/firewalls/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/floating_ips/domain.py b/hcloud/floating_ips/domain.py index 133cc11..e59a8dc 100644 --- a/hcloud/floating_ips/domain.py +++ b/hcloud/floating_ips/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/images/domain.py b/hcloud/images/domain.py index 8b1c63a..4ca0600 100644 --- a/hcloud/images/domain.py +++ b/hcloud/images/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain, DomainIdentityMixin diff --git a/hcloud/isos/domain.py b/hcloud/isos/domain.py index 6d4572e..52ae695 100644 --- a/hcloud/isos/domain.py +++ b/hcloud/isos/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain, DomainIdentityMixin diff --git a/hcloud/load_balancers/domain.py b/hcloud/load_balancers/domain.py index 963fb27..e9eda77 100644 --- a/hcloud/load_balancers/domain.py +++ b/hcloud/load_balancers/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/networks/domain.py b/hcloud/networks/domain.py index 709a3d7..8a05cb1 100644 --- a/hcloud/networks/domain.py +++ b/hcloud/networks/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/placement_groups/domain.py b/hcloud/placement_groups/domain.py index 41d0680..2484414 100644 --- a/hcloud/placement_groups/domain.py +++ b/hcloud/placement_groups/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/primary_ips/domain.py b/hcloud/primary_ips/domain.py index 66e73c0..6a0b83a 100644 --- a/hcloud/primary_ips/domain.py +++ b/hcloud/primary_ips/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/servers/domain.py b/hcloud/servers/domain.py index 286ba86..b28f62e 100644 --- a/hcloud/servers/domain.py +++ b/hcloud/servers/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain diff --git a/hcloud/ssh_keys/domain.py b/hcloud/ssh_keys/domain.py index 25096f4..5f162f7 100644 --- a/hcloud/ssh_keys/domain.py +++ b/hcloud/ssh_keys/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain, DomainIdentityMixin diff --git a/hcloud/volumes/domain.py b/hcloud/volumes/domain.py index 0366cd5..6b4ae90 100644 --- a/hcloud/volumes/domain.py +++ b/hcloud/volumes/domain.py @@ -1,4 +1,5 @@ -from .._compat import isoparse +from dateutil.parser import isoparse + from ..core.domain import BaseDomain, DomainIdentityMixin diff --git a/setup.py b/setup.py index bb1945d..d0cdbf5 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,7 @@ ], python_requires=">=3.7", install_requires=[ + "python-dateutil>=2.7.5", "requests>=2.20", ], extras_require={ diff --git a/tests/unit/core/test_domain.py b/tests/unit/core/test_domain.py index b1116df..9e71cee 100644 --- a/tests/unit/core/test_domain.py +++ b/tests/unit/core/test_domain.py @@ -1,6 +1,6 @@ import pytest +from dateutil.parser import isoparse -from hcloud._compat import isoparse from hcloud.core.domain import ( BaseDomain, DomainIdentityMixin, diff --git a/tests/unit/networks/test_client.py b/tests/unit/networks/test_client.py index 9442919..5d70d99 100644 --- a/tests/unit/networks/test_client.py +++ b/tests/unit/networks/test_client.py @@ -1,8 +1,8 @@ from unittest import mock import pytest +from dateutil.parser import isoparse -from hcloud._compat import isoparse from hcloud.actions.client import BoundAction from hcloud.networks.client import BoundNetwork, NetworksClient from hcloud.networks.domain import Network, NetworkRoute, NetworkSubnet diff --git a/tests/unit/test_compat.py b/tests/unit/test_compat.py deleted file mode 100644 index 095d0f3..0000000 --- a/tests/unit/test_compat.py +++ /dev/null @@ -1,36 +0,0 @@ -from datetime import datetime, timedelta, timezone - -import pytest - -from hcloud._compat import isoparse - - -@pytest.mark.parametrize( - ["value", "expected"], - [ - ( - "2023-06-29T15:37:22", - datetime(2023, 6, 29, 15, 37, 22), - ), - ( - "2023-06-29T15:37:22+00:00", - datetime(2023, 6, 29, 15, 37, 22, tzinfo=timezone.utc), - ), - ( - "2023-06-29T15:37:22+02:12", - datetime( - 2023, 6, 29, 15, 37, 22, tzinfo=timezone(timedelta(hours=2, minutes=12)) - ), - ), - ( - "2023-06-29T15:37:22Z", - datetime(2023, 6, 29, 15, 37, 22, tzinfo=timezone.utc), - ), - ( - "2023-06-29T15:37:22z", - datetime(2023, 6, 29, 15, 37, 22, tzinfo=timezone.utc), - ), - ], -) -def test_isoparse(value: str, expected: datetime): - assert isoparse(value) == expected diff --git a/tests/unit/volumes/test_client.py b/tests/unit/volumes/test_client.py index 16fea07..fda74f9 100644 --- a/tests/unit/volumes/test_client.py +++ b/tests/unit/volumes/test_client.py @@ -1,8 +1,8 @@ from unittest import mock import pytest +from dateutil.parser import isoparse -from hcloud._compat import isoparse from hcloud.actions.client import BoundAction from hcloud.locations.client import BoundLocation from hcloud.locations.domain import Location