
    keJi<7                        d dl Z d dlZd dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZ  G d de          Z G d	 d
e          Z G d de          Z G d de          Z G d de          Z G d d          Z G d de          Z G d de          Z G d d          Z G d d          Z G d d          Z G d d          Z G d d           Z G d! d"e          Z  G d# d$e          Z! G d% d&e          Z" G d' d(e          Z# G d) d*e          Z$ G d+ d,e          Z% G d- d.e          Z&dS )/    N)ABCabstractmethod)Enum)DictListOptionalTypeUnion)TokenInterface)CredentialProviderStreamingCredentialProviderc                   .    e Zd ZdZedefd            ZdS )EventListenerInterfacez7
    Represents a listener for given event object.
    eventc                     d S N selfr   s     Q/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/redis/event.pylistenzEventListenerInterface.listen           N__name__
__module____qualname____doc__r   objectr   r   r   r   r   r      sE          F    ^  r   r   c                   .    e Zd ZdZedefd            ZdS )AsyncEventListenerInterfacez>
    Represents an async listener for given event object.
    r   c                 
   K   d S r   r   r   s     r   r   z"AsyncEventListenerInterface.listen         r   Nr   r   r   r   r!   r!      sE          &    ^  r   r!   c                       e Zd ZdZedefd            Zedefd            Zedee	e         e
eeef                  f         fd            ZdS )EventDispatcherInterfacezf
    Represents a dispatcher that dispatches events to listeners
    associated with given event.
    r   c                     d S r   r   r   s     r   dispatchz!EventDispatcherInterface.dispatch%   r   r   c                 
   K   d S r   r   r   s     r   dispatch_asyncz'EventDispatcherInterface.dispatch_async)   r#   r   mappingsc                     dS )zRegister additional listeners.Nr   )r   r*   s     r   register_listenersz+EventDispatcherInterface.register_listeners-   s	     	r   N)r   r   r   r   r   r   r'   r)   r   r	   r   r
   r   r!   r,   r   r   r   r%   r%      s         
 f    ^ &    ^ L-/JJKLN
   ^  r   r%   c                   ,     e Zd ZdZdedef fdZ xZS )EventExceptionzM
    Exception wrapper that adds an event object into exception context.
    	exceptionr   c                 f    || _         || _        t                                          |           d S r   )r/   r   super__init__)r   r/   r   	__class__s      r   r2   zEventException.__init__>   s/    "
#####r   )r   r   r   r   	Exceptionr   r2   __classcell__)r3   s   @r   r.   r.   9   sU         $) $F $ $ $ $ $ $ $ $ $ $r   r.   c                       e Zd Z	 d	deeee         ee         f                  fdZ	defdZ
defdZdeee         eeeef                  f         fdZdS )
EventDispatcherNevent_listenersc                 t   t           t                      gt          t                      gt          t                      gt          t                      gt          t                      gt          t                      gi| _        t          j                    | _        d| _        |r|                     |           dS dS )z]
        Dispatcher that dispatches events to listeners associated with given event.
        N)AfterConnectionReleasedEventReAuthConnectionListener(AfterPooledConnectionsInstantiationEvent"RegisterReAuthForPooledConnections'AfterSingleConnectionInstantiationEvent!RegisterReAuthForSingleConnection'AfterPubSubConnectionInstantiationEventRegisterReAuthForPubSub#AfterAsyncClusterInstantiationEvent"RegisterReAuthForAsyncClusterNodes!AsyncAfterConnectionReleasedEventAsyncReAuthConnectionListener_event_listeners_mapping	threadingLock_lock_async_lockr,   )r   r8   s     r   r2   zEventDispatcher.__init__F   s     )(**+ 52447 41336 46M6O6O5P/2T2V2V1W--//0
 	%& ^%%
 	5##O44444	5 	5r   r   c                     | j         5  | j                            t          |          g           }|D ]}|                    |           	 d d d            d S # 1 swxY w Y   d S r   )rI   rF   gettyper   r   r   	listenerslisteners       r   r'   zEventDispatcher.dispatchh   s    Z 	' 	'599$u++rJJI% ' '&&&&'	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   AAA Ac                 >  K   | j         t          j                    | _         | j         4 d {V  | j                            t          |          g           }|D ]}|                    |           d {V  	 d d d           d {V  d S # 1 d {V swxY w Y   d S r   )rJ   asynciorH   rF   rL   rM   r   rN   s       r   r)   zEventDispatcher.dispatch_asynco   s=     #&|~~D# 	- 	- 	- 	- 	- 	- 	- 	-599$u++rJJI% - -ooe,,,,,,,,,,-	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   A	B
BBr*   c           	          | j         5  |D ]T}|| j        v r9t          t          | j        |         ||         z                       | j        |<   D||         | j        |<   U	 d d d            d S # 1 swxY w Y   d S r   )rI   rF   listset)r   r*   
event_types      r   r,   z"EventDispatcher.register_listenersy   s    Z 
	U 
	U& 	U 	U
