diff options
author | Miroslav Šedivý <[email protected]> | 2022-11-30 20:21:04 +0100 |
---|---|---|
committer | Miroslav Šedivý <[email protected]> | 2022-11-30 20:21:04 +0100 |
commit | 5262d58a0b97a04bbc3bd07a1c46c4a6a564a61c (patch) | |
tree | 549f8c109190a88257e2c55bfc6c6e05ce532ff4 | |
parent | 53cb42117bd99653f6f86280011cd25299356889 (diff) | |
download | mastodon.py-5262d58a0b97a04bbc3bd07a1c46c4a6a564a61c.tar.gz |
replace pytz with datetime.timezone and zoneinfo
-rw-r--r-- | mastodon/Mastodon.py | 11 | ||||
-rw-r--r-- | setup.py | 1 | ||||
-rw-r--r-- | tests/test_status.py | 4 |
3 files changed, 7 insertions, 9 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 2074224..e0b9257 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -11,7 +11,6 @@ import string | |||
11 | import datetime | 11 | import datetime |
12 | import collections | 12 | import collections |
13 | from contextlib import closing | 13 | from contextlib import closing |
14 | import pytz | ||
15 | import requests | 14 | import requests |
16 | from requests.models import urlencode | 15 | from requests.models import urlencode |
17 | import dateutil | 16 | import dateutil |
@@ -3928,11 +3927,11 @@ class Mastodon: | |||
3928 | """ | 3927 | """ |
3929 | date_time_utc = None | 3928 | date_time_utc = None |
3930 | if date_time.tzinfo is None: | 3929 | if date_time.tzinfo is None: |
3931 | date_time_utc = date_time.replace(tzinfo=pytz.utc) | 3930 | date_time_utc = date_time.replace(tzinfo=datetime.timezone.utc) |
3932 | else: | 3931 | else: |
3933 | date_time_utc = date_time.astimezone(pytz.utc) | 3932 | date_time_utc = date_time.astimezone(datetime.timezone.utc) |
3934 | 3933 | ||
3935 | epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc) | 3934 | epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc) |
3936 | 3935 | ||
3937 | return (date_time_utc - epoch_utc).total_seconds() | 3936 | return (date_time_utc - epoch_utc).total_seconds() |
3938 | 3937 | ||
@@ -3967,7 +3966,7 @@ class Mastodon: | |||
3967 | if v is not None: | 3966 | if v is not None: |
3968 | try: | 3967 | try: |
3969 | if isinstance(v, int): | 3968 | if isinstance(v, int): |
3970 | json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc) | 3969 | json_object[k] = datetime.datetime.fromtimestamp(v, datetime.timezone.utc) |
3971 | else: | 3970 | else: |
3972 | json_object[k] = dateutil.parser.parse(v) | 3971 | json_object[k] = dateutil.parser.parse(v) |
3973 | except: | 3972 | except: |
@@ -4023,7 +4022,7 @@ class Mastodon: | |||
4023 | every time instead of randomly doing different things on some systems | 4022 | every time instead of randomly doing different things on some systems |
4024 | and also it represents that time as the equivalent UTC time. | 4023 | and also it represents that time as the equivalent UTC time. |
4025 | """ | 4024 | """ |
4026 | isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z") | 4025 | isotime = datetime_val.astimezone(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z") |
4027 | if isotime[-2] != ":": | 4026 | if isotime[-2] != ":": |
4028 | isotime = isotime[:-2] + ":" + isotime[-2:] | 4027 | isotime = isotime[:-2] + ":" + isotime[-2:] |
4029 | return isotime | 4028 | return isotime |
@@ -33,7 +33,6 @@ setup(name='Mastodon.py', | |||
33 | 'requests>=2.4.2', | 33 | 'requests>=2.4.2', |
34 | 'python-dateutil', | 34 | 'python-dateutil', |
35 | 'six', | 35 | 'six', |
36 | 'pytz', | ||
37 | 'python-magic', | 36 | 'python-magic', |
38 | 'decorator>=4.0.0', | 37 | 'decorator>=4.0.0', |
39 | ] + blurhash_deps, | 38 | ] + blurhash_deps, |
diff --git a/tests/test_status.py b/tests/test_status.py index e747571..1fa7fd5 100644 --- a/tests/test_status.py +++ b/tests/test_status.py | |||
@@ -1,7 +1,7 @@ | |||
1 | import pytest | 1 | import pytest |
2 | from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError | 2 | from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError |
3 | import datetime | 3 | import datetime |
4 | import pytz | 4 | import zoneinfo |
5 | import vcr | 5 | import vcr |
6 | import time | 6 | import time |
7 | import pickle | 7 | import pickle |
@@ -154,7 +154,7 @@ def test_status_pin_unpin(status, api): | |||
154 | 154 | ||
155 | @pytest.mark.vcr(match_on=['path']) | 155 | @pytest.mark.vcr(match_on=['path']) |
156 | def test_scheduled_status(api): | 156 | def test_scheduled_status(api): |
157 | base_time = datetime.datetime(4000, 1, 1, 12, 13, 14, 0, pytz.timezone("Etc/GMT+2")) | 157 | base_time = datetime.datetime(4000, 1, 1, 12, 13, 14, 0, zoneinfo.ZoneInfo("Etc/GMT+2")) |
158 | the_future = base_time + datetime.timedelta(minutes=20) | 158 | the_future = base_time + datetime.timedelta(minutes=20) |
159 | scheduled_toot = api.status_post("please ensure adequate headroom", scheduled_at=the_future) | 159 | scheduled_toot = api.status_post("please ensure adequate headroom", scheduled_at=the_future) |
160 | assert scheduled_toot | 160 | assert scheduled_toot |