� ���g�(��V�ddlmZddlZddlmZddlZddlmZGd�de��ZdS)�)�partialN)�json�)�Managerc����eZdZdZdZd�fd� Z�fd�Z d�fd� Z�fd �Zd�fd � Z d�fd � Z �fd �Z dd �Z d�Z d�Z�fd�Zd�Zd�Zd�Z�fd�Z�fd�Z�fd�Zd�Z�xZS)� PubSubManagera=Manage a client list attached to a pub/sub backend. This is a base class that enables multiple servers to share the list of clients, with the servers communicating events through a pub/sub backend. The use of a pub/sub backend also allows any client connected to the backend to emit events addressed to Socket.IO clients. The actual backends must be implemented by subclasses, this class only provides a pub/sub generic framework. :param channel: The channel name on which the server sends and receives notifications. �pubsub�socketioFNc���t�����||_||_t j��j|_||_dS�N) �super�__init__�channel� write_only�uuid�uuid4�hex�host_id�logger)�selfrrr� __class__s ��g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/socketio/pubsub_manager.pyrzPubSubManager.__init__sB��� ���������� �$����z�|�|�'�� ��� � � �c����t�����|js$|j�|j��|_|����|j dz��dS)Nz backend initialized.) r � initializer�server�start_background_task�_thread�thread� _get_logger�info�name)rrs �rrzPubSubManager.initialize!sk��� ���������� J��+�;�;�D�L�I�I�D�K� �������� �,C� C�D�D�D�D�Drc ���|p|}|�d��r't���||||||���S|pd}|�C|j�t d���|�t d���|�||��} ||| f}nd}d|||||||jd�} |�| ��|� | ��dS) a/Emit a message to a single client, a room, or all the clients connected to the namespace. This method takes care or propagating the message to all the servers that are connected through the message queue. The parameters are the same as in :meth:`.Server.emit`. � ignore_queue�� namespace�room�skip_sid�callback�/Nz:Callbacks can only be issued from the context of a server.z'Cannot use callback without a room set.�emit)�method�event�datar&r'r(r)r) �getr r+r� RuntimeError� ValueError�_generate_ack_idr� _handle_emit�_publish) rr-r.r&r'r(r)�to�kwargs�id�messagers �rr+zPubSubManager.emit's ����z�T�� �:�:�n� %� %� #��7�7�<�<��t�y�t�h�!� �#�#� #��$�� � � ��{�"�"�$:�;�;�;��|� �!J�K�K�K��&�&�t�X�6�6�B��i��,�H�H��H�#�e�T� )�4�'�X�"�l�,�,�� ���'�"�"�"� � � �g�����rc����|�||��r"t���||��Sd||pd|jd�}|�|��|�|��dS)N� disconnectr*�r,�sidr&r)� is_connectedr �can_disconnectr�_handle_disconnectr4)rr<r&r8rs �rr>zPubSubManager.can_disconnectHs���� � � �S�)� ,� ,� #��7�7�)�)�#�y�9�9� 9�".�c�$-�$4����O�O�G� � #� #�G� ,� ,� ,� �M�M�'� "� "� "� "� "rc ����|�d��r#t���||���Sd||pd|jd�}|�|��|�|��dS)Nr$)r&r:r*r;)r/r r:rr?r4)rr<r&r6r8rs �rr:zPubSubManager.disconnectSs���� �:�:�n� %� %� @��7�7�%�%�c�Y�%�?�?� ?�)�#� )� 0�S�T�\�K�K�� ����(�(�(� � � �g�����rc����|�||��r%t���||||���Sd|||pd|jd�}|�|��dS)N)�eio_sid� enter_roomr*�r,r<r'r&r)r=r rCrr4)rr<r&r'rBr8rs �rrCzPubSubManager.enter_room[su��� � � �S�)� ,� ,� #��7�7�%�%�c�9�d�G�%�L�L� L�!-�c�4�$-�$4����O�O�G� �M�M�'� "� "� "� "� "rc����|�||��r#t���|||��Sd|||pd|jd�}|�|��dS)N� leave_roomr*rD)r=r rFrr4)rr<r&r'r8rs �rrFzPubSubManager.leave_roomdsp��� � � �S�)� ,� ,� #��7�7�%�%�c�9�d�;�;� ;�!-�c�4�$-�$4����O�O�G� �M�M�'� "� "� "� "� "rc�v�d||pd|jd�}|�|��|�|��dS)N� close_roomr*)r,r'r&r)r�_handle_close_roomr4)rr'r&r8s rrHzPubSubManager.close_roommsM��)�4� )� 0�S�T�\�K�K�� ����(�(�(� � � �g�����rc� �td���)z�Publish a message on the Socket.IO channel. This method needs to be implemented by the different subclasses that support pub/sub backends. �.This method must be implemented in a subclass.��NotImplementedError)rr.s rr4zPubSubManager._publishss�� "�#.�/�/� /rc� �td���)z�Return the next message published on the Socket.IO channel, blocking until a message is available. This method needs to be implemented by the different subclasses that support pub/sub backends. rKrL)rs r�_listenzPubSubManager._listen|s��"�#.�/�/� /rc ���|�d��}|�d��}|�'t|��dkrt|j|g|�R�}nd}t ���|d|d|�d��|�d��|�d��|� ��dS) Nr)r�r-r.r&r'r(r%)r/�lenr�_return_callbackr r+)rr8�remote_callback�remote_host_idr)rs �rr3zPubSubManager._handle_emit�s����"�+�+�j�1�1�� ���Y�/�/�� � &�3��+?�+?�1�+D�+D��t�4�n�1� /�1�1�1�H�H��H� ��� � �W�W�%�w�v��&�{�{�;�7�7�!�+�+�f�-�-�%�k�k�*�5�5�� � J� J� J� J� Jrc���|j|�d��krD |d}|d}|d}n#t$rYdSwxYw|�|||��dSdS)Nrr<r7�args)rr/�KeyError�trigger_callback)rr8r<r7rWs r�_handle_callbackzPubSubManager._handle_callback�s��� �<�7�;�;�y�1�1� 1� 1� ��e�n���T�]���v������ � � ���� ���� � !� !�#�r�4� 0� 0� 0� 0� 0� 2� 1s�9� A�Ac ��||jkr|�|||��dS|�d|||||d���dS)Nr))r,rr<r&r7rW)rrYr4)rrr<r&� callback_idrWs rrSzPubSubManager._return_callback�sg�� �d�l� "� "� � !� !�#�{�D� 9� 9� 9� 9� 9� �M�M�Z�G�"%�I�!,�d�<�<� =� =� =� =� =rc��|j�|�d��|�d��d���dS)Nr<r&T)r<r&r$)rr:r/)rr8s rr?z PubSubManager._handle_disconnect�sK�� � ���7�;�;�u�#5�#5�)0���[�)A�)A�,0� � 2� 2� 2� 2� 2rc����|�d��}|�d��}|�||��r8t���|||�d����dSdS�Nr<r&r')r/r=r rC�rr8r<r&rs �r�_handle_enter_roomz PubSubManager._handle_enter_room��x����k�k�%� � ���K�K� �,�,� � � � �S�)� ,� ,� D� �G�G� � �s�I�w�{�{�6�/B�/B� C� C� C� C� C� D� Drc����|�d��}|�d��}|�||��r8t���|||�d����dSdSr_)r/r=r rFr`s �r�_handle_leave_roomz PubSubManager._handle_leave_room�rbrc���t���|�d��|�d�����dS)Nr'r&)r'r&)r rHr/)rr8rs �rrIz PubSubManager._handle_close_room�sK��� ������ � �F� 3� 3�%,�[�[��%=�%=� � ?� ?� ?� ?� ?rc�z� |���D�]�}d}t|t��r|}nQt|t��r t j|��}n#YnxYw|� t j|��}n#YnxYw|�rad|v�r\|����d� |d���� |ddkr|� |��n�|� d��|j kr�|ddkr|� |��n�|ddkr|�|��ne|ddkr|�|��nC|dd kr|�|��n!|dd kr|�|�����#t$$r#|jj�d ��Y���wxYw���|jj�d ��dS#t$$r"|jj�d ��YnwxYw��;)NTr,zpubsub message: {}r)rr+r:rCrFrHz(Handler error in pubsub listening threadz#pubsub listen() exited unexpectedlyz+Unexpected Error in pubsub listening thread)rO� isinstance�dict�bytes�pickle�loadsrr �debug�formatrZr/rr3r?rardrI� Exceptionrr� exception�error)rr8r.s rrzPubSubManager._thread�s���) A�( A�#�|�|�~�~�"L�"L�G��D�!�'�4�0�0� %�&���%�g�u�5�5�%�%�'-�|�G�'<�'<����%� $������<�%�'+�z�'�':�':����%� $������L��D� 0� 0��(�(�*�*�0�0�1E�1L�1L� ��N�2,�2,�-�-�-�L�#�H�~��;�;� $� 5� 5�d� ;� ;� ;� ;�!%���)�!4�!4�� �!D�!D�#'��>�V�#;�#;�$(�$5�$5�d�$;�$;�$;�$;�%)�(�^�|�%C�%C�$(�$;�$;�D�$A�$A�$A�$A�%)�(�^�|�%C�%C�$(�$;�$;�D�$A�$A�$A�$A�%)�(�^�|�%C�%C�$(�$;�$;�D�$A�$A�$A�$A�%)�(�^�|�%C�%C�$(�$;�$;�D�$A�$A�$A���(�L�L�L� �K�.�8�8� J�L�L�L�L�L�L������ �"�(�(�)N�O�O�O����� A� A� A�� �"�,�,�.@�A�A�A�A�A� A����O) Ash�AH � A�H �A#�!H �)A>�=H �>B�A H �C)F9�7H �9)G&�"H �%G&�&$H � )H8�7H8)r FN)NNNNNr )�__name__� __module__� __qualname__�__doc__r"rrr+r>r:rCrFrHr4rOr3rZrSr?rardrIr� __classcell__)rs@rrr s�������� � � �D�������E�E�E�E�E� EI�#�������B #� #� #� #� #�������#�#�#�#�#�#�#�#�#�#�#����� /�/�/�/�/�/�J�J�J�J�J� 1�1�1�=�=�=�2�2�2� D�D�D�D�D� D�D�D�D�D� ?�?�?�?�?�*A�*A�*A�*A�*A�*A�*Arr) � functoolsrr�engineiorrj�managerrr�rr�<module>rzs��������� � � � ������� � � � �������_A�_A�_A�_A�_A�G�_A�_A�_A�_A�_Ar
Memory