!>>>@D 9*E&z23 A AD1*== AI@TD1*==	U
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	U 
	Us   AA..A25A2r   )r   r   r   r   r   r	   r   r   r   r2   r'   r)   r
   r!   r,   r   r   r   r7   r7   D   s         	 5  5!ft$:;;<
 5  5  5  5D'f ' ' ' '-& - - - -UL-/JJKLN
U U U U U Ur   r7   c                   .    e Zd ZdZd Zed             ZdS )r:   zA
    Event that will be fired before each command execution.
    c                     || _         d S r   _connection)r   
connections     r   r2   z%AfterConnectionReleasedEvent.__init__   s    %r   c                     | j         S r   rY   r   s    r   r[   z'AfterConnectionReleasedEvent.connection       r   N)r   r   r   r   r2   propertyr[   r   r   r   r:   r:      sH         & & &     X     r   r:   c                       e Zd ZdS )rD   Nr   r   r   r   r   r   rD   rD              Dr   rD   c                       e Zd ZdZdZdS )
ClientType)sync)asyncN)r   r   r   SYNCASYNCr   r   r   rd   rd      s        DEEEr   rd   c                       e Zd ZdZ	 ddededee         fdZe	d             Z
e	defd	            Ze	deedf         fd
            ZdS )r<   zQ
    Event that will be fired after pooled connection instances was created.
    Nconnection_poolsclient_typecredential_providerc                 0    || _         || _        || _        d S r   )_connection_pools_client_type_credential_provider)r   rj   rk   rl   s       r   r2   z1AfterPooledConnectionsInstantiationEvent.__init__   s"     "2'$7!!!r   c                     | j         S r   )rn   r]   s    r   rj   z9AfterPooledConnectionsInstantiationEvent.connection_pools   s    %%r   returnc                     | j         S r   ro   r]   s    r   rk   z4AfterPooledConnectionsInstantiationEvent.client_type         r   c                     | j         S r   rp   r]   s    r   rl   z<AfterPooledConnectionsInstantiationEvent.credential_provider       ((r   r   )r   r   r   r   r   rd   r   r   r2   r_   rj   rk   r
   rl   r   r   r   r<   r<      s          =A	8 88  8 &&89	8 8 8 8 & & X& !Z ! ! ! X! )U+=t+C%D ) ) ) X) ) )r   r<   c                       e Zd ZdZdedeej        ej	        f         fdZ
