From 906be858533c051540a8a8db16757cf84508f38b Mon Sep 17 00:00:00 2001 From: Takashi Natsume Date: Sun, 6 Oct 2024 00:56:41 +0900 Subject: [PATCH] Replace deprecated functions in datetime The datetime.utcfromtimestamp() and datetime.utcnow() are deprecated in Python 3.12. Replace datetime.utcfromtimestamp() with datetime.fromtimestamp(). Replace datetime.utcnow() with oslo_utils.timeutils.utcnow(). This bumps oslo.utils to 7.0.0. Change-Id: Ifa8a892aeaece7575a29c979bf48a1c27ec1643f Signed-off-by: Takashi Natsume --- horizon/utils/functions.py | 4 ++-- openstack_dashboard/api/swift.py | 8 ++++++-- requirements.txt | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/horizon/utils/functions.py b/horizon/utils/functions.py index b4d5622d50..92d38f8ee2 100644 --- a/horizon/utils/functions.py +++ b/horizon/utils/functions.py @@ -15,6 +15,7 @@ import decimal import math import re +from oslo_utils import timeutils from oslo_utils import units from django.conf import settings @@ -186,5 +187,4 @@ def format_value(value): def one_year_from_now(): - now = datetime.datetime.utcnow() - return now + datetime.timedelta(days=365) + return timeutils.utcnow() + datetime.timedelta(days=365) diff --git a/openstack_dashboard/api/swift.py b/openstack_dashboard/api/swift.py index ff67d5592c..b4a9bc6a6e 100644 --- a/openstack_dashboard/api/swift.py +++ b/openstack_dashboard/api/swift.py @@ -198,7 +198,9 @@ def swift_get_container(request, container_name, with_data=False): parameters = parse.quote(container_name.encode('utf8')) public_url = swift_endpoint + '/' + parameters ts_float = float(headers.get('x-timestamp')) - timestamp = datetime.utcfromtimestamp(ts_float).isoformat() + timestamp = datetime.fromtimestamp( + ts_float, tz=datetime.timezone.utc).replace( + tzinfo=None).isoformat() except Exception: pass container_info = { @@ -411,7 +413,9 @@ def swift_get_object(request, container_name, object_name, with_data=True, timestamp = None try: ts_float = float(headers.get('x-timestamp')) - timestamp = datetime.utcfromtimestamp(ts_float).isoformat() + timestamp = datetime.fromtimestamp( + ts_float, tz=datetime.timezone.utc).replace( + tzinfo=None).isoformat() except Exception: pass obj_info = { diff --git a/requirements.txt b/requirements.txt index e7178e2028..a6cdf32309 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ oslo.i18n>=5.1.0 # Apache-2.0 oslo.policy>=3.11.0 # Apache-2.0 oslo.serialization>=4.3.0 # Apache-2.0 oslo.upgradecheck>=1.5.0 # Apache-2.0 -oslo.utils>=4.12.0 # Apache-2.0 +oslo.utils>=7.0.0 # Apache-2.0 osprofiler>=3.4.2 # Apache-2.0 pyScss>=1.4.0 # MIT License python-cinderclient>=8.0.0 # Apache-2.0