Skip to content

Commit

Permalink
Avoid importing private APIs from websockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Nov 27, 2022
1 parent 19762d6 commit 3cddcf4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions sanic/server/protocols/websocket_protocol.py
Expand Up @@ -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
Expand All @@ -21,6 +21,11 @@
from websockets import http11


OPEN = State.OPEN
CLOSING = State.CLOSING
CLOSED = State.CLOSED


class WebSocketProtocol(HttpProtocol):
__slots__ = (
"websocket",
Expand Down
9 changes: 7 additions & 2 deletions sanic/server/websockets/impl.py
Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 3cddcf4

Please sign in to comment.