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

Method __init__

src/websockets/legacy/client.py:419–544  ·  view source on GitHub ↗
(
        self,
        uri: str,
        *,
        create_protocol: Callable[..., WebSocketClientProtocol] | None = None,
        logger: LoggerLike | None = None,
        compression: str | None = "deflate",
        origin: Origin | None = None,
        extensions: Sequence[ClientExtensionFactory] | None = None,
        subprotocols: Sequence[Subprotocol] | None = None,
        extra_headers: HeadersLike | None = None,
        user_agent_header: str | None = USER_AGENT,
        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

417 MAX_REDIRECTS_ALLOWED = int(os.environ.get("WEBSOCKETS_MAX_REDIRECTS", "10"))
418
419 def __init__(
420 self,
421 uri: str,
422 *,
423 create_protocol: Callable[..., WebSocketClientProtocol] | None = None,
424 logger: LoggerLike | None = None,
425 compression: str | None = "deflate",
426 origin: Origin | None = None,
427 extensions: Sequence[ClientExtensionFactory] | None = None,
428 subprotocols: Sequence[Subprotocol] | None = None,
429 extra_headers: HeadersLike | None = None,
430 user_agent_header: str | None = USER_AGENT,
431 open_timeout: float | None = 10,
432 ping_interval: float | None = 20,
433 ping_timeout: float | None = 20,
434 close_timeout: float | None = None,
435 max_size: int | None = 2**20,
436 max_queue: int | None = 2**5,
437 read_limit: int = 2**16,
438 write_limit: int = 2**16,
439 **kwargs: Any,
440 ) -> None:
441 # Backwards compatibility: close_timeout used to be called timeout.
442 timeout: float | None = kwargs.pop("timeout", None)
443 if timeout is None:
444 timeout = 10
445 else:
446 warnings.warn("rename timeout to close_timeout", DeprecationWarning)
447 # If both are specified, timeout is ignored.
448 if close_timeout is None:
449 close_timeout = timeout
450
451 # Backwards compatibility: create_protocol used to be called klass.
452 klass: type[WebSocketClientProtocol] | None = kwargs.pop("klass", None)
453 if klass is None:
454 klass = WebSocketClientProtocol
455 else:
456 warnings.warn("rename klass to create_protocol", DeprecationWarning)
457 # If both are specified, klass is ignored.
458 if create_protocol is None:
459 create_protocol = klass
460
461 # Backwards compatibility: recv() used to return None on closed connections
462 legacy_recv: bool = kwargs.pop("legacy_recv", False)
463
464 # Backwards compatibility: the loop parameter used to be supported.
465 _loop: asyncio.AbstractEventLoop | None = kwargs.pop("loop", None)
466 if _loop is None:
467 loop = asyncio.get_event_loop()
468 else:
469 loop = _loop
470 warnings.warn("remove loop argument", DeprecationWarning)
471
472 wsuri = parse_uri(uri)
473 if wsuri.secure:
474 kwargs.setdefault("ssl", True)
475 elif kwargs.get("ssl") is not None:
476 raise ValueError(

Callers 1

__init__Method · 0.45

Calls 4

parse_uriFunction · 0.85
validate_subprotocolsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected