File tree 7 files changed +17
-23
lines changed
7 files changed +17
-23
lines changed Original file line number Diff line number Diff line change 1
1
# Copyright 2024 Canonical Ltd.
2
2
# Licensed under the Apache V2, see LICENCE file for details.
3
3
"""Python Library for Juju."""
4
-
5
- from backports .datetime_fromisoformat import MonkeyPatch
6
-
7
- MonkeyPatch .patch_fromisoformat ()
Original file line number Diff line number Diff line change 6
6
import json
7
7
import time
8
8
9
+ from backports .datetime_fromisoformat import datetime_fromisoformat
10
+
9
11
10
12
class GoCookieJar (cookiejar .FileCookieJar ):
11
13
"""A CookieJar implementation that reads and writes cookies
@@ -50,7 +52,7 @@ def go_to_py_cookie(go_cookie):
50
52
"""Convert a Go-style JSON-unmarshaled cookie into a Python cookie"""
51
53
expires = None
52
54
if go_cookie .get ("Expires" ) is not None :
53
- t = datetime . datetime . fromisoformat (go_cookie ["Expires" ])
55
+ t = datetime_fromisoformat (go_cookie ["Expires" ])
54
56
expires = t .timestamp ()
55
57
return cookiejar .Cookie (
56
58
version = 0 ,
Original file line number Diff line number Diff line change 1
1
# Copyright 2023 Canonical Ltd.
2
2
# Licensed under the Apache V2, see LICENCE file for details.
3
3
4
- import datetime
5
4
import asyncio
6
5
import ipaddress
7
6
import logging
8
7
import typing
9
8
9
+ from backports .datetime_fromisoformat import datetime_fromisoformat
10
+
10
11
from juju .utils import block_until , juju_ssh_key_paths
11
12
12
13
from . import model , tag
@@ -238,7 +239,7 @@ def agent_status(self):
238
239
@property
239
240
def agent_status_since (self ):
240
241
"""Get the time when the `agent_status` was last updated."""
241
- return datetime . datetime . fromisoformat (self .safe_data ["agent-status" ]["since" ])
242
+ return datetime_fromisoformat (self .safe_data ["agent-status" ]["since" ])
242
243
243
244
@property
244
245
def agent_version (self ):
@@ -265,9 +266,7 @@ def status_message(self):
265
266
@property
266
267
def status_since (self ):
267
268
"""Get the time when the `status` was last updated."""
268
- return datetime .datetime .fromisoformat (
269
- self .safe_data ["instance-status" ]["since" ]
270
- )
269
+ return datetime_fromisoformat (self .safe_data ["instance-status" ]["since" ])
271
270
272
271
@property
273
272
def dns_name (self ):
Original file line number Diff line number Diff line change 1
1
# Copyright 2023 Canonical Ltd.
2
2
# Licensed under the Apache V2, see LICENCE file for details.
3
3
4
- import datetime
5
4
import logging
6
5
6
+ from backports .datetime_fromisoformat import datetime_fromisoformat
7
+
7
8
from juju .errors import JujuAPIError , JujuError
8
9
9
10
from . import model , tag
@@ -24,7 +25,7 @@ def agent_status(self):
24
25
@property
25
26
def agent_status_since (self ):
26
27
"""Get the time when the `agent_status` was last updated."""
27
- return datetime . datetime . fromisoformat (self .safe_data ["agent-status" ]["since" ])
28
+ return datetime_fromisoformat (self .safe_data ["agent-status" ]["since" ])
28
29
29
30
@property
30
31
def is_subordinate (self ):
@@ -51,9 +52,7 @@ def workload_status(self):
51
52
@property
52
53
def workload_status_since (self ):
53
54
"""Get the time when the `workload_status` was last updated."""
54
- return datetime .datetime .fromisoformat (
55
- self .safe_data ["workload-status" ]["since" ]
56
- )
55
+ return datetime_fromisoformat (self .safe_data ["workload-status" ]["since" ])
57
56
58
57
@property
59
58
def workload_status_message (self ):
Original file line number Diff line number Diff line change 1
1
# Copyright 2023 Canonical Ltd.
2
2
# Licensed under the Apache V2, see LICENCE file for details.
3
3
4
- import datetime
5
4
import logging
6
5
6
+ from backports .datetime_fromisoformat import datetime_fromisoformat
7
+
7
8
from . import errors , tag
8
9
from .client import client
9
10
@@ -30,7 +31,7 @@ def display_name(self):
30
31
31
32
@property
32
33
def last_connection (self ):
33
- return datetime . datetime . fromisoformat (self ._user_info .last_connection )
34
+ return datetime_fromisoformat (self ._user_info .last_connection )
34
35
35
36
@property
36
37
def access (self ):
Original file line number Diff line number Diff line change 2
2
# Licensed under the Apache V2, see LICENCE file for details.
3
3
"""Tests for the gocookies code."""
4
4
5
- import datetime
6
5
import os
7
6
import shutil
8
7
import tempfile
9
8
import unittest
10
9
import urllib .request
11
10
11
+ from backports .datetime_fromisoformat import datetime_fromisoformat
12
+
12
13
from juju .client .gocookies import GoCookieJar
13
14
14
15
# cookie_content holds the JSON contents of a Go-produced
@@ -223,9 +224,7 @@ def test_expiry_time(self):
223
224
]"""
224
225
jar = self .load_jar (content )
225
226
got_expires = tuple (jar )[0 ].expires
226
- want_expires = int (
227
- datetime .datetime .fromisoformat ("2345-11-15T18:16:08Z" ).timestamp ()
228
- )
227
+ want_expires = int (datetime_fromisoformat ("2345-11-15T18:16:08Z" ).timestamp ())
229
228
self .assertEqual (got_expires , want_expires )
230
229
231
230
def load_jar (self , content ):
Original file line number Diff line number Diff line change @@ -52,8 +52,6 @@ commands =
52
52
envdir = {toxworkdir}/py3
53
53
deps =
54
54
backports-datetime-fromisoformat
55
- allowlist_externals =
56
- pytest
57
55
commands =
58
56
pytest {toxinidir}/tests/unit {posargs}
59
57
You can’t perform that action at this time.
0 commit comments