Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ aiohttp/_http_writer.html
aiohttp/_websocket.c
aiohttp/_websocket.html
aiohttp/_websocket/mask.c
aiohttp/_websocket/reader_c.c
bin
build
coverage.xml
Expand Down
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ endif
aiohttp/_find_header.c: $(call to-hash,aiohttp/hdrs.py ./tools/gen.py)
./tools/gen.py

# Special case for reader since we want to be able to disable
# the extension with AIOHTTP_NO_EXTENSIONS
aiohttp/_websocket/reader_c.c: aiohttp/_websocket/reader_py.py
cython -3 --module-name aiohttp._websocket.reader_c -X freethreading_compatible=True $(CYTHON_EXTRA) -o $@ $< -I aiohttp -Werror

# _find_headers generator creates _headers.pyi as well
aiohttp/%.c: aiohttp/%.pyx $(call to-hash,$(CYS)) aiohttp/_find_header.c
cython -3 -X freethreading_compatible=True $(CYTHON_EXTRA) -o $@ $< -I aiohttp -Werror
Expand All @@ -81,12 +76,12 @@ vendor/llhttp/node_modules: vendor/llhttp/package.json
generate-llhttp: .llhttp-gen

.PHONY: cythonize
cythonize: .install-cython $(PYXS:.pyx=.c) aiohttp/_websocket/reader_c.c
cythonize: .install-cython $(PYXS:.pyx=.c)

.PHONY: cythonize-nodeps
cythonize-nodeps: $(PYXS:.pyx=.c) aiohttp/_websocket/reader_c.c
cythonize-nodeps: $(PYXS:.pyx=.c)

.install-deps: .install-cython $(PYXS:.pyx=.c) aiohttp/_websocket/reader_c.c $(call to-hash,$(CYS) $(REQS))
.install-deps: .install-cython $(PYXS:.pyx=.c) $(call to-hash,$(CYS) $(REQS))
@$(PIP) install -r requirements/dev.in -c requirements/dev.txt
@touch .install-deps

Expand Down Expand Up @@ -157,7 +152,8 @@ clean:
@rm -f aiohttp/_http_parser.c
@rm -f aiohttp/_http_writer.c
@rm -f aiohttp/_websocket.c
@rm -f aiohttp/_websocket/reader_c.c
@rm -f aiohttp/_websocket/*.so
@rm -f aiohttp/_websocket/*.pyd
@rm -rf .tox
@rm -f .develop
@rm -f .flake
Expand Down
15 changes: 15 additions & 0 deletions aiohttp/_websocket/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
"""WebSocket protocol versions 13 and 8."""

import importlib.util
import os
import sys

# The mypyc-compiled reader shadows reader.py on import, so force .py import.
if os.environ.get("AIOHTTP_NO_EXTENSIONS"):
_spec = importlib.util.spec_from_file_location(
f"{__name__}.reader", os.path.join(os.path.dirname(__file__), "reader.py")
)
assert _spec is not None and _spec.loader is not None
reader = importlib.util.module_from_spec(_spec)
sys.modules[_spec.name] = reader
_spec.loader.exec_module(reader)
del _spec
27 changes: 27 additions & 0 deletions aiohttp/_websocket/_wrbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import asyncio
from typing import TYPE_CHECKING, cast

if TYPE_CHECKING:
from .models import WSMessage
from .reader import WebSocketDataQueue


class _WeakrefBase:
"""Hack for https://github.com/mypyc/mypyc/issues/1102"""


class _InterpretedReadMixin:
"""Hack for https://github.com/mypyc/mypyc/issues/1214"""

async def read(self) -> "WSMessage":
q = cast("WebSocketDataQueue", self)
if not q._buffer and not q._eof:
assert not q._waiter
waiter: "asyncio.Future[None]" = q._loop.create_future()
q._waiter = waiter
try:
await waiter
except (asyncio.CancelledError, asyncio.TimeoutError):
q._waiter = None
raise
return q._read_from_buffer()
Loading
Loading