ed             Zedefd            Zedeej        ej	        f         fd            Zd	S )
r>   z
    Event that will be fired after single connection instances was created.

    :param connection_lock: For sync client thread-lock should be provided,
    for async asyncio.Lock
    rk   connection_lockc                 0    || _         || _        || _        d S r   )rZ   ro   _connection_lock)r   r[   rk   rz   s       r   r2   z0AfterSingleConnectionInstantiationEvent.__init__   s"     &' /r   c                     | j         S r   rY   r]   s    r   r[   z2AfterSingleConnectionInstantiationEvent.connection   r^   r   rr   c                     | j         S r   rt   r]   s    r   rk   z3AfterSingleConnectionInstantiationEvent.client_type   ru   r   c                     | j         S r   r|   r]   s    r   rz   z7AfterSingleConnectionInstantiationEvent.connection_lock       $$r   N)r   r   r   r   rd   r
   rG   RLockrR   rH   r2   r_   r[   rk   rz   r   r   r   r>   r>      s         0  0 y<=	0 0 0 0     X  !Z ! ! ! X! %y'D!E % % % X% % %r   r>   c                       e Zd Zdedeej        ej        f         fdZ	e
d             Ze
d             Ze
defd            Ze
deej        ej        f         fd            Zd	S )
r@   rk   rz   c                 >    || _         || _        || _        || _        d S r   )_pubsub_connection_connection_poolro   r|   )r   pubsub_connectionconnection_poolrk   rz   s        r   r2   z0AfterPubSubConnectionInstantiationEvent.__init__   s*     #4 /' /r   c                     | j         S r   )r   r]   s    r   r   z9AfterPubSubConnectionInstantiationEvent.pubsub_connection   s    &&r   c                     | j         S r   )r   r]   s    r   r   z7AfterPubSubConnectionInstantiationEvent.connection_pool   r   r   rr   c                     | j         S r   rt   r]   s    r   rk   z3AfterPubSubConnectionInstantiationEvent.client_type   ru   r   c                     | j         S r   r   r]   s    r   rz   z7AfterPubSubConnectionInstantiationEvent.connection_lock   r   r   N)r   r   r   rd   r
   rG   r   rR   rH   r2   r_   r   r   rk   rz   r   r   r   r@   r@      s        
0  	
0
 y<=
0 
0 
0 
0 ' ' X' % % X% !Z ! ! ! X! %y'D!E % % % X% % %r   r@   c                   z    e Zd ZdZ	 d	dedee         fdZedefd            Z	ede
edf         fd            ZdS )
rB   z
    Event that will be fired after async cluster instance was created.

    Async cluster doesn't use connection pools,
    instead ClusterNode object manages connections.
    Nnodesrl   c                 "    || _         || _        d S r   )_nodesrp   )r   r   rl   s      r   r2   z,AfterAsyncClusterInstantiationEvent.__init__  s    
 $7!!!r   rr   c                     | j         S r   )r   r]   s    r   r   z)AfterAsyncClusterInstantiationEvent.nodes  s
    {r   c                     | j         S r   rw   r]   s    r   rl   z7AfterAsyncClusterInstantiationEvent.credential_provider  rx   r   r   )r   r   r   r   dictr   r   r2   r_   r   r
   rl   r   r   r   rB   rB      s          =A8 88 &&898 8 8 8 t    X )U+=t+C%D ) ) ) X) ) )r   rB   c                   Z    e Zd ZdZdedefdZedefd            Zedefd            Z	dS )	OnCommandsFailEventzD
    Event fired whenever a command fails during the execution.
    commandsr/   c                 "    || _         || _        d S r   )	_commands
_exception)r   r   r/   s      r   r2   zOnCommandsFailEvent.__init__  s    
 "#r   rr   c                     | j         S r   )r   r]   s    r   r   zOnCommandsFailEvent.commands"  s
    ~r   c                     | j         S r   )r   r]   s    r   r/   zOnCommandsFailEvent.exception&  s
    r   N)
