From b3bfbd61353c0e639af50e9dd7844e28ba80f2ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Sep 2022 09:35:26 +0200 Subject: [PATCH 01/54] [pre-commit.ci] pre-commit autoupdate (#438) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 22.6.0 → 22.8.0](https://github.com/psf/black/compare/22.6.0...22.8.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c47198d..fba2292 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 22.8.0 hooks: - id: black language_version: python3 From e9637419df41548297226ffc23d3ab57415aa262 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Sep 2022 10:07:55 +0100 Subject: [PATCH 02/54] [pre-commit.ci] pre-commit autoupdate (#439) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fba2292..574f5d1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.37.3 + rev: v2.38.0 hooks: - id: pyupgrade args: [--py36-plus] From 898529c48947692ed329ccda6c8d38eb7df3d57d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 21:47:43 +0100 Subject: [PATCH 03/54] [pre-commit.ci] pre-commit autoupdate (#441) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 574f5d1..de5f780 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.38.0 + rev: v2.38.2 hooks: - id: pyupgrade args: [--py36-plus] From fef1490eff28e106c93ff6539faa196ce5aee626 Mon Sep 17 00:00:00 2001 From: Jakub Stawowy Date: Fri, 7 Oct 2022 12:21:22 +0200 Subject: [PATCH 04/54] =?UTF-8?q?Removed=20deprecated=20=E2=80=94ws-protoc?= =?UTF-8?q?ols=20CLI=20option.=20(#387)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.txt | 2 ++ daphne/cli.py | 8 -------- daphne/server.py | 2 -- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9416110..eb2c58a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -39,6 +39,8 @@ This is a beta release to allow testing compatibility with the upcoming Channels ... ] +* Removed deprecated ``--ws_protocols`` CLI option. + 3.0.2 (2021-04-07) ------------------ diff --git a/daphne/cli.py b/daphne/cli.py index accafe1..7c0c3c9 100755 --- a/daphne/cli.py +++ b/daphne/cli.py @@ -113,13 +113,6 @@ class CommandLineInterface: help="The number of seconds an ASGI application has to exit after client disconnect before it is killed", default=10, ) - self.parser.add_argument( - "--ws-protocol", - nargs="*", - dest="ws_protocols", - help="The WebSocket protocols you wish to support", - default=None, - ) self.parser.add_argument( "--root-path", dest="root_path", @@ -280,7 +273,6 @@ class CommandLineInterface: action_logger=AccessLogGenerator(access_log_stream) if access_log_stream else None, - ws_protocols=args.ws_protocols, root_path=args.root_path, verbosity=args.verbosity, proxy_forwarded_address_header=self._get_forwarded_host(args=args), diff --git a/daphne/server.py b/daphne/server.py index e5728b3..8da4a61 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -65,8 +65,6 @@ class Server: application_close_timeout=10, ready_callable=None, server_name="daphne", - # Deprecated and does not work, remove in version 2.2 - ws_protocols=None, ): self.application = application self.endpoints = endpoints or [] From 12e543750b0c3c4792904f5b80ae11ef7bcff0fc Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 7 Oct 2022 12:22:40 +0100 Subject: [PATCH 05/54] Make DaphneProcess pickleable (#440) --- CHANGELOG.txt | 3 +++ daphne/testing.py | 23 +++++++++++++++-------- tests/test_websocket.py | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index eb2c58a..c462568 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -41,6 +41,9 @@ This is a beta release to allow testing compatibility with the upcoming Channels * Removed deprecated ``--ws_protocols`` CLI option. +* Made the ``DaphneProcess`` tests helper class compatible with the ``spawn`` + process start method, which is used on macOS and Windows. + 3.0.2 (2021-04-07) ------------------ diff --git a/daphne/testing.py b/daphne/testing.py index e2c7200..785edf9 100644 --- a/daphne/testing.py +++ b/daphne/testing.py @@ -26,6 +26,9 @@ class BaseDaphneTestingInstance: self.request_buffer_size = request_buffer_size self.application = application + def get_application(self): + return self.application + def __enter__(self): # Option Daphne features kwargs = {} @@ -41,7 +44,7 @@ class BaseDaphneTestingInstance: # Start up process self.process = DaphneProcess( host=self.host, - application=self.application, + get_application=self.get_application, kwargs=kwargs, setup=self.process_setup, teardown=self.process_teardown, @@ -123,13 +126,13 @@ class DaphneProcess(multiprocessing.Process): port it ends up listening on back to the parent process. """ - def __init__(self, host, application, kwargs=None, setup=None, teardown=None): + def __init__(self, host, get_application, kwargs=None, setup=None, teardown=None): super().__init__() self.host = host - self.application = application + self.get_application = get_application self.kwargs = kwargs or {} - self.setup = setup or (lambda: None) - self.teardown = teardown or (lambda: None) + self.setup = setup + self.teardown = teardown self.port = multiprocessing.Value("i") self.ready = multiprocessing.Event() self.errors = multiprocessing.Queue() @@ -146,11 +149,13 @@ class DaphneProcess(multiprocessing.Process): from .endpoints import build_endpoint_description_strings from .server import Server + application = self.get_application() + try: # Create the server class endpoints = build_endpoint_description_strings(host=self.host, port=0) self.server = Server( - application=self.application, + application=application, endpoints=endpoints, signal_handlers=False, **self.kwargs @@ -158,11 +163,13 @@ class DaphneProcess(multiprocessing.Process): # Set up a poller to look for the port reactor.callLater(0.1, self.resolve_port) # Run with setup/teardown - self.setup() + if self.setup is not None: + self.setup() try: self.server.run() finally: - self.teardown() + if self.teardown is not None: + self.teardown() except BaseException as e: # Put the error on our queue so the parent gets it self.errors.put((e, traceback.format_exc())) diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 9b67aa1..e954486 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -288,7 +288,7 @@ async def cancelling_application(scope, receive, send): from twisted.internet import reactor # Stop the server after a short delay so that the teardown is run. - reactor.callLater(2, lambda: reactor.stop()) + reactor.callLater(2, reactor.stop) await send({"type": "websocket.accept"}) raise asyncio.CancelledError() From 060202f4914b0f46fc2d7398d9b769a8481300ef Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 7 Oct 2022 14:53:16 +0200 Subject: [PATCH 06/54] Updated change log and version for v4.0 release. --- CHANGELOG.txt | 39 ++++++++++++++++++++++----------------- daphne/__init__.py | 2 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c462568..996b763 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,8 +1,26 @@ -4.0.0b1 (2022-08-25) --------------------- +4.0.0 (2022-10-07) +------------------ -This is a beta release to allow testing compatibility with the upcoming Channels -4.0. +Major versioning targeting use with Channels 4.0 and beyond. Except where +noted should remain usable with Channels v3 projects, but updating Channels to the latest version is recommended. + +* Added a ``runserver`` command to run an ASGI Django development server. + + Added ``"daphne"`` to the ``INSTALLED_APPS`` setting, before + ``"django.contrib.staticfiles"`` to enable: + + INSTALLED_APPS = [ + "daphne", + ... + ] + + This replaces the Channels implementation of ``runserver``, which is removed + in Channels 4.0. + +* Made the ``DaphneProcess`` tests helper class compatible with the ``spawn`` + process start method, which is used on macOS and Windows. + + Note that requires Channels v4 if using with ``ChannelsLiveServerTestCase``. * Dropped support for Python 3.6. @@ -29,21 +47,8 @@ This is a beta release to allow testing compatibility with the upcoming Channels Set e.g. ``ASGI_THREADS=4 daphne ...`` when running to limit the number of workers. -* Added a ``runserver`` command to run an ASGI Django development server. - - Added ``"daphne"`` to the ``INSTALLED_APPS`` setting, before - ``"django.contrib.staticfiles"`` to enable: - - INSTALLED_APPS = [ - "daphne", - ... - ] - * Removed deprecated ``--ws_protocols`` CLI option. -* Made the ``DaphneProcess`` tests helper class compatible with the ``spawn`` - process start method, which is used on macOS and Windows. - 3.0.2 (2021-04-07) ------------------ diff --git a/daphne/__init__.py b/daphne/__init__.py index 6ac6f94..ae556a6 100755 --- a/daphne/__init__.py +++ b/daphne/__init__.py @@ -1,6 +1,6 @@ import sys -__version__ = "4.0.0b1" +__version__ = "4.0.0" # Windows on Python 3.8+ uses ProactorEventLoop, which is not compatible with From 91c61f4ff4148d8e540520c5c8962672753263d6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:39:20 +0100 Subject: [PATCH 07/54] [pre-commit.ci] pre-commit autoupdate (#443) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index de5f780..c4c1dec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.38.2 + rev: v3.0.0 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/psf/black - rev: 22.8.0 + rev: 22.10.0 hooks: - id: black language_version: python3 From 71be46265dffb11ad2da7560e67dfa95be246755 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 23:09:03 +0100 Subject: [PATCH 08/54] [pre-commit.ci] pre-commit autoupdate (#444) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c4c1dec..a4c0210 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.0.0 + rev: v3.1.0 hooks: - id: pyupgrade args: [--py36-plus] From d5fbdfc4cbca77fa7c3b9a4d0ff7fcc285f6e971 Mon Sep 17 00:00:00 2001 From: Michael K Date: Tue, 25 Oct 2022 12:46:20 +0000 Subject: [PATCH 09/54] Run tests against Python 3.11 and add trove classifier (#446) --- .github/workflows/tests.yml | 1 + setup.py | 1 + tox.ini | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9792252..3a00cce 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,6 +20,7 @@ jobs: - "3.8" - "3.9" - "3.10" + - "3.11" steps: - uses: actions/checkout@v2 diff --git a/setup.py b/setup.py index ae19f5d..b95f0e9 100755 --- a/setup.py +++ b/setup.py @@ -41,6 +41,7 @@ setup( "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Topic :: Internet :: WWW/HTTP", ], ) diff --git a/tox.ini b/tox.ini index 876ff99..20e9a33 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{37,38,39,310} + py{37,38,39,310,311} [testenv] usedevelop = true extras = tests From afd0d51b83f7d4ac9deab44257e3064e064f0b11 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Nov 2022 11:09:39 +0000 Subject: [PATCH 10/54] [pre-commit.ci] pre-commit autoupdate (#448) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4c0210..97db8ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.1.0 + rev: v3.2.0 hooks: - id: pyupgrade args: [--py36-plus] From a0b2ac0e8f8409a9e183e1f123e3ecc0a2983ff9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Nov 2022 20:47:53 +0000 Subject: [PATCH 11/54] [pre-commit.ci] pre-commit autoupdate (#452) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.2.0 → v3.2.2](https://github.com/asottile/pyupgrade/compare/v3.2.0...v3.2.2) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 97db8ed..490fc85 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.2.0 + rev: v3.2.2 hooks: - id: pyupgrade args: [--py36-plus] From ef946d56379115e4593622d627eadb93e1187d4b Mon Sep 17 00:00:00 2001 From: Michael K Date: Fri, 18 Nov 2022 10:33:03 +0000 Subject: [PATCH 12/54] Upgrade GitHub Actions actions (#454) And set up dependabot to take care of them in the future. --- .github/dependabot.yml | 6 ++++++ .github/workflows/tests.yml | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e5903e0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: weekly diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3a00cce..36e0589 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,10 +23,10 @@ jobs: - "3.11" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} From 18e936eed11a908bb7f3783f755a373f5d65c3c4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Nov 2022 20:34:37 +0000 Subject: [PATCH 13/54] [pre-commit.ci] pre-commit autoupdate (#456) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 490fc85..b4f91a3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: From 2015ecdd8fcef5910a6f4c7383bda182161fe975 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:01:28 +0000 Subject: [PATCH 14/54] [pre-commit.ci] pre-commit autoupdate (#457) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b4f91a3..e2b915e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.2.2 + rev: v3.3.0 hooks: - id: pyupgrade args: [--py36-plus] From d59c2bd4242f81206f5aaa04832d7aba898b4cd6 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 8 Dec 2022 01:06:41 +0000 Subject: [PATCH 15/54] Upgrade to tox 4 (#458) --- .github/workflows/tests.yml | 4 +-- pyproject.toml | 3 +++ setup.cfg | 50 +++++++++++++++++++++++++++++++++++++ setup.py | 47 ---------------------------------- tox.ini | 2 +- 5 files changed, 56 insertions(+), 50 deletions(-) create mode 100644 pyproject.toml delete mode 100755 setup.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36e0589..8d4d1c4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade tox tox-py + python -m pip install --upgrade tox - name: Run tox targets for ${{ matrix.python-version }} - run: tox --py current + run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d .) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fed528d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg index e7c19e5..cdde703 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,53 @@ +[metadata] +name = daphne +version = attr: daphne.__version__ +url = https://github.com/django/daphne +author = Django Software Foundation +author_email = foundation@djangoproject.com +description = Django ASGI (HTTP/WebSocket) server +long_description = file: README.rst +long_description_content_type = text/x-rst +license = BSD +classifiers = + Development Status :: 4 - Beta + Environment :: Web Environment + Intended Audience :: Developers + License :: OSI Approved :: BSD License + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Topic :: Internet :: WWW/HTTP + +[options] +package_dir = + twisted=daphne/twisted +packages = find: +include_package_data = True +install_requires = + asgiref>=3.5.2,<4 + autobahn>=22.4.2 + twisted[tls]>=22.4 +python_requires = >=3.7 +setup_requires = + pytest-runner +zip_safe = False + +[options.entry_points] +console_scripts = + daphne = daphne.cli:CommandLineInterface.entrypoint + +[options.extras_require] +tests = + django + hypothesis + pytest + pytest-asyncio + [flake8] exclude = venv/*,tox/*,docs/*,testproject/*,js_client/*,.eggs/* extend-ignore = E123, E128, E266, E402, W503, E731, W601 diff --git a/setup.py b/setup.py deleted file mode 100755 index b95f0e9..0000000 --- a/setup.py +++ /dev/null @@ -1,47 +0,0 @@ -import os - -from setuptools import find_packages, setup - -from daphne import __version__ - -# We use the README as the long_description -readme_path = os.path.join(os.path.dirname(__file__), "README.rst") -with open(readme_path) as fp: - long_description = fp.read() - -setup( - name="daphne", - version=__version__, - url="https://github.com/django/daphne", - author="Django Software Foundation", - author_email="foundation@djangoproject.com", - description="Django ASGI (HTTP/WebSocket) server", - long_description=long_description, - license="BSD", - zip_safe=False, - package_dir={"twisted": "daphne/twisted"}, - packages=find_packages() + ["twisted.plugins"], - include_package_data=True, - install_requires=["twisted[tls]>=22.4", "autobahn>=22.4.2", "asgiref>=3.5.2,<4"], - python_requires=">=3.7", - setup_requires=["pytest-runner"], - extras_require={"tests": ["hypothesis", "pytest", "pytest-asyncio", "django"]}, - entry_points={ - "console_scripts": ["daphne = daphne.cli:CommandLineInterface.entrypoint"] - }, - classifiers=[ - "Development Status :: 4 - Beta", - "Environment :: Web Environment", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Topic :: Internet :: WWW/HTTP", - ], -) diff --git a/tox.ini b/tox.ini index 20e9a33..305bf14 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] envlist = py{37,38,39,310,311} + [testenv] -usedevelop = true extras = tests commands = pytest -v {posargs} From c9343aa9d6a2f63bb49d39462a78170a3dd52c8f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 23:15:35 +0000 Subject: [PATCH 16/54] [pre-commit.ci] pre-commit autoupdate (#460) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.3.0 → v3.3.1](https://github.com/asottile/pyupgrade/compare/v3.3.0...v3.3.1) - [github.com/psf/black: 22.10.0 → 22.12.0](https://github.com/psf/black/compare/22.10.0...22.12.0) - [github.com/pycqa/isort: 5.10.1 → 5.11.0](https://github.com/pycqa/isort/compare/5.10.1...5.11.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2b915e..758f79c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,16 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.3.0 + rev: v3.3.1 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 22.12.0 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.11.0 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 From fdc944a28016d1e3e45ceb128264b1d3c07e5d00 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Dec 2022 10:37:51 +0100 Subject: [PATCH 17/54] [pre-commit.ci] pre-commit autoupdate (#461) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pycqa/isort: 5.11.0 → v5.11.3](https://github.com/pycqa/isort/compare/5.11.0...v5.11.3) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 758f79c..bd5e7bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: black language_version: python3 - repo: https://github.com/pycqa/isort - rev: 5.11.0 + rev: v5.11.3 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 From 5681d71c1791cf83acfd8464946b8993320ac7ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 29 Dec 2022 12:19:00 +0000 Subject: [PATCH 18/54] [pre-commit.ci] pre-commit autoupdate (#462) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd5e7bb..0b2411a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: black language_version: python3 - repo: https://github.com/pycqa/isort - rev: v5.11.3 + rev: 5.11.4 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 From 79fd65dec38826819ebb7aaf5514a2792fb31aaa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Jan 2023 06:52:32 +0000 Subject: [PATCH 19/54] [pre-commit.ci] pre-commit autoupdate (#464) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pycqa/isort: 5.11.4 → 5.12.0](https://github.com/pycqa/isort/compare/5.11.4...5.12.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b2411a..bd89b14 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: black language_version: python3 - repo: https://github.com/pycqa/isort - rev: 5.11.4 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 From b0204165b1fc1ccb786e9ba65ad32d20f1fc83f5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 15:20:08 +0000 Subject: [PATCH 20/54] [pre-commit.ci] pre-commit autoupdate (#466) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd89b14..00bac0b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black language_version: python3 From 077dd8180968d75c222c1f84d62ff5c630e6b38a Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 14 Apr 2023 14:53:12 +0200 Subject: [PATCH 21/54] Added missing stacklevel warning parameter. (#471) --- daphne/server.py | 1 + 1 file changed, 1 insertion(+) diff --git a/daphne/server.py b/daphne/server.py index 8da4a61..a6d3819 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -21,6 +21,7 @@ if current_reactor is not None: + "you can fix this warning by importing daphne.server early in your codebase or " + "finding the package that imports Twisted and importing it later on.", UserWarning, + stacklevel=2, ) del sys.modules["twisted.internet.reactor"] asyncioreactor.install(twisted_loop) From 21513b84da2558ba84cc35ed77985e77f8308754 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Apr 2023 15:03:51 +0200 Subject: [PATCH 22/54] [pre-commit.ci] pre-commit autoupdate (#470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.1.0 → 23.3.0](https://github.com/psf/black/compare/23.1.0...23.3.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Carlton Gibson --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 00bac0b..3f61b80 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.3.0 hooks: - id: black language_version: python3 From 09da15dc4e6c542325bad9f1b4f060cd55fd12ba Mon Sep 17 00:00:00 2001 From: Abenezer Belachew <43050633+abenezerBelachew@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:10:16 +0300 Subject: [PATCH 23/54] Double quotes during pip (#467) Single quotes return => ERROR: Invalid requirement: "'Twisted[tls,http2]'" --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 70c4ba5..aa18798 100644 --- a/README.rst +++ b/README.rst @@ -54,7 +54,7 @@ Daphne supports terminating HTTP/2 connections natively. You'll need to do a couple of things to get it working, though. First, you need to make sure you install the Twisted ``http2`` and ``tls`` extras:: - pip install -U 'Twisted[tls,http2]' + pip install -U "Twisted[tls,http2]" Next, because all current browsers only support HTTP/2 when using TLS, you will need to start Daphne with TLS turned on, which can be done using the Twisted endpoint syntax:: From 1eaf2206cce86d7ada71875a4ff5651201f101a7 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Sun, 16 Apr 2023 10:33:27 +0200 Subject: [PATCH 24/54] Set pre-commit to quarterly updates. (#472) --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f61b80..02e0fa6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,3 +19,5 @@ repos: - id: flake8 additional_dependencies: - flake8-bugbear +ci: + autoupdate_schedule: quarterly From e49c39a4e5fac8ec170dd653641a9e90844fd3f1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jul 2023 05:48:51 +0100 Subject: [PATCH 25/54] [pre-commit.ci] pre-commit autoupdate (#477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.3.1 → v3.8.0](https://github.com/asottile/pyupgrade/compare/v3.3.1...v3.8.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 02e0fa6..e7a2b46 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.8.0 hooks: - id: pyupgrade args: [--py36-plus] From f108bbc7c1076fbdbce10809da8ee3e73ecb68c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 07:51:07 +0200 Subject: [PATCH 26/54] Bump actions/checkout from 3 to 4 (#480) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8d4d1c4..357d648 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: - "3.11" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 From 3758c514fdedfdfd8df32cfbecc5df2c00bb2d1a Mon Sep 17 00:00:00 2001 From: InvalidInterrupt Date: Thu, 7 Sep 2023 00:09:10 -0700 Subject: [PATCH 27/54] Raise minimum supported Python version to 3.8 (#481) --- .github/workflows/tests.yml | 1 - README.rst | 2 +- setup.cfg | 3 +-- tox.ini | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 357d648..a719751 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,6 @@ jobs: - ubuntu - windows python-version: - - "3.7" - "3.8" - "3.9" - "3.10" diff --git a/README.rst b/README.rst index aa18798..d93ad02 100644 --- a/README.rst +++ b/README.rst @@ -108,7 +108,7 @@ should start with a slash, but not end with one; for example:: Python Support -------------- -Daphne requires Python 3.7 or later. +Daphne requires Python 3.8 or later. Contributing diff --git a/setup.cfg b/setup.cfg index cdde703..c73c92a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,7 +16,6 @@ classifiers = Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 @@ -32,7 +31,7 @@ install_requires = asgiref>=3.5.2,<4 autobahn>=22.4.2 twisted[tls]>=22.4 -python_requires = >=3.7 +python_requires = >=3.8 setup_requires = pytest-runner zip_safe = False diff --git a/tox.ini b/tox.ini index 305bf14..b638f4c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{37,38,39,310,311} + py{38,39,310,311} [testenv] extras = tests From 2d4dcbf14952458e1abe8e5451910f463c97a218 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:59:12 +0200 Subject: [PATCH 28/54] [pre-commit.ci] pre-commit autoupdate (#485) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e7a2b46..db154b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.8.0 + rev: v3.14.0 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.9.1 hooks: - id: black language_version: python3 @@ -14,7 +14,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 additional_dependencies: From 4d24e22c72e1545ad753f53753291f301bd3dae5 Mon Sep 17 00:00:00 2001 From: Paolo Melchiorre Date: Sun, 26 Nov 2023 16:12:23 +0100 Subject: [PATCH 29/54] Fixed #489 -- Add support for Python 3.12 (#490) --- .github/workflows/tests.yml | 1 + .pre-commit-config.yaml | 6 +++--- CHANGELOG.txt | 6 ++++++ setup.cfg | 1 + tox.ini | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a719751..670a8ac 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,6 +20,7 @@ jobs: - "3.9" - "3.10" - "3.11" + - "3.12" steps: - uses: actions/checkout@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db154b8..c1fd822 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.14.0 + rev: v3.15.0 hooks: - id: pyupgrade - args: [--py36-plus] + args: [--py38-plus] - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.11.0 hooks: - id: black language_version: python3 diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 996b763..5a15c1d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,9 @@ +4.1.0 (unreleased) +------------------ + +* Added support for Python 3.12 + + 4.0.0 (2022-10-07) ------------------ diff --git a/setup.cfg b/setup.cfg index c73c92a..26b3352 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,7 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Topic :: Internet :: WWW/HTTP [options] diff --git a/tox.ini b/tox.ini index b638f4c..a741f0e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{38,39,310,311} + py{38,39,310,311,312} [testenv] extras = tests From c07925d53fa2f29e8ec79a91aade6f515a201305 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Dec 2023 07:19:48 +0100 Subject: [PATCH 30/54] Bump actions/setup-python from 4 to 5 (#491) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 670a8ac..af816f7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,7 +26,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} From 993efe62ce9e9c1cd64c81b6ee7dfa7b819482c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 19:58:51 +0100 Subject: [PATCH 31/54] [pre-commit.ci] pre-commit autoupdate (#492) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c1fd822..05fe3f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,12 +5,12 @@ repos: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 23.12.1 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 From 5fdc9176e53e730338c51205bf216c108e669a5a Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 6 Feb 2024 09:04:10 +0100 Subject: [PATCH 32/54] Ignored flake8-bugbear B036. (#499) "except BaseException: without re-raising" used in testing.py --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 26b3352..a78e654 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,7 +50,7 @@ tests = [flake8] exclude = venv/*,tox/*,docs/*,testproject/*,js_client/*,.eggs/* -extend-ignore = E123, E128, E266, E402, W503, E731, W601 +extend-ignore = E123, E128, E266, E402, W503, E731, W601, B036 max-line-length = 120 [isort] From 9a282dd6277f4b921e494a9fc30a534a7f0d6ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20R=2E=20Sede=C3=B1o?= Date: Tue, 6 Feb 2024 03:15:03 -0500 Subject: [PATCH 33/54] Handle Daphne-Root-Path for websockets, adding root_path to scope. (#453) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro R. Sedeño --- daphne/ws_protocol.py | 9 +++++++-- tests/test_websocket.py | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index 975b1a9..184515d 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -31,17 +31,21 @@ class WebSocketProtocol(WebSocketServerProtocol): self.server.protocol_connected(self) self.request = request self.protocol_to_accept = None + self.root_path = self.server.root_path self.socket_opened = time.time() self.last_ping = time.time() try: - # Sanitize and decode headers + # Sanitize and decode headers, potentially extracting root path self.clean_headers = [] for name, value in request.headers.items(): name = name.encode("ascii") # Prevent CVE-2015-0219 if b"_" in name: continue - self.clean_headers.append((name.lower(), value.encode("latin1"))) + if name.lower() == b"daphne-root-path": + self.root_path = unquote(value) + else: + self.clean_headers.append((name.lower(), value.encode("latin1"))) # Get client address if possible peer = self.transport.getPeer() host = self.transport.getHost() @@ -76,6 +80,7 @@ class WebSocketProtocol(WebSocketServerProtocol): "type": "websocket", "path": unquote(self.path.decode("ascii")), "raw_path": self.path, + "root_path": self.root_path, "headers": self.clean_headers, "query_string": self._raw_query_string, # Passed by HTTP protocol "client": self.client_addr, diff --git a/tests/test_websocket.py b/tests/test_websocket.py index e954486..851143c 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -192,6 +192,30 @@ class TestWebsocket(DaphneTestCase): self.assertEqual(scope["path"], "/foo/bar") self.assertEqual(scope["raw_path"], b"/foo%2Fbar") + @given(daphne_path=http_strategies.http_path()) + @settings(max_examples=5, deadline=2000) + def test_root_path(self, *, daphne_path): + """ + Tests root_path handling. + """ + headers = [("Daphne-Root-Path", parse.quote(daphne_path))] + with DaphneTestingInstance() as test_app: + test_app.add_send_messages([{"type": "websocket.accept"}]) + self.websocket_handshake( + test_app, + path="/", + headers=headers, + ) + # Validate the scope and messages we got + scope, _ = test_app.get_received() + + # Daphne-Root-Path is not included in the returned 'headers' section. + self.assertNotIn( + "daphne-root-path", (header[0].lower() for header in scope["headers"]) + ) + # And what we're looking for, root_path being set. + self.assertEqual(scope["root_path"], daphne_path) + def test_text_frames(self): """ Tests we can send and receive text frames. From ef247962439eb19c52ae36e431307b98ed16b7f5 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Sat, 10 Feb 2024 15:31:37 +0100 Subject: [PATCH 34/54] Validate HTTP header names as per RFC 9110. (#500) Fixes #497. --- daphne/http_protocol.py | 9 ++++++++- daphne/utils.py | 5 +++++ tests/test_http_request.py | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index f0657fd..b7da1bf 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -9,7 +9,7 @@ from twisted.protocols.policies import ProtocolWrapper from twisted.web import http from zope.interface import implementer -from .utils import parse_x_forwarded_for +from .utils import HEADER_NAME_RE, parse_x_forwarded_for logger = logging.getLogger(__name__) @@ -69,6 +69,13 @@ class WebRequest(http.Request): def process(self): try: self.request_start = time.time() + + # Validate header names. + for name, _ in self.requestHeaders.getAllRawHeaders(): + if not HEADER_NAME_RE.fullmatch(name): + self.basic_error(400, b"Bad Request", "Invalid header name") + return + # Get upgrade header upgrade_header = None if self.requestHeaders.hasHeader(b"Upgrade"): diff --git a/daphne/utils.py b/daphne/utils.py index 81f1f9d..0699314 100644 --- a/daphne/utils.py +++ b/daphne/utils.py @@ -1,7 +1,12 @@ import importlib +import re from twisted.web.http_headers import Headers +# Header name regex as per h11. +# https://github.com/python-hyper/h11/blob/a2c68948accadc3876dffcf979d98002e4a4ed27/h11/_abnf.py#L10-L21 +HEADER_NAME_RE = re.compile(rb"[-!#$%&'*+.^_`|~0-9a-zA-Z]+") + def import_by_path(path): """ diff --git a/tests/test_http_request.py b/tests/test_http_request.py index 52f6dd1..dca5bd7 100644 --- a/tests/test_http_request.py +++ b/tests/test_http_request.py @@ -310,3 +310,15 @@ class TestHTTPRequest(DaphneTestCase): b"GET /?\xc3\xa4\xc3\xb6\xc3\xbc HTTP/1.0\r\n\r\n" ) self.assertTrue(response.startswith(b"HTTP/1.0 400 Bad Request")) + + def test_invalid_header_name(self): + """ + Tests that requests with invalid header names fail. + """ + # Test cases follow those used by h11 + # https://github.com/python-hyper/h11/blob/a2c68948accadc3876dffcf979d98002e4a4ed27/h11/tests/test_headers.py#L24-L35 + for header_name in [b"foo bar", b"foo\x00bar", b"foo\xffbar", b"foo\x01bar"]: + response = self.run_daphne_raw( + f"GET / HTTP/1.0\r\n{header_name}: baz\r\n\r\n".encode("ascii") + ) + self.assertTrue(response.startswith(b"HTTP/1.0 400 Bad Request")) From df0680c9ad699817725e18a9264df17fff2927da Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Sat, 10 Feb 2024 15:39:05 +0100 Subject: [PATCH 35/54] Updated change notes and version for 4.1 release. --- CHANGELOG.txt | 9 +++++++-- daphne/__init__.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5a15c1d..3f37b37 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,8 +1,13 @@ -4.1.0 (unreleased) +4.1.0 (2024-02-10) ------------------ -* Added support for Python 3.12 +* Added support for Python 3.12. +* Dropped support for EOL Python 3.7. + +* Handled root path for websocket scopes. + +* Validate HTTP header names as per RFC 9110. 4.0.0 (2022-10-07) ------------------ diff --git a/daphne/__init__.py b/daphne/__init__.py index ae556a6..9c10154 100755 --- a/daphne/__init__.py +++ b/daphne/__init__.py @@ -1,6 +1,6 @@ import sys -__version__ = "4.0.0" +__version__ = "4.1.0" # Windows on Python 3.8+ uses ProactorEventLoop, which is not compatible with From 63790936d1f5728ff358ff9c5d519454c36f4e33 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 07:14:14 +0200 Subject: [PATCH 36/54] [pre-commit.ci] pre-commit autoupdate (#503) --- .pre-commit-config.yaml | 6 +++--- daphne/cli.py | 12 ++++++------ daphne/http_protocol.py | 8 +++++--- daphne/ws_protocol.py | 24 ++++++++++++------------ 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 05fe3f8..16c31cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.15.2 hooks: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.3.0 hooks: - id: black language_version: python3 @@ -14,7 +14,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 additional_dependencies: diff --git a/daphne/cli.py b/daphne/cli.py index 7c0c3c9..a036821 100755 --- a/daphne/cli.py +++ b/daphne/cli.py @@ -270,16 +270,16 @@ class CommandLineInterface: websocket_connect_timeout=args.websocket_connect_timeout, websocket_handshake_timeout=args.websocket_connect_timeout, application_close_timeout=args.application_close_timeout, - action_logger=AccessLogGenerator(access_log_stream) - if access_log_stream - else None, + action_logger=( + AccessLogGenerator(access_log_stream) if access_log_stream else None + ), root_path=args.root_path, verbosity=args.verbosity, proxy_forwarded_address_header=self._get_forwarded_host(args=args), proxy_forwarded_port_header=self._get_forwarded_port(args=args), - proxy_forwarded_proto_header="X-Forwarded-Proto" - if args.proxy_headers - else None, + proxy_forwarded_proto_header=( + "X-Forwarded-Proto" if args.proxy_headers else None + ), server_name=args.server_name, ) self.server.run() diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index b7da1bf..e9eba96 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -286,9 +286,11 @@ class WebRequest(http.Request): "path": uri, "status": self.code, "method": self.method.decode("ascii", "replace"), - "client": "%s:%s" % tuple(self.client_addr) - if self.client_addr - else None, + "client": ( + "%s:%s" % tuple(self.client_addr) + if self.client_addr + else None + ), "time_taken": self.duration(), "size": self.sentLength, }, diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index 184515d..b1e29c3 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -115,9 +115,9 @@ class WebSocketProtocol(WebSocketServerProtocol): "connecting", { "path": self.request.path, - "client": "%s:%s" % tuple(self.client_addr) - if self.client_addr - else None, + "client": ( + "%s:%s" % tuple(self.client_addr) if self.client_addr else None + ), }, ) @@ -138,9 +138,9 @@ class WebSocketProtocol(WebSocketServerProtocol): "connected", { "path": self.request.path, - "client": "%s:%s" % tuple(self.client_addr) - if self.client_addr - else None, + "client": ( + "%s:%s" % tuple(self.client_addr) if self.client_addr else None + ), }, ) @@ -175,9 +175,9 @@ class WebSocketProtocol(WebSocketServerProtocol): "disconnected", { "path": self.request.path, - "client": "%s:%s" % tuple(self.client_addr) - if self.client_addr - else None, + "client": ( + "%s:%s" % tuple(self.client_addr) if self.client_addr else None + ), }, ) @@ -242,9 +242,9 @@ class WebSocketProtocol(WebSocketServerProtocol): "rejected", { "path": self.request.path, - "client": "%s:%s" % tuple(self.client_addr) - if self.client_addr - else None, + "client": ( + "%s:%s" % tuple(self.client_addr) if self.client_addr else None + ), }, ) From c0b630834cc5a794bfc7b4855b30e4631c32e88e Mon Sep 17 00:00:00 2001 From: sdc50 Date: Wed, 10 Apr 2024 09:33:21 -0600 Subject: [PATCH 37/54] Fix twisted.plugin install (#507) --- setup.cfg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index a78e654..cef2824 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,7 +26,9 @@ classifiers = [options] package_dir = twisted=daphne/twisted -packages = find: +packages = + daphne + twisted.plugins include_package_data = True install_requires = asgiref>=3.5.2,<4 From cf9145985b17ecab2bb260ef30a592328b87a599 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Wed, 10 Apr 2024 17:42:01 +0200 Subject: [PATCH 38/54] Updated version and changelog for v4.1.1 release. --- CHANGELOG.txt | 7 +++++++ daphne/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3f37b37..82521fe 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,10 @@ +4.1.1 (2024-04-10) +------------------ + +* Fixed a twisted.plugin packaging error in 4.1.0. + + Thanks to sdc50. + 4.1.0 (2024-02-10) ------------------ diff --git a/daphne/__init__.py b/daphne/__init__.py index 9c10154..ee354c7 100755 --- a/daphne/__init__.py +++ b/daphne/__init__.py @@ -1,6 +1,6 @@ import sys -__version__ = "4.1.0" +__version__ = "4.1.1" # Windows on Python 3.8+ uses ProactorEventLoop, which is not compatible with From 0f15e4595b195a7d6c0cb4df58df69afd6b17045 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Thu, 11 Apr 2024 15:23:49 +0200 Subject: [PATCH 39/54] Fixed packaging configuration. (#510) Use auto-discovery, but make sure daphne package is correctly listed. --- CHANGELOG.txt | 5 +++++ daphne/__init__.py | 2 +- setup.cfg | 4 +--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 82521fe..5df13c7 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +4.1.2 (2024-04-11) +------------------ + +* Fixed a setuptools configuration error in 4.1.1. + 4.1.1 (2024-04-10) ------------------ diff --git a/daphne/__init__.py b/daphne/__init__.py index ee354c7..19ba8ff 100755 --- a/daphne/__init__.py +++ b/daphne/__init__.py @@ -1,6 +1,6 @@ import sys -__version__ = "4.1.1" +__version__ = "4.1.2" # Windows on Python 3.8+ uses ProactorEventLoop, which is not compatible with diff --git a/setup.cfg b/setup.cfg index cef2824..8e08789 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,10 +25,8 @@ classifiers = [options] package_dir = + daphne=daphne twisted=daphne/twisted -packages = - daphne - twisted.plugins include_package_data = True install_requires = asgiref>=3.5.2,<4 From 4a55faca45db2e2a4c275ee02c44893e6af0b5c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:38:28 +0200 Subject: [PATCH 40/54] [pre-commit.ci] pre-commit autoupdate (#515) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.15.2 → v3.16.0](https://github.com/asottile/pyupgrade/compare/v3.15.2...v3.16.0) - [github.com/psf/black: 24.3.0 → 24.4.2](https://github.com/psf/black/compare/24.3.0...24.4.2) - [github.com/PyCQA/flake8: 7.0.0 → 7.1.0](https://github.com/PyCQA/flake8/compare/7.0.0...7.1.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 16c31cf..8c5f5b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 + rev: v3.16.0 hooks: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/psf/black - rev: 24.3.0 + rev: 24.4.2 hooks: - id: black language_version: python3 @@ -14,7 +14,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 + rev: 7.1.0 hooks: - id: flake8 additional_dependencies: From 420f065d9e85df332f6f1f6ba28688efb09b4bc3 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Sat, 24 Aug 2024 11:34:29 -0700 Subject: [PATCH 41/54] Remove pytest-runner Closes: https://github.com/django/daphne/issues/523 --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 8e08789..790bd16 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,8 +33,6 @@ install_requires = autobahn>=22.4.2 twisted[tls]>=22.4 python_requires = >=3.8 -setup_requires = - pytest-runner zip_safe = False [options.entry_points] From 3607351212ea01159c95e05868733f804fcea48b Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Sat, 24 Aug 2024 11:36:44 -0700 Subject: [PATCH 42/54] Revert "Remove pytest-runner" This reverts commit 420f065d9e85df332f6f1f6ba28688efb09b4bc3. --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.cfg b/setup.cfg index 790bd16..8e08789 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,6 +33,8 @@ install_requires = autobahn>=22.4.2 twisted[tls]>=22.4 python_requires = >=3.8 +setup_requires = + pytest-runner zip_safe = False [options.entry_points] From 9ec5798c0d17f0858229dd800955abab4fa803fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sat, 24 Aug 2024 11:47:58 -0700 Subject: [PATCH 43/54] fix tests with Twisted 24.7.0 (#526) In the fixed test cases the responses now contain `HTTP/1.1` rather than `HTTP/1.0`. --- tests/test_http_request.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_http_request.py b/tests/test_http_request.py index dca5bd7..f0fe376 100644 --- a/tests/test_http_request.py +++ b/tests/test_http_request.py @@ -304,12 +304,12 @@ class TestHTTPRequest(DaphneTestCase): response = self.run_daphne_raw( b"GET /\xc3\xa4\xc3\xb6\xc3\xbc HTTP/1.0\r\n\r\n" ) - self.assertTrue(response.startswith(b"HTTP/1.0 400 Bad Request")) + self.assertTrue(b"400 Bad Request" in response) # Bad querystring response = self.run_daphne_raw( b"GET /?\xc3\xa4\xc3\xb6\xc3\xbc HTTP/1.0\r\n\r\n" ) - self.assertTrue(response.startswith(b"HTTP/1.0 400 Bad Request")) + self.assertTrue(b"400 Bad Request" in response) def test_invalid_header_name(self): """ @@ -321,4 +321,4 @@ class TestHTTPRequest(DaphneTestCase): response = self.run_daphne_raw( f"GET / HTTP/1.0\r\n{header_name}: baz\r\n\r\n".encode("ascii") ) - self.assertTrue(response.startswith(b"HTTP/1.0 400 Bad Request")) + self.assertTrue(b"400 Bad Request" in response) From b1902e8ccda05d3fed3513e5c534f25607712052 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Sat, 24 Aug 2024 11:51:43 -0700 Subject: [PATCH 44/54] Remove pytest-runner (#528) Closes: https://github.com/django/daphne/issues/523 --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 8e08789..790bd16 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,8 +33,6 @@ install_requires = autobahn>=22.4.2 twisted[tls]>=22.4 python_requires = >=3.8 -setup_requires = - pytest-runner zip_safe = False [options.entry_points] From 862ebcd08dcd9f392e9603a880fb00a6e710f3b6 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Mon, 26 Aug 2024 07:02:23 -0700 Subject: [PATCH 45/54] Include test support files in sdist (#530) Closes: https://github.com/django/daphne/issues/522 --- CHANGELOG.txt | 6 ++++++ MANIFEST.in | 1 + daphne/__init__.py | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5df13c7..437c517 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,9 @@ +4.1.3 (to be released) +------------------ + +* Removed unused pytest-runner +* Fixed sdist file to ensure it includes all tests + 4.1.2 (2024-04-11) ------------------ diff --git a/MANIFEST.in b/MANIFEST.in index 1aba38f..90b3902 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include LICENSE +recursive-include tests *.py \ No newline at end of file diff --git a/daphne/__init__.py b/daphne/__init__.py index 19ba8ff..2a21298 100755 --- a/daphne/__init__.py +++ b/daphne/__init__.py @@ -1,6 +1,6 @@ import sys -__version__ = "4.1.2" +__version__ = "4.1.3" # Windows on Python 3.8+ uses ProactorEventLoop, which is not compatible with From ffad9c3cfdeec25a9014ce416c601587273bf190 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:10:56 -0700 Subject: [PATCH 46/54] [pre-commit.ci] pre-commit autoupdate (#532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.16.0 → v3.17.0](https://github.com/asottile/pyupgrade/compare/v3.16.0...v3.17.0) - [github.com/psf/black: 24.4.2 → 24.10.0](https://github.com/psf/black/compare/24.4.2...24.10.0) - [github.com/PyCQA/flake8: 7.1.0 → 7.1.1](https://github.com/PyCQA/flake8/compare/7.1.0...7.1.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8c5f5b0..38c1361 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.16.0 + rev: v3.17.0 hooks: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/psf/black - rev: 24.4.2 + rev: 24.10.0 hooks: - id: black language_version: python3 @@ -14,7 +14,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 7.1.0 + rev: 7.1.1 hooks: - id: flake8 additional_dependencies: From 06afd9b94aa82ebdfea945a1810ce25d32d3593b Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 29 Oct 2024 03:03:41 +0100 Subject: [PATCH 47/54] Drop support for EOL Python 3.8. (#536) --- .github/workflows/tests.yml | 1 - CHANGELOG.txt | 5 ++++- README.rst | 2 +- setup.cfg | 3 +-- tox.ini | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index af816f7..749d897 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,6 @@ jobs: - ubuntu - windows python-version: - - "3.8" - "3.9" - "3.10" - "3.11" diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 437c517..72738ff 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,7 +1,10 @@ -4.1.3 (to be released) +4.2.0 (to be released) ------------------ +* Drop support for EOL Python 3.8. + * Removed unused pytest-runner + * Fixed sdist file to ensure it includes all tests 4.1.2 (2024-04-11) diff --git a/README.rst b/README.rst index d93ad02..f7b8e32 100644 --- a/README.rst +++ b/README.rst @@ -108,7 +108,7 @@ should start with a slash, but not end with one; for example:: Python Support -------------- -Daphne requires Python 3.8 or later. +Daphne requires Python 3.9 or later. Contributing diff --git a/setup.cfg b/setup.cfg index 790bd16..a717acc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,7 +16,6 @@ classifiers = Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 @@ -32,7 +31,7 @@ install_requires = asgiref>=3.5.2,<4 autobahn>=22.4.2 twisted[tls]>=22.4 -python_requires = >=3.8 +python_requires = >=3.9 zip_safe = False [options.entry_points] diff --git a/tox.ini b/tox.ini index a741f0e..95eb7f9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{38,39,310,311,312} + py{39,310,311,312} [testenv] extras = tests From e25b4bcc3165c844e7f0cc33ebaed25a27998479 Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:56:40 +0000 Subject: [PATCH 48/54] Target py39-plus with pyupgrade. (#540) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 38c1361..4397d89 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,9 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + rev: v3.19.0 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py39-plus] - repo: https://github.com/psf/black rev: 24.10.0 hooks: From 32ac73e1a0fb87af0e3280c89fe4cc3ff1231b37 Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:57:11 +0000 Subject: [PATCH 49/54] Added support for Python 3.13. (#539) --- .github/workflows/tests.yml | 1 + CHANGELOG.txt | 2 ++ setup.cfg | 1 + tox.ini | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 749d897..c68ac58 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,6 +20,7 @@ jobs: - "3.10" - "3.11" - "3.12" + - "3.13" steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 72738ff..40e6e3f 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,8 @@ 4.2.0 (to be released) ------------------ +* Added support for Python 3.13. + * Drop support for EOL Python 3.8. * Removed unused pytest-runner diff --git a/setup.cfg b/setup.cfg index a717acc..8d2b2e7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,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 [options] diff --git a/tox.ini b/tox.ini index 95eb7f9..e3bae91 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{39,310,311,312} + py{39,310,311,312,313} [testenv] extras = tests From f0a3ec60e949ee181e09aa11965ed0e25403d4c2 Mon Sep 17 00:00:00 2001 From: David Fuentes Baldomir Date: Sat, 4 Jan 2025 09:37:17 +0100 Subject: [PATCH 50/54] Add --nostatic and --insecure args to runserver command. (#450) Fixes #449 --- daphne/management/commands/runserver.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/daphne/management/commands/runserver.py b/daphne/management/commands/runserver.py index b2fd2ee..7e67e07 100644 --- a/daphne/management/commands/runserver.py +++ b/daphne/management/commands/runserver.py @@ -73,6 +73,18 @@ class Command(RunserverCommand): "seconds (default: 5)" ), ) + parser.add_argument( + "--nostatic", + action="store_false", + dest="use_static_handler", + help="Tells Django to NOT automatically serve static files at STATIC_URL.", + ) + parser.add_argument( + "--insecure", + action="store_true", + dest="insecure_serving", + help="Allows serving static files even if DEBUG is False.", + ) def handle(self, *args, **options): self.http_timeout = options.get("http_timeout", None) From 786e4c120a6e0f4819570901ab848fb08522ea8b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 07:33:08 +0100 Subject: [PATCH 51/54] [pre-commit.ci] pre-commit autoupdate (#546) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4397d89..bdb453c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.19.0 + rev: v3.19.1 hooks: - id: pyupgrade args: [--py39-plus] From 630caed9153f8eb62aecfade3e349d3cc6ee1bb0 Mon Sep 17 00:00:00 2001 From: Andrew Sears Date: Wed, 22 Jan 2025 11:34:39 -0500 Subject: [PATCH 52/54] Upgrade project metadata (#542) --- .flake8 | 11 ++++++ .github/workflows/tests.yml | 4 ++ .gitignore | 1 + daphne/testing.py | 2 +- pyproject.toml | 78 +++++++++++++++++++++++++++++++++++++ setup.cfg | 59 ---------------------------- 6 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 .flake8 delete mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..d60ef28 --- /dev/null +++ b/.flake8 @@ -0,0 +1,11 @@ +[flake8] +exclude = + .venv, + .tox, + docs, + testproject, + js_client, + .eggs + +extend-ignore = E123, E128, E266, E402, W503, E731, W601, B036 +max-line-length = 120 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c68ac58..68b91f7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,10 @@ on: branches: - main pull_request: + workflow_dispatch: + +permissions: + contents: read jobs: tests: diff --git a/.gitignore b/.gitignore index 20cb4bd..0616f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ test_consumer* .python-version .pytest_cache/ .vscode +.coverage diff --git a/daphne/testing.py b/daphne/testing.py index 785edf9..46787bb 100644 --- a/daphne/testing.py +++ b/daphne/testing.py @@ -158,7 +158,7 @@ class DaphneProcess(multiprocessing.Process): application=application, endpoints=endpoints, signal_handlers=False, - **self.kwargs + **self.kwargs, ) # Set up a poller to look for the port reactor.callLater(0.1, self.resolve_port) diff --git a/pyproject.toml b/pyproject.toml index fed528d..7a2e796 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,81 @@ +[project] +name = "daphne" +dynamic = ["version"] +description = "Django ASGI (HTTP/WebSocket) server" +requires-python = ">=3.9" +authors = [ + { name = "Django Software Foundation", email = "foundation@djangoproject.com" }, +] + +license = { text = "BSD" } +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "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 = ["asgiref>=3.5.2,<4", "autobahn>=22.4.2", "twisted[tls]>=22.4"] + +[project.optional-dependencies] +tests = [ + "django", + "hypothesis", + "pytest", + "pytest-asyncio", + "pytest-cov", + "black", + "tox", + "flake8", + "flake8-bugbear", + "mypy", +] + +[project.urls] +homepage = "https://github.com/django/daphne" +documentation = "https://channels.readthedocs.io" +repository = "https://github.com/django/daphne.git" +changelog = "https://github.com/django/daphne/blob/main/CHANGELOG.txt" +issues = "https://github.com/django/daphne/issues" + +[project.scripts] +daphne = "daphne.cli:CommandLineInterface.entrypoint" + [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["daphne"] + +[tool.setuptools.dynamic] +version = { attr = "daphne.__version__" } +readme = { file = "README.rst", content-type = "text/x-rst" } + +[tool.isort] +profile = "black" + +[tool.pytest] +testpaths = ["tests"] +asyncio_mode = "strict" +filterwarnings = ["ignore::pytest.PytestDeprecationWarning"] + +[tool.coverage.run] +omit = ["tests/*"] +concurrency = ["multiprocessing"] + +[tool.coverage.report] +show_missing = "true" +skip_covered = "true" + +[tool.coverage.html] +directory = "reports/coverage_html_report" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 8d2b2e7..0000000 --- a/setup.cfg +++ /dev/null @@ -1,59 +0,0 @@ -[metadata] -name = daphne -version = attr: daphne.__version__ -url = https://github.com/django/daphne -author = Django Software Foundation -author_email = foundation@djangoproject.com -description = Django ASGI (HTTP/WebSocket) server -long_description = file: README.rst -long_description_content_type = text/x-rst -license = BSD -classifiers = - Development Status :: 4 - Beta - Environment :: Web Environment - Intended Audience :: Developers - License :: OSI Approved :: BSD License - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Programming Language :: Python :: 3.13 - Topic :: Internet :: WWW/HTTP - -[options] -package_dir = - daphne=daphne - twisted=daphne/twisted -include_package_data = True -install_requires = - asgiref>=3.5.2,<4 - autobahn>=22.4.2 - twisted[tls]>=22.4 -python_requires = >=3.9 -zip_safe = False - -[options.entry_points] -console_scripts = - daphne = daphne.cli:CommandLineInterface.entrypoint - -[options.extras_require] -tests = - django - hypothesis - pytest - pytest-asyncio - -[flake8] -exclude = venv/*,tox/*,docs/*,testproject/*,js_client/*,.eggs/* -extend-ignore = E123, E128, E266, E402, W503, E731, W601, B036 -max-line-length = 120 - -[isort] -profile = black - -[tool:pytest] -testpaths = tests -asyncio_mode = strict From 7c9334952d2b0282543f04bc63b77d77616a92df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Apr 2025 06:58:38 -0700 Subject: [PATCH 53/54] [pre-commit.ci] pre-commit autoupdate (#551) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 24.10.0 → 25.1.0](https://github.com/psf/black/compare/24.10.0...25.1.0) - [github.com/pycqa/isort: 5.13.2 → 6.0.1](https://github.com/pycqa/isort/compare/5.13.2...6.0.1) - [github.com/PyCQA/flake8: 7.1.1 → 7.2.0](https://github.com/PyCQA/flake8/compare/7.1.1...7.2.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bdb453c..c315a04 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,16 +5,16 @@ repos: - id: pyupgrade args: [--py39-plus] - repo: https://github.com/psf/black - rev: 24.10.0 + rev: 25.1.0 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 6.0.1 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.2.0 hooks: - id: flake8 additional_dependencies: From beef1c15142250ed145bea1d968d0276f7892f63 Mon Sep 17 00:00:00 2001 From: Mohammed <74480856+MohammedSaleh2001@users.noreply.github.com> Date: Wed, 7 May 2025 08:33:22 -0600 Subject: [PATCH 54/54] Allowed assigning a port in DaphneProcess test helper. (#550) --- daphne/testing.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/daphne/testing.py b/daphne/testing.py index 46787bb..9120327 100644 --- a/daphne/testing.py +++ b/daphne/testing.py @@ -126,14 +126,16 @@ class DaphneProcess(multiprocessing.Process): port it ends up listening on back to the parent process. """ - def __init__(self, host, get_application, kwargs=None, setup=None, teardown=None): + def __init__( + self, host, get_application, kwargs=None, setup=None, teardown=None, port=None + ): super().__init__() self.host = host self.get_application = get_application self.kwargs = kwargs or {} self.setup = setup self.teardown = teardown - self.port = multiprocessing.Value("i") + self.port = multiprocessing.Value("i", port if port is not None else 0) self.ready = multiprocessing.Event() self.errors = multiprocessing.Queue() @@ -153,7 +155,9 @@ class DaphneProcess(multiprocessing.Process): try: # Create the server class - endpoints = build_endpoint_description_strings(host=self.host, port=0) + endpoints = build_endpoint_description_strings( + host=self.host, port=self.port.value + ) self.server = Server( application=application, endpoints=endpoints,