summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-01-18 12:45:07 +0000
committerGitHub <noreply@github.com>2023-01-18 13:45:07 +0100
commit26a395f27d86bbf65f330851c8136c33694ac867 (patch)
tree70c1ab33cf0740889a7d6bccfa7e7e056f67211f
parenta04565845ae3e766a1a4ec827a6e1f4fac335c3a (diff)
Refs #34233 -- Used aiter() and anext().
Available since Python 3.10.
-rw-r--r--django/core/handlers/asgi.py2
-rw-r--r--django/http/response.py2
-rw-r--r--tests/httpwrappers/tests.py2
3 files changed, 3 insertions, 3 deletions
diff --git a/django/core/handlers/asgi.py b/django/core/handlers/asgi.py
index 998d135691..2aede079b9 100644
--- a/django/core/handlers/asgi.py
+++ b/django/core/handlers/asgi.py
@@ -268,7 +268,7 @@ class ASGIHandler(base.BaseHandler):
# allow mapping of a sync iterator.
# - Use aclosing() when consuming aiter.
# See https://github.com/python/cpython/commit/6e8dcda
- async with aclosing(response.__aiter__()) as content:
+ async with aclosing(aiter(response)) as content:
async for part in content:
for chunk, _ in self.chunk_bytes(part):
await send(
diff --git a/django/http/response.py b/django/http/response.py
index 465a8553dc..f62dec8ce9 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -502,7 +502,7 @@ class StreamingHttpResponse(HttpResponseBase):
self._iterator = iter(value)
self.is_async = False
except TypeError:
- self._iterator = value.__aiter__()
+ self._iterator = aiter(value)
self.is_async = True
if hasattr(value, "close"):
self._resource_closers.append(value.close)
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index fa2c8fd5d2..0a41ea5ec6 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -754,7 +754,7 @@ class StreamingHttpResponseTests(SimpleTestCase):
"serve them asynchronously. Use an asynchronous iterator instead."
)
with self.assertWarnsMessage(Warning, msg):
- self.assertEqual(b"hello", await r.__aiter__().__anext__())
+ self.assertEqual(b"hello", await anext(aiter(r)))
class FileCloseTests(SimpleTestCase):