
    fia/                     P   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"dS )+    N)ABCabstractmethod)Enum)ListOptional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     [/var/www/html/Pagina-Ingenieria-Requisitos/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                   J    e Zd ZdZedefd            Zede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   N)r   r   r   r   r   r   r%   r'   r   r   r   r#   r#      sl         
 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                 f    || _         || _        t                                          |           d S 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)   .   sU         $) $F $ $ $ $ $ $ $ $ $ $r   r)   c                   ,    e Zd Zd ZdefdZdefdZdS )EventDispatcherc                    t           t                      gt          t                      gt          t                      gt          t                      gt          t                      gt          t                      gi| _        dS )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__;   s|    
 )(**+ 52447 41336 46M6O6O5P/2T2V2V1W--//0)
%%%r   r   c                     | j                             t          |                    }|D ]}|                    |           d S r   r@   gettyper   r   r   	listenerslisteners       r   r%   zEventDispatcher.dispatchP   sL    155d5kkBB	! 	# 	#HOOE""""	# 	#r   c                    K   | j                             t          |                    }|D ]}|                    |           d {V  d S r   rC   rF   s       r   r'   zEventDispatcher.dispatch_asyncV   sb      155d5kkBB	! 	) 	)H//%((((((((((	) 	)r   N)r   r   r   r-   r   r%   r'   r   r   r   r2   r2   9   sY        
 
 
*#f # # # #)& ) ) ) ) ) )r   r2   c                   .    e Zd ZdZd Zed             ZdS )r4   zA
    Event that will be fired before each command execution.
    c                     || _         d S r   _connection)r   
connections     r   r-   z%AfterConnectionReleasedEvent.__init__b   s    %r   c                     | j         S r   rL   rA   s    r   rN   z'AfterConnectionReleasedEvent.connectione       r   N)r   r   r   r   r-   propertyrN   r   r   r   r4   r4   ]   sH         & & &     X     r   r4   c                       e Zd ZdS )r>   N)r   r   r   r   r   r   r>   r>   j   s        Dr   r>   c                       e Zd ZdZdZdS )
ClientType)sync)asyncN)r   r   r   SYNCASYNCr   r   r   rT   rT   n   s        DEEEr   rT   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 )r6   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   rZ   r[   r\   s       r   r-   z1AfterPooledConnectionsInstantiationEvent.__init__x   s"     "2'$7!!!r   c                     | j         S r   )r^   rA   s    r   rZ   z9AfterPooledConnectionsInstantiationEvent.connection_pools   s    %%r   returnc                     | j         S r   r_   rA   s    r   r[   z4AfterPooledConnectionsInstantiationEvent.client_type         r   c                     | j         S r   r`   rA   s    r   r\   z<AfterPooledConnectionsInstantiationEvent.credential_provider       ((r   r   )r   r   r   r   r   rT   r   r
   r-   rQ   rZ   r[   r   r\   r   r   r   r6   r6   s   s          =A	8 88  8 &&89	8 8 8 8 & & X& !Z ! ! ! X! )U+=t+C%D ) ) ) X) ) )r   r6   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 )
