diff --git a/daphne/cli.py b/daphne/cli.py index 0becb7b..6eead10 100755 --- a/daphne/cli.py +++ b/daphne/cli.py @@ -5,6 +5,7 @@ import inspect import logging import sys from argparse import ArgumentError, Namespace +from asgiref.compatibility import is_double_callable from .access import AccessLogGenerator from .endpoints import build_endpoint_description_strings @@ -221,23 +222,6 @@ class CommandLineInterface(object): if args.proxy_headers: return "X-Forwarded-Port" - def _guess_asgi_protocol(self, application): - if getattr(application, "_asgi_single_callable", False): - return "asgi3" - if getattr(application, "_asgi_double_callable", False): - return "asgi2" - # Uninstanted classes are double-callable - if inspect.isclass(application): - return "asgi2" - # Instanted classes depend on their __call__ - if hasattr(application, "__call__"): - # We only check to see if its __call__ is a coroutine function - - # if it's not, it still might be a coroutine function itself. - if asyncio.iscoroutinefunction(application.__call__): - return "asgi3" - # Non-classes we just check directly - return "asgi3" if asyncio.iscoroutinefunction(application) else "asgi2" - def run(self, args): """ Pass in raw argument list and it will decode them @@ -270,7 +254,7 @@ class CommandLineInterface(object): asgi_protocol = args.asgi_protocol if asgi_protocol == "auto": - asgi_protocol = self._guess_asgi_protocol(application) + asgi_protocol = "asgi2" if is_double_callable(application) else "asgi3" if asgi_protocol == "asgi3": application = ASGI3Middleware(application) diff --git a/setup.py b/setup.py index 65d7bf9..1c15325 100755 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ setup( package_dir={"twisted": "daphne/twisted"}, packages=find_packages() + ["twisted.plugins"], include_package_data=True, - install_requires=["twisted>=18.7", "autobahn>=0.18"], + install_requires=["twisted>=18.7", "autobahn>=0.18", "asgiref>=3.0.0"], setup_requires=["pytest-runner"], extras_require={ "tests": ["hypothesis~=3.88", "pytest~=3.10", "pytest-asyncio~=0.8"]