
    he/                        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
 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 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"y)+    N)ABCabstractmethod)Enum)ListOptionalUnion)TokenInterface)CredentialProviderStreamingCredentialProviderc                   &    e Zd ZdZedefd       Zy)EventListenerInterfacez7
    Represents a listener for given event object.
    eventc                      y N selfr   s     m/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/redis/event.pylistenzEventListenerInterface.listen           N__name__
__module____qualname____doc__r   objectr   r   r   r   r   r      s"     F  r   r   c                   &    e Zd ZdZedefd       Zy)AsyncEventListenerInterfacez>
    Represents an async listener for given event object.
    r   c                    K   y wr   r   r   s     r   r   z"AsyncEventListenerInterface.listen   	        Nr   r   r   r   r   r      s"     &  r   r   c                   <    e Zd ZdZedefd       Zedefd       Zy)EventDispatcherInterfacezf
    Represents a dispatcher that dispatches events to listeners
    associated with given event.
    r   c                      y r   r   r   s     r   dispatchz!EventDispatcherInterface.dispatch%   r   r   c                    K   y wr   r   r   s     r   dispatch_asyncz'EventDispatcherInterface.dispatch_async)   r!   r"   N)r   r   r   r   r   r   r&   r(   r   r   r   r$   r$      s=    
 f   &  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                 @    || _         || _        t        |   |       y r   )r+   r   super__init__)r   r+   r   	__class__s      r   r.   zEventException.__init__3   s    "
#r   )r   r   r   r   	Exceptionr   r.   __classcell__)r/   s   @r   r*   r*   .   s     $) $F $ $r   r*   c                   *    e Zd Zd ZdefdZdefdZy)EventDispatcherc                     t         t               gt        t               gt        t               gt        t               gt        t               gt        t               gi| _        y)zY
        Mapping should be extended for any new events or listeners to be added.
        N)AfterConnectionReleasedEventReAuthConnectionListener(AfterPooledConnectionsInstantiationEvent"RegisterReAuthForPooledConnections'AfterSingleConnectionInstantiationEvent!RegisterReAuthForSingleConnection'AfterPubSubConnectionInstantiationEventRegisterReAuthForPubSub#AfterAsyncClusterInstantiationEvent"RegisterReAuthForAsyncClusterNodes!AsyncAfterConnectionReleasedEventAsyncReAuthConnectionListener_event_listeners_mappingr   s    r   r.   zEventDispatcher.__init__;   sd    
 )(*+ 5247 4136 46M6O5P/2T2V1W--/0)
%r   r   c                 |    | j                   j                  t        |            }|D ]  }|j                  |        y r   rA   gettyper   r   r   	listenerslisteners       r   r&   zEventDispatcher.dispatchP   s7    1155d5kB	! 	#HOOE"	#r   c                    K   | j                   j                  t        |            }|D ]  }|j                  |       d {     y 7 wr   rD   rG   s       r   r(   zEventDispatcher.dispatch_asyncV   sD     1155d5kB	! 	)H//%(((	)(s   >A
 AA
N)r   r   r   r.   r   r&   r(   r   r   r   r3   r3   9   s    
*#f #)& )r   r3   c                   &    e Zd ZdZd Zed        Zy)r5   zA
    Event that will be fired before each command execution.
    c                     || _         y r   _connection)r   
connections     r   r.   z%AfterConnectionReleasedEvent.__init__b   s
    %r   c                     | j                   S r   rM   rB   s    r   rO   z'AfterConnectionReleasedEvent.connectione       r   N)r   r   r   r   r.   propertyrO   r   r   r   r5   r5   ]   s     &    r   r5   c                       e Zd Zy)r?   N)r   r   r   r   r   r   r?   r?   j   s    r   r?   c                       e Zd ZdZdZy)
