o
    <‘ði!;  ã                   @   sÌ  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 d dlmZmZ d dlmZmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZ G dd„ dƒZ!G dd„ dƒZ"G dd„ dƒZ#G dd „ d ƒZ$G d!d"„ d"ƒZ%G d#d$„ d$e%ƒZ&G d%d&„ d&eƒZ'G d'd(„ d(eƒZ(G d)d*„ d*eƒZ)G d+d,„ d,eƒZ*G d-d.„ d.eƒZ+G d/d0„ d0eƒZ,G d1d2„ d2eƒZ-dS )3é    N)ÚABCÚabstractmethod)ÚEnum)ÚDictÚListÚOptionalÚTypeÚUnion)ÚTokenInterface)ÚCredentialProviderÚStreamingCredentialProvider)Úinit_connection_countÚregister_pools_connection_count)Úcheck_protocol_versionÚdeprecated_functionc                   @   ó"   e Zd ZdZedefdd„ƒZdS )ÚEventListenerInterfacez7
    Represents a listener for given event object.
    Úeventc                 C   ó   d S ©N© ©Úselfr   r   r   úJ/root/parts/websockify/install/lib/python3.10/site-packages/redis/event.pyÚlisten   ó   zEventListenerInterface.listenN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úobjectr   r   r   r   r   r      ó    r   c                   @   r   )ÚAsyncEventListenerInterfacez>
    Represents an async listener for given event object.
    r   c                 Ã   ó   �d S r   r   r   r   r   r   r      ó   €z"AsyncEventListenerInterface.listenNr   r   r   r   r   r#      r"   r#   c                   @   s^   e Zd ZdZedefdd„ƒZedefdd„ƒZedee	e e
eeef  f fdd	„ƒZd
S )ÚEventDispatcherInterfacezf
    Represents a dispatcher that dispatches events to listeners
    associated with given event.
    r   c                 C   r   r   r   r   r   r   r   Údispatch*   r   z!EventDispatcherInterface.dispatchc                 Ã   r$   r   r   r   r   r   r   Údispatch_async.   r%   z'EventDispatcherInterface.dispatch_asyncÚmappingsc                 C   s   dS )zRegister additional listeners.Nr   )r   r)   r   r   r   Úregister_listeners2   s   	z+EventDispatcherInterface.register_listenersN)r   r   r   r    r   r!   r'   r(   r   r   r   r	   r   r#   r*   r   r   r   r   r&   $   s    ÿÿþr&   c                       s*   e Zd ZdZdedef‡ fdd„Z‡  ZS )ÚEventExceptionzM
    Exception wrapper that adds an event object into exception context.
    Ú	exceptionr   c                    s   || _ || _tƒ  |¡ d S r   )r,   r   ÚsuperÚ__init__)r   r,   r   ©Ú	__class__r   r   r.   C   s   zEventException.__init__)r   r   r   r    Ú	Exceptionr!   r.   Ú__classcell__r   r   r/   r   r+   >   s    r+   c                   @   st   e Zd Z	ddeeee ee f  fdd„Z	defdd„Z