r8   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                 0    || _         || _        || _        d S r   )rM   r_   _connection_lock)r   rN   r[   rj   s       r   r-   z0AfterSingleConnectionInstantiationEvent.__init__   s"     &' /r   c                     | j         S r   rL   rA   s    r   rN   z2AfterSingleConnectionInstantiationEvent.connection   rP   r   rb   c                     | j         S r   rd   rA   s    r   r[   z3AfterSingleConnectionInstantiationEvent.client_type   re   r   c                     | j         S r   rl   rA   s    r   rj   z7AfterSingleConnectionInstantiationEvent.connection_lock       $$r   N)r   r   r   r   rT   r   	threadingLockasyncior-   rQ   rN   r[   rj   r   r   r   r8   r8      s         0  0 y~w|;<	0 0 0 0     X  !Z ! ! ! X! %y~w|'C!D % % % X% % %r   r8   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:   r[   rj   c                 >    || _         || _        || _        || _        d S r   )_pubsub_connection_connection_poolr_   rl   )r   pubsub_connectionconnection_poolr[   rj   s        r   r-   z0AfterPubSubConnectionInstantiationEvent.__init__   s*     #4 /' /r   c                     | j         S r   )rw   rA   s    r   ry   z9AfterPubSubConnectionInstantiationEvent.pubsub_connection   s    &&r   c                     | j         S r   )rx   rA   s    r   rz   z7AfterPubSubConnectionInstantiationEvent.connection_pool   rq   r   rb   c                     | j         S r   rd   rA   s    r   r[   z3AfterPubSubConnectionInstantiationEvent.client_type   re   r   c                     | j         S r   rp   rA   s    r   rj   z7AfterPubSubConnectionInstantiationEvent.connection_lock   rq   r   N)r   r   r   rT   r   rr   rs   rt   r-   rQ   ry   rz   r[   rj   r   r   r   r:   r:      s        
0  	
0
 y~w|;<
0 
0 
0 
0 ' ' X' % % X% !Z ! ! ! X! %y~w|'C!D % % % 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 )
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                 "    || _         || _        d S r   )_nodesr`   )r   r   r\   s      r   r-   z,AfterAsyncClusterInstantiationEvent.__init__   s    
 $7!!!r   rb   c                     | j         S r   )r   rA   s    r   r   z)AfterAsyncClusterInstantiationEvent.nodes   s
    {r   c                     | j         S r   rg   rA   s    r   r\   z7AfterAsyncClusterInstantiationEvent.credential_provider   rh   r   r   )r   r   r   r   dictr   r
   r-   rQ   r   r   r\   r   r   r   r<   r<      s          =A8 88 &&898 8 8 8 t    X )U+=t+C%D ) ) ) X) ) )r   r<   c                       e Zd ZdZdefdZdS )r5   zG
    Listener that performs re-authentication of given connection.
    r   c                 8    |j                                          d S r   rN   re_authr   s     r   r   zReAuthConnectionListener.listen   s      """""r   N)r   r   r   r   r4   r   r   r   r   r5   r5      s:         #8 # # # # # #r   r5   c                       e Zd ZdZdefdZdS )r?   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   r>   r   r   r   r   r?   r?      s:         )"C ) ) ) ) ) )r   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 )r7   z
    Listener that registers a re-authentication callback for pooled connections.
    Required by :class:`StreamingCredentialProvider`.
    c                     d | _         d S r   _eventrA   s    r   r-   z+RegisterReAuthForPooledConnections.__init__       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   )
isinstancer\   r   r   r[   rT   rW   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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   rZ   re_auth_callbackr   tokenpools      r   r   z+RegisterReAuthForPooledConnections._re_auth  s7    K0 	) 	)D!!%((((	) 	)r   c                 ^   K   | j         j        D ]}|                    |           d {V  d S r   r   r   s      r   r   z1RegisterReAuthForPooledConnections._re_auth_async  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   r-   r6   r   r   r   r/   r   r   r   r   r   r7   r7      s         
  	OD 	O 	O 	O 	O) ) )/ / /1Y 1 1 1 11 1 1 1 1 1 1r   r7   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 )r9   z
    Listener that registers a re-authentication callback for single connection.
    Required by :class:`StreamingCredentialProvider`.
    c                     d | _         d S r   r   rA   s    r   r-   z*RegisterReAuthForSingleConnection.__init__   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   rN   r\   r   r   r[   rT   rW   r   r   r   r   r   r   r   s     r   r   z(RegisterReAuthForSingleConnection.listen#  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   rj   rN   send_commandtry_get	get_valueread_responser   r   s     r   r   z*RegisterReAuthForSingleConnection._re_auth2  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_async9  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_asyncC  r   r   N)r   r   r   r   r-   r8   r   r   r   r/   r   r   r   r   r   r9   r9     s         
  C    3 3 39 9 91Y 1 1 1 11 1 1 1 1 1 1r   r9   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 )	r=   c                     d | _         d S r   r   rA   s    r   r-   z+RegisterReAuthForAsyncClusterNodes.__init__H  r   r   r   c                     t          |j        t                    rG|| _        |j                            | j                   |j                            | j                   d S d S r   )r   r\   r   r   r   r   r   r   r   s     r   r   z)RegisterReAuthForAsyncClusterNodes.listenK  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_authQ  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_errorU  r   r   N)
r   r   r   r-   r<   r   r	   r   r/   r   r   r   r   r=   r=   G  s          E? E E E EAN A A A A19 1 1 1 1 1 1r   r=   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 )r;   c                 L    d | _         d | _        d | _        d | _        d | _        d S r   )rM   rx   r_   rl   r   rA   s    r   r-   z RegisterReAuthForPubSub.__init__Z  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   ry   r\   r   get_protocolr   rM   rz   rx   r[   r_   rj   rl   rT   rW   r   r   r   r   r   r   r   s     r   r   zRegisterReAuthForPubSub.listena  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   rl   rM   r   r   r   r   rx   r   r   s     r   r   z RegisterReAuthForPubSub._re_autht  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   r-   r:   r   r	   r   r   r/   r   r   r   r   r   r;   r;   Y  s          C    &6n 6 6 6 6<. < < < <1Y 1 1 1 11 1 1 1 1 1 1r   r;   )#rt   rr   abcr   r   enumr   typingr   r   r   redis.auth.tokenr	   redis.credentialsr
   r   r   r   r#   r/   r)   r2   r4   r>   rT   r6   r8   r:   r<   r5   r?   r7   r9   r=   r;   r   r   r   <module>r      s        # # # # # # # #       ( ( ( ( ( ( ( ( ( ( + + + + + + M M M M M M M M    S       #       s   $ $ $ $ $Y $ $ $!) !) !) !) !). !) !) !)H
  
  
  
  
  
  
  
 	 	 	 	 	(D 	 	 	       
) ) ) ) ) ) ) )8% % % % % % % %>% % % % % % % %<) ) ) ) ) ) ) )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   