File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import json
77import time
88
9- import pyrfc3339
9+ from backports . datetime_fromisoformat import datetime_fromisoformat
1010
1111
1212class GoCookieJar (cookiejar .FileCookieJar ):
@@ -52,7 +52,7 @@ def go_to_py_cookie(go_cookie):
5252 """Convert a Go-style JSON-unmarshaled cookie into a Python cookie"""
5353 expires = None
5454 if go_cookie .get ("Expires" ) is not None :
55- t = pyrfc3339 . parse (go_cookie ["Expires" ])
55+ t = datetime_fromisoformat (go_cookie ["Expires" ])
5656 expires = t .timestamp ()
5757 return cookiejar .Cookie (
5858 version = 0 ,
@@ -101,8 +101,9 @@ def py_to_go_cookie(py_cookie):
101101 if py_cookie .path_specified :
102102 go_cookie ["Path" ] = py_cookie .path
103103 if py_cookie .expires is not None :
104- unix_time = datetime .datetime .fromtimestamp (py_cookie .expires )
105104 # Note: fromtimestamp bizarrely produces a time without
106105 # a time zone, so we need to use accept_naive.
107- go_cookie ["Expires" ] = pyrfc3339 .generate (unix_time , accept_naive = True )
106+ go_cookie ["Expires" ] = datetime .datetime .fromtimestamp (
107+ py_cookie .expires
108+ ).isoformat ()
108109 return go_cookie
Original file line number Diff line number Diff line change 66import logging
77import typing
88
9- import pyrfc3339
9+ from backports . datetime_fromisoformat import datetime_fromisoformat
1010
1111from juju .utils import block_until , juju_ssh_key_paths
1212
@@ -239,7 +239,7 @@ def agent_status(self):
239239 @property
240240 def agent_status_since (self ):
241241 """Get the time when the `agent_status` was last updated."""
242- return pyrfc3339 . parse (self .safe_data ["agent-status" ]["since" ])
242+ return datetime_fromisoformat (self .safe_data ["agent-status" ]["since" ])
243243
244244 @property
245245 def agent_version (self ):
@@ -266,7 +266,7 @@ def status_message(self):
266266 @property
267267 def status_since (self ):
268268 """Get the time when the `status` was last updated."""
269- return pyrfc3339 . parse (self .safe_data ["instance-status" ]["since" ])
269+ return datetime_fromisoformat (self .safe_data ["instance-status" ]["since" ])
270270
271271 @property
272272 def dns_name (self ):
Original file line number Diff line number Diff line change 33
44import logging
55
6- import pyrfc3339
6+ from backports . datetime_fromisoformat import datetime_fromisoformat
77
88from juju .errors import JujuAPIError , JujuError
99
@@ -27,7 +27,7 @@ def agent_status(self):
2727 @property
2828 def agent_status_since (self ):
2929 """Get the time when the `agent_status` was last updated."""
30- return pyrfc3339 . parse (self .safe_data ["agent-status" ]["since" ])
30+ return datetime_fromisoformat (self .safe_data ["agent-status" ]["since" ])
3131
3232 @property
3333 def is_subordinate (self ):
@@ -54,7 +54,7 @@ def workload_status(self):
5454 @property
5555 def workload_status_since (self ):
5656 """Get the time when the `workload_status` was last updated."""
57- return pyrfc3339 . parse (self .safe_data ["workload-status" ]["since" ])
57+ return datetime_fromisoformat (self .safe_data ["workload-status" ]["since" ])
5858
5959 @property
6060 def workload_status_message (self ):
Original file line number Diff line number Diff line change 33
44import logging
55
6- import pyrfc3339
6+ from backports . datetime_fromisoformat import datetime_fromisoformat
77
88from . import errors , tag
99from .client import client
@@ -31,7 +31,7 @@ def display_name(self):
3131
3232 @property
3333 def last_connection (self ):
34- return pyrfc3339 . parse (self ._user_info .last_connection )
34+ return datetime_fromisoformat (self ._user_info .last_connection )
3535
3636 @property
3737 def access (self ):
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ classifiers = [
2323]
2424dependencies = [
2525 " macaroonbakery>=1.1,<2.0" ,
26- " pyRFC3339>=1.0,<2.0" ,
2726 " pyyaml>=5.1.2" ,
2827 " websockets>=13.0.1" ,
2928 " paramiko>=2.4.0" ,
@@ -35,6 +34,7 @@ dependencies = [
3534 " packaging" ,
3635 " typing-extensions>=4.5.0" ,
3736 ' backports.strenum>=1.3.1; python_version < "3.11"' ,
37+ " backports-datetime-fromisoformat>=2.0.2" ,
3838]
3939[project .optional-dependencies ]
4040dev = [
Original file line number Diff line number Diff line change 2121 package_data = {"juju" : ["py.typed" ]},
2222 install_requires = [
2323 "macaroonbakery>=1.1,<2.0" ,
24- "pyRFC3339>=1.0,<2.0" ,
2524 "pyyaml>=5.1.2" ,
2625 "websockets>=13.0.1" ,
2726 "paramiko>=2.4.0" ,
3332 "packaging" ,
3433 "typing-extensions>=4.5.0" ,
3534 'backports.strenum>=1.3.1; python_version < "3.11"' ,
35+ "backports-datetime-fromisoformat>=2.0.2" ,
3636 ],
3737 extras_require = {
3838 "dev" : [
Original file line number Diff line number Diff line change 88import unittest
99import urllib .request
1010
11- import pyrfc3339
11+ from backports . datetime_fromisoformat import datetime_fromisoformat
1212
1313from juju .client .gocookies import GoCookieJar
1414
1515# cookie_content holds the JSON contents of a Go-produced
1616# cookie file (reformatted so it's not all on one line but
1717# otherwise unchanged).
18+
1819cookie_content = """
1920[
2021 {
@@ -223,7 +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 (pyrfc3339 . parse ("2345-11-15T18:16:08Z" ).timestamp ())
227+ want_expires = int (datetime_fromisoformat ("2345-11-15T18:16:08Z" ).timestamp ())
227228 self .assertEqual (got_expires , want_expires )
228229
229230 def load_jar (self , content ):
You can’t perform that action at this time.
0 commit comments