defdd	„Zd
eee eeeef  f fdd„ZdS )ÚEventDispatcherNÚevent_listenersc                 C   s\   t tƒ gttƒ gttƒ gttƒ gtt	ƒ gt
tƒ gi| _t ¡ | _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   r4   r   r   r   r.   K   s*   ÿÿÿÿôþ
ÿzEventDispatcher.__init__r   c                 C   sR   | j � | j t|ƒg ¡}|D ]}| |¡ qW d   ƒ d S 1 s"w   Y  d S r   )rD   rA   ÚgetÚtyper   ©r   r   Ú	listenersÚlistenerr   r   r   r'   m   s   ÿ"ýzEventDispatcher.dispatchc              	   Ã   s‚   �| j d u rt ¡ | _ | j 4 I d H š" | j t|ƒg ¡}|D ]
}| |¡I d H  qW d   ƒI d H  d S 1 I d H s:w   Y  d S r   )rE   ÚasynciorC   rA   rF   rG   r   rH   r   r   r   r(   t   s   €

ÿ.ýzEventDispatcher.dispatch_asyncr)   c                 C   sp   | j �+ |D ]}|| jv rtt| j| ||  ƒƒ| j|< q|| | j|< qW d   ƒ d S 1 s1w   Y  d S r   )rD   rA   ÚlistÚset)r   r)   Ú
event_typer   r   r   r*   ~   s   
ÿÿÿ÷"ÿz"EventDispatcher.register_listenersr   )r   r   r   r   r   r   r!   r   r   r.   r'   r(   r	   r#   r*   r   r   r   r   r3   I   s     üÿ
þ"
ÿÿþr3   c                   @   s$   e Zd ZdZdd„ Zedd„ ƒZdS )r5   zA
    Event that will be fired before each command execution.
    c                 C   s
   || _ d S r   ©Ú_connection)r   Ú
connectionr   r   r   r.   —   ó   
z%AfterConnectionReleasedEvent.__init__c                 C   ó   | j S r   rO   ©r   r   r   r   rQ   š   ó   z'AfterConnectionReleasedEvent.connectionN)r   r   r   r    r.   ÚpropertyrQ   r   r   r   r   r5   ’   s
    r5   c                   @   ó   e Zd ZdS )r?   N©r   r   r   r   r   r   r   r?   Ÿ   ó    r?   c                   @   s   e Zd ZdZdZdS )Ú
ClientType)Úsync)ÚasyncN)r   r   r   ÚSYNCÚASYNCr   r   r   r   rZ   £   s    rZ   c                   @   sf   e Zd ZdZ	ddededee fdd„Ze	dd	„ ƒZ
e	d
efdd„ƒZe	d
eedf fdd„ƒZdS )r7   zQ
    Event that will be fired after pooled connection instances was created.
    NÚconnection_poolsÚclient_typeÚcredential_providerc                 C   ó   || _ || _|| _d S r   )Ú_connection_poolsÚ_client_typeÚ_credential_provider)r   r_   r`   ra   r   r   r   r.   ­   ó   
z1AfterPooledConnectionsInstantiationEvent.__init__c                 C   rS   r   )rc   rT   r   r   r   r_   ·   rU   z9AfterPooledConnectionsInstantiationEvent.connection_poolsÚreturnc                 C   rS   r   ©rd   rT   r   r   r   r`   »   rU   z4AfterPooledConnectionsInstantiationEvent.client_typec                 C   rS   r   ©re   rT   r   r   r   ra   ¿   rU   z<AfterPooledConnectionsInstantiationEvent.credential_providerr   )r   r   r   r    r   rZ   r   r   r.   rV   r_   r`   r	   ra   r   r   r   r   r7   ¨   s     üþý
ü

r7   c                   @   sj   e Zd ZdZdedeejej	f fdd„Z
edd„ ƒZedefd	d
„ƒZedeejej	f fdd„ƒZdS )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                 C   rb   r   )rP   rd   Ú_connection_lock)r   rQ   r`   rj   r   r   r   r.   Ì   rf   z0AfterSingleConnectionInstantiationEvent.__init__c                 C   rS   r   rO   rT   r   r   r   rQ   Ö   rU   z2AfterSingleConnectionInstantiationEvent.connectionrg   c                 C   rS   r   rh   rT   r   r   r   r`   Ú   rU   z3AfterSingleConnectionInstantiationEvent.client_typec                 C   rS   r   ©rk   rT   r   r   r   rj   Þ   rU   z7AfterSingleConnectionInstantiationEvent.connection_lockN)r   r   r   r    rZ   r	   rB   ÚRLockrK   rC   r.   rV   rQ   r`   rj   r   r   r   r   r9   Ä   s    ý
ü

 r9   c                   @   sr   e Zd Zdedeejejf fdd„Z	e
