Support Python 3.13 (#2662)

* Support Python 3.13

* Use `exc_type_str` instead of `exc_type.__name__`

* Close GzipFile

* min changes
This commit is contained in:
Marcelo Trylesinski 2024-08-06 17:08:22 +02:00 committed by GitHub
parent e46165a1ca
commit 55cbba9456
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 6 deletions

View File

@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: "actions/checkout@v4"

View File

@ -23,6 +23,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP",
]
dependencies = [

View File

@ -2,6 +2,7 @@ from __future__ import annotations
import html
import inspect
import sys
import traceback
import typing
@ -237,11 +238,13 @@ class ServerErrorMiddleware:
exc_html += self.generate_frame_html(frame, is_collapsed)
is_collapsed = True
if sys.version_info >= (3, 13): # pragma: no cover
exc_type_str = traceback_obj.exc_type_str
else: # pragma: no cover
exc_type_str = traceback_obj.exc_type.__name__
# escape error class and text
error = (
f"{html.escape(traceback_obj.exc_type.__name__)}: "
f"{html.escape(str(traceback_obj))}"
)
error = f"{html.escape(exc_type_str)}: {html.escape(str(traceback_obj))}"
return TEMPLATE.format(styles=STYLES, js=JS, error=error, exc_html=exc_html)

View File

@ -41,7 +41,8 @@ class GZipResponder:
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
self.send = send
await self.app(scope, receive, self.send_with_gzip)
with self.gzip_buffer, self.gzip_file:
await self.app(scope, receive, self.send_with_gzip)
async def send_with_gzip(self, message: Message) -> None:
message_type = message["type"]