diff options
author | halcy <halcy@ARARAGI-KUN> | 2022-11-30 22:43:03 +0200 |
---|---|---|
committer | halcy <halcy@ARARAGI-KUN> | 2022-11-30 22:43:03 +0200 |
commit | 2d7f495b0f702ca156697e7c7f0dd2e40a68e4a6 (patch) | |
tree | 06b61042d1a76694422a517bada8aebf6103927c | |
parent | 262d150c05b328324ae5becc5da0d5b55dd74b89 (diff) | |
parent | bf428f58efbf7989d7771e9edb54fade1009a4e7 (diff) | |
download | mastodon.py-2d7f495b0f702ca156697e7c7f0dd2e40a68e4a6.tar.gz |
Merge branch 'modern-datetime' of https://github.com/eumiro/Mastodon.py into eumiro-modern-datetime
-rw-r--r-- | mastodon/Mastodon.py | 2 | ||||
-rw-r--r-- | mastodon/internals.py | 16 | ||||
-rw-r--r-- | setup.py | 1 | ||||
-rw-r--r-- | tests/test_status.py | 4 |
4 files changed, 8 insertions, 15 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index c454aa1..ad8e963 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -7,6 +7,7 @@ import os.path | |||
7 | import time | 7 | import time |
8 | import datetime | 8 | import datetime |
9 | import collections | 9 | import collections |
10 | from contextlib import closing | ||
10 | import requests | 11 | import requests |
11 | from requests.models import urlencode | 12 | from requests.models import urlencode |
12 | import dateutil | 13 | import dateutil |
@@ -3744,4 +3745,3 @@ class Mastodon(Internals): | |||
3744 | if api_okay in [b'OK', b'success']: | 3745 | if api_okay in [b'OK', b'success']: |
3745 | return True | 3746 | return True |
3746 | return False | 3747 | return False |
3747 | |||
diff --git a/mastodon/internals.py b/mastodon/internals.py index a19ed77..415e22d 100644 --- a/mastodon/internals.py +++ b/mastodon/internals.py | |||
@@ -4,7 +4,6 @@ import mimetypes | |||
4 | import threading | 4 | import threading |
5 | import six | 5 | import six |
6 | import uuid | 6 | import uuid |
7 | import pytz | ||
8 | import dateutil.parser | 7 | import dateutil.parser |
9 | import time | 8 | import time |
10 | import copy | 9 | import copy |
@@ -24,7 +23,7 @@ from .defaults import _DEFAULT_STREAM_TIMEOUT, _DEFAULT_STREAM_RECONNECT_WAIT_SE | |||
24 | ### | 23 | ### |
25 | # Internal helpers, dragons probably | 24 | # Internal helpers, dragons probably |
26 | ### | 25 | ### |
27 | class Mastodon(): | 26 | class Mastodon(): |
28 | def __datetime_to_epoch(self, date_time): | 27 | def __datetime_to_epoch(self, date_time): |
29 | """ | 28 | """ |
30 | Converts a python datetime to unix epoch, accounting for | 29 | Converts a python datetime to unix epoch, accounting for |
@@ -32,15 +31,10 @@ class Mastodon(): | |||
32 | 31 | ||
33 | Assumes UTC if timezone is not given. | 32 | Assumes UTC if timezone is not given. |
34 | """ | 33 | """ |
35 | date_time_utc = None | ||
36 | if date_time.tzinfo is None: | 34 | if date_time.tzinfo is None: |
37 | date_time_utc = date_time.replace(tzinfo=pytz.utc) | 35 | date_time = date_time.replace(tzinfo=datetime.timezone.utc) |
38 | else: | 36 | return date_time.timestamp() |
39 | date_time_utc = date_time.astimezone(pytz.utc) | ||
40 | |||
41 | epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc) | ||
42 | 37 | ||
43 | return (date_time_utc - epoch_utc).total_seconds() | ||
44 | 38 | ||
45 | def __get_logged_in_id(self): | 39 | def __get_logged_in_id(self): |
46 | """ | 40 | """ |
@@ -73,7 +67,7 @@ class Mastodon(): | |||
73 | if v is not None: | 67 | if v is not None: |
74 | try: | 68 | try: |
75 | if isinstance(v, int): | 69 | if isinstance(v, int): |
76 | json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc) | 70 | json_object[k] = datetime.datetime.fromtimestamp(v, datetime.timezone.utc) |
77 | else: | 71 | else: |
78 | json_object[k] = dateutil.parser.parse(v) | 72 | json_object[k] = dateutil.parser.parse(v) |
79 | except: | 73 | except: |
@@ -129,7 +123,7 @@ class Mastodon(): | |||
129 | every time instead of randomly doing different things on some systems | 123 | every time instead of randomly doing different things on some systems |
130 | and also it represents that time as the equivalent UTC time. | 124 | and also it represents that time as the equivalent UTC time. |
131 | """ | 125 | """ |
132 | isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z") | 126 | isotime = datetime_val.astimezone(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z") |
133 | if isotime[-2] != ":": | 127 | if isotime[-2] != ":": |
134 | isotime = isotime[:-2] + ":" + isotime[-2:] | 128 | isotime = isotime[:-2] + ":" + isotime[-2:] |
135 | return isotime | 129 | 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 |