ClientType)sync)asyncN)r   r   r   SYNCASYNCr   r   r   rU   rU   n   s    DEr   rU   c                   t    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y)r7   zQ
    Event that will be fired after pooled connection instances was created.
    Nconnection_poolsclient_typecredential_providerc                 .    || _         || _        || _        y r   )_connection_pools_client_type_credential_provider)r   r[   r\   r]   s       r   r.   z1AfterPooledConnectionsInstantiationEvent.__init__x   s     "2'$7!r   c                     | j                   S r   )r_   rB   s    r   r[   z9AfterPooledConnectionsInstantiationEvent.connection_pools   s    %%%r   returnc                     | j                   S r   r`   rB   s    r   r\   z4AfterPooledConnectionsInstantiationEvent.client_type          r   c                     | j                   S r   ra   rB   s    r   r]   z<AfterPooledConnectionsInstantiationEvent.credential_provider       (((r   r   )r   r   r   r   r   rU   r   r
   r.   rR   r[   r\   r   r]   r   r   r   r7   r7   s   s     =A	88  8 &&89	8 & & !Z ! ! )U+=t+C%D ) )r   r7   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y	)
r9   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
    r\   connection_lockc                 .    || _         || _        || _        y r   )rN   r`   _connection_lock)r   rO   r\   rk   s       r   r.   z0AfterSingleConnectionInstantiationEvent.__init__   s     &' /r   c                     | j                   S r   rM   rB   s    r   rO   z2AfterSingleConnectionInstantiationEvent.connection   rQ   r   rc   c                     | j                   S r   re   rB   s    r   r\   z3AfterSingleConnectionInstantiationEvent.client_type   rf   r   c                     | j                   S r   rm   rB   s    r   rk   z7AfterSingleConnectionInstantiationEvent.connection_lock       $$$r   N)r   r   r   r   rU   r   	threadingRLockasyncioLockr.   rR   rO   r\   rk   r   r   r   r9   r9      s    0  0 y<=	0     !Z ! ! %y'D!E % %r   r9   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y	)
r;   r\   rk   c                 <    || _         || _        || _        || _        y r   )_pubsub_connection_connection_poolr`   rm   )r   pubsub_connectionconnection_poolr\   rk   s        r   r.   z0AfterPubSubConnectionInstantiationEvent.__init__   s$     #4 /' /r   c                     | j                   S r   )ry   rB   s    r   r{   z9AfterPubSubConnectionInstantiationEvent.pubsub_connection   s    &&&r   c                     | j                   S r   )rz   rB   s    r   r|   z7AfterPubSubConnectionInstantiationEvent.connection_pool   rr   r   rc   c                     | j                   S r   re   rB   s    r   r\   z3AfterPubSubConnectionInstantiationEvent.client_type   rf   r   c                     | j                   S r   rq   rB   s    r   rk   z7AfterPubSubConnectionInstantiationEvent.connection_lock   rr   r   N)r   r   r   rU   r   rs   rt   ru   rv   r.   rR   r{   r|   r\   rk   r   r   r   r;   r;      s    
0  	
0
 y<=
