MCPcopy Create free account
hub / github.com/python-websockets/websockets / remove_path_argument

Function remove_path_argument

src/websockets/legacy/server.py:1162–1191  ·  view source on GitHub ↗
(
    ws_handler: (
        Callable[[WebSocketServerProtocol], Awaitable[Any]]
        | Callable[[WebSocketServerProtocol, str], Awaitable[Any]]
    ),
)

Source from the content-addressed store, hash-verified

1160
1161
1162def remove_path_argument(
1163 ws_handler: (
1164 Callable[[WebSocketServerProtocol], Awaitable[Any]]
1165 | Callable[[WebSocketServerProtocol, str], Awaitable[Any]]
1166 ),
1167) -> Callable[[WebSocketServerProtocol], Awaitable[Any]]:
1168 try:
1169 inspect.signature(ws_handler).bind(None)
1170 except TypeError:
1171 try:
1172 inspect.signature(ws_handler).bind(None, "")
1173 except TypeError: # pragma: no cover
1174 # ws_handler accepts neither one nor two arguments; leave it alone.
1175 pass
1176 else:
1177 # ws_handler accepts two arguments; activate backwards compatibility.
1178 warnings.warn("remove second argument of ws_handler", DeprecationWarning)
1179
1180 async def _ws_handler(websocket: WebSocketServerProtocol) -> Any:
1181 return await cast(
1182 Callable[[WebSocketServerProtocol, str], Awaitable[Any]],
1183 ws_handler,
1184 )(websocket, websocket.path)
1185
1186 return _ws_handler
1187
1188 return cast(
1189 Callable[[WebSocketServerProtocol], Awaitable[Any]],
1190 ws_handler,
1191 )

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…