Skip to content

Commit 5a9370d

Browse files
chore: remove pyrfc3339 and change to datetime.datetime.fromisoformat() and datetime.datetime.isoformat()
1 parent b5f7a5a commit 5a9370d

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

juju/client/gocookies.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import json
77
import time
88

9-
import pyrfc3339
10-
119

1210
class GoCookieJar(cookiejar.FileCookieJar):
1311
"""A CookieJar implementation that reads and writes cookies
@@ -52,7 +50,7 @@ def go_to_py_cookie(go_cookie):
5250
"""Convert a Go-style JSON-unmarshaled cookie into a Python cookie"""
5351
expires = None
5452
if go_cookie.get("Expires") is not None:
55-
t = pyrfc3339.parse(go_cookie["Expires"])
53+
t = datetime.datetime.fromisoformat(go_cookie["Expires"])
5654
expires = t.timestamp()
5755
return cookiejar.Cookie(
5856
version=0,
@@ -101,8 +99,9 @@ def py_to_go_cookie(py_cookie):
10199
if py_cookie.path_specified:
102100
go_cookie["Path"] = py_cookie.path
103101
if py_cookie.expires is not None:
104-
unix_time = datetime.datetime.fromtimestamp(py_cookie.expires)
105102
# Note: fromtimestamp bizarrely produces a time without
106103
# a time zone, so we need to use accept_naive.
107-
go_cookie["Expires"] = pyrfc3339.generate(unix_time, accept_naive=True)
104+
go_cookie["Expires"] = datetime.datetime.fromtimestamp(
105+
py_cookie.expires
106+
).isoformat()
108107
return go_cookie

juju/machine.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
33

4+
import datetime
45
import ipaddress
56
import logging
67
import typing
78

8-
import pyrfc3339
9-
109
from juju.utils import block_until, juju_ssh_key_paths
1110

1211
from . import jasyncio, model, tag
@@ -238,7 +237,7 @@ def agent_status(self):
238237
@property
239238
def agent_status_since(self):
240239
"""Get the time when the `agent_status` was last updated."""
241-
return pyrfc3339.parse(self.safe_data["agent-status"]["since"])
240+
return datetime.datetime.fromisoformat(self.safe_data["agent-status"]["since"])
242241

243242
@property
244243
def agent_version(self):
@@ -265,7 +264,9 @@ def status_message(self):
265264
@property
266265
def status_since(self):
267266
"""Get the time when the `status` was last updated."""
268-
return pyrfc3339.parse(self.safe_data["instance-status"]["since"])
267+
return datetime.datetime.fromisoformat(
268+
self.safe_data["instance-status"]["since"]
269+
)
269270

270271
@property
271272
def dns_name(self):

juju/unit.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
33

4+
import datetime
45
import logging
56

6-
import pyrfc3339
7-
87
from juju.errors import JujuAPIError, JujuError
98

109
from . import model, tag
@@ -25,7 +24,7 @@ def agent_status(self):
2524
@property
2625
def agent_status_since(self):
2726
"""Get the time when the `agent_status` was last updated."""
28-
return pyrfc3339.parse(self.safe_data["agent-status"]["since"])
27+
return datetime.datetime.fromisoformat(self.safe_data["agent-status"]["since"])
2928

3029
@property
3130
def is_subordinate(self):
@@ -52,7 +51,9 @@ def workload_status(self):
5251
@property
5352
def workload_status_since(self):
5453
"""Get the time when the `workload_status` was last updated."""
55-
return pyrfc3339.parse(self.safe_data["workload-status"]["since"])
54+
return datetime.datetime.fromisoformat(
55+
self.safe_data["workload-status"]["since"]
56+
)
5657

5758
@property
5859
def workload_status_message(self):

juju/user.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
33

4+
import datetime
45
import logging
56

6-
import pyrfc3339
7-
87
from . import errors, tag
98
from .client import client
109

@@ -31,7 +30,7 @@ def display_name(self):
3130

3231
@property
3332
def last_connection(self):
34-
return pyrfc3339.parse(self._user_info.last_connection)
33+
return datetime.datetime.fromisoformat(self._user_info.last_connection)
3534

3635
@property
3736
def access(self):

tests/unit/test_gocookies.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
# Licensed under the Apache V2, see LICENCE file for details.
33
"""Tests for the gocookies code."""
44

5+
import datetime
56
import os
67
import shutil
78
import tempfile
89
import unittest
910
import urllib.request
1011

11-
import pyrfc3339
12-
1312
from juju.client.gocookies import GoCookieJar
1413

1514
# cookie_content holds the JSON contents of a Go-produced
1615
# cookie file (reformatted so it's not all on one line but
1716
# otherwise unchanged).
17+
1818
cookie_content = """
1919
[
2020
{
@@ -223,7 +223,9 @@ def test_expiry_time(self):
223223
]"""
224224
jar = self.load_jar(content)
225225
got_expires = tuple(jar)[0].expires
226-
want_expires = int(pyrfc3339.parse("2345-11-15T18:16:08Z").timestamp())
226+
want_expires = int(
227+
datetime.datetime.fromisoformat("2345-11-15T18:16:08Z").timestamp()
228+
)
227229
self.assertEqual(got_expires, want_expires)
228230

229231
def load_jar(self, content):

0 commit comments

Comments
 (0)