auto.py 611 B

123456789101112131415161718192021
  1. from __future__ import annotations
  2. import asyncio
  3. from collections.abc import Callable
  4. AutoWebSocketsProtocol: Callable[..., asyncio.Protocol] | None
  5. try:
  6. import websockets # noqa
  7. except ImportError: # pragma: no cover
  8. try:
  9. import wsproto # noqa
  10. except ImportError:
  11. AutoWebSocketsProtocol = None
  12. else:
  13. from uvicorn.protocols.websockets.wsproto_impl import WSProtocol
  14. AutoWebSocketsProtocol = WSProtocol
  15. else:
  16. from uvicorn.protocols.websockets.websockets_sansio_impl import WebSocketsSansIOProtocol
  17. AutoWebSocketsProtocol = WebSocketsSansIOProtocol