Replace deprecated datetime.utcfromtimestamp()
The datetime.utcfromtimestamp() is deprecated in Python 3.12. Replace datetime.utcfromtimestamp() with datetime.fromtimestamp(). Change-Id: I495e783c3a7c37e1b328c5d0920553d0d1eb9352 Signed-off-by: Takashi Natsume <takanattie@gmail.com>
This commit is contained in:
parent
b438cffeb5
commit
568cd86eee
@ -142,11 +142,13 @@ class ClaimController(storage.Claim):
|
|||||||
|
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
claim_expires = now + ttl
|
claim_expires = now + ttl
|
||||||
claim_expires_dt = datetime.datetime.utcfromtimestamp(claim_expires)
|
claim_expires_dt = datetime.datetime.fromtimestamp(
|
||||||
|
claim_expires, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
|
|
||||||
message_ttl = ttl + grace
|
message_ttl = ttl + grace
|
||||||
message_expiration = datetime.datetime.utcfromtimestamp(
|
message_expiration = datetime.datetime.fromtimestamp(
|
||||||
claim_expires + grace)
|
claim_expires + grace, tz=datetime.timezone.utc).replace(
|
||||||
|
tzinfo=None)
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
'id': oid,
|
'id': oid,
|
||||||
@ -293,10 +295,12 @@ class ClaimController(storage.Claim):
|
|||||||
grace = metadata['grace']
|
grace = metadata['grace']
|
||||||
ttl = metadata['ttl']
|
ttl = metadata['ttl']
|
||||||
claim_expires = now + ttl
|
claim_expires = now + ttl
|
||||||
claim_expires_dt = datetime.datetime.utcfromtimestamp(claim_expires)
|
claim_expires_dt = datetime.datetime.fromtimestamp(
|
||||||
|
claim_expires, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
message_ttl = ttl + grace
|
message_ttl = ttl + grace
|
||||||
message_expires = datetime.datetime.utcfromtimestamp(
|
message_expires = datetime.datetime.fromtimestamp(
|
||||||
claim_expires + grace)
|
claim_expires + grace, tz=datetime.timezone.utc).replace(
|
||||||
|
tzinfo=None)
|
||||||
|
|
||||||
msg_ctrl = self.driver.message_controller
|
msg_ctrl = self.driver.message_controller
|
||||||
claimed = msg_ctrl._claimed(queue, cid, expires=now,
|
claimed = msg_ctrl._claimed(queue, cid, expires=now,
|
||||||
|
@ -668,7 +668,8 @@ class MessageController(storage.Message):
|
|||||||
# is an upsert.
|
# is an upsert.
|
||||||
self._get_counter(queue_name, project)
|
self._get_counter(queue_name, project)
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
collection = self._collection(queue_name, project)
|
collection = self._collection(queue_name, project)
|
||||||
|
|
||||||
messages = list(messages)
|
messages = list(messages)
|
||||||
@ -854,7 +855,8 @@ class FIFOMessageController(MessageController):
|
|||||||
# is an upsert.
|
# is an upsert.
|
||||||
self._get_counter(queue_name, project)
|
self._get_counter(queue_name, project)
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
collection = self._collection(queue_name, project)
|
collection = self._collection(queue_name, project)
|
||||||
|
|
||||||
# Set the next basis marker for the first attempt.
|
# Set the next basis marker for the first attempt.
|
||||||
|
@ -104,7 +104,8 @@ class SubscriptionController(base.Subscription):
|
|||||||
def create(self, queue, subscriber, ttl, options, project=None):
|
def create(self, queue, subscriber, ttl, options, project=None):
|
||||||
source = queue
|
source = queue
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
expires = now_dt + datetime.timedelta(seconds=ttl)
|
expires = now_dt + datetime.timedelta(seconds=ttl)
|
||||||
confirmed = False
|
confirmed = False
|
||||||
|
|
||||||
@ -138,7 +139,8 @@ class SubscriptionController(base.Subscription):
|
|||||||
new_ttl = fields.get('t')
|
new_ttl = fields.get('t')
|
||||||
if new_ttl is not None:
|
if new_ttl is not None:
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
expires = now_dt + datetime.timedelta(seconds=new_ttl)
|
expires = now_dt + datetime.timedelta(seconds=new_ttl)
|
||||||
fields['e'] = expires
|
fields['e'] = expires
|
||||||
|
|
||||||
|
@ -565,7 +565,8 @@ class MessageController(storage.Message):
|
|||||||
# is an upsert.
|
# is an upsert.
|
||||||
self._get_counter(topic_name, project)
|
self._get_counter(topic_name, project)
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
collection = self._collection(topic_name, project)
|
collection = self._collection(topic_name, project)
|
||||||
|
|
||||||
messages = list(messages)
|
messages = list(messages)
|
||||||
@ -753,7 +754,8 @@ class FIFOMessageController(MessageController):
|
|||||||
# is an upsert.
|
# is an upsert.
|
||||||
self._get_counter(topic_name, project)
|
self._get_counter(topic_name, project)
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
collection = self._collection(topic_name, project)
|
collection = self._collection(topic_name, project)
|
||||||
|
|
||||||
# Set the next basis marker for the first attempt.
|
# Set the next basis marker for the first attempt.
|
||||||
|
@ -31,7 +31,8 @@ from zaqar.storage import errors as storage_errors
|
|||||||
|
|
||||||
# BSON ObjectId gives TZ-aware datetime, so we generate a
|
# BSON ObjectId gives TZ-aware datetime, so we generate a
|
||||||
# TZ-aware UNIX epoch for convenience.
|
# TZ-aware UNIX epoch for convenience.
|
||||||
EPOCH = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=tz_util.utc)
|
EPOCH = datetime.datetime.fromtimestamp(
|
||||||
|
0, tz=datetime.timezone.utc).replace(tzinfo=tz_util.utc)
|
||||||
|
|
||||||
# NOTE(cpp-cabrera): the authoritative form of project/queue keys.
|
# NOTE(cpp-cabrera): the authoritative form of project/queue keys.
|
||||||
PROJ_QUEUE_KEY = 'p_q'
|
PROJ_QUEUE_KEY = 'p_q'
|
||||||
@ -133,7 +134,8 @@ def stat_message(message, now):
|
|||||||
msg_id = message['id']
|
msg_id = message['id']
|
||||||
created = oid_ts(to_oid(msg_id))
|
created = oid_ts(to_oid(msg_id))
|
||||||
age = now - created
|
age = now - created
|
||||||
created_iso = datetime.datetime.utcfromtimestamp(created).strftime(
|
created_iso = datetime.datetime.fromtimestamp(
|
||||||
|
created, tz=datetime.timezone.utc).replace(tzinfo=None).strftime(
|
||||||
'%Y-%m-%dT%H:%M:%SZ')
|
'%Y-%m-%dT%H:%M:%SZ')
|
||||||
return {
|
return {
|
||||||
'id': msg_id,
|
'id': msg_id,
|
||||||
|
@ -237,8 +237,9 @@ class Message(MessageEnvelope):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if include_created:
|
if include_created:
|
||||||
created_iso = datetime.datetime.utcfromtimestamp(
|
created_iso = datetime.datetime.fromtimestamp(
|
||||||
self.created).strftime('%Y-%m-%dT%H:%M:%SZ')
|
self.created, tz=datetime.timezone.utc).replace(
|
||||||
|
tzinfo=None).strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
basic_msg['created'] = created_iso
|
basic_msg['created'] = created_iso
|
||||||
if self.checksum:
|
if self.checksum:
|
||||||
basic_msg['checksum'] = self.checksum
|
basic_msg['checksum'] = self.checksum
|
||||||
|
@ -352,8 +352,9 @@ class MessageQueueHandler(object):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
created = float(headers['x-timestamp'])
|
created = float(headers['x-timestamp'])
|
||||||
created_iso = datetime.datetime.utcfromtimestamp(
|
created_iso = datetime.datetime.fromtimestamp(
|
||||||
created).strftime('%Y-%m-%dT%H:%M:%SZ')
|
created, tz=datetime.timezone.utc).replace(
|
||||||
|
tzinfo=None).strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
newest = {
|
newest = {
|
||||||
'id': obj['name'],
|
'id': obj['name'],
|
||||||
'age': now - created,
|
'age': now - created,
|
||||||
@ -442,8 +443,9 @@ class MessageTopicHandler(object):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
created = float(headers['x-timestamp'])
|
created = float(headers['x-timestamp'])
|
||||||
created_iso = datetime.datetime.utcfromtimestamp(
|
created_iso = datetime.datetime.fromtimestamp(
|
||||||
created).strftime('%Y-%m-%dT%H:%M:%SZ')
|
created, tz=datetime.timezone.utc).replace(
|
||||||
|
tzinfo=None).strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
newest = {
|
newest = {
|
||||||
'id': obj['name'],
|
'id': obj['name'],
|
||||||
'age': now - created,
|
'age': now - created,
|
||||||
|
@ -598,7 +598,8 @@ class Validator(object):
|
|||||||
# NOTE(flwang): By this change, technically, user can set a very
|
# NOTE(flwang): By this change, technically, user can set a very
|
||||||
# big TTL so as to get a very long subscription.
|
# big TTL so as to get a very long subscription.
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
msg = _(u'The TTL seconds for a subscription plus current time'
|
msg = _(u'The TTL seconds for a subscription plus current time'
|
||||||
' must be less than {0}.')
|
' must be less than {0}.')
|
||||||
try:
|
try:
|
||||||
|
@ -206,7 +206,8 @@ class CollectionResource(object):
|
|||||||
raise wsgi_errors.HTTPServiceUnavailable(description)
|
raise wsgi_errors.HTTPServiceUnavailable(description)
|
||||||
|
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
expires = now_dt + datetime.timedelta(seconds=ttl)
|
expires = now_dt + datetime.timedelta(seconds=ttl)
|
||||||
api_version = req.path.split('/')[1]
|
api_version = req.path.split('/')[1]
|
||||||
if created:
|
if created:
|
||||||
@ -272,7 +273,8 @@ class ConfirmResource(object):
|
|||||||
confirmed=confirmed)
|
confirmed=confirmed)
|
||||||
if confirmed is False:
|
if confirmed is False:
|
||||||
now = timeutils.utcnow_ts()
|
now = timeutils.utcnow_ts()
|
||||||
now_dt = datetime.datetime.utcfromtimestamp(now)
|
now_dt = datetime.datetime.fromtimestamp(
|
||||||
|
now, tz=datetime.timezone.utc).replace(tzinfo=None)
|
||||||
ttl = self._conf.transport.default_subscription_ttl
|
ttl = self._conf.transport.default_subscription_ttl
|
||||||
expires = now_dt + datetime.timedelta(seconds=ttl)
|
expires = now_dt + datetime.timedelta(seconds=ttl)
|
||||||
api_version = req.path.split('/')[1]
|
api_version = req.path.split('/')[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user