Skip to content

Commit a6dfd70

Browse files
authored
Merge pull request #3341 from bdarnell/more-utcnow
web,demos: Remove more uses of deprecated datetime utc methods
2 parents 55db80e + c60d80c commit a6dfd70

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

Diff for: demos/blog/templates/feed.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{% if len(entries) > 0 %}
66
<updated>{{ max(e.updated for e in entries).strftime(date_format) }}</updated>
77
{% else %}
8-
<updated>{{ datetime.datetime.utcnow().strftime(date_format) }}</updated>
8+
<updated>{{ datetime.datetime.now(datetime.timezone.utc).strftime(date_format) }}</updated>
99
{% end %}
1010
<id>http://{{ request.host }}/</id>
1111
<link rel="alternate" href="http://{{ request.host }}/" title="{{ handler.settings["blog_title"] }}" type="text/html"/>

Diff for: demos/s3server/s3server.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def get(self):
138138
buckets.append(
139139
{
140140
"Name": name,
141-
"CreationDate": datetime.datetime.utcfromtimestamp(info.st_ctime),
141+
"CreationDate": datetime.datetime.fromtimestamp(
142+
info.st_ctime, datetime.timezone.utc
143+
),
142144
}
143145
)
144146
self.render_xml({"ListAllMyBucketsResult": {"Buckets": {"Bucket": buckets}}})

Diff for: tornado/test/web_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,15 @@ def test_static_files(self):
11281128
self.assertTrue(b"Disallow: /" in response.body)
11291129
self.assertEqual(response.headers.get("Content-Type"), "text/plain")
11301130

1131+
def test_static_files_cacheable(self):
1132+
# Test that the version parameter triggers cache-control headers. This
1133+
# test is pretty weak but it gives us coverage of the code path which
1134+
# was important for detecting the deprecation of datetime.utcnow.
1135+
response = self.fetch("/robots.txt?v=12345")
1136+
self.assertTrue(b"Disallow: /" in response.body)
1137+
self.assertIn("Cache-Control", response.headers)
1138+
self.assertIn("Expires", response.headers)
1139+
11311140
def test_static_compressed_files(self):
11321141
response = self.fetch("/static/sample.xml.gz")
11331142
self.assertEqual(response.headers.get("Content-Type"), "application/gzip")

Diff for: tornado/web.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2797,7 +2797,8 @@ def set_headers(self) -> None:
27972797
if cache_time > 0:
27982798
self.set_header(
27992799
"Expires",
2800-
datetime.datetime.utcnow() + datetime.timedelta(seconds=cache_time),
2800+
datetime.datetime.now(datetime.timezone.utc)
2801+
+ datetime.timedelta(seconds=cache_time),
28012802
)
28022803
self.set_header("Cache-Control", "max-age=" + str(cache_time))
28032804

0 commit comments

Comments
 (0)