dd„ ƒZe
dd„ ƒZe
d	efd
d„ƒZe
d	eejejf fdd„ƒZdS )r;   r`   rj   c                 C   s   || _ || _|| _|| _d S r   )Ú_pubsub_connectionÚ_connection_poolrd   rk   )r   Úpubsub_connectionÚconnection_poolr`   rj   r   r   r   r.   ä   s   
z0AfterPubSubConnectionInstantiationEvent.__init__c                 C   rS   r   )rn   rT   r   r   r   rp   ð   rU   z9AfterPubSubConnectionInstantiationEvent.pubsub_connectionc                 C   rS   r   )ro   rT   r   r   r   rq   ô   rU   z7AfterPubSubConnectionInstantiationEvent.connection_poolrg   c                 C   rS   r   rh   rT   r   r   r   r`   ø   rU   z3AfterPubSubConnectionInstantiationEvent.client_typec                 C   rS   r   rl   rT   r   r   r   rj   ü   rU   z7AfterPubSubConnectionInstantiationEvent.connection_lockN)r   r   r   rZ   r	   rB   rm   rK   rC   r.   rV   rp   rq   r`   rj   r   r   r   r   r;   ã   s    ü
û

 r;   c                   @   sV   e Zd ZdZ	ddedee fdd„Zedefdd	„ƒZ	ede
edf fd
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Únodesra   c                 C   ó   || _ || _d S r   )Ú_nodesre   )r   rr   ra   r   r   r   r.   	  ó   
z,AfterAsyncClusterInstantiationEvent.__init__rg   c                 C   rS   r   )rt   rT   r   r   r   rr     rU   z)AfterAsyncClusterInstantiationEvent.nodesc                 C   rS   r   ri   rT   r   r   r   ra     rU   z7AfterAsyncClusterInstantiationEvent.credential_providerr   )r   r   r   r    Údictr   r   r.   rV   rr   r	   ra   r   r   r   r   r=     s    
ýþ
ýr=   c                   @   sF   e Zd ZdZdedefdd„Zedefdd„ƒZedefd	d
„ƒZ	dS )ÚOnCommandsFailEventzD
    Event fired whenever a command fails during the execution.
    Úcommandsr,   c                 C   rs   r   )Ú	_commandsÚ
_exception)r   rx   r,   r   r   r   r.     ru   zOnCommandsFailEvent.__init__rg   c                 C   rS   r   )ry   rT   r   r   r   rx   '  rU   zOnCommandsFailEvent.commandsc                 C   rS   r   )rz   rT   r   r   r   r,   +  rU   zOnCommandsFailEvent.exceptionN)
r   r   r   r    Útupler1   r.   rV   rx   r,   r   r   r   r   rw     s    þ
ýrw   c                   @   rW   )ÚAsyncOnCommandsFailEventNrX   r   r   r   r   r|   0  rY   r|   c                   @   ó   e Zd ZdZdefdd„ZdS )r6   zG
    Listener that performs re-authentication of given connection.
    r   c                 C   s   |j  ¡  d S r   ©rQ   Úre_authr   r   r   r   r   9  s   zReAuthConnectionListener.listenN)r   r   r   r    r5   r   r   r   r   r   r6   4  ó    r6   c                   @   r}   )r@   zM
    Async listener that performs re-authentication of given connection.
    r   c                 Ã   s   �|j  ¡ I d H  d S r   r~   r   r   r   r   r   B  s   €z$AsyncReAuthConnectionListener.listenN)r   r   r   r    r?   r   r   r   r   r   r@   =  r€   r@   c                   @   óR   e Zd ZdZdd„ Zdefdd„Zdd„ Zd	d