r   r   r   r   tupler4   r2   r_   r   r/   r   r   r   r   r     s         $$ $ $ $ $ %    X 9    X  r   r   c                       e Zd ZdS )AsyncOnCommandsFailEventNra   r   r   r   r   r   +  rb   r   r   c                       e Zd ZdZdefdZdS )r;   zG
    Listener that performs re-authentication of given connection.
    r   c                 8    |j                                          d S r   r[   re_authr   s     r   r   zReAuthConnectionListener.listen4  s      """""r   N)r   r   r   r   r:   r   r   r   r   r;   r;   /  s:         #8 # # # # # #r   r;   c                       e Zd ZdZdefdZdS )rE   zM
    Async listener that performs re-authentication of given connection.
    r   c                 H   K   |j                                          d {V  d S r   r   r   s     r   r   z$AsyncReAuthConnectionListener.listen=  s3      &&(((((((((((r   N)r   r   r   r   rD   r   r   r   r   rE   rE   8  s:         )"C ) ) ) ) ) )r   rE   c                   H    e Zd ZdZd ZdefdZd Zd Zde	fdZ
de	fd	Zd
S )r=   z
    Listener that registers a re-authentication callback for pooled connections.
    Required by :class:`StreamingCredentialProvider`.
    c                     d | _         d S r   _eventr]   s    r   r2   z+RegisterReAuthForPooledConnections.__init__G      r   r   c                 r   t          |j        t                    r|| _        |j        t
          j        k    r@|j                            | j                   |j        	                    | j
                   d S |j                            | j                   |j        	                    | j                   d S d S r   )
isinstancerl   r   r   rk   rd   rg   on_next_re_authon_error_raise_on_error_re_auth_async_raise_on_error_asyncr   s     r   r   z)RegisterReAuthForPooledConnections.listenJ  s    e/1LMM 	ODK JO33)11$-@@@)2243GHHHHH)11$2EFFF)2243MNNNNN	O 	Or   c                 N    | j         j        D ]}|                    |           d S r   r   rj   re_auth_callbackr   tokenpools      r   r   z+RegisterReAuthForPooledConnections._re_authU  s7    K0 	) 	)D!!%((((	) 	)r   c                 ^   K   | j         j        D ]}|                    |           d {V  d S r   r   r   s      r   r   z1RegisterReAuthForPooledConnections._re_auth_asyncY  sM      K0 	/ 	/D''..........	/ 	/r   errorc                 ,    t          || j                  r   r.   r   r   r   s     r   r   z2RegisterReAuthForPooledConnections._raise_on_error]      UDK000r   c                 0   K   t          || j                  r   r   r   s     r   r   z8RegisterReAuthForPooledConnections._raise_on_error_async`        UDK000r   N)r   r   r   r   r2   r<   r   r   r   r4   r   r   r   r   r   r=   r=   A  s         
  	OD 	O 	O 	O 	O) ) )/ / /1Y 1 1 1 11 1 1 1 1 1 1r   r=   c                   H    e Zd ZdZd ZdefdZd Zd Zde	fdZ
de	fd	Zd
S )r?   z
    Listener that registers a re-authentication callback for single connection.
    Required by :class:`StreamingCredentialProvider`.
    c                     d | _         d S r   r   r]   s    r   r2   z*RegisterReAuthForSingleConnection.__init__j  r   r   r   c                    t          |j        j        t                    r|| _        |j        t          j        k    rJ|j        j                            | j	                   |j        j        
                    | j                   d S |j        j                            | j                   |j        j        
                    | j                   d S d S r   )r   r[   rl   r   r   rk   rd   rg   r   r   r   r   r   r   r   s     r   r   z(RegisterReAuthForSingleConnection.listenm  s    02M
 
 	  DK JO33 4<<T]KKK 4==d>RSSSSS 4<<T=PQQQ 4==.    	 	r   c                    | j         j        5  | j         j                            d|                    d          |                                           | j         j                                         d d d            d S # 1 swxY w Y   d S NAUTHoidr   rz   r[   send_commandtry_get	get_valueread_responser   r   s     r   r   z*RegisterReAuthForSingleConnection._re_auth|  s    [( 	3 	3K"//e,,eoo.?.?   K"00222		3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   A%A??BBc                 X  K   | j         j        4 d {V  | j         j                            d|                    d          |                                           d {V  | j         j                                         d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S r   r   r   s     r   r   z0RegisterReAuthForSingleConnection._re_auth_async  sR     ;. 	9 	9 	9 	9 	9 	9 	9 	9+(55e,,eoo.?.?         +(66888888888		9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s   A1B
B#&B#r   c                 ,    t          || j                  r   r   r   s     r   r   z1RegisterReAuthForSingleConnection._raise_on_error  r   r   c                 0   K   t          || j                  r   r   r   s     r   r   z7RegisterReAuthForSingleConnection._raise_on_error_async  r   r   N)r   r   r   r   r2   r>   r   r   r   r4   r   r   r   r   r   r?   r?   d  s         
  C    3 3 39 9 91Y 1 1 1 11 1 1 1 1 1 1r   r?   c                   8    e Zd Zd ZdefdZdefdZdefdZ	dS )	rC   c                     d | _         d S r   r   r]   s    r   r2   z+RegisterReAuthForAsyncClusterNodes.__init__  r   r   r   c                     t          |j        t                    rG|| _        |j                            | j                   |j                            | j                   d S d S r   )r   rl   r   r   r   r   r   r   r   s     r   r   z)RegisterReAuthForAsyncClusterNodes.listen  se    e/1LMM 	EDK%--dm<<<%..t/CDDDDD	E 	Er   r   c                 ~   K   | j         j        D ]-}| j         j        |                             |           d {V  .d S r   )r   r   r   )r   r   keys      r   r   z+RegisterReAuthForAsyncClusterNodes._re_auth  s[      ;$ 	A 	AC+#C(99%@@@@@@@@@@	A 	Ar   r   c                 0   K   t          || j                  r   r   r   s     r   r   z2RegisterReAuthForAsyncClusterNodes._raise_on_error  r   r   N)
r   r   r   r2   rB   r   r   r   r4   r   r   r   r   rC   rC     s          E? E E E EAN A A A A19 1 1 1 1 1 1r   rC   c                   P    e Zd Zd ZdefdZdefdZdefdZde	fdZ
de	fd	Zd
S )rA   c                 L    d | _         d | _        d | _        d | _        d | _        d S r   )rZ   r   ro   r|   r   r]   s    r   r2   z RegisterReAuthForPubSub.__init__  s-     $  $r   r   c                 >   t          |j        j        t                    r|j                                        dv r|| _        |j        | _        |j        | _        |j	        | _
        |j        | _        | j
        t          j        k    rJ| j        j                            | j                   | j        j                            | j                   d S | j        j                            | j                   | j        j                            | j                   d S d S d S )N)   3)r   r   rl   r   get_protocolr   rZ   r   r   rk   ro   rz   r|   rd   rg   r   r   r   r   r   r   r   s     r   r   zRegisterReAuthForPubSub.listen  s   #79T
 
 	%2244@@DK$6D$)$9D! % 1D$)$9D! JO33 4<<T]KKK 4==d>RSSSSS 4<<T=PQQQ 4==.    	 	@@r   r   c                 ,   | j         5  | j                            d|                    d          |                                           | j                                         d d d            n# 1 swxY w Y   | j                            |           d S r   r|   rZ   r   r   r   r   r   r   r   s     r   r   z RegisterReAuthForPubSub._re_auth  s    " 	- 	-))e,,eoo.?.?   **,,,		- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	..u55555s   AA//A36A3c                 x  K   | j         4 d {V  | j                            d|                    d          |                                           d {V  | j                                         d {V  d d d           d {V  n# 1 d {V swxY w Y   | j                            |           d {V  d S r   r   r   s     r   r   z&RegisterReAuthForPubSub._re_auth_async  sn     ( 	3 	3 	3 	3 	3 	3 	3 	3"//e,,eoo.?.?         "00222222222		3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 #44U;;;;;;;;;;;s   A'B		
BBr   c                 ,    t          || j                  r   r   r   s     r   r   z'RegisterReAuthForPubSub._raise_on_error  r   r   c                 0   K   t          || j                  r   r   r   s     r   r   z-RegisterReAuthForPubSub._raise_on_error_async  r   r   N)r   r   r   r2   r@   r   r   r   r   r4   r   r   r   r   r   rA   rA     s          C    &6n 6 6 6 6<. < < < <1Y 1 1 1 11 1 1 1 1 1 1r   rA   )'rR   rG   abcr   r   enumr   typingr   r   r   r	   r
   redis.auth.tokenr   redis.credentialsr   r   r   r!   r%   r4   r.   r7   r:   rD   rd   r<   r>   r@   rB   r   r   r;   rE   r=   r?   rC   rA   r   r   r   <module>r      s        # # # # # # # #       4 4 4 4 4 4 4 4 4 4 4 4 4 4 + + + + + + M M M M M M M M    S       #       s   4$ $ $ $ $Y $ $ $FU FU FU FU FU. FU FU FUR
  
  
  
  
  
  
  
 	 	 	 	 	(D 	 	 	       
) ) ) ) ) ) ) )8% % % % % % % %>% % % % % % % %<) ) ) ) ) ) ) )2       ,	 	 	 	 	2 	 	 	# # # # #5 # # #) ) ) ) )$? ) ) ) 1  1  1  1  1)?  1  1  1F*1 *1 *1 *1 *1(> *1 *1 *1Z1 1 1 1 1)? 1 1 1$11 11 11 11 114 11 11 11 11 11r   