�
���g�Y � � � d dl Z d dlZddlmZ ddlmZ ddlmZ ddlmZ e j d� � Z G d� d ej � � Z
dS )
� N� )�base_server)�
exceptions)�packet)�socketzengineio.serverc �h � e Zd ZdZd� Zd� Zd� Zd� Zd� Zdd�Z d � Z
d
� Zd� Zdd
�Z
dd�Zd� Zd� ZdS )�Servera, An Engine.IO server.
This class implements a fully compliant Engine.IO web server with support
for websocket and long-polling transports.
: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 "threading",
"eventlet", "gevent" and "gevent_uwsgi". If this
argument is not given, "eventlet" is tried first, then
"gevent_uwsgi", then "gevent", and finally "threading".
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. The
default is ``True``.
:param http_compression: Whether to compress packages when using the
polling transport. The default is ``True``.
:param compression_threshold: Only compress messages when their byte size
is greater than this value. The default is
1024 bytes.
: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. The default
is ``True``.
:param logger: To enable logging set to ``True`` or pass a logger object to
use. To disable logging set to ``False``. The default is
``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 �n � | � |t j t j |�� � � � dS )a> 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.
)�dataN)�send_packetr �Packet�MESSAGE)�self�sidr s �_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/engineio/server.py�sendzServer.sendS s1 � �
����f�m�F�N��F�F�F�G�G�G�G�G� c � � | � |� � }n,# t $ r | j � d|� � Y dS w xY w |j |� � 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.
zCannot send to sid %sN)�_get_socket�KeyError�logger�warningr )r r �pktr s r r zServer.send_packet] sq � � ��%�%�c�*�*�F�F��� � � ��K��� 7��=�=�=��F�F� ���� ���C�����s � �%A� Ac �: � | � |� � }|j S )aC Return the user session for a client.
:param sid: The session id of the client.
The return value is a dictionary. Modifications made to this
dictionary are not guaranteed to be preserved unless
``save_session()`` is called, or when the ``session`` context manager
is used.
�r �session)r r r s r �get_sessionzServer.get_sessionk s � � �!�!�#�&�&���~�r c �>