0 ' ' % % !Z ! ! %y'D!E % %r   r;   c                   `    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y)
r=   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nodesr]   c                      || _         || _        y r   )_nodesra   )r   r   r]   s      r   r.   z,AfterAsyncClusterInstantiationEvent.__init__   s    
 $7!r   rc   c                     | j                   S r   )r   rB   s    r   r   z)AfterAsyncClusterInstantiationEvent.nodes   s    {{r   c                     | j                   S r   rh   rB   s    r   r]   z7AfterAsyncClusterInstantiationEvent.credential_provider   ri   r   r   )r   r   r   r   dictr   r
   r.   rR   r   r   r]   r   r   r   r=   r=      sk     =A88 &&898 t   )U+=t+C%D ) )r   r=   c                       e Zd ZdZdefdZy)r6   zG
    Listener that performs re-authentication of given connection.
    r   c                 8    |j                   j                          y r   rO   re_authr   s     r   r   zReAuthConnectionListener.listen   s      "r   N)r   r   r   r   r5   r   r   r   r   r6   r6      s    #8 #r   r6   c                       e Zd ZdZdefdZy)r@   zM
    Async listener that performs re-authentication of given connection.
    r   c                 T   K   |j                   j                          d {    y 7 wr   r   r   s     r   r   z$AsyncReAuthConnectionListener.listen   s     &&(((s   (&(N)r   r   r   r   r?   r   r   r   r   r@   r@      s    )"C )r   r@   c                   F    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y
)r8   z
    Listener that registers a re-authentication callback for pooled connections.
    Required by :class:`StreamingCredentialProvider`.
    c                     d | _         y r   _eventrB   s    r   r.   z+RegisterReAuthForPooledConnections.__init__   	    r   r   c                    t        |j                  t              r|| _        |j                  t
        j                  k(  rK|j                  j                  | j                         |j                  j                  | j                         y |j                  j                  | j                         |j                  j                  | j                         y y r   )
isinstancer]   r   r   r\   rU   rX   on_next_re_authon_error_raise_on_error_re_auth_async_raise_on_error_asyncr   s     r   r   z)RegisterReAuthForPooledConnections.listen   s    e//1LMDK  JOO3))11$--@))2243G3GH))11$2E2EF))2243M3MN Nr   c                 \    | j                   j                  D ]  }|j                  |        y r   r   r[   re_auth_callbackr   tokenpools      r   r   z+RegisterReAuthForPooledConnections._re_auth  s)    KK00 	)D!!%(	)r   c                 x   K   | j                   j                  D ]  }|j                  |       d {     y 7 wr   r   r   s      r   r   z1RegisterReAuthForPooledConnections._re_auth_async  s6     KK00 	/D''...	/.s   .:8:errorc                 .    t        || j                        r   r*   r   r   r   s     r   r   z2RegisterReAuthForPooledConnections._raise_on_error      UDKK00r   c                 6   K   t        || j                        wr   r   r   s     r   r   z8RegisterReAuthForPooledConnections._raise_on_error_async       UDKK00   N)r   r   r   r   r.   r7   r   r   r   r0   r   r   r   r   r   r8   r8      s=    
	OD 	O)/1Y 11 1r   r8   c                   F    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y
)r:   z
    Listener that registers a re-authentication callback for single connection.
    Required by :class:`StreamingCredentialProvider`.
    c                     d | _         y r   r   rB   s    r   r.   z*RegisterReAuthForSingleConnection.__init__   r   r   r   c                    t        |j                  j                  t              r|| _        |j
                  t        j                  k(  r_|j                  j                  j                  | j                         |j                  j                  j                  | j                         y |j                  j                  j                  | j                         |j                  j                  j                  | j                         y y r   )r   rO   r]   r   r   r\   rU   rX   r   r   r   r   r   r   r   s     r   r   z(RegisterReAuthForSingleConnection.listen#  s    002M
  DK  JOO3  44<<T]]K  44==d>R>RS  44<<T=P=PQ  44==..
r   c                 *   | j                   j                  5  | j                   j                  j                  d|j	                  d      |j                                | j                   j                  j                          d d d        y # 1 sw Y   y xY wNAUTHoidr   rk   rO   send_commandtry_get	get_valueread_responser   r   s     r   r   z*RegisterReAuthForSingleConnection._re_auth2  sk    [[(( 	3KK""//e,eoo.? KK""002		3 	3 	3s   A)B		Bc                   K   | j                   j                  4 d {    | j                   j                  j                  d|j	                  d      |j                                d {    | j                   j                  j                          d {    d d d       d {    y 7 7 C7 7 # 1 d {  7  sw Y   y xY wwr   r   r   s     r   r   z0RegisterReAuthForSingleConnection._re_auth_async9  s     ;;.. 	9 	9++((55e,eoo.?   ++((66888		9 	9 	9 9		9 	9 	9 	9si   CB+CAB3)B-*+B3B/B3C%B1&C-B3/B31C3C9B<:CCr   c                 .    t        || j                        r   r   r   s     r   r   z1RegisterReAuthForSingleConnection._raise_on_error@  r   r   c                 6   K   t        || j                        wr   r   r   s     r   r   z7RegisterReAuthForSingleConnection._raise_on_error_asyncC  r   r   N)r   r   r   r   r.   r9   r   r   r   r0   r   r   r   r   r   r:   r:     s;    
C 391Y 11 1r   r:   c                   6    e Zd Zd ZdefdZdefdZdefdZ	y)	r>   c                     d | _         y r   r   rB   s    r   r.   z+RegisterReAuthForAsyncClusterNodes.__init__H  r   r   r   c                     t        |j                  t              rR|| _        |j                  j	                  | j
                         |j                  j                  | j                         y y r   )r   r]   r   r   r   r   r   r   r   s     r   r   z)RegisterReAuthForAsyncClusterNodes.listenK  sR    e//1LMDK%%--dmm<%%..t/C/CD Nr   r   c                    K   | j                   j                  D ]2  }| j                   j                  |   j                  |       d {    4 y 7 wr   )r   r   r   )r   r   keys      r   r   z+RegisterReAuthForAsyncClusterNodes._re_authQ  sG     ;;$$ 	AC++##C(99%@@@	A@s   AAAAr   c                 6   K   t        || j                        wr   r   r   s     r   r   z2RegisterReAuthForAsyncClusterNodes._raise_on_errorU  r   r   N)
