mirror of
https://github.com/django/daphne.git
synced 2025-07-27 07:29:46 +03:00
Use asgiref.compatibility
This commit is contained in:
parent
220c07b260
commit
d1723e064b
|
@ -5,6 +5,7 @@ import inspect
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentError, Namespace
|
from argparse import ArgumentError, Namespace
|
||||||
|
from asgiref.compatibility import is_double_callable
|
||||||
|
|
||||||
from .access import AccessLogGenerator
|
from .access import AccessLogGenerator
|
||||||
from .endpoints import build_endpoint_description_strings
|
from .endpoints import build_endpoint_description_strings
|
||||||
|
@ -221,23 +222,6 @@ class CommandLineInterface(object):
|
||||||
if args.proxy_headers:
|
if args.proxy_headers:
|
||||||
return "X-Forwarded-Port"
|
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):
|
def run(self, args):
|
||||||
"""
|
"""
|
||||||
Pass in raw argument list and it will decode them
|
Pass in raw argument list and it will decode them
|
||||||
|
@ -270,7 +254,7 @@ class CommandLineInterface(object):
|
||||||
|
|
||||||
asgi_protocol = args.asgi_protocol
|
asgi_protocol = args.asgi_protocol
|
||||||
if asgi_protocol == "auto":
|
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":
|
if asgi_protocol == "asgi3":
|
||||||
application = ASGI3Middleware(application)
|
application = ASGI3Middleware(application)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -22,7 +22,7 @@ setup(
|
||||||
package_dir={"twisted": "daphne/twisted"},
|
package_dir={"twisted": "daphne/twisted"},
|
||||||
packages=find_packages() + ["twisted.plugins"],
|
packages=find_packages() + ["twisted.plugins"],
|
||||||
include_package_data=True,
|
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"],
|
setup_requires=["pytest-runner"],
|
||||||
extras_require={
|
extras_require={
|
||||||
"tests": ["hypothesis~=3.88", "pytest~=3.10", "pytest-asyncio~=0.8"]
|
"tests": ["hypothesis~=3.88", "pytest~=3.10", "pytest-asyncio~=0.8"]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user