Fix compatibility with Python 3.8
We removed compatibility with Python 3.8 once but it was added back to tested runtimes for 2023.2. Thus we have to make sure the code works with Python 3.8, which was broken by [1]. Note that ptyz is added back to requirmenets.txt and is now required regardless of the python version. This is a short term solution until we figure out the way to fix the requirement-check job (or we again remove python 3.8 support). [1] 7d9fda625fd5e16c91a9b95920c477f857193389 Change-Id: Ica344021a4e922bcfd20d20cffcce585a5742c8f
This commit is contained in:
parent
439f39bdbf
commit
2c8668c4e5
@ -22,10 +22,16 @@ import datetime
|
||||
import functools
|
||||
import logging
|
||||
import time
|
||||
import zoneinfo
|
||||
|
||||
import iso8601
|
||||
|
||||
try:
|
||||
import zoneinfo
|
||||
except ImportError:
|
||||
# zoneinfo is available in Python >= 3.9
|
||||
import pytz
|
||||
zoneinfo = None
|
||||
|
||||
from oslo_utils import reflection
|
||||
|
||||
# ISO 8601 extended time format with microseconds
|
||||
@ -225,8 +231,14 @@ def unmarshall_time(tyme):
|
||||
if tzname:
|
||||
# Need to handle either iso8601 or python UTC format
|
||||
tzname = 'UTC' if tzname == 'UTC+00:00' else tzname
|
||||
tzinfo = zoneinfo.ZoneInfo(tzname)
|
||||
dt = dt.replace(tzinfo=tzinfo)
|
||||
|
||||
if zoneinfo:
|
||||
tzinfo = zoneinfo.ZoneInfo(tzname)
|
||||
dt = dt.replace(tzinfo=tzinfo)
|
||||
else:
|
||||
tzinfo = pytz.timezone(tzname)
|
||||
dt = tzinfo.localize(dt)
|
||||
|
||||
return dt
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
---
|
||||
other:
|
||||
- |
|
||||
Implement zoneinfo to allow us to remove pytz's dependency. zoneinfo
|
||||
was introduced by python 3.9, and the series 2023.2 (bobcat) set py39
|
||||
as the minimal supported runtime, so we are able to remove pytz.
|
||||
Implement zoneinfo to allow us to remove pytz's dependency for Python 3.9
|
||||
and 3.10.
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
iso8601>=0.1.11 # MIT
|
||||
oslo.i18n>=3.15.3 # Apache-2.0
|
||||
pytz>=2013.6 # MIT
|
||||
netaddr>=0.7.18 # BSD
|
||||
netifaces>=0.10.4 # MIT
|
||||
debtcollector>=1.2.0 # Apache-2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user