diff --git a/sanic/server/protocols/websocket_protocol.py b/sanic/server/protocols/websocket_protocol.py index c3c7b460f3..1e57983656 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.protocol import CLOSED, CLOSING, OPEN + from websockets.protocol import State from websockets.server import ServerProtocol except ImportError: # websockets < 11.0 - from websockets.connection import CLOSED, CLOSING, OPEN + from websockets.connection import State from websockets.server import ServerConnection as 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 3d8461fe10..429009f8a0 100644 --- a/sanic/server/websockets/impl.py +++ b/sanic/server/websockets/impl.py @@ -21,10 +21,10 @@ try: # websockets >= 11.0 - from websockets.protocol import CLOSED, CLOSING, OPEN, Event + from websockets.protocol import State, Event from websockets.server import ServerProtocol except ImportError: # websockets < 11.0 - from websockets.connection import CLOSED, CLOSING, OPEN, Event + from websockets.connection import State, Event from websockets.server import ServerConnection as 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]