]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
aclosing on py < 3.10
authorflorimondmanca <florimond.manca@protonmail.com>
Tue, 14 Jun 2022 21:21:30 +0000 (23:21 +0200)
committerflorimondmanca <florimond.manca@protonmail.com>
Tue, 14 Jun 2022 21:21:30 +0000 (23:21 +0200)
setup.py
starlette/_compat.py
starlette/middleware/http.py

index 1597ef452a4b18e5ff35779a9cdc329d65812ab0..f0c160d9b8dd6948d46e3b6a70c0c19945dfde2a 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -39,6 +39,7 @@ setup(
     install_requires=[
         "anyio>=3.4.0,<5",
         "typing_extensions>=3.10.0; python_version < '3.10'",
+        "async_generator; python < '3.10'",
     ],
     extras_require={
         "full": [
index 116561917f3abebb2aa1911c8297d1ddd0e4969f..bba8821f8ae98048af669d9dc48a6d08cb6bc159 100644 (file)
@@ -1,5 +1,10 @@
 import hashlib
 
+__all__ = [
+    "md5_hexdigest",
+    "aclosing",
+]
+
 # Compat wrapper to always include the `usedforsecurity=...` parameter,
 # which is only added from Python 3.9 onwards.
 # We use this flag to indicate that we use `md5` hashes only for non-security
@@ -23,7 +28,14 @@ try:
             data, usedforsecurity=usedforsecurity
         ).hexdigest()
 
+
 except TypeError:  # pragma: no cover
 
     def md5_hexdigest(data: bytes, *, usedforsecurity: bool = True) -> str:
         return hashlib.md5(data).hexdigest()
+
+
+try:
+    from contextlib import aclosing
+except ImportError:  # Python < 3.10
+    from async_generator import aclosing  # type: ignore
index 8284e98917a6a820a5708df7ace6321029dffa52..f3c07064ae563eaab667fc3d651b7ccff12a4a18 100644 (file)
@@ -1,7 +1,7 @@
-from contextlib import aclosing
 from functools import partial
 from typing import AsyncGenerator, Callable, Optional
 
+from .._compat import aclosing
 from ..datastructures import MutableHeaders
 from ..responses import Response
 from ..types import ASGIApp, Message, Receive, Scope, Send