Skip to content

Commit

Permalink
Fix Python 3.12 CI
Browse files Browse the repository at this point in the history
Ignore warnings, fix others and work around
python/cpython#105162
  • Loading branch information
graingert committed Jun 1, 2023
1 parent b63cc4c commit bfbd47e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
6 changes: 4 additions & 2 deletions dummyserver/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import typing
import zlib
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from http.client import responses
from io import BytesIO
from urllib.parse import urlsplit
Expand Down Expand Up @@ -344,7 +344,9 @@ def redirect_after(self, request: httputil.HTTPServerRequest) -> Response:
date = params.get("date")
if date:
retry_after = str(
httputil.format_timestamp(datetime.utcfromtimestamp(float(date)))
httputil.format_timestamp(
datetime.fromtimestamp(float(date), tz=timezone.utc)
)
)
else:
retry_after = "1"
Expand Down
48 changes: 15 additions & 33 deletions dummyserver/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,6 @@ class ProxyHandler(tornado.web.RequestHandler):
SUPPORTED_METHODS = ["GET", "POST", "CONNECT"] # type: ignore[assignment]

async def get(self) -> None:
async def handle_response(response: tornado.httpclient.HTTPResponse) -> None:
if response.error and not isinstance(
response.error, tornado.httpclient.HTTPError
):
self.set_status(500)
self.write("Internal server error:\n" + str(response.error))
await self.finish()
else:
self.set_status(response.code)
for header in (
"Date",
"Cache-Control",
"Server",
"Content-Type",
"Location",
):
v = response.headers.get(header)
if v:
self.set_header(header, v)
if response.body:
self.write(response.body)
await self.finish()

upstream_ca_certs = self.application.settings.get("upstream_ca_certs", None)
ssl_options = None

Expand All @@ -87,16 +64,21 @@ async def handle_response(response: tornado.httpclient.HTTPResponse) -> None:
)

client = tornado.httpclient.AsyncHTTPClient()
try:
response = await client.fetch(req)
await handle_response(response)
except tornado.httpclient.HTTPError as e:
if hasattr(e, "response") and e.response:
await handle_response(e.response)
else:
self.set_status(500)
self.write("Internal server error:\n" + str(e))
self.finish()
response = await client.fetch(req, raise_error=False)
self.set_status(response.code)
for header in (
"Date",
"Cache-Control",
"Server",
"Content-Type",
"Location",
):
v = response.headers.get(header)
if v:
self.set_header(header, v)
if response.body:
self.write(response.body)
await self.finish()

async def post(self) -> None:
await self.get()
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ filterwarnings = [
'''default:ssl\.PROTOCOL_TLSv1_2 is deprecated:DeprecationWarning''',
'''default:unclosed .*:ResourceWarning''',
'''default:ssl NPN is deprecated, use ALPN instead:DeprecationWarning''',
'''default:URLs without a scheme''',
# https://github.com/pytest-dev/pytest/issues/10977
'''default:ast\.(Num|NameConstant|Str) is deprecated and will be removed in Python 3\.14; use ast\.Constant instead:DeprecationWarning:_pytest''',
'''default:Attribute s is deprecated and will be removed in Python 3\.14; use value instead:DeprecationWarning:_pytest''',
# https://github.com/dateutil/dateutil/issues/1284
'''default:datetime\.utcfromtimestamp\(\) is deprecated and scheduled for removal in a future version\.*:DeprecationWarning:dateutil''',
]

[tool.isort]
Expand Down

0 comments on commit bfbd47e

Please sign in to comment.