]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Support Python 3.13 (#2662)
authorMarcelo Trylesinski <marcelotryle@gmail.com>
Tue, 6 Aug 2024 15:08:22 +0000 (17:08 +0200)
committerGitHub <noreply@github.com>
Tue, 6 Aug 2024 15:08:22 +0000 (09:08 -0600)
* Support Python 3.13

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

* Close GzipFile

* min changes

.github/workflows/test-suite.yml
pyproject.toml
starlette/middleware/errors.py
starlette/middleware/gzip.py

index 0bb570cedb51dbc57b08f097523c5e9aa245f854..fac94603928643768cd5caf0f115eeda4073d3be 100644 (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"
index b1271db8da94e7151e1ec04f4d4728ef282268a5..f2721c870f86ea11d122cc0a1a1a15d92bebe724 100644 (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 = [
index e9eba62b0bdf9ad0f2941e8eac420f80185da53e..3fc4a44024e5aa62e037cba391ecdbc82d201ef4 100644 (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)
 
index cbb0f4a5b23bb25c3c5f1cb1699c896c78a135e7..0579e0410acc7e113f3cc176c3d5b0a31db25121 100644 (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"]