File tree 4 files changed +15
-3
lines changed
4 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 5
5
{% if len(entries) > 0 %}
6
6
<updated >{{ max(e.updated for e in entries).strftime(date_format) }}</updated >
7
7
{% else %}
8
- <updated >{{ datetime.datetime.utcnow( ).strftime(date_format) }}</updated >
8
+ <updated >{{ datetime.datetime.now(datetime.timezone.utc ).strftime(date_format) }}</updated >
9
9
{% end %}
10
10
<id >http://{{ request.host }}/</id >
11
11
<link rel =" alternate" href =" http://{{ request.host }}/" title =" {{ handler.settings[" blog_title" ] }}" type =" text/html" />
Original file line number Diff line number Diff line change @@ -138,7 +138,9 @@ def get(self):
138
138
buckets .append (
139
139
{
140
140
"Name" : name ,
141
- "CreationDate" : datetime .datetime .utcfromtimestamp (info .st_ctime ),
141
+ "CreationDate" : datetime .datetime .fromtimestamp (
142
+ info .st_ctime , datetime .timezone .utc
143
+ ),
142
144
}
143
145
)
144
146
self .render_xml ({"ListAllMyBucketsResult" : {"Buckets" : {"Bucket" : buckets }}})
Original file line number Diff line number Diff line change @@ -1128,6 +1128,15 @@ def test_static_files(self):
1128
1128
self .assertTrue (b"Disallow: /" in response .body )
1129
1129
self .assertEqual (response .headers .get ("Content-Type" ), "text/plain" )
1130
1130
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
+
1131
1140
def test_static_compressed_files (self ):
1132
1141
response = self .fetch ("/static/sample.xml.gz" )
1133
1142
self .assertEqual (response .headers .get ("Content-Type" ), "application/gzip" )
Original file line number Diff line number Diff line change @@ -2797,7 +2797,8 @@ def set_headers(self) -> None:
2797
2797
if cache_time > 0 :
2798
2798
self .set_header (
2799
2799
"Expires" ,
2800
- datetime .datetime .utcnow () + datetime .timedelta (seconds = cache_time ),
2800
+ datetime .datetime .now (datetime .timezone .utc )
2801
+ + datetime .timedelta (seconds = cache_time ),
2801
2802
)
2802
2803
self .set_header ("Cache-Control" , "max-age=" + str (cache_time ))
2803
2804
You can’t perform that action at this time.
0 commit comments