164 lines
7.1 KiB
Python
164 lines
7.1 KiB
Python
"""
|
|
This type stub file was generated by pyright.
|
|
"""
|
|
|
|
class AioBase:
|
|
def __init__(self, connection_type=..., receive_bytes=..., ping_interval=..., max_message_size=...) -> None:
|
|
...
|
|
|
|
async def connect(self): # -> None:
|
|
...
|
|
|
|
async def handshake(self): # -> None:
|
|
...
|
|
|
|
async def send(self, data): # -> None:
|
|
"""Send data over the WebSocket connection.
|
|
|
|
:param data: The data to send. If ``data`` is of type ``bytes``, then
|
|
a binary message is sent. Else, the message is sent in
|
|
text format.
|
|
"""
|
|
...
|
|
|
|
async def receive(self, timeout=...): # -> None:
|
|
"""Receive data over the WebSocket connection.
|
|
|
|
:param timeout: Amount of time to wait for the data, in seconds. Set
|
|
to ``None`` (the default) to wait indefinitely. Set
|
|
to 0 to read without blocking.
|
|
|
|
The data received is returned, as ``bytes`` or ``str``, depending on
|
|
the type of the incoming message.
|
|
"""
|
|
...
|
|
|
|
async def close(self, reason=..., message=...): # -> None:
|
|
"""Close the WebSocket connection.
|
|
|
|
:param reason: A numeric status code indicating the reason of the
|
|
closure, as defined by the WebSocket specification. The
|
|
default is 1000 (normal closure).
|
|
:param message: A text message to be sent to the other side.
|
|
"""
|
|
...
|
|
|
|
def choose_subprotocol(self, request): # -> None:
|
|
...
|
|
|
|
|
|
|
|
class AioServer(AioBase):
|
|
"""This class implements a WebSocket server.
|
|
|
|
Instead of creating an instance of this class directly, use the
|
|
``accept()`` class method to create individual instances of the server,
|
|
each bound to a client request.
|
|
"""
|
|
def __init__(self, request, subprotocols=..., receive_bytes=..., ping_interval=..., max_message_size=...) -> None:
|
|
...
|
|
|
|
@classmethod
|
|
async def accept(cls, aiohttp=..., asgi=..., sock=..., headers=..., subprotocols=..., receive_bytes=..., ping_interval=..., max_message_size=...): # -> WebSocketASGI | Self:
|
|
"""Accept a WebSocket connection from a client.
|
|
|
|
:param aiohttp: The request object from aiohttp. If this argument is
|
|
provided, ``asgi``, ``sock`` and ``headers`` must not
|
|
be set.
|
|
:param asgi: A (scope, receive, send) tuple from an ASGI request. If
|
|
this argument is provided, ``aiohttp``, ``sock`` and
|
|
``headers`` must not be set.
|
|
:param sock: A connected socket to use. If this argument is provided,
|
|
``aiohttp`` and ``asgi`` must not be set. The ``headers``
|
|
argument must be set with the incoming request headers.
|
|
:param headers: A dictionary with the incoming request headers, when
|
|
``sock`` is used.
|
|
:param subprotocols: A list of supported subprotocols, or ``None`` (the
|
|
default) to disable subprotocol negotiation.
|
|
:param receive_bytes: The size of the receive buffer, in bytes. The
|
|
default is 4096.
|
|
:param ping_interval: Send ping packets to clients at the requested
|
|
interval in seconds. Set to ``None`` (the
|
|
default) to disable ping/pong logic. Enable to
|
|
prevent disconnections when the line is idle for
|
|
a certain amount of time, or to detect
|
|
unresponsive clients and disconnect them. A
|
|
recommended interval is 25 seconds.
|
|
:param max_message_size: The maximum size allowed for a message, in
|
|
bytes, or ``None`` for no limit. The default
|
|
is ``None``.
|
|
"""
|
|
...
|
|
|
|
async def handshake(self): # -> None:
|
|
...
|
|
|
|
def choose_subprotocol(self, request): # -> None:
|
|
"""Choose a subprotocol to use for the WebSocket connection.
|
|
|
|
The default implementation selects the first protocol requested by the
|
|
client that is accepted by the server. Subclasses can override this
|
|
method to implement a different subprotocol negotiation algorithm.
|
|
|
|
:param request: A ``Request`` object.
|
|
|
|
The method should return the subprotocol to use, or ``None`` if no
|
|
subprotocol is chosen.
|
|
"""
|
|
...
|
|
|
|
|
|
|
|
class AioClient(AioBase):
|
|
"""This class implements a WebSocket client.
|
|
|
|
Instead of creating an instance of this class directly, use the
|
|
``connect()`` class method to create an instance that is connected to a
|
|
server.
|
|
"""
|
|
def __init__(self, url, subprotocols=..., headers=..., receive_bytes=..., ping_interval=..., max_message_size=..., ssl_context=...) -> None:
|
|
...
|
|
|
|
@classmethod
|
|
async def connect(cls, url, subprotocols=..., headers=..., receive_bytes=..., ping_interval=..., max_message_size=..., ssl_context=..., thread_class=..., event_class=...): # -> Self:
|
|
"""Returns a WebSocket client connection.
|
|
|
|
:param url: The connection URL. Both ``ws://`` and ``wss://`` URLs are
|
|
accepted.
|
|
:param subprotocols: The name of the subprotocol to use, or a list of
|
|
subprotocol names in order of preference. Set to
|
|
``None`` (the default) to not use a subprotocol.
|
|
:param headers: A dictionary or list of tuples with additional HTTP
|
|
headers to send with the connection request. Note that
|
|
custom headers are not supported by the WebSocket
|
|
protocol, so the use of this parameter is not
|
|
recommended.
|
|
:param receive_bytes: The size of the receive buffer, in bytes. The
|
|
default is 4096.
|
|
:param ping_interval: Send ping packets to the server at the requested
|
|
interval in seconds. Set to ``None`` (the
|
|
default) to disable ping/pong logic. Enable to
|
|
prevent disconnections when the line is idle for
|
|
a certain amount of time, or to detect an
|
|
unresponsive server and disconnect. A recommended
|
|
interval is 25 seconds. In general it is
|
|
preferred to enable ping/pong on the server, and
|
|
let the client respond with pong (which it does
|
|
regardless of this setting).
|
|
:param max_message_size: The maximum size allowed for a message, in
|
|
bytes, or ``None`` for no limit. The default
|
|
is ``None``.
|
|
:param ssl_context: An ``SSLContext`` instance, if a default SSL
|
|
context isn't sufficient.
|
|
"""
|
|
...
|
|
|
|
async def handshake(self): # -> None:
|
|
...
|
|
|
|
async def close(self, reason=..., message=...): # -> None:
|
|
...
|
|
|
|
|
|
|