This repository was archived by the owner on Mar 6, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,7 +92,14 @@ def utcnow():
9292 Returns:
9393 datetime: The current time in UTC.
9494 """
95- return datetime .datetime .utcnow ()
95+ # We used datetime.utcnow() before, since it's deprecated from python 3.12,
96+ # we are using datetime.now(timezone.utc) now. "utcnow()" is offset-native
97+ # (no timezone info), but "now()" is offset-aware (with timezone info).
98+ # This will cause datetime comparison problem. For backward compatibility,
99+ # we need to remove the timezone info.
100+ now = datetime .datetime .now (datetime .timezone .utc )
101+ now = now .replace (tzinfo = None )
102+ return now
96103
97104
98105def datetime_to_secs (value ):
Original file line number Diff line number Diff line change @@ -55,17 +55,15 @@ def test_expired_and_valid():
5555 # Set the expiration to one second more than now plus the clock skew
5656 # accomodation. These credentials should be valid.
5757 credentials .expiry = (
58- datetime .datetime .utcnow ()
59- + _helpers .REFRESH_THRESHOLD
60- + datetime .timedelta (seconds = 1 )
58+ _helpers .utcnow () + _helpers .REFRESH_THRESHOLD + datetime .timedelta (seconds = 1 )
6159 )
6260
6361 assert credentials .valid
6462 assert not credentials .expired
6563
6664 # Set the credentials expiration to now. Because of the clock skew
6765 # accomodation, these credentials should report as expired.
68- credentials .expiry = datetime . datetime .utcnow ()
66+ credentials .expiry = _helpers .utcnow ()
6967
7068 assert not credentials .valid
7169 assert credentials .expired
Original file line number Diff line number Diff line change @@ -46,17 +46,15 @@ def test_expired_and_valid():
4646 # Set the expiration to one second more than now plus the clock skew
4747 # accomodation. These credentials should be valid.
4848 credentials .expiry = (
49- datetime .datetime .utcnow ()
50- + _helpers .REFRESH_THRESHOLD
51- + datetime .timedelta (seconds = 1 )
49+ _helpers .utcnow () + _helpers .REFRESH_THRESHOLD + datetime .timedelta (seconds = 1 )
5250 )
5351
5452 assert credentials .valid
5553 assert not credentials .expired
5654
5755 # Set the credentials expiration to now. Because of the clock skew
5856 # accomodation, these credentials should report as expired.
59- credentials .expiry = datetime . datetime .utcnow ()
57+ credentials .expiry = _helpers .utcnow ()
6058
6159 assert not credentials .valid
6260 assert credentials .expired
You can’t perform that action at this time.
0 commit comments