]> git.ipfire.org Git - thirdparty/tornado.git/commit
*: Adapt to deprecation of datetime utc methods 3288/head
authorBen Darnell <ben@bendarnell.com>
Fri, 9 Jun 2023 02:52:19 +0000 (22:52 -0400)
committerBen Darnell <ben@bendarnell.com>
Thu, 22 Jun 2023 00:53:56 +0000 (20:53 -0400)
commit4d4d80c1d076dcb4e051c969ae4b66557d3856b8
tree1ab21e0f9ef32fa9ad895cc5f2fda6363f6eaaa8
parent4c6b8cacf56594760f80dc3cf4e2b6115cf8dc87
*: Adapt to deprecation of datetime utc methods

Python 3.12 deprecates the utcnow and utcfromtimestamp methods and
discourages the use of naive datetimes to represent UTC. This was
previously the main way that Tornado used datetimes (since it was
the only option available in Python 2 before the introduction
of datetime.timezone.utc in Python 3.2).

- httpclient_test: Test-only change to test that both kinds of datetimes
  are supported in If-Modified-Since (this just calls
  httputil.format_timestamp)
- httputil: No functional changes, but format_timestamp's
  support for both naive and aware datetimes is now tested.
- locale: format_timestamp now supports aware datetimes (in
  addition to the existing support for naive datetimes).
- web: Cookie expirations internally use aware datetimes.
  StaticFileHandler.get_modified_time now supports both and the
  standard implementation returns aware.

It feels fragile that "naive" and "aware" datetimes are not distinct
types but subject to data-dependent behavior. This change uses
"aware" datetimes throughout Tornado, but some operations (comparisons
and subtraction) fail with mixed datetime types and if I missed any
in this change may cause errors if naive datetimes were used (where
previously naive datetimes would have been required). But that's
apparently the API we have to work with.
tornado/httputil.py
tornado/locale.py
tornado/test/httpclient_test.py
tornado/test/httputil_test.py
tornado/test/locale_test.py
tornado/test/web_test.py
tornado/web.py