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 <takanattie@gmail.com>
This commit is contained in:
Takashi Natsume 2024-10-06 00:56:41 +09:00
parent d3c4ffe496
commit 906be85853
3 changed files with 9 additions and 5 deletions

View File

@ -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)

View File

@ -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 = {

View File

@ -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