File tree 5 files changed +21
-19
lines changed
5 files changed +21
-19
lines changed Original file line number Diff line number Diff line change 6
6
import json
7
7
import time
8
8
9
- import pyrfc3339
10
-
11
9
12
10
class GoCookieJar (cookiejar .FileCookieJar ):
13
11
"""A CookieJar implementation that reads and writes cookies
@@ -52,7 +50,7 @@ def go_to_py_cookie(go_cookie):
52
50
"""Convert a Go-style JSON-unmarshaled cookie into a Python cookie"""
53
51
expires = None
54
52
if go_cookie .get ("Expires" ) is not None :
55
- t = pyrfc3339 . parse (go_cookie ["Expires" ])
53
+ t = datetime . datetime . fromisoformat (go_cookie ["Expires" ])
56
54
expires = t .timestamp ()
57
55
return cookiejar .Cookie (
58
56
version = 0 ,
@@ -101,8 +99,9 @@ def py_to_go_cookie(py_cookie):
101
99
if py_cookie .path_specified :
102
100
go_cookie ["Path" ] = py_cookie .path
103
101
if py_cookie .expires is not None :
104
- unix_time = datetime .datetime .fromtimestamp (py_cookie .expires )
105
102
# Note: fromtimestamp bizarrely produces a time without
106
103
# 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 ()
108
107
return go_cookie
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
4
5
import ipaddress
5
6
import logging
6
7
import typing
7
8
8
- import pyrfc3339
9
-
10
9
from juju .utils import block_until , juju_ssh_key_paths
11
10
12
11
from . import jasyncio , model , tag
@@ -238,7 +237,7 @@ def agent_status(self):
238
237
@property
239
238
def agent_status_since (self ):
240
239
"""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" ])
242
241
243
242
@property
244
243
def agent_version (self ):
@@ -265,7 +264,9 @@ def status_message(self):
265
264
@property
266
265
def status_since (self ):
267
266
"""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
+ )
269
270
270
271
@property
271
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
4
5
import logging
5
6
6
- import pyrfc3339
7
-
8
7
from juju .errors import JujuAPIError , JujuError
9
8
10
9
from . import model , tag
@@ -25,7 +24,7 @@ def agent_status(self):
25
24
@property
26
25
def agent_status_since (self ):
27
26
"""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" ])
29
28
30
29
@property
31
30
def is_subordinate (self ):
@@ -52,7 +51,9 @@ def workload_status(self):
52
51
@property
53
52
def workload_status_since (self ):
54
53
"""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
+ )
56
57
57
58
@property
58
59
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
4
5
import logging
5
6
6
- import pyrfc3339
7
-
8
7
from . import errors , tag
9
8
from .client import client
10
9
@@ -31,7 +30,7 @@ def display_name(self):
31
30
32
31
@property
33
32
def last_connection (self ):
34
- return pyrfc3339 . parse (self ._user_info .last_connection )
33
+ return datetime . datetime . fromisoformat (self ._user_info .last_connection )
35
34
36
35
@property
37
36
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
5
6
import os
6
7
import shutil
7
8
import tempfile
8
9
import unittest
9
10
import urllib .request
10
11
11
- import pyrfc3339
12
-
13
12
from juju .client .gocookies import GoCookieJar
14
13
15
14
# cookie_content holds the JSON contents of a Go-produced
16
15
# cookie file (reformatted so it's not all on one line but
17
16
# otherwise unchanged).
17
+
18
18
cookie_content = """
19
19
[
20
20
{
@@ -223,7 +223,9 @@ def test_expiry_time(self):
223
223
]"""
224
224
jar = self .load_jar (content )
225
225
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
+ )
227
229
self .assertEqual (got_expires , want_expires )
228
230
229
231
def load_jar (self , content ):
You can’t perform that action at this time.
0 commit comments