
    i                     h    d dl Z d dlZd dlZd dlmZmZ  ej        d          Z G d d          ZdS )    N)bidictValueDuplicationErrorsocketioc                   v    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZddZd Zd Zd Zd Zd ZdS )BaseManagerc                 r    d | _         d | _        i | _        i | _        i | _        i | _        t          | _        d S N)loggerserverrooms
eio_to_sid	callbackspending_disconnectjsonselfs    @/usr/local/lib/python3.11/dist-packages/socketio/base_manager.py__init__zBaseManager.__init__   s8    
"$			    c                 @    || _         | j         j        j        | _        d S r	   )r   packet_classr   )r   r   s     r   
set_serverzBaseManager.set_server   s    K,1			r   c                     dS )zqInvoked before the first request is received. Subclasses can add
        their initialization code here.
        N r   s    r   
initializezBaseManager.initialize   s	     	r   c                 4    | j                                         S )z3Return an iterable with the active namespace names.)r   keysr   s    r   get_namespaceszBaseManager.get_namespaces   s    z   r   c              #     K   | j                             |i           }t          |d          rzt          |t                    se|d         |v r%||d                  j                                        ni }|dd         D ](}|                    ||v r||         j        ni            )n%||v r||         j                                        ni }|                                E d{V  dS )aJ  Return an iterable with the active participants in a room.

        Note that in a multi-server scenario this method only returns the
        participants connect to the server in which the method is called. There
        is currently no functionality to assemble a complete list of users
        across multiple servers.
        __len__r      N)	r   gethasattr
isinstancestr_fwdmcopyupdateitems)r   	namespaceroomnsparticipantsrs         r   get_participantszBaseManager.get_participants"   s      Z^^Ir**4## 	GJtS,A,A 	G7;Aw"}}2d1g;,11333"L!""X D D##177BqEKKCCCCD 59BJJ2d8>..000BL%%'''''''''''r   c                     | j         j                                        }	 |                     ||d|           n# t          $ r Y dS w xY w|                     ||||           |S )z,Register a client connection to a namespace.N)eio_sid)r   eiogenerate_idbasic_enter_roomr   )r   r1   r*   sids       r   connectzBaseManager.connect3   s    ko))++	!!#y$!HHHH$ 	 	 	44	 	c9c7CCC
s   : 
AAc                     || j         v r|| j         |         v rdS 	 | j        |         d          |         d uS # t          $ r Y nw xY wdS )NF)r   r   KeyErrorr   r5   r*   s      r   is_connectedzBaseManager.is_connected>   sn    ///t.y9995	:i(.s34?? 	 	 	D	us   7 
AAc                 b    	 | j         |         d          j        |         S # t          $ r Y d S w xY wr	   )r   _invmr8   )r   r1   r*   s      r   sid_from_eio_sidzBaseManager.sid_from_eio_sidI   sC    	:i(.4W== 	 	 	DD	s     
..c                 d    || j         v r&| j         |         d                              |          S d S r	   )r   r"   r9   s      r   eio_sid_from_sidzBaseManager.eio_sid_from_sidO   s7    
"":i(.223777 #"r   c                     || j         vr
g | j         |<   | j         |                             |           | j        |         d                             |          S )zPut the client in the to-be-disconnected list.

        This allows the client data structures to be present while the
        disconnect handler is invoked, but still recognize the fact that the
        client is soon going away.
        N)r   appendr   r"   r9   s      r   pre_disconnectzBaseManager.pre_disconnectS   s[     D33313D#I.	*11#666z)$T*..s333r   c                    || j         vrd S g }| j         |                                                                         D ]\  }}||v r|                    |           |D ]}|                     |||           || j        v r| j        |= || j        v rW|| j        |         v rJ| j        |                             |           t          | j        |                   dk    r| j        |= d S d S d S d S Nr   )	r   r'   r)   rA   basic_leave_roomr   r   removelen)r   r5   r*   kwargsr   	room_namer+   s          r   basic_disconnectzBaseManager.basic_disconnect_   s%   DJ&&F#z)499;;AACC 	( 	(OItd{{Y''' 	8 	8D!!#y$7777$.  s#///t.y999#I.55c:::4*9566!;;+I666	 0/99;;r   Nc                    ||| j         vrt          d          || j         vr
i | j         |<   || j         |         vrt                      | j         |         |<   || j         |         d          |         }|| j         |         |         |<   d S )Nz+sid is not connected to requested namespace)r   
ValueErrorr   )r   r5   r*   r+   r1   s        r   r4   zBaseManager.basic_enter_roomp   s    ?y
::JKKKDJ&&$&DJy!tz),,,*0((DJy!$'?j+D1#6G+2
9d#C(((r   c                 
   	 | j         |         |         |= t          | j         |         |                   dk    r6| j         |         |= t          | j         |                   dk    r| j         |= d S d S d S # t          $ r Y d S w xY wrD   )r   rG   r8   )r   r5   r*   r+   s       r   rE   zBaseManager.basic_leave_room{   s    	
9%d+C04:i(.//144Jy)$/tz),--22
9--- 5422 	 	 	DD	s   A,A4 4
BBc                     	 |                      ||          D ]\  }}|                     |||           d S # t          $ r Y d S w xY wr	   )r/   rE   r8   )r   r+   r*   r5   _s        r   basic_close_roomzBaseManager.basic_close_room   sq    	//	4@@ < <Q%%c9d;;;;< < 	 	 	DD	s   37 
AAc                     g }	 | j         |                                         D ] \  }}|||v r|                    |           !n# t          $ r Y nw xY w|S )z Return the rooms a client is in.)r   r)   rA   r8   )r   r5   r*   r.   rI   r+   s         r   	get_roomszBaseManager.get_rooms   s    	#':i#8#>#>#@#@ ( (	4(SD[[HHY'''(  	 	 	D	s   A A 
AAc                     || j         vrdt          j        d          i| j         |<   t          | j         |         d                   }|| j         |         |<   |S )z/Generate a unique identifier for an ACK packet.r   r!   )r   	itertoolscountnext)r   r5   callbackids       r   _generate_ack_idzBaseManager._generate_ack_id   sY    dn$$#$ioa&8&8"9DN3$.%a())"*sB	r   c                 R    | j         r| j         S | j        r| j        j         S t          S )zlGet the appropriate logger

        Prevents uninitialized servers in write-only mode from failing.
        )r
   r   default_loggerr   s    r   _get_loggerzBaseManager._get_logger   s1     ; 	";[ 	";%%!!r   r	   )__name__
__module____qualname__r   r   r   r   r/   r6   r:   r=   r?   rB   rJ   r4   rE   rP   rR   rY   r\   r   r   r   r   r   
   s         2 2 2  ! ! !( ( ("	 	 		 	 	  8 8 8
4 
4 
47 7 7"	3 	3 	3 	3    	 	 	  " " " " "r   r   )rT   loggingr   r   r   	getLoggerr[   r   r   r   r   <module>rb      s          0 0 0 0 0 0 0 0"":..`" `" `" `" `" `" `" `" `" `"r   