� ���g����ddlZddlZddlZddlmZ ddlZn #e$rdZYnwxYwddlmZej d��Z d�Z Gd�de��Z dS) �N)�urlparse�)� PubSubManager�socketioc��t|��}|jdkrtd���g}|j�d��d�d��D]?}|�dd��\}}|�|t|��f���@i}|jr |j|d<|j r |j |d <d }|j rx|j �d ��}t|��d kr$|dd krt|d��|d<t|��dkr|d d kr|d }|||fS)z}Parse a Redis Sentinel URL with the format: redis+sentinel://[:password]@host1:port1,host2:port2,.../db/service_name zredis+sentinelzInvalid Redis Sentinel URL�@������,�:r�username�passwordN�/���db�) r�scheme� ValueError�netloc�split�rsplit�append�intr r �path�len) �url� parsed_url� sentinels� host_port�host�port�kwargs� service_name�partss �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/socketio/redis_manager.py�parse_redis_sentinel_urlr&sX���#���J���,�,�,��5�6�6�6��I��&�,�,�S�1�1�"�5�;�;�C�@�@�,�,� ��%�%�c�1�-�-� ��d����$��D� � �*�+�+�+�+� �F���1�'�0��z����1�'�0��z���L���$���%�%�c�*�*�� �u�:�:��?�?�u�Q�x�2�~�~��u�Q�x�=�=�F�4�L� �u�:�:��?�?�u�Q�x�2�~�~� ��8�L� �l�F� *�*�c�N��eZdZdZdZ d �fd� Z�fd�Zd �Zd �Zd �Z d �Z �xZ S)� RedisManagera�Redis based client manager. This class implements a Redis backend for event sharing across multiple processes. Only kept here as one more example of how to build a custom backend, since the kombu backend is perfectly adequate to support a Redis message queue. To use a Redis backend, initialize the :class:`Server` instance as follows:: url = 'redis://hostname:port/0' server = socketio.Server(client_manager=socketio.RedisManager(url)) :param url: The connection URL for the Redis server. For a default Redis store running on the same host, use ``redis://``. To use a TLS connection, use ``rediss://``. To use Redis Sentinel, use ``redis+sentinel://`` with a comma-separated list of hosts and the service name after the db in the URL path. Example: ``redis+sentinel://user:pw@host1:1234,host2:2345/0/myredis``. :param channel: The channel name on which the server sends and receives notifications. Must be the same in all the servers. :param write_only: If set to ``True``, only initialize to emit events. The default of ``False`` initializes the class for emitting and receiving. :param redis_options: additional keyword arguments to be passed to ``Redis.from_url()`` or ``Sentinel()``. �redis�redis://localhost:6379/0rFNc����t�td���||_|pi|_|���t ���|||���dS)NzLRedis package is not installed (Run "pip install redis" in your virtualenv).)�channel� write_only�logger)r*� RuntimeError� redis_url� redis_options�_redis_connect�super�__init__)�selfrr-r.r/r2� __class__s �r%r5zRedisManager.__init__Hsl��� �=�� .�/�/� /����*�0�b��� ������ ������Z���O�O�O�O�Or'c� ��t�����d}|jjdkrddlm}|d��}nd|jjvrddlm}|d��}|std|jjz���dS) NT�eventletr)�is_monkey_patched�socket�gevent)�is_module_patchedz<Redis requires a monkey patched socket library to work with ) r4� initialize�server� async_mode�eventlet.patcherr:� gevent.monkeyr=r0)r6�monkey_patchedr:r=r7s �r%r>zRedisManager.initializeSs���� ���������� �;� !�Z� /� /� :� :� :� :� :� :�.�.�x�8�8�N�N� ���/� /� /� 7� 7� 7� 7� 7� 7�.�.�x�8�8�N�� 2����+�0�1�2�2� 2� 2� 2r'c��|j�d��s'tjj|jfi|j��|_nlt |j��\}}}|j}|�|��tjj |fi|��}|� |p|j ��|_|j� d���|_ dS)Nzredis+sentinel://T)�ignore_subscribe_messages) r1� startswithr*�Redis�from_urlr2r&�update�sentinel�Sentinel� master_forr-�pubsub)r6rr#�connection_kwargsr"rJs r%r3zRedisManager._redis_connectbs����~�(�(�)<�=�=� K���-�d�n�D�D�04�0B�D�D�D�J�J�)���8�8� 7�I�|�%6��'�F� �M�M�+� ,� ,� ,��~�.�y�C�C�F�C�C�H�!�,�,�\�-I�T�\�J�J�D�J��j�'�'�$�'�G�G�� � � r'c�H�d} |s|���|j�|jt j|����S#tjj$r?|rt� d��d}nt� d��YdSYnwxYw��)NTz#Cannot publish to redis... retryingFz$Cannot publish to redis... giving up) r3r*�publishr-�pickle�dumps� exceptions� RedisErrorr/�error)r6�data�retrys r%�_publishzRedisManager._publishos����� � ��*��'�'�)�)�)��z�)�)�$�,�� �T�8J�8J�K�K�K���#�.� � � ����L�L�!F�G�G�G�!�E�E��L�L�!G�H�H�H��E�E��E� ���� s�AA � A B �B c#�K�d}d} |r5|���|j�|j��d}|j���Ed{V��nj#t jj$rSt� d� |����d}tj |��|dz}|dkrd}YnwxYw��)NrFTz0Cannot receive from redis... retrying in {} secsr�<) r3rM� subscriber-�listenr*rSrTr/rU�format�time�sleep)r6� retry_sleep�connects r%�_redis_listen_with_retriesz'RedisManager._redis_listen_with_retries~s������ ��� %� %��$��'�'�)�)�)��K�)�)�$�,�7�7�7�"#�K��;�-�-�/�/�/�/�/�/�/�/�/�/���#�.� %� %� %�� � �3�39�6�+�3F�3F�H�H�H���� �;�'�'�'��q� � ���#�#�"$�K��� %���� %s�AA � A$C�Cc#�4K�|j�d��}|j�|j��|���D](}|d|kr|ddkrd|vr |dV��)|j�|j��dS)Nzutf-8r-�type�messagerV)r-�encoderMr[rb� unsubscribe)r6r-res r%�_listenzRedisManager._listen�s������,�%�%�g�.�.�� � ���d�l�+�+�+��6�6�8�8� &� &�G��y�!�W�,�,��F�O�y�0�0�V�w�5F�5F��f�o�%�%�%�� � ���� �-�-�-�-�-r')r+rFNN) �__name__� __module__� __qualname__�__doc__�namer5r>r3rXrbrh� __classcell__)r7s@r%r)r)*s����������6 �D�?I�>B� P� P� P� P� P� P� 2� 2� 2� 2� 2� H� H� H� � � �%�%�%�&.�.�.�.�.�.�.r'r)) �loggingrQr^� urllib.parserr*� ImportError�pubsub_managerr� getLoggerr/r&r)�r'r%�<module>rus������� � � � � � � � �!�!�!�!�!�!���L�L�L�L������ �E�E�E�����*�)�)�)�)�)� �� �:� &� &��+�+�+�4n.�n.�n.�n.�n.�=�n.�n.�n.�n.�n.s ��#�#
Memory