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

Method __init__

src/websockets/legacy/server.py:976–1100  ·  view source on GitHub ↗
(
        self,
        # The version that accepts the path in the second argument is deprecated.
        ws_handler: (
            Callable[[WebSocketServerProtocol], Awaitable[Any]]
            | Callable[[WebSocketServerProtocol, str], Awaitable[Any]]
        ),
        host: str | Sequence[str] | None = None,
        port: int | None = None,
        *,
        create_protocol: Callable[..., WebSocketServerProtocol] | None = None,
        logger: LoggerLike | None = None,
        compression: str | None = "deflate",
        origins: Sequence[Origin | None] | None = None,
        extensions: Sequence[ServerExtensionFactory] | None = None,
        subprotocols: Sequence[Subprotocol] | None = None,
        extra_headers: HeadersLikeOrCallable | None = None,
        server_header: str | None = SERVER,
        process_request: (
            Callable[[str, Headers], Awaitable[HTTPResponse | None]] | None
        ) = None,
        select_subprotocol: (
            Callable[[Sequence[Subprotocol], Sequence[Subprotocol]], Subprotocol] | None
        ) = None,
        open_timeout: float | None = 10,
        ping_interval: float | None = 20,
        ping_timeout: float | None = 20,
        close_timeout: float | None = None,
        max_size: int | None = 2**20,
        max_queue: int | None = 2**5,
        read_limit: int = 2**16,
        write_limit: int = 2**16,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

974 """
975
976 def __init__(
977 self,
978 # The version that accepts the path in the second argument is deprecated.
979 ws_handler: (
980 Callable[[WebSocketServerProtocol], Awaitable[Any]]
981 | Callable[[WebSocketServerProtocol, str], Awaitable[Any]]
982 ),
983 host: str | Sequence[str] | None = None,
984 port: int | None = None,
985 *,
986 create_protocol: Callable[..., WebSocketServerProtocol] | None = None,
987 logger: LoggerLike | None = None,
988 compression: str | None = "deflate",
989 origins: Sequence[Origin | None] | None = None,
990 extensions: Sequence[ServerExtensionFactory] | None = None,
991 subprotocols: Sequence[Subprotocol] | None = None,
992 extra_headers: HeadersLikeOrCallable | None = None,
993 server_header: str | None = SERVER,
994 process_request: (
995 Callable[[str, Headers], Awaitable[HTTPResponse | None]] | None
996 ) = None,
997 select_subprotocol: (
998 Callable[[Sequence[Subprotocol], Sequence[Subprotocol]], Subprotocol] | None
999 ) = None,
1000 open_timeout: float | None = 10,
1001 ping_interval: float | None = 20,
1002 ping_timeout: float | None = 20,
1003 close_timeout: float | None = None,
1004 max_size: int | None = 2**20,
1005 max_queue: int | None = 2**5,
1006 read_limit: int = 2**16,
1007 write_limit: int = 2**16,
1008 **kwargs: Any,
1009 ) -> None:
1010 # Backwards compatibility: close_timeout used to be called timeout.
1011 timeout: float | None = kwargs.pop("timeout", None)
1012 if timeout is None:
1013 timeout = 10
1014 else:
1015 warnings.warn("rename timeout to close_timeout", DeprecationWarning)
1016 # If both are specified, timeout is ignored.
1017 if close_timeout is None:
1018 close_timeout = timeout
1019
1020 # Backwards compatibility: create_protocol used to be called klass.
1021 klass: type[WebSocketServerProtocol] | None = kwargs.pop("klass", None)
1022 if klass is None:
1023 klass = WebSocketServerProtocol
1024 else:
1025 warnings.warn("rename klass to create_protocol", DeprecationWarning)
1026 # If both are specified, klass is ignored.
1027 if create_protocol is None:
1028 create_protocol = klass
1029
1030 # Backwards compatibility: recv() used to return None on closed connections
1031 legacy_recv: bool = kwargs.pop("legacy_recv", False)
1032
1033 # Backwards compatibility: the loop parameter used to be supported.

Callers 1

__init__Method · 0.45

Calls 5

WebSocketServerClass · 0.85
validate_subprotocolsFunction · 0.85
remove_path_argumentFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected