File tree Expand file tree Collapse file tree 7 files changed +17
-23
lines changed
Expand file tree Collapse file tree 7 files changed +17
-23
lines changed Original file line number Diff line number Diff line change 11# Copyright 2024 Canonical Ltd.
22# Licensed under the Apache V2, see LICENCE file for details.
33"""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 66import json
77import time
88
9+ from backports .datetime_fromisoformat import datetime_fromisoformat
10+
911
1012class GoCookieJar (cookiejar .FileCookieJar ):
1113 """A CookieJar implementation that reads and writes cookies
@@ -50,7 +52,7 @@ def go_to_py_cookie(go_cookie):
5052 """Convert a Go-style JSON-unmarshaled cookie into a Python cookie"""
5153 expires = None
5254 if go_cookie .get ("Expires" ) is not None :
53- t = datetime . datetime . fromisoformat (go_cookie ["Expires" ])
55+ t = datetime_fromisoformat (go_cookie ["Expires" ])
5456 expires = t .timestamp ()
5557 return cookiejar .Cookie (
5658 version = 0 ,
Original file line number Diff line number Diff line change 11# Copyright 2023 Canonical Ltd.
22# Licensed under the Apache V2, see LICENCE file for details.
33
4- import datetime
54import asyncio
65import ipaddress
76import logging
87import typing
98
9+ from backports .datetime_fromisoformat import datetime_fromisoformat
10+
1011from juju .utils import block_until , juju_ssh_key_paths
1112
1213from . import model , tag
@@ -238,7 +239,7 @@ def agent_status(self):
238239 @property
239240 def agent_status_since (self ):
240241 """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" ])
242243
243244 @property
244245 def agent_version (self ):
@@ -265,9 +266,7 @@ def status_message(self):
265266 @property
266267 def status_since (self ):
267268 """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" ])
271270
272271 @property
273272 def dns_name (self ):
Original file line number Diff line number Diff line change 11# Copyright 2023 Canonical Ltd.
22# Licensed under the Apache V2, see LICENCE file for details.
33
4- import datetime
54import logging
65
6+ from backports .datetime_fromisoformat import datetime_fromisoformat
7+
78from juju .errors import JujuAPIError , JujuError
89
910from . import model , tag
@@ -24,7 +25,7 @@ def agent_status(self):
2425 @property
2526 def agent_status_since (self ):
2627 """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" ])
2829
2930 @property
3031 def is_subordinate (self ):
@@ -51,9 +52,7 @@ def workload_status(self):
5152 @property
5253 def workload_status_since (self ):
5354 """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" ])
5756
5857 @property
5958 def workload_status_message (self ):
Original file line number Diff line number Diff line change 11# Copyright 2023 Canonical Ltd.
22# Licensed under the Apache V2, see LICENCE file for details.
33
4- import datetime
54import logging
65
6+ from backports .datetime_fromisoformat import datetime_fromisoformat
7+
78from . import errors , tag
89from .client import client
910
@@ -30,7 +31,7 @@ def display_name(self):
3031
3132 @property
3233 def last_connection (self ):
33- return datetime . datetime . fromisoformat (self ._user_info .last_connection )
34+ return datetime_fromisoformat (self ._user_info .last_connection )
3435
3536 @property
3637 def access (self ):
Original file line number Diff line number Diff line change 22# Licensed under the Apache V2, see LICENCE file for details.
33"""Tests for the gocookies code."""
44
5- import datetime
65import os
76import shutil
87import tempfile
98import unittest
109import urllib .request
1110
11+ from backports .datetime_fromisoformat import datetime_fromisoformat
12+
1213from juju .client .gocookies import GoCookieJar
1314
1415# cookie_content holds the JSON contents of a Go-produced
@@ -223,9 +224,7 @@ def test_expiry_time(self):
223224 ]"""
224225 jar = self .load_jar (content )
225226 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 ())
229228 self .assertEqual (got_expires , want_expires )
230229
231230 def load_jar (self , content ):
Original file line number Diff line number Diff line change @@ -52,8 +52,6 @@ commands =
5252envdir = {toxworkdir}/py3
5353deps =
5454 backports-datetime-fromisoformat
55- allowlist_externals =
56- pytest
5755commands =
5856 pytest {toxinidir}/tests/unit {posargs}
5957
You can’t perform that action at this time.
0 commit comments