„ Zde	fdd„Z
de	fdd„ZdS )r8   zŒ
    Listener that registers a re-authentication callback for pooled connections.
    Required by :class:`StreamingCredentialProvider`.
    c                 C   ó
   d | _ d S r   ©Ú_eventrT   r   r   r   r.   L  rR   z+RegisterReAuthForPooledConnections.__init__r   c                 C   sb   t |jtƒr/|| _|jtjkr|j | j¡ |j 	| j
¡ d S |j | j¡ |j 	| j¡ d S d S r   )Ú
isinstancera   r   r„   r`   rZ   r]   Úon_nextÚ_re_authÚon_errorÚ_raise_on_errorÚ_re_auth_asyncÚ_raise_on_error_asyncr   r   r   r   r   O  s   øz)RegisterReAuthForPooledConnections.listenc                 C   s   | j jD ]}| |¡ qd S r   ©r„   r_   Úre_auth_callback©r   ÚtokenÚpoolr   r   r   r‡   Z  s   ÿz+RegisterReAuthForPooledConnections._re_authc                 Ã   s$   �| j jD ]
}| |¡I d H  qd S r   rŒ   rŽ   r   r   r   rŠ   ^  s   €ÿz1RegisterReAuthForPooledConnections._re_auth_asyncÚerrorc                 C   ó   t || jƒ‚r   ©r+   r„   ©r   r‘   r   r   r   r‰   b  ó   z2RegisterReAuthForPooledConnections._raise_on_errorc                 Ã   ó   �t || jƒ‚r   r“   r”   r   r   r   r‹   e  ó   €z8RegisterReAuthForPooledConnections._raise_on_error_asyncN)r   r   r   r    r.   r7   r   r‡   rŠ   r1   r‰   r‹   r   r   r   r   r8   F  s    r8   c                   @   r�   )r:   z‹
    Listener that registers a re-authentication callback for single connection.
    Required by :class:`StreamingCredentialProvider`.
    c                 C   r‚   r   rƒ   rT   r   r   r   r.   o  rR   z*RegisterReAuthForSingleConnection.__init__r   c                 C   sl   t |jjtƒr4|| _|jtjkr"|jj | j	¡ |jj 
| j¡ d S |jj | j¡ |jj 
| j¡ d S d S r   )r…   rQ   ra   r   r„   r`   rZ   r]   r†   r‡   rˆ   r‰   rŠ   r‹   r   r   r   r   r   r  s   ÿÿöz(RegisterReAuthForSingleConnection.listenc                 C   sV   | j j� | j j d| d¡| ¡ ¡ | j j ¡  W d   ƒ d S 1 s$w   Y  d S ©NÚAUTHÚoid©r„   rj   rQ   Úsend_commandÚtry_getÚ	get_valueÚread_response©r   r�   r   r   r   r‡   �  s   
ÿ"üz*RegisterReAuthForSingleConnection._re_authc              	   Ã   sx   �| j j4 I d H š& | j j d| d¡| ¡ ¡I d H  | j j ¡ I d H  W d   ƒI d H  d S 1 I d H s5w   Y  d S r˜   r›   r    r   r   r   rŠ   ˆ  s   €
ÿ.üz0RegisterReAuthForSingleConnection._re_auth_asyncr‘   c                 C   r’   r   r“   r”   r   r   r   r‰   �  r•   z1RegisterReAuthForSingleConnection._raise_on_errorc                 Ã   r–   r   r“   r”   r   r   r   r‹   ’  r—   z7RegisterReAuthForSingleConnection._raise_on_error_asyncN)r   r   r   r    r.   r9   r   r‡   rŠ   r1   r‰   r‹   r   r   r   r   r:   i  s    r:   c                   @   s>   e Zd Zdd„ Zdefdd„Zdefdd„Zd	efd
d„Z	dS )r>   c                 C   r‚   r   rƒ   rT   r   r   r   r.   —  rR   z+RegisterReAuthForAsyncClusterNodes.__init__r   c                 C   s6   t |jtƒr|| _|j | j¡ |j | j¡ d S d S r   )r…   ra   r   r„   r†   r‡   rˆ   r‰   r   r   r   r   r   š  s
   ýz)RegisterReAuthForAsyncClusterNodes.listenr�   c                 Ã   s,   �| j jD ]}| j j|  |¡I d H  qd S r   )r„   rr   r�   )r   r�   Úkeyr   r   r   r‡      s   €ÿz+RegisterReAuthForAsyncClusterNodes._re_authr‘   c                 Ã   r–   r   r“   r”   r   r   r   r‰   ¤  r—   z2RegisterReAuthForAsyncClusterNodes._raise_on_errorN)
