�
���gk � � � d dl Z d dlZddlmZ ddlmZ ddlmZ ddlmZ e� � Z G d� dej � � Z
dS ) � N� )�base_server)�
exceptions)�packet)�async_socketc � � e Zd ZdZd� Zd� Zdd�Zd� Zd� Zd� Z d � Z
d
� Zdd�Zd
� Z
d� Zd� Zdd�Zd� Zd� Zd� Zd� Zdd�Zd� Zd� ZdS )�AsyncServeraw An Engine.IO server for asyncio.
This class implements a fully compliant Engine.IO web server with support
for websocket and long-polling transports, compatible with the asyncio
framework on Python 3.5 or newer.
:param async_mode: The asynchronous model to use. See the Deployment
section in the documentation for a description of the
available options. Valid async modes are "aiohttp",
"sanic", "tornado" and "asgi". If this argument is not
given, "aiohttp" is tried first, followed by "sanic",
"tornado", and finally "asgi". The first async mode that
has all its dependencies installed is the one that is
chosen.
:param ping_interval: The interval in seconds at which the server pings
the client. The default is 25 seconds. For advanced
control, a two element tuple can be given, where
the first number is the ping interval and the second
is a grace period added by the server.
:param ping_timeout: The time in seconds that the client waits for the
server to respond before disconnecting. The default
is 20 seconds.
:param max_http_buffer_size: The maximum size that is accepted for incoming
messages. The default is 1,000,000 bytes. In
spite of its name, the value set in this
argument is enforced for HTTP long-polling and
WebSocket connections.
:param allow_upgrades: Whether to allow transport upgrades or not.
:param http_compression: Whether to compress packages when using the
polling transport.
:param compression_threshold: Only compress messages when their byte size
is greater than this value.
:param cookie: If set to a string, it is the name of the HTTP cookie the
server sends back tot he client containing the client
session id. If set to a dictionary, the ``'name'`` key
contains the cookie name and other keys define cookie
attributes, where the value of each attribute can be a
string, a callable with no arguments, or a boolean. If set
to ``None`` (the default), a cookie is not sent to the
client.
:param cors_allowed_origins: Origin or list of origins that are allowed to
connect to this server. Only the same origin
is allowed by default. Set this argument to
``'*'`` to allow all origins, or to ``[]`` to
disable CORS handling.
:param cors_credentials: Whether credentials (cookies, authentication) are
allowed in requests to this server.
:param logger: To enable logging set to ``True`` or pass a logger object to
use. To disable logging set to ``False``. Note that fatal
errors are logged even when ``logger`` is ``False``.
:param json: An alternative json module to use for encoding and decoding
packets. Custom json modules must have ``dumps`` and ``loads``
functions that are compatible with the standard library
versions.
:param async_handlers: If set to ``True``, run message event handlers in
non-blocking threads. To run handlers synchronously,
set to ``False``. The default is ``True``.
:param monitor_clients: If set to ``True``, a background task will ensure
inactive clients are closed. Set to ``False`` to
disable the monitoring task (not recommended). The
default is ``True``.
:param transports: The list of allowed transports. Valid transports
are ``'polling'`` and ``'websocket'``. Defaults to
``['polling', 'websocket']``.
:param kwargs: Reserved for future extensions, any additional parameters
given as keyword arguments will be silently ignored.
c � � dS )NT� ��selfs �e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/engineio/async_server.py�is_asyncio_basedzAsyncServer.is_asyncio_basedS s � ��t� c �
� g d�S )N)�aiohttp�sanic�tornado�asgir r s r �async_modeszAsyncServer.async_modesV s � �6�6�6�6r � engine.ioc �h � |� d� � } | j d || d|� d�� � dS )z.Attach the Engine.IO server to an application.�/�create_routeN)�strip�_async)r
�app�
engineio_paths r �attachzAsyncServer.attachY sB � �%�+�+�C�0�0�
�#���N�#�C��/C�=�/C�/C�/C�D�D�D�D�Dr c � �~ K � | � |t j t j |�� � � � � d{V �� dS )ai Send a message to a client.
:param sid: The session id of the recipient client.
:param data: The data to send to the client. Data can be of type
``str``, ``bytes``, ``list`` or ``dict``. If a ``list``
or ``dict``, the data will be serialized as JSON.
Note: this method is a coroutine.
)�dataN)�send_packetr �Packet�MESSAGE)r
�sidr! s r �sendzAsyncServer.send^ sG � � � � ���s�F�M�&�.�t�$L�$L�$L�M�M�M�M�M�M�M�M�M�M�Mr c � �� K � | � |� � }n,# t $ r | j � d|� � Y dS w xY w|� |� � � d{V �� dS )z�Send a raw packet to a client.
:param sid: The session id of the recipient client.
:param pkt: The packet to send to the client.
Note: this method is a coroutine.
zCannot send to sid %sN)�_get_socket�KeyError�logger�warningr&