Skip to content

Commit

Permalink
Merge branch 'MaayanLab-patch'
Browse files Browse the repository at this point in the history
  • Loading branch information
etianen committed Feb 20, 2022
2 parents 322b511 + 57b119d commit 2c23c22
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
PYTHONDEVMODE: 1
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
14 changes: 4 additions & 10 deletions aiohttp_wsgi/wsgi.py
Expand Up @@ -65,9 +65,6 @@
:mod:`aiohttp_wsgi` adds the following additional keys to the WSGI environ:
``asyncio.loop``
The ``asyncio.EventLoop`` running the server.
``asyncio.executor``
The :class:`Executor <concurrent.futures.Executor>` running the WSGI request.
Expand All @@ -88,6 +85,7 @@
.. include:: /_include/links.rst
"""
import asyncio
from asyncio.base_events import Server
from functools import partial
from io import BytesIO
import logging
Expand Down Expand Up @@ -173,7 +171,6 @@ class WSGIHandler:
:param int inbuf_overflow: {inbuf_overflow}
:param int max_request_body_size: {max_request_body_size}
:param concurrent.futures.Executor executor: {executor}
:param loop: {loop}
"""

def __init__(
Expand All @@ -187,7 +184,6 @@ def __init__(
max_request_body_size: int = 1073741824,
# asyncio config.
executor: Optional[Executor] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
):
assert callable(application), "application should be callable"
self._application = application
Expand All @@ -206,7 +202,6 @@ def __init__(
self._max_request_body_size = max_request_body_size
# asyncio config.
self._executor = executor
self._loop = loop or asyncio.get_event_loop()

def _get_environ(self, request: Request, body: IO[bytes], content_length: int) -> WSGIEnviron:
# Resolve the path info.
Expand Down Expand Up @@ -254,7 +249,6 @@ def _get_environ(self, request: Request, body: IO[bytes], content_length: int) -
"wsgi.multithread": True,
"wsgi.multiprocess": False,
"wsgi.run_once": False,
"asyncio.loop": self._loop,
"asyncio.executor": self._executor,
"aiohttp.request": request,
}
Expand Down Expand Up @@ -291,7 +285,8 @@ async def handle_request(self, request: Request) -> Response:
body.seek(0)
# Get the environ.
environ = self._get_environ(request, body, content_length)
return await self._loop.run_in_executor(
loop = asyncio.get_event_loop()
return await loop.run_in_executor(
self._executor,
_run_application,
self._application,
Expand Down Expand Up @@ -363,7 +358,6 @@ def run_server(
f"{format_path(script_name)}{{path_info:.*}}",
WSGIHandler(
application,
loop=loop,
executor=executor,
**kwargs
).handle_request,
Expand All @@ -388,6 +382,7 @@ def run_server(
os.chmod(unix_socket, unix_socket_perms)
# Report.
assert site._server is not None
assert isinstance(site._server, Server)
assert site._server.sockets is not None
server_uri = " ".join(
"http://{}:{}".format(*parse_sockname(socket.getsockname()))
Expand Down Expand Up @@ -470,7 +465,6 @@ def serve(application: WSGIApplication, **kwargs: Any) -> None: # pragma: no co
"Larger requests will receive a HTTP 413 (Request Entity Too Large) response."
).format_map(DEFAULTS),
"executor": "An Executor instance used to run WSGI requests. Defaults to the :mod:`asyncio` base executor.",
"loop": "The asyncio loop. Defaults to :func:`asyncio.get_event_loop`.",
"host": "Host interfaces to bind. Defaults to ``'0.0.0.0'`` and ``'::'``.",
"port": "Port to bind. Defaults to ``{port!r}``.".format_map(DEFAULTS),
"unix_socket": "Path to a unix socket to bind, cannot be used with ``host``.",
Expand Down
2 changes: 2 additions & 0 deletions tests/base.py
@@ -1,3 +1,4 @@
from asyncio.base_events import Server
import unittest
from collections import namedtuple
from contextlib import contextmanager
Expand Down Expand Up @@ -68,6 +69,7 @@ class AsyncTestCase(unittest.TestCase):
def _run_server(self, *args: Any, **kwargs: Any) -> Generator[TestClient, None, None]:
with run_server(*args, **kwargs) as (loop, site):
assert site._server is not None
assert isinstance(site._server, Server)
assert site._server.sockets is not None
host, port = parse_sockname(site._server.sockets[0].getsockname())
async def create_session() -> aiohttp.ClientSession:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_environ.py
@@ -1,4 +1,3 @@
import asyncio
from concurrent.futures import ThreadPoolExecutor
from functools import wraps
from io import TextIOBase
Expand Down Expand Up @@ -35,7 +34,6 @@ def assert_environ(environ: WSGIEnviron) -> None:
assert environ["wsgi.multithread"]
assert not environ["wsgi.multiprocess"]
assert not environ["wsgi.run_once"]
assert isinstance(environ["asyncio.loop"], asyncio.BaseEventLoop)
assert isinstance(environ["asyncio.executor"], ThreadPoolExecutor)
assert "aiohttp.request" in environ

Expand Down

0 comments on commit 2c23c22

Please sign in to comment.