diff --git a/sanic/server/protocols/websocket_protocol.py b/sanic/server/protocols/websocket_protocol.py index fdd931bdda..06efd9cac1 100644 --- a/sanic/server/protocols/websocket_protocol.py +++ b/sanic/server/protocols/websocket_protocol.py @@ -2,10 +2,10 @@ try: # websockets < 11.0 - from websockets.connection import CLOSED, CLOSING, OPEN + from websockets.connection import State from websockets.server import ServerConnection as ServerProtocol except ImportError: # websockets >= 11.0 - from websockets.protocol import CLOSED, CLOSING, OPEN + from websockets.protocol import State from websockets.server import ServerProtocol from websockets.typing import Subprotocol @@ -21,6 +21,11 @@ from websockets import http11 +OPEN = State.OPEN +CLOSING = State.CLOSING +CLOSED = State.CLOSED + + class WebSocketProtocol(HttpProtocol): __slots__ = ( "websocket", diff --git a/sanic/server/websockets/impl.py b/sanic/server/websockets/impl.py index c15db1710b..ee2df5ae1d 100644 --- a/sanic/server/websockets/impl.py +++ b/sanic/server/websockets/impl.py @@ -21,10 +21,10 @@ try: # websockets < 11.0 - from websockets.connection import CLOSED, CLOSING, OPEN, Event + from websockets.connection import Event, State from websockets.server import ServerConnection as ServerProtocol except ImportError: # websockets >= 11.0 - from websockets.protocol import CLOSED, CLOSING, OPEN, Event + from websockets.protocol import Event, State from websockets.server import ServerProtocol from websockets.typing import Data @@ -36,6 +36,11 @@ from .frame import WebsocketFrameAssembler +OPEN = State.OPEN +CLOSING = State.CLOSING +CLOSED = State.CLOSED + + class WebsocketImplProtocol: ws_proto: ServerProtocol io_proto: Optional[SanicProtocol]