�
���g� � � � d dl Z d dlZddlmZ ddlmZ ddlmZ e j d� � Z G d� dej � � Z dS ) � N� )�base_server)�
exceptions)�packetzsocketio.serverc �� � e Zd ZdZ d$d�Z d%d�Z d&d�Zd'd�Zd'd �Zd'd
�Z d'd�Z
d'd�Zd'd
�Zd(d�Z
d� Zd� Zd� Zd)d�Z d*d�Zd� Zd� Zd� Zd'd�Zd� Zd� Zd� Zd� Zd � Zd!� Zd"� Zd#� ZdS )+�Serveraa A Socket.IO server.
This class implements a fully compliant Socket.IO web server with support
for websocket and long-polling transports.
:param client_manager: The client manager instance that will manage the
client list. When this is omitted, the client list
is stored in an in-memory structure, so the use of
multiple connected servers is not possible.
: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 serializer: The serialization method to use when transmitting
packets. Valid values are ``'default'``, ``'pickle'``,
``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
of the :class:`Packet` class with custom implementations
of the ``encode()`` and ``decode()`` methods can be
provided. Client and server must use compatible
serializers.
: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``, event handlers for a client are
executed in separate threads. To run handlers for a
client synchronously, set to ``False``. The default
is ``True``.
:param always_connect: When set to ``False``, new connections are
provisory until the connect handler returns
something other than ``False``, at which point they
are accepted. When set to ``True``, connections are
immediately accepted, and then if the connect
handler returns ``False`` a disconnect is issued.
Set to ``True`` if you need to emit events from the
connect handler and your client is confused when it
receives events before the connection acceptance.
In any other case use the default of ``False``.
:param namespaces: a list of namespaces that are accepted, in addition to
any namespaces for which handlers have been defined. The
default is `['/']`, which always accepts connections to
the default namespace. Set to `'*'` to accept all
namespaces.
:param kwargs: Connection parameters for the underlying Engine.IO server.
The Engine.IO configuration supports the following settings:
: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 then 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 to the 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 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 engineio_logger: To enable Engine.IO 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
``engineio_logger`` is ``False``.
NFc � � |pd}|p|}| j � d||pd|� � | j � |||||||�� � dS )a�
Emit a custom event to one or more connected clients.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and should not be used.
:param data: The data to send to the client or clients. Data can be of
type ``str``, ``bytes``, ``list`` or ``dict``. To send
multiple arguments, use a tuple where each element is of
one of the types indicated above.
:param to: The recipient of the message. This can be set to the
session ID of a client to address only that client, to any
custom room created by the application to address all
the clients in that room, or to a list of custom room
names. If this argument is omitted the event is broadcasted
to all connected clients.
:param room: Alias for the ``to`` parameter.
:param skip_sid: The session ID of a client to skip when broadcasting
to a room or to all clients. This can be used to
prevent a message from being sent to the sender. To
skip multiple sids, pass a list.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the event is emitted to the
default namespace.
:param callback: If given, this function will be called to acknowledge
the client has received the message. The arguments
that will be passed to the function are those provided
by the client. Callback functions can only be used
when addressing an individual client.
:param ignore_queue: Only used when a message queue is configured. If
set to ``True``, the event is emitted to the
clients directly, without going through the queue.
This is more efficient, but only works when a
single server process is used. It is recommended
to always leave this parameter with its default
value of ``False``.
Note: this method is not thread safe. If multiple threads are emitting
at the same time to the same client, then messages composed of
multiple packets may end up being sent in an incorrect sequence. Use
standard concurrency solutions (such as a Lock object) to prevent this
situation.
�/zemitting event "%s" to %s [%s]�all)�room�skip_sid�callback�ignore_queueN)�logger�info�manager�emit) �self�event�data�tor r
� namespacer r s �_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/socketio/server.pyr zServer.emitv sy � �X �$�� ��z�T������9�5���� � 3� 3� 3�����%��y�t�#+�h�'3� � 5� 5� 5� 5� 5� c
�@ � | � d|||||||�� � dS )a Send a message to one or more connected clients.
This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.
:param data: The data to send to the client or clients. Data can be of
type ``str``, ``bytes``, ``list`` or ``dict``. To send
multiple arguments, use a tuple where each element is of
one of the types indicated above.
:param to: The recipient of the message. This can be set to the
session ID of a client to address only that client, to any
any custom room created by the application to address all
the clients in that room, or to a list of custom room
names. If this argument is omitted the event is broadcasted
to all connected clients.
:param room: Alias for the ``to`` parameter.
:param skip_sid: The session ID of a client to skip when broadcasting
to a room or to all clients. This can be used to
prevent a message from being sent to the sender. To
skip multiple sids, pass a list.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the event is emitted to the
default namespace.
:param callback: If given, this function will be called to acknowledge
the client has received the message. The arguments
that will be passed to the function are those provided
by the client. Callback functions can only be used
when addressing an individual client.
:param ignore_queue: Only used when a message queue is configured. If
set to ``True``, the event is emitted to the
clients directly, without going through the queue.
This is more efficient, but only works when a
single server process is used. It is recommended
to always leave this parameter with its default
value of ``False``.
�message)r r r r
r r r N)r )r r r r r
r r r s r �sendzServer.send� s<