82 lines
3.5 KiB
Diff
82 lines
3.5 KiB
Diff
Taken from https://github.com/tornadoweb/tornado/pull/3335
|
|
|
|
From 0bfca3f2d72a0c6e5d3ba17caac88a79e7b4e0dd Mon Sep 17 00:00:00 2001
|
|
From: Thomas Grainger <tagrain@gmail.com>
|
|
Date: Tue, 3 Oct 2023 15:08:08 +0100
|
|
Subject: [PATCH] remove calls to utcnow and utcfromtimestamp
|
|
|
|
---
|
|
demos/blog/templates/feed.xml | 2 +-
|
|
demos/s3server/s3server.py | 16 +++++++++++-----
|
|
tornado/web.py | 3 ++-
|
|
3 files changed, 14 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/demos/blog/templates/feed.xml b/demos/blog/templates/feed.xml
|
|
index a98826c8d3..4a4a252f60 100644
|
|
--- a/demos/blog/templates/feed.xml
|
|
+++ b/demos/blog/templates/feed.xml
|
|
@@ -5,7 +5,7 @@
|
|
{% if len(entries) > 0 %}
|
|
<updated>{{ max(e.updated for e in entries).strftime(date_format) }}</updated>
|
|
{% else %}
|
|
- <updated>{{ datetime.datetime.utcnow().strftime(date_format) }}</updated>
|
|
+ <updated>{{ datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None).strftime(date_format) }}</updated>
|
|
{% end %}
|
|
<id>http://{{ request.host }}/</id>
|
|
<link rel="alternate" href="http://{{ request.host }}/" title="{{ handler.settings["blog_title"] }}" type="text/html"/>
|
|
diff --git a/demos/s3server/s3server.py b/demos/s3server/s3server.py
|
|
index 5c5e6af2ba..104a7c8f81 100644
|
|
--- a/demos/s3server/s3server.py
|
|
+++ b/demos/s3server/s3server.py
|
|
@@ -138,7 +138,9 @@ def get(self):
|
|
buckets.append(
|
|
{
|
|
"Name": name,
|
|
- "CreationDate": datetime.datetime.utcfromtimestamp(info.st_ctime),
|
|
+ "CreationDate": datetime.datetime.fromtimestamp(
|
|
+ info.st_ctime, datetime.timezone.utc
|
|
+ ).replace(tzinfo=None),
|
|
}
|
|
)
|
|
self.render_xml({"ListAllMyBucketsResult": {"Buckets": {"Bucket": buckets}}})
|
|
@@ -183,9 +185,10 @@ def get(self, bucket_name):
|
|
info = os.stat(object_path)
|
|
c.update(
|
|
{
|
|
- "LastModified": datetime.datetime.utcfromtimestamp(
|
|
- info.st_mtime
|
|
- ),
|
|
+ "LastModified": datetime.datetime.fromtimestamp(
|
|
+ info.st_mtime,
|
|
+ datetime.timezone.utc,
|
|
+ ).replace(tzinfo=None),
|
|
"Size": info.st_size,
|
|
}
|
|
)
|
|
@@ -231,7 +234,10 @@ def get(self, bucket, object_name):
|
|
info = os.stat(path)
|
|
self.set_header("Content-Type", "application/unknown")
|
|
self.set_header(
|
|
- "Last-Modified", datetime.datetime.utcfromtimestamp(info.st_mtime)
|
|
+ "Last-Modified",
|
|
+ datetime.datetime.fromtimestamp(
|
|
+ info.st_mtime, datetime.timezone.utc
|
|
+ ).replace(tzinfo=None),
|
|
)
|
|
with open(path, "rb") as object_file:
|
|
self.finish(object_file.read())
|
|
diff --git a/tornado/web.py b/tornado/web.py
|
|
index 333f736808..4416e2013e 100644
|
|
--- a/tornado/web.py
|
|
+++ b/tornado/web.py
|
|
@@ -2797,7 +2797,8 @@ def set_headers(self) -> None:
|
|
if cache_time > 0:
|
|
self.set_header(
|
|
"Expires",
|
|
- datetime.datetime.utcnow() + datetime.timedelta(seconds=cache_time),
|
|
+ datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
|
|
+ + datetime.timedelta(seconds=cache_time),
|
|
)
|
|
self.set_header("Cache-Control", "max-age=" + str(cache_time))
|
|
|