r   r   r   r.   r=   r   r
   r‡   r1   r‰   r   r   r   r   r>   –  s
    r>   c                   @   sZ   e Zd Zdd„ Zdefdd„Zdefdd„Zdefd	d
„Zde	fdd„Z
de	fdd„ZdS )r<   c                 C   s"   d | _ d | _d | _d | _d | _d S r   )rP   ro   rd   rk   r„   rT   r   r   r   r.   ©  s
   
z RegisterReAuthForPubSub.__init__r   c                 C   s    t |jjtƒrLt|j ¡ dƒrN|| _|j| _|j| _	|j
| _|j| _| jtjkr:| jj | j¡ | jj | j¡ d S | jj | j¡ | jj | j¡ d S d S d S )Né   )r…   rp   ra   r   r   Úget_protocolr„   rP   rq   ro   r`   rd   rj   rk   rZ   r]   r†   r‡   rˆ   r‰   rŠ   r‹   r   r   r   r   r   °  s$   ÿþÿòzRegisterReAuthForPubSub.listenr�   c                 C   sZ   | j � | j d| d¡| ¡ ¡ | j ¡  W d   ƒ n1 s w   Y  | j |¡ d S r˜   ©rk   rP   rœ   r�   rž   rŸ   ro   r�   r    r   r   r   r‡   Ã  s   ÿüz RegisterReAuthForPubSub._re_authc              	   Ã   s‚   �| j 4 I d H š# | j d| d¡| ¡ ¡I d H  | j ¡ I d H  W d   ƒI d H  n1 I d H s1w   Y  | j |¡I d H  d S r˜   r¤   r    r   r   r   rŠ   Ì  s   €
ÿ(üz&RegisterReAuthForPubSub._re_auth_asyncr‘   c                 C   r’   r   r“   r”   r   r   r   r‰   Õ  r•   z'RegisterReAuthForPubSub._raise_on_errorc                 Ã   r–   r   r“   r”   r   r   r   r‹   Ø  r—   z-RegisterReAuthForPubSub._raise_on_error_asyncN)r   r   r   r.   r;   r   r
   r‡   rŠ   r1   r‰   r‹   r   r   r   r   r<   ¨  s    		r<   c                   @   s*   e Zd ZdZeddd�defdd„ƒZdS )	Ú&InitializeConnectionCountObservabilityzC
    Listener that initializes connection count observability.
    z{Connection count is now tracked via record_connection_count(). This functionality will be removed in the next major versionz7.4.0)ÚreasonÚversionr   c                 C   s   t ƒ  t|jƒ d S r   )r   r   r_   r   r   r   r   r   á  s   	z-InitializeConnectionCountObservability.listenN)r   r   r   r    r   r7   r   r   r   r   r   r¥   Ü  s    ýr¥   ).rK   rB   Úabcr   r   Úenumr   Útypingr   r   r   r   r	   Úredis.auth.tokenr
   Úredis.credentialsr   r   Úredis.observability.recorderr   r   Úredis.utilsr   r   r   r#   r&   r1   r+   r3   r5   r?   rZ   r7   r9   r;   r=   rw   r|   r6   r@   r8   r:   r>   r<   r¥   r   r   r   r   Ú<module>   s<    

I		#-4