r   r   r   r.   r=   r   r	   r   r0   r   r   r   r   r>   r>   G  s0    E? EAN A19 1r   r>   c                   N    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y
)r<   c                 J    d | _         d | _        d | _        d | _        d | _        y r   )rN   rz   r`   rm   r   rB   s    r   r.   z RegisterReAuthForPubSub.__init__Z  s)     $  $r   r   c                    t        |j                  j                  t              rD|j                  j	                         dv r&|| _        |j                  | _        |j                  | _        |j                  | _
        |j                  | _        | j                  t        j                  k(  r_| j                  j                  j                  | j                          | j                  j                  j#                  | j$                         y | j                  j                  j                  | j&                         | j                  j                  j#                  | j(                         y y y )N)   3)r   r{   r]   r   get_protocolr   rN   r|   rz   r\   r`   rk   rm   rU   rX   r   r   r   r   r   r   r   s     r   r   zRegisterReAuthForPubSub.listena  s   ##779T
%%224@DK$66D$)$9$9D! % 1 1D$)$9$9D!  JOO3  44<<T]]K  44==d>R>RS  44<<T=P=PQ  44==.. A
r   r   c                 $   | j                   5  | j                  j                  d|j                  d      |j	                                | j                  j                          d d d        | j                  j                  |       y # 1 sw Y   %xY wr   rm   rN   r   r   r   r   rz   r   r   s     r   r   z RegisterReAuthForPubSub._re_autht  su    "" 	-))e,eoo.? **,		- 	..u5	- 	-s   ABBc                   K   | j                   4 d {    | j                  j                  d|j                  d      |j	                                d {    | j                  j                          d {    d d d       d {    | j                  j                  |       d {    y 7 7 \7 <7 .# 1 d {  7  sw Y   >xY w7 "wr   r   r   s     r   r   z&RegisterReAuthForPubSub._re_auth_async}  s     (( 	3 	3""//e,eoo.?   ""00222		3 	3 ##44U;;;	3 3		3 	3 	3 	3 	<st   CB0C>B8B2!B87B48B8<CB6"C*C+C2B84B86C8C
>C?C
Cr   c                 .    t        || j                        r   r   r   s     r   r   z'RegisterReAuthForPubSub._raise_on_error  r   r   c                 6   K   t        || j                        wr   r   r   s     r   r   z-RegisterReAuthForPubSub._raise_on_error_async  r   r   N)r   r   r   r.   r;   r   r	   r   r   r0   r   r   r   r   r   r<   r<   Y  sD    C &6n 6<. <1Y 11 1r   r<   )#ru   rs   abcr   r   enumr   typingr   r   r   redis.auth.tokenr	   redis.credentialsr
   r   r   r   r$   r0   r*   r3   r5   r?   rU   r7   r9   r;   r=   r6   r@   r8   r:   r>   r<   r   r   r   <module>r      s      #  ( ( + MS # s $Y $!). !)H
  
 	(D 	 
) )8% %>% %<) )2#5 #)$? ) 1)?  1F*1(> *1Z1)? 1$114 11r   