o
    <‘ðiÁø  ã                   @   s¬  U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z' dd	l(m)Z) e)r†d dl*Z*d d
l*m+Z+m,Z,m-Z- ndZ*dZ,dZ+dZ-ddl.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl(m6Z6m7Z7 ej8dkr¸d dl m9Z: nd dl:m9Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZF d dlGmHZHmIZI d dlJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZR d dlSmTZT d dlUmVZV d dlWmXZXmYZY ddlZm[Z[m\Z\m]Z]m^Z^m_Z_ dZ`dZadZbdZcdZdG d d!„ d!ejeƒZfefjgZheee^e_e]f  eid"< eX�rCe]Zjne^ZjG d#d$„ d$eƒZkG d%d&„ d&eƒZleekelf ZmG d'd(„ d(ƒZnG d)d*„ d*enƒZoG d+d,„ d,eoƒZpG d-d.„ d.ƒZqG d/d0„ d0enƒZrd1Zsd2eet fd3d4„Zud5d6„ Zveewexexeueueweweuevevexd7œƒZyeezed8e{f f eid9< G d:d;„ d;ed<d=�Z|d>ezd2e|fd?d@„Z}edAdBdC�Z~G dDdB„ dBƒZG dEdF„ dFeƒZ€dS )Gé    N)Úabstractmethod)Úchain)ÚMappingProxyType)ÚAnyÚCallableÚIterableÚListÚMappingÚOptionalÚProtocolÚSetÚTupleÚTypeÚ	TypedDictÚTypeVarÚUnion)ÚParseResultÚparse_qsÚunquoteÚurlparseé   )ÚDB_CLIENT_CONNECTION_POOL_NAMEÚDB_CLIENT_CONNECTION_STATEÚAttributeBuilderÚConnectionStateÚget_pool_name)ÚSSL_AVAILABLE)Ú
SSLContextÚ
TLSVersionÚVerifyFlags)ÚTokenInterface)Ú
DriverInfoÚresolve_driver_info)Ú!AsyncAfterConnectionReleasedEventÚEventDispatcher)Údeprecated_argsÚformat_error_message)é   é   r'   )Útimeout)Úrecord_connection_closedÚrecord_connection_countÚrecord_connection_create_timeÚrecord_connection_wait_timeÚrecord_error_count)ÚRetry)Ú	NoBackoff)ÚDEFAULT_RESP_VERSION)ÚCredentialProviderÚ"UsernamePasswordCredentialProvider)ÚAuthenticationErrorÚ$AuthenticationWrongNumberOfArgsErrorÚConnectionErrorÚ	DataErrorÚMaxConnectionsErrorÚ
RedisErrorÚResponseErrorÚTimeoutError)ÚCloseReason)Ú
EncodableT)ÚHIREDIS_AVAILABLEÚstr_if_bytes)Ú
BaseParserÚEncoderÚ_AsyncHiredisParserÚ_AsyncRESP2ParserÚ_AsyncRESP3Parseró   *ó   $s   
ó   
ó    c                   @   s   e Zd Zeƒ ZdS )Ú	_SentinelN)Ú__name__Ú
__module__Ú__qualname__ÚobjectÚsentinel© rO   rO   úW/root/parts/websockify/install/lib/python3.10/site-packages/redis/asyncio/connection.pyrI   d   s    
rI   ÚDefaultParserc                   @   ó   e Zd Zddd„ZdS )ÚConnectCallbackProtocolÚ
connectionÚAbstractConnectionc                 C   ó   d S ©NrO   ©ÚselfrT   rO   rO   rP   Ú__call__s   s    z ConnectCallbackProtocol.__call__N©rT   rU   ©rJ   rK   rL   rZ   rO   rO   rO   rP   rS   r   ó    rS   c                   @   rR   )ÚAsyncConnectCallbackProtocolrT   rU   c                 Ã   ó   �d S rW   rO   rX   rO   rO   rP   rZ   w   s   € z%AsyncConnectCallbackProtocol.__call__Nr[   r\   rO   rO   rO   rP   r^   v   r]   r^   c                1   @   s"  e Zd ZdZdZeddgdd�ddddd	ed
dd	edddddddddeddddœde	e
ef dee
 dee dee dede	eef de
de
dedee dededee
 dee
 dee
 dee dee
 dee dee d ee d!ee d"ee d#ee f.d$d%„ƒZefd&efd'd(„Zd)d*„ Zd+d,„ Zed-d.„ ƒZe d/d0„ ƒZ!d1d2„ Z"d3d4„ Z#dee d5dfd6d7„Z$d8d9„ Z%	:d~d;ed<efd=d>„Z&d?d@„ Z'dAdB„ Z(dCdD„ Z)edEdF„ ƒZ*ed5e
fdGdH„ƒZ+dIe,d5e
fdJdK„Z-dLdM„ Z.ddNdO„Z/d€d;ed5dfdPdQ„Z0						d�dRedSee1 dTee dUed5df
dVdW„Z2dXdY„ Z3dZd[„ Z4d\d]„ Z5d^e6e7 d5dfd_d`„Z8	:d€d^e	e7e
e6e7 f d;ed5dfdadb„Z9dcedded5dfdedf„Z:dgdh„ Z;			d‚d:d	diœdjedkee dledmee fdndo„Z<dce=d5e>e7 fdpdq„Z?dre6e6e=  d5e>e7 fdsdt„Z@dudv„ ZAdwdx„ ZBdyeCfdzd{„ZDd|d}„ ZEdS )ƒrU   z0Manages communication to and from a Redis server)ÚdbÚusernameÚclient_nameÚlib_nameÚlib_versionÚcredential_providerÚpasswordÚsocket_timeoutÚsocket_connect_timeoutÚredis_connect_funcÚretry_on_timeoutÚretry_on_errorÚhealth_check_intervalÚnext_health_checkÚlast_active_atÚencoderÚssl_contextÚprotocolÚ_readerÚ_writerÚ_parserÚ_connect_callbacksÚ_buffer_cutoffÚ_lockÚ_socket_read_sizeÚ__dict__rc   rd   zbUse 'driver_info' parameter instead. lib_name and lib_version will be removed in a future version.)Úargs_to_warnÚreasonr   NFúutf-8Ústricti   r   )r`   rf   rg   rh   rj   rk   ÚencodingÚencoding_errorsÚdecode_responsesÚparser_classÚsocket_read_sizerl   rb   rc   rd   Údriver_infora   Úretryri   Úencoder_classre   rq   Úevent_dispatcherr`   rf   rg   rh   rj   rk   r~   r   r€   r�   r‚   rl   rb   rƒ   ra   r„   ri   r…   re   rq   r†   c                C   s¤  |s|r|durt dƒ‚|du rtƒ | _n|| _|| _|| _t|||ƒ| _|| _|| _|| _	|| _
|du r7|}|| _|| _|tu rCg }|rV| t¡ | tj¡ | tj¡ || _|s]|rt|sgttƒ dƒ| _nt |¡| _| j |¡ nttƒ dƒ| _|| _d| _||||	ƒ| _|| _d| _d| _|| _ |  !|
¡ g | _"d| _#d| _$d| _%zt&|ƒ}W n t'y¶   t(}Y n t)yÀ   t*dƒ‚w |d	k sÉ|d
krÍt*dƒ‚|| _+dS )ag  
        Initialize a new async Connection.

        Parameters
        ----------
        driver_info : DriverInfo, optional
            Driver metadata for CLIENT SETINFO. If provided, lib_name and lib_version
            are ignored. If not provided, a DriverInfo will be created from lib_name
            and lib_version (or defaults if those are also None).
        lib_name : str, optional
            **Deprecated.** Use driver_info instead. Library name for CLIENT SETINFO.
        lib_version : str, optional
            **Deprecated.** Use driver_info instead. Library version for CLIENT SETINFO.
        NzÂ'username' and 'password' cannot be passed along with 'credential_provider'. Please provide only one of the following arguments: 
1. 'password' and (optional) 'username'
2. 'credential_provider'é   r   éÿÿÿÿip  Fzprotocol must be an integerr   r'   zprotocol must be either 2 or 3),r7   r$   Ú_event_dispatcherr`   rb   r"   rƒ   re   rf   ra   rg   rh   rj   ÚSENTINELÚappendr;   Úsocketr)   Úasynciork   r/   r0   r„   ÚcopyÚdeepcopyÚupdate_supported_errorsrl   rm   ro   ri   rr   rs   rx   Ú
set_parserru   rv   Ú_re_auth_tokenÚ_should_reconnectÚintÚ	TypeErrorr1   Ú
ValueErrorr6   rq   )rY   r`   rf   rg   rh   rj   rk   r~   r   r€   r�   r‚   rl   rb   rc   rd   rƒ   ra   r„   ri   r…   re   rq   r†   ÚprO   rO   rP   Ú__init__�   sj   .ÿ


ÿ
zAbstractConnection.__init__Ú	_warningsc                 C   sR   t | dd ƒr'|jd| ›�t| d� zt ¡  |  ¡  W d S  ty&   Y d S w d S )Nrs   zunclosed Connection )Úsource)ÚgetattrÚwarnÚResourceWarningr�   Úget_running_loopÚ_closeÚRuntimeError)rY   r™   rO   rO   rP   Ú__del__  s   ÿþøzAbstractConnection.__del__c                 C   s$   | j r| j  ¡  d | _ | _dS dS )zR
        Internal method to silently close the connection without waiting
        N)rs   Úcloserr   ©rY   rO   rO   rP   rŸ     s   
þzAbstractConnection._closec                 C   s8   d  dd„ |  ¡ D ƒ¡}d| jj› d| jj› d|› d�S )Nú,c                 s   s"   � | ]\}}|› d |› �V  qdS )ú=NrO   ©Ú.0ÚkÚvrO   rO   rP   Ú	<genexpr>&  s   €  z.AbstractConnection.__repr__.<locals>.<genexpr>ú<Ú.ú(z)>)ÚjoinÚrepr_piecesÚ	__class__rK   rJ   )rY   Ú	repr_argsrO   rO   rP   Ú__repr__%  s    zAbstractConnection.__repr__c                 C   rV   rW   rO   r£   rO   rO   rP   r¯   )  ó   zAbstractConnection.repr_piecesc                 C   s   | j d uo	| jd uS rW   )rr   rs   r£   rO   rO   rP   Úis_connected-  s   zAbstractConnection.is_connectedc                 C   s(   t  |¡}|| jvr| j |¡ dS dS )a^  
        Register a callback to be called when the connection is established either
        initially or reconnected.  This allows listeners to issue commands that
        are ephemeral to the connection, for example pub/sub subscription or
        key tracking.  The callback must be a _method_ and will be kept as
        a weak reference.
        N)ÚweakrefÚ
WeakMethodru   r‹   )rY   ÚcallbackÚwmrO   rO   rP   Úregister_connect_callback1  s   

ÿz,AbstractConnection.register_connect_callbackc                 C   s.   z| j  t |¡¡ W dS  ty   Y dS w )z÷
        De-register a previously registered callback.  It will no-longer receive
        notifications on connection events.  Calling this is not required when the
        listener goes away, since the callbacks are kept as weak methods.
        N)ru   Úremoverµ   r¶   r–   )rY   r·   rO   rO   rP   Úderegister_connect_callback=  s
   ÿz.AbstractConnection.deregister_connect_callbackÚreturnc                 C   s   || j d�| _dS )zË
        Creates a new instance of parser_class with socket size:
        _socket_read_size and assigns it to the parser for the connection
        :param parser_class: The required parser class
        )r‚   N)rx   rt   )rY   r�   rO   rO   rP   r‘   H  s   zAbstractConnection.set_parserc                 ƒ   s.   �ˆ j j‡ fdd„‡ fdd„dd�I dH  dS )z5Connects to the Redis server if not already connectedc                      s   ˆ j ddd�S )NTF)Úcheck_healthÚretry_socket_connect)Úconnect_check_healthrO   r£   rO   rP   Ú<lambda>U  ó    ÿz,AbstractConnection.connect.<locals>.<lambda>c                    s   ˆ j | |d�S ©N©ÚerrorÚfailure_count©Ú
disconnectrÃ   r£   rO   rP   rÀ   X  rÁ   T©Úwith_failure_countN)r„   Úcall_with_retryr£   rO   r£   rP   ÚconnectP  s   €

ùzAbstractConnection.connectTr½   r¾   c           	      ƒ   sö  �ˆj rd S d‰ ‡ ‡fdd„}z|r#ˆjj‡fdd„|dd�I d H  nˆ ¡ I d H  W ny tjy4   ‚  tjtjfyb   tdƒ}t	t
ˆd	d ƒt
ˆd
d ƒt
ˆd	d ƒt
ˆd
d ƒ|ˆ dd�I d H  |‚ ty” } z'tˆ |¡ƒ}t	t
ˆd	d ƒt
ˆd
d ƒt
ˆd	d ƒt
ˆd
d ƒ|ˆ dd�I d H  |‚d }~w ty¤ } zt|ƒ|‚d }~ww z"ˆjs³ˆj|d�I d H  nt ˆj¡rÁˆ ˆ¡I d H nˆ ˆ¡ W n tyÖ   ˆ ¡ I d H  ‚ w dd„ ˆjD ƒˆ_ˆjD ]}|ƒ }|ˆƒ}|røt |¡rø|I d H  qãd S )Nr   c                    s   |‰ ˆj | |d�S rÂ   rÆ   rÃ   ©Úactual_retry_attemptsrY   rO   rP   Úfailure_callbackf  s   zAAbstractConnection.connect_check_health.<locals>.failure_callbackc                      ó   ˆ   ¡ S rW   )Ú_connectrO   r£   rO   rP   rÀ   n  ó    z9AbstractConnection.connect_check_health.<locals>.<lambda>TrÈ   zTimeout connecting to serverÚhostÚportF)Úserver_addressÚserver_portÚnetwork_peer_addressÚnetwork_peer_portÚ
error_typeÚretry_attemptsÚis_internal©r½   c                 S   s   g | ]}|ƒ r|‘qS rO   rO   )r§   ÚrefrO   rO   rP   Ú
<listcomp>¤  s    z;AbstractConnection.connect_check_health.<locals>.<listcomp>)r´   r„   rÊ   rÐ   r�   ÚCancelledErrorrŒ   r)   r;   r.   r›   ÚOSErrorr6   Ú_error_messageÚ	Exceptionri   Úon_connect_check_healthÚiscoroutinefunctionr9   rÇ   ru   ÚinspectÚisawaitable)	rY   r½   r¾   rÎ   ÚeÚexcrÜ   r·   ÚtaskrO   rÌ   rP   r¿   ^  s€   €
ý€



ù	



ù	€
€ÿ
ÿ€ý

€üz'AbstractConnection.connect_check_healthc                 C   ó
   d| _ d S )NT©r“   r£   rO   rO   rP   Úmark_for_reconnect«  ó   
z%AbstractConnection.mark_for_reconnectc                 C   ó   | j S rW   rê   r£   rO   rO   rP   Úshould_reconnect®  ó   z#AbstractConnection.should_reconnectc                 C   ré   )NFrê   r£   rO   rO   rP   Úreset_should_reconnect±  rì   z)AbstractConnection.reset_should_reconnectc                 Ã   r_   rW   rO   r£   rO   rO   rP   rÐ   ´  s   €zAbstractConnection._connectc                 C   rV   rW   rO   r£   rO   rO   rP   Ú_host_error¸  r³   zAbstractConnection._host_errorÚ	exceptionc                 C   s   t |  ¡ |ƒS rW   )r&   rñ   )rY   rò   rO   rO   rP   rà   ¼  ó   z!AbstractConnection._error_messagec                 C   rí   rW   )rq   r£   rO   rO   rP   Úget_protocol¿  rï   zAbstractConnection.get_protocolc                 Ã   s   �| j dd�I dH  dS )z=Initialize the connection, authenticate and select a databaseTrÛ   N)râ   r£   rO   rO   rP   Ú
on_connectÂ  s   €zAbstractConnection.on_connectc           
   	   Ã   s&  �| j  | ¡ | j }d }| js| js| jr&| jpt| j| jƒ}| ¡ I d H }|r�| jdvr�t| j t	ƒrC|  
t¡ |j| j _| j  | ¡ t|ƒdkrOd|d g}| jd| jdg|¢R ddiŽI d H  |  ¡ I d H }| d	¡t| jƒkr€| d
¡t| jƒkr€tdƒ‚nq|rÄ| jdg|¢R ddiŽI d H  z	|  ¡ I d H }W n ty¸   | jd|d dd�I d H  |  ¡ I d H }Y nw t|ƒdkrÃtdƒ‚n.| jdvròt| j t	ƒrß|  
t¡ |j| j _| j  | ¡ | jd| j|d�I d H  |  ¡ I d H }| j�r| jdd| j|d�I d H  t|  ¡ I d H ƒdk�rtdƒ‚d}d}| j�r1| jj�r1| jddd| jj|d�I d H  d}| j�rK| jj�rK| jddd| jj|d�I d H  d}| j�r[| jd| j|d�I d H  tt||gƒƒD ]}	z
|  ¡ I d H  W �qc t�yz   Y �qcw | j�r�t|  ¡ I d H ƒdk�r‘tdƒ‚d S d S )N)r   Ú2r‡   Údefaultr   ÚHELLOÚAUTHr½   Fs   protoÚprotozInvalid RESP versionrˆ   rÛ   ÚOKzInvalid Username or PasswordÚCLIENTÚSETNAMEzError setting client nameÚSETINFOzLIB-NAMETzLIB-VERÚSELECTzInvalid Database)rt   rõ   re   ra   rf   r3   Úget_credentials_asyncrq   Ú
isinstancerC   r‘   rD   ÚEXCEPTION_CLASSESÚlenÚsend_commandÚread_responseÚgetr”   r6   r5   r?   r4   rb   rƒ   Úformatted_namerd   r`   ÚrangeÚsumr:   )
rY   r½   ÚparserÚ	auth_argsÚcred_providerÚresponseÚauth_responseÚlib_name_sentÚlib_version_sentÚ_rO   rO   rP   râ   Æ  s¶   €þ

ÿÿÿÿþ€úÿ


üûûÿþz*AbstractConnection.on_connect_check_healthÚnowaitrÄ   rÅ   Úhealth_check_failedc              	   Ã   s‚  �zet | jƒ4 I dH šO | j ¡  |  ¡  | js%	 W d  ƒI dH  W dS z#z| j ¡  |s6| j ¡ I dH  W n	 t	y@   Y nw W d| _
d| _nd| _
d| _w W d  ƒI dH  n1 I dH s`w   Y  W n tjyw   td| j› �ƒd‚w |r¶|r€tj}ntj}|dur«|| j ¡ kr«tt| ddƒt| ddƒt| ddƒt| ddƒ||d�I dH  t||d�I dH  dS ttjd�I dH  dS )z!Disconnects from the Redis serverNz#Timed out closing connection after rÒ   rÓ   )rÔ   rÕ   rÖ   r×   rØ   rÙ   )Úclose_reasonrØ   )r  )Úasync_timeoutrh   rt   Úon_disconnectrð   r´   rs   r¢   Úwait_closedrß   rr   r�   r;   r<   ÚHEALTHCHECK_FAILEDÚERRORr„   Úget_retriesr.   r›   r*   ÚAPPLICATION_CLOSE)rY   r  rÄ   rÅ   r  r  rO   rO   rP   rÇ   9  sd   €
û
€ÿ€ÿ
(ð€
ÿþÿ



ú	þÿzAbstractConnection.disconnectc                 Ã   s8   �| j ddd�I dH  t|  ¡ I dH ƒdkrtdƒ‚dS )z Send PING, expect PONG in returnÚPINGFrÛ   NÚPONGz#Bad response from PING health check)r  r?   r  r6   r£   rO   rO   rP   Ú
_send_pingq  s
   €ÿzAbstractConnection._send_pingc                 Ã   s   �| j ||dd�I dH  dS )z Function to call when PING failsT)rÄ   rÅ   r  NrÆ   )rY   rÄ   rÅ   rO   rO   rP   Ú_ping_failedw  s   €ÿzAbstractConnection._ping_failedc                 Ã   sB   �| j rt ¡  ¡ | jkr| jj| j| jdd�I dH  dS dS dS )z3Check the health of the connection with a PING/PONGTrÈ   N)	rl   r�   rž   Útimerm   r„   rÊ   r  r  r£   rO   rO   rP   r½   }  s   €ÿ
ÿüzAbstractConnection.check_healthÚcommandc                 Ã   s"   �| j  |¡ | j  ¡ I d H  d S rW   )rs   Ú
writelinesÚdrain)rY   r!  rO   rO   rP   Ú_send_packed_command‡  s   €z'AbstractConnection._send_packed_commandc              
   Ã   sX  �| j s| jdd�I d H  |r|  ¡ I d H  z5t|tƒr | ¡ }t|tƒr(|g}| jr;t 	|  
|¡| j¡I d H  W d S | j |¡ | j ¡ I d H  W d S  tjya   | jdd�I d H  tdƒd ‚ ty› } z/| jdd�I d H  t|jƒdkr�d|jd }}n
|jd }|jd }td	|› d
|› d�ƒ|‚d }~w ty«   | jdd�I d H  ‚ w )NFrÛ   T©r  zTimeout writing to socketr‡   ÚUNKNOWNr   zError z while writing to socket. r¬   )r´   r¿   r½   r  ÚstrÚencodeÚbytesrg   r�   Úwait_forr$  rs   r"  r#  r;   rÇ   rß   r  Úargsr6   ÚBaseException)rY   r!  r½   ræ   Úerr_noÚerrmsgrO   rO   rP   Úsend_packed_command‹  sF   €

ÿ


ÿþ€úz&AbstractConnection.send_packed_commandr+  Úkwargsc                 Ï   s(   �| j | j|Ž | dd¡d�I dH  dS )z+Pack and send a command to the Redis serverr½   TrÛ   N)r/  Úpack_commandr  )rY   r+  r0  rO   rO   rP   r  ´  s   €ÿzAbstractConnection.send_commandc              
   Ã   s^   �z	| j  ¡ I dH W S  ty. } z| jdd�I dH  |  ¡ }td|› d|j› �ƒ‚d}~ww )z8Poll the socket to see if there's data that can be read.NTr%  úError while reading from z: )rt   Úcan_read_destructiverß   rÇ   rñ   r6   r+  )rY   ræ   Ú
host_errorrO   rO   rP   r3  º  s   €€ýz'AbstractConnection.can_read_destructive)Údisconnect_on_errorÚpush_requestÚdisable_decodingr)   r5  r6  c          
   
   Ã   sò  �|dur|n| j }|  ¡ }z}|durB| jdv rBt|ƒ4 I dH š | jj||d�I dH }W d  ƒI dH  n1 I dH s<w   Y  nH|durot|ƒ4 I dH š | jj|d�I dH }W d  ƒI dH  n1 I dH siw   Y  n| jdv r€| jj||d�I dH }n
| jj|d�I dH }W nT tjy¬   |duršY dS |r¥| jdd�I dH  td|› �ƒ‚ t	yÍ } z|r¾| jdd�I dH  t
d|› d	|j› �ƒ‚d}~w tyß   |rÞ| jdd�I dH  ‚ w | jrït ¡  ¡ | j }	|	| _t|tƒr÷|d‚|S )
z0Read the response from a previously sent commandN)Ú3r'   )r7  r6  )r7  Tr%  zTimeout reading from r2  z : )rg   rñ   rq   r  rt   r  r�   r;   rÇ   rß   r6   r+  r,  rl   rž   r   rm   r  r:   )
rY   r7  r)   r5  r6  Úread_timeoutr4  r  ræ   Ú	next_timerO   rO   rP   r  Ã  s`   €	ÿ(ÿ€ÿ(ÿ€
ÿÿ€€ú
z AbstractConnection.read_responsec              	   G   s*  g }t |d tƒrJ ‚t |d tƒr#t|d  ¡  ¡ ƒ|dd…  }nd|d v r7t|d  ¡ ƒ|dd…  }t ttt	|ƒƒ ¡ t
f¡}| j}t| jj|ƒD ]>}t	|ƒ}t	|ƒ|ksd||ksdt |tƒr~t |tt|ƒ ¡ t
f¡}| |¡ | |¡ t
}qOt |tt|ƒ ¡ t
|t
f¡}qO| |¡ |S )z2Pack a series of arguments into the Redis protocolr   r‡   Nó    )r  Úfloatr'  Útupler(  ÚsplitÚ	SYM_EMPTYr®   ÚSYM_STARr  ÚSYM_CRLFrv   Úmapro   Ú
memoryviewÚ
SYM_DOLLARr‹   )rY   r+  ÚoutputÚbuffÚbuffer_cutoffÚargÚ
arg_lengthrO   rO   rP   r1  ý  s>   "ÿÿ


úÿ

zAbstractConnection.pack_commandÚcommandsc           	      C   s²   g }g }d}| j }|D ]A}| j|Ž D ]9}t|ƒ}||ks%||ks%t|tƒr3|r/| t |¡¡ d}g }||ks<t|tƒrB| |¡ q| |¡ ||7 }qq|rW| t |¡¡ |S )z.Pack multiple commands into the Redis protocolr   )rv   r1  r  r  rC  r‹   r?  r®   )	rY   rJ  rE  ÚpiecesÚbuffer_lengthrG  ÚcmdÚchunkÚchunklenrO   rO   rP   Úpack_commands+  s.   ÿ

ðz AbstractConnection.pack_commandsc                 C   s   t | jjƒdkS )zCheck if the socket is emptyr   )r  rr   Ú_bufferr£   rO   rO   rP   Ú_socket_is_emptyI  s   z#AbstractConnection._socket_is_emptyc                 Ã   s,   �|   ¡ s| jdd�I d H  |   ¡ rd S d S )NT)r6  )rR  r  r£   rO   rO   rP   Úprocess_invalidation_messagesM  s   €ÿz0AbstractConnection.process_invalidation_messagesÚtokenc                 C   s
   || _ d S rW   )r’   ©rY   rT  rO   rO   rP   Úset_re_auth_tokenQ  rì   z$AbstractConnection.set_re_auth_tokenc                 Ã   sJ   �| j d ur#|  d| j  d¡| j  ¡ ¡I d H  |  ¡ I d H  d | _ d S d S ©Nrù   Úoid)r’   r  Útry_getÚ	get_valuer  r£   rO   rO   rP   Úre_authT  s   €


ý
ùzAbstractConnection.re_auth)TT©r¼   N©T)FNNF)FN)FrJ   rK   rL   Ú__doc__Ú	__slots__r%   rŠ   rQ   rA   r   r'  r”   r
   r<  ÚboolÚlistrI   r   r@   r!   r/   ÚConnectCallbackTr2   r$   r˜   Úwarningsr   r¡   rŸ   r²   r   r¯   Úpropertyr´   r¹   r»   r‘   rË   r¿   rë   rî   rð   rÐ   rñ   r,  rà   rô   rõ   râ   rá   rÇ   r  r  r½   r   r)  r$  r/  r  r3  r  r=   r   r1  rP  rR  rS  r    rV  r[  rO   rO   rO   rP   rU   }   s4   þç
ýüûúù
ø	÷
öõôóòñðïîíìëêéèçk

ÿÿ
ÿM

uûþýüû
ú8
ÿÿÿ
þ)ýúþýû
ú:.rU   c                       sŒ   e Zd ZdZddddddœded	eeef d
edee	eeee
f f  def
‡ fdd„Zdd„ Zde	fdd„Zdd„ Zdefdd„Z‡  ZS )Ú
Connectionz4Manages TCP communication to and from a Redis serverÚ	localhostië  FNr   )rÒ   rÓ   Úsocket_keepaliveÚsocket_keepalive_optionsÚsocket_typerÒ   rÓ   rg  rh  ri  c                   s<   || _ t|ƒ| _|| _|pi | _|| _tƒ jdi |¤Ž d S ©NrO   )rÒ   r”   rÓ   rg  rh  ri  Úsuperr˜   )rY   rÒ   rÓ   rg  rh  ri  r0  ©r°   rO   rP   r˜   b  s   


zConnection.__init__c                 C   s6   d| j fd| jfd| jfg}| jr| d| jf¡ |S )NrÒ   rÓ   r`   rb   )rÒ   rÓ   r`   rb   r‹   ©rY   rK  rO   rO   rP   r¯   s  s   zConnection.repr_piecesr¼   c                 C   s   | j | jdœS )N©rÒ   rÓ   rn  r£   rO   rO   rP   Ú_connection_argumentsy  ró   z Connection._connection_argumentsc              	   Ã   sö   �t | jƒ4 I dH š tjdi |  ¡ ¤ŽI dH \}}W d  ƒI dH  n1 I dH s*w   Y  || _|| _|j d¡}|ry| 	t
jt
jd¡ z$| jre| 	t
jt
jd¡ | j ¡ D ]\}}| 	t
j||¡ qXW dS W dS  ttfyx   | ¡  ‚ w dS )zCreate a TCP socket connectionNrŒ   r‡   rO   )r  rh   r�   Úopen_connectionro  rr   rs   Ú	transportÚget_extra_infoÚ
setsockoptrŒ   ÚIPPROTO_TCPÚTCP_NODELAYrg  Ú
SOL_SOCKETÚSO_KEEPALIVErh  ÚitemsÚSOL_TCPrß   r•   r¢   )rY   ÚreaderÚwriterÚsockr¨   r©   rO   rO   rP   rÐ   |  s.   €ÿ(ÿýü÷zConnection._connectc                 C   s   | j › d| j› �S )Nú:rn  r£   rO   rO   rP   rñ   ”  s   zConnection._host_error)rJ   rK   rL   r^  r'  r   r”   r`  r
   r	   r)  r˜   r¯   ro  rÐ   rñ   Ú__classcell__rO   rO   rl  rP   re  _  s,    ùý
üûúùre  c                       s$  e Zd ZdZ												d)dee dee deeejf dee	d	  d
ee	d	  dee dee dee de
dee dee dee f‡ fdd„Zdef‡ fdd„Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd „ ƒZed!d"„ ƒZed#d$„ ƒZed%d&„ ƒZed'd(„ ƒZ‡  ZS )*ÚSSLConnectionzåManages SSL connections to and from the Redis server(s).
    This class extends the Connection class, adding SSL functionality, and making
    use of ssl.SSLContext (https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
    NÚrequiredTÚssl_keyfileÚssl_certfileÚssl_cert_reqsÚssl_include_verify_flagsússl.VerifyFlagsÚssl_exclude_verify_flagsÚssl_ca_certsÚssl_ca_dataÚssl_ca_pathÚssl_check_hostnameÚssl_min_versionÚssl_ciphersÚssl_passwordc                    sD   t stdƒ‚t|||||||||	|
||d�| _tƒ jdi |¤Ž d S )Nú$Python wasn't built with SSL support)ÚkeyfileÚcertfileÚ	cert_reqsÚinclude_verify_flagsÚexclude_verify_flagsÚca_certsÚca_dataÚca_pathÚcheck_hostnameÚmin_versionÚciphersrf   rO   )r   r9   ÚRedisSSLContextrp   rk  r˜   )rY   r�  r‚  rƒ  r„  r†  r‡  rˆ  r‰  rŠ  r‹  rŒ  r�  r0  rl  rO   rP   r˜   ž  s"   ôzSSLConnection.__init__r¼   c                    s   t ƒ  ¡ }| j ¡ |d< |S )NÚssl)rk  ro  rp   r  ©rY   r0  rl  rO   rP   ro  Á  s   
z#SSLConnection._connection_argumentsc                 C   ó   | j jS rW   )rp   r�  r£   rO   rO   rP   r�  Æ  ó   zSSLConnection.keyfilec                 C   r�  rW   )rp   r�  r£   rO   rO   rP   r�  Ê  rž  zSSLConnection.certfilec                 C   r�  rW   )rp   r‘  r£   rO   rO   rP   r‘  Î  rž  zSSLConnection.cert_reqsc                 C   r�  rW   )rp   r’  r£   rO   rO   rP   r’  Ò  rž  z"SSLConnection.include_verify_flagsc                 C   r�  rW   )rp   r“  r£   rO   rO   rP   r“  Ö  rž  z"SSLConnection.exclude_verify_flagsc                 C   r�  rW   )rp   r”  r£   rO   rO   rP   r”  Ú  rž  zSSLConnection.ca_certsc                 C   r�  rW   )rp   r•  r£   rO   rO   rP   r•  Þ  rž  zSSLConnection.ca_datac                 C   r�  rW   )rp   r—  r£   rO   rO   rP   r—  â  rž  zSSLConnection.check_hostnamec                 C   r�  rW   )rp   r˜  r£   rO   rO   rP   r˜  æ  rž  zSSLConnection.min_version)NNr€  NNNNNTNNN)rJ   rK   rL   r^  r
   r'  r   r›  Ú
VerifyModer   r`  r   r˜   r	   ro  rd  r�  r�  r‘  r’  r“  r”  r•  r—  r˜  r~  rO   rO   rl  rP   r  ˜  st    óþýü
û
úùø	÷
öõôó#







r  c                   @   s°   e Zd ZdZ												ddee dee deeeejf  dee	d  d	ee	d  d
ee dee dee de
dee dee dee fdd„Zdefdd„ZdS )rš  )r�  r�  r‘  r’  r“  r”  r•  r–  Úcontextr—  r˜  r™  rf   NFr�  r�  r‘  r’  r…  r“  r”  r•  r–  r—  r˜  r™  rf   c                 C   s¸   t stdƒ‚|| _|| _|d u rtj}nt|tƒr1tjtjtj	dœ}||vr-td|› �ƒ‚|| }|| _
|| _|| _|| _|| _|| _| j
tjkrK|	nd| _|
| _|| _|| _d | _d S )NrŽ  )ÚnoneÚoptionalr€  z+Invalid SSL Certificate Requirements Flag: F)r   r9   r�  r�  r›  Ú	CERT_NONEr  r'  ÚCERT_OPTIONALÚCERT_REQUIREDr‘  r’  r“  r”  r•  r–  r—  r˜  r™  rf   r   )rY   r�  r�  r‘  r’  r“  r”  r•  r–  r—  r˜  r™  rf   Ú	CERT_REQSrO   rO   rP   r˜   ü  s8   
ýÿÿ
zRedisSSLContext.__init__r¼   c                 C   sÞ   | j slt ¡ }| j|_| j|_| jr| jD ]	}| j|O  _q| jr0| jD ]
}| j| M  _q%| j	s6| j
rA|j| j	| j
| jd� | jsJ| jsJ| jrU|j| j| j| jd� | jd ur^| j|_| jd uri| | j¡ || _ | j S )N)r�  r�  rf   )ÚcafileÚcapathÚcadata)r   r›  Úcreate_default_contextr—  r‘  Úverify_moder’  Úverify_flagsr“  r�  r�  Úload_cert_chainrf   r”  r•  r–  Úload_verify_locationsr˜  Úminimum_versionr™  Úset_ciphers)rY   r   ÚflagrO   rO   rP   r  +  s4   

ýÿ

zRedisSSLContext.get)NNNNNNNNFNNN)rJ   rK   rL   r_  r
   r'  r   r›  rŸ  r   r`  r   r˜   r   r  rO   rO   rO   rP   rš  ë  sP    óþýü
û
úùø	÷
öõô
ó/rš  c                       sd   e Zd ZdZddœdef‡ fdd„Zdeeeeee	f f  fdd	„Z
d
d„ Zdefdd„Z‡  ZS )ÚUnixDomainSocketConnectionz4Manages UDS communication to and from a Redis serverÚ ©Úpathrµ  c                   s   || _ tƒ jdi |¤Ž d S rj  )rµ  rk  r˜   )rY   rµ  r0  rl  rO   rP   r˜   K  s   z#UnixDomainSocketConnection.__init__r¼   c                 C   s.   d| j fd| jfg}| jr| d| jf¡ |S )Nrµ  r`   rb   )rµ  r`   rb   r‹   rm  rO   rO   rP   r¯   O  s   z&UnixDomainSocketConnection.repr_piecesc              	   Ã   sv   �t | jƒ4 I d H š tj| jd�I d H \}}W d   ƒI d H  n1 I d H s'w   Y  || _|| _|  ¡ I d H  d S )Nr´  )r  rh   r�   Úopen_unix_connectionrµ  rr   rs   rõ   )rY   rz  r{  rO   rO   rP   rÐ   U  s   €(ÿz#UnixDomainSocketConnection._connectc                 C   rí   rW   r´  r£   rO   rO   rP   rñ   \  rï   z&UnixDomainSocketConnection._host_error)rJ   rK   rL   r^  r'  r˜   r   r   r   r”   r¯   rÐ   rñ   r~  rO   rO   rl  rP   r²  H  s    "r²  )Ú0ÚFÚFALSEÚNÚNOr¼   c                 C   s6   | d u s| dkr
d S t | tƒr|  ¡ tv rdS t| ƒS )Nr³  F)r  r'  ÚupperÚFALSE_STRINGSr`  )ÚvaluerO   rO   rP   Úto_boolc  s
   r¿  c                 C   s\   |   dd¡  dd¡}g }| d¡D ]}| ¡ }tt|ƒs#td|› �ƒ‚| tt|ƒ¡ q|S )Nú[r³  ú]r¤   zInvalid ssl verify flag: )Úreplacer>  ÚstripÚhasattrr   r–   r‹   r›   )r¾  Úverify_flags_strr¬  r±  rO   rO   rP   Úparse_ssl_verify_flagsk  s   
rÆ  )r`   rg   rh   rg  rj   Úmax_connectionsrl   rŠ  r„  r†  r)   .ÚURL_QUERY_ARGUMENT_PARSERSc                   @   sJ   e Zd ZU eed< eed< ee ed< eed< eed< eed< eed< dS )	ÚConnectKwargsra   rf   Úconnection_classrÒ   rÓ   r`   rµ  N)rJ   rK   rL   r'  Ú__annotations__r   rU   r”   rO   rO   rO   rP   rÉ  Š  s   
 rÉ  F)ÚtotalÚurlc              
   C   s|  t | ƒ}i }t|jƒ ¡ D ]7\}}|rDt|ƒdkrDt|d ƒ}t |¡}|r@z||ƒ||< W q tt	fy?   t	d|› d�ƒ‚w |||< q|j
rOt|j
ƒ|d< |jrYt|jƒ|d< |jdkrn|jrht|jƒ|d< t|d< |S |jd	v r´|jr}t|jƒ|d
< |jr‡t|jƒ|d< |jr©d|vr©ztt|jƒ dd¡ƒ|d< W n tt	fy¨   Y nw |jdkr²t|d< |S d}t	d|› d�ƒ‚)Nr   zInvalid value for 'z' in connection URL.ra   rf   Úunixrµ  rÊ  )ÚredisÚredissrÒ   rÓ   r`   ú/r³  rÐ  zredis://, rediss://, unix://z5Redis URL must specify one of the following schemes (ú))r   r   Úqueryrx  r  r   rÈ  r  r•   r–   ra   rf   Úschemerµ  r²  ÚhostnamerÓ   r”   rÂ  ÚAttributeErrorr  )rÍ  Úparsedr0  ÚnameÚ
value_listr¾  r
  Úvalid_schemesrO   rO   rP   Ú	parse_url”  sR   
ÿ€

éÿ
û
ÿrÛ  Ú_CPÚConnectionPool)Úboundc                   @   s2  e Zd ZdZedee dedefdd„ƒZe	dfdee
 d	ee fd
d„Zeh d£ƒZdd„ Zdd„ Zd:dd„Zdefdd„Zedgddd�d;dd„ƒZdd„ Zdd„ Zdd „ Zd!e
fd"d#„Zd!e
fd$d%„Zd<d'efd(d)„Zd*d+„ Zd:d,d-„Zd=d0d1„Zd2e fd3d4„Z!d5e"fd6d7„Z#de$e%ee&f  fd8d9„Z'dS )>rÝ  aù  
    Create a connection pool. ``If max_connections`` is set, then this
    object raises :py:class:`~redis.ConnectionError` when the pool's
    limit is reached.

    By default, TCP connections are created unless ``connection_class``
    is specified. Use :py:class:`~redis.UnixDomainSocketConnection` for
    unix sockets.
    :py:class:`~redis.SSLConnection` can be used for SSL enabled connections.

    Any additional keyword arguments are passed to the constructor of
    ``connection_class``.
    ÚclsrÍ  r¼   c                 K   s    t |ƒ}| |¡ | di |¤ŽS )a  
        Return a connection pool configured from the given URL.

        For example::

            redis://[[username]:[password]]@localhost:6379/0
            rediss://[[username]:[password]]@localhost:6379/0
            unix://[username@]/path/to/socket.sock?db=0[&password=password]

        Three URL schemes are supported:

        - `redis://` creates a TCP socket connection. See more at:
          <https://www.iana.org/assignments/uri-schemes/prov/redis>
        - `rediss://` creates a SSL wrapped TCP socket connection. See more at:
          <https://www.iana.org/assignments/uri-schemes/prov/rediss>
        - ``unix://``: creates a Unix Domain Socket connection.

        The username, password, hostname, path and all querystring values
        are passed through urllib.parse.unquote in order to replace any
        percent-encoded values with their corresponding characters.

        There are several ways to specify a database number. The first value
        found will be used:

        1. A ``db`` querystring option, e.g. redis://localhost?db=0

        2. If using the redis:// or rediss:// schemes, the path argument
               of the url, e.g. redis://localhost/0

        3. A ``db`` keyword argument to this function.

        If none of these options are specified, the default db=0 is used.

        All querystring options are cast to their appropriate Python types.
        Boolean arguments can be specified with string values "True"/"False"
        or "Yes"/"No". Values that cannot be properly cast cause a
        ``ValueError`` to be raised. Once parsed, the querystring arguments
        and keyword arguments are passed to the ``ConnectionPool``'s
        class initializer. In the case of conflicting arguments, querystring
        arguments always win.
        NrO   )rÛ  Úupdate)rß  rÍ  r0  Úurl_optionsrO   rO   rP   Úfrom_urlÛ  s   +
zConnectionPool.from_urlNrÊ  rÇ  c                 K   s†   |pd}t |tƒr|dk rtdƒ‚|| _|| _|| _g | _tƒ | _| j 	dt
¡| _t ¡ | _| j 	dd ¡| _| jd u rAtƒ | _d S d S )Nl        r   z,"max_connections" must be a positive integerr…   r†   )r  r”   r–   rÊ  Úconnection_kwargsrÇ  Ú_available_connectionsÚsetÚ_in_use_connectionsr  rA   r…   r�   ÚLockrw   r‰   r$   )rY   rÊ  rÇ  rã  rO   rO   rP   r˜   
  s   

ÿzConnectionPool.__init__>   rf   ra   r�  re   c                    sR   d  ‡ fdd„ˆ j ¡ D ƒ¡}dˆ jj› dˆ jj› dˆ jj› dˆ jj› d|› d�S )	Nr¤   c                    s,   g | ]\}}|› d |ˆ j v rdn|› �‘qS )r¥   z
<REDACTED>)ÚSENSITIVE_REPR_KEYSr¦   r£   rO   rP   rÝ   ,  s    ÿÿz+ConnectionPool.__repr__.<locals>.<listcomp>r«   r¬   z(<r­   z)>)>)r®   rã  rx  r°   rK   rJ   rÊ  )rY   Úconn_kwargsrO   r£   rP   r²   *  s   
þÿÿÿþÿzConnectionPool.__repr__c                 C   s”   t | dƒr@t | dƒr@t| jƒ}t| jƒ}|dks|dkr@t| ƒ}ddlm} |dkr3||tj| d� |dkr@||tj	| d� g | _t
 ¡ | _d S )Nrä  ræ  r   ©r+   ©Ú	pool_nameÚconnection_stateÚcounter)rÄ  r  rä  ræ  r   Úredis.observability.recorderr+   r   ÚIDLEÚUSEDrµ   ÚWeakSet©rY   Ú
idle_countÚin_use_countrì  Úsync_record_connection_countrO   rO   rP   Úreset7  s,   ÿ

ýýzConnectionPool.resetc                 C   s®   zLt | dƒrt | dƒsW dS t| jƒ}t| jƒ}|dks |dkrGt| ƒ}ddlm} |dkr7||tj| d� |dkrJ||tj	| d� W dS W dS W dS  t
yV   Y dS w )zCClean up connection pool and record metrics when garbage collected.rä  ræ  Nr   rê  rë  )rÄ  r  rä  ræ  r   rï  r+   r   rð  rñ  rá   ró  rO   rO   rP   r¡   V  s6   ÿ

ýýòÿzConnectionPool.__del__c                 C   s   | j p
t| jƒ| jk S )z;Return True if a connection can be retrieved from the pool.)rä  r  ræ  rÇ  r£   rO   rO   rP   Úcan_get_connectionu  s   þz!ConnectionPool.can_get_connectionÚ*ú)Use get_connection() without args insteadú5.3.0©rz   r{   Úversionc           
   	   Ï   s"  �| j 4 I dH š+ t| jƒt| jƒ }t ¡ }|  ¡ }t| jƒt| jƒ }||k}W d  ƒI dH  n1 I dH s9w   Y  t| ƒ}	|rPt|	t	j
dd�I dH  nt|	t	jdd�I dH  t|	t	j
dd�I dH  z|  |¡I dH  |r~t| t ¡ | d�I dH  |W S  ty�   |  |¡I dH  ‚ w )z(Get a connected connection from the poolNr‡   rë  rˆ   ©Úconnection_poolÚduration_seconds)rw   r  rä  ræ  r   Ú	monotonicÚget_available_connectionr   r+   r   rñ  rð  Úensure_connectionr,   r,  Úrelease)
rY   Úcommand_nameÚkeysÚoptionsÚconnections_beforeÚstart_time_createdrT   Úconnections_afterÚ
is_createdrì  rO   rO   rP   Úget_connection|  sR   €
ÿ
ÿ
(÷ýýý
þþzConnectionPool.get_connectionc                 C   sT   z| j  ¡ }W n ty!   t| jƒ| jkrtdƒd‚|  ¡ }Y nw | j |¡ |S )zCGet a connection from the pool, without making sure it is connectedzToo many connectionsN)	rä  ÚpopÚ
IndexErrorr  ræ  rÇ  r8   Úmake_connectionÚaddrX   rO   rO   rP   r  µ  s   
ýz'ConnectionPool.get_available_connectionc                 C   s.   | j }| j| dd¡| dd¡| dd¡d�S )z,Return an encoder based on encoding settingsr~   r|   r   r}   r€   F)r~   r   r€   )rã  r…   r  rœ  rO   rO   rP   Úget_encoderÀ  s   


ýzConnectionPool.get_encoderc                 C   s   | j di | j¤ŽS )z=Create a new connection.  Can be overridden by child classes.NrO   )rÊ  rã  r£   rO   rO   rP   r  É  s   zConnectionPool.make_connectionrT   c              
   Ã   s~   �|  ¡ I dH  z| ¡ I dH rtdƒd‚W dS  tttfy>   | ¡ I dH  |  ¡ I dH  | ¡ I dH r;tdƒd‚Y dS w )z8Ensure that the connection object is connected and validNzConnection has datazConnection not ready)rË   r3  r6   r;   rß   rÇ   rX   rO   rO   rP   r  Ï  s   €
ÿ
ÿýz ConnectionPool.ensure_connectionc                 Ã   s~   �| j  |¡ | ¡ r| ¡ I dH  | j |¡ | j t|ƒ¡I dH  t	| ƒ}t
|tjdd�I dH  t
|tjdd�I dH  dS )z(Releases the connection back to the poolNrˆ   rë  r‡   )ræ  rº   rî   rÇ   rä  r‹   r‰   Údispatch_asyncr#   r   r+   r   rñ  rð  )rY   rT   rì  rO   rO   rP   r  ß  s&   €
ÿýýzConnectionPool.releaseTÚinuse_connectionsc                 Ã   s\   �|rt | j| jƒ}n| j}tjdd„ |D ƒddiŽI dH }tdd„ |D ƒdƒ}|r,|‚dS )zý
        Disconnects connections in the pool

        If ``inuse_connections`` is True, disconnect connections that are
        current in use, potentially by other tasks. Otherwise only disconnect
        connections that are idle in the pool.
        c                 s   s   � | ]}|  ¡ V  qd S rW   rÆ   )r§   rT   rO   rO   rP   rª   	  s   € z,ConnectionPool.disconnect.<locals>.<genexpr>Úreturn_exceptionsTNc                 s   s   � | ]
}t |tƒr|V  qd S rW   )r  r,  )r§   ÚrrO   rO   rP   rª     s   € )r   rä  ræ  r�   ÚgatherÚnext)rY   r  ÚconnectionsÚresprç   rO   rO   rP   rÇ   ú  s   €ÿÿþÿzConnectionPool.disconnectc              	   Ã   sV   �| j 4 I dH š | jD ]}| ¡  qW d  ƒI dH  dS 1 I dH s$w   Y  dS )z<
        Mark all active connections for reconnect.
        N)rw   ræ  rë   )rY   ÚconnrO   rO   rP   Ú'update_active_connections_for_reconnect  s   €

ÿ.ÿz6ConnectionPool.update_active_connections_for_reconnectc                 Ã   s   �|   ¡ I dH  dS )z-Close the pool, disconnecting all connectionsNrÆ   r£   rO   rO   rP   Úaclose  s   €zConnectionPool.acloser„   r/   c                 C   s(   | j D ]}||_q| jD ]}||_qd S rW   )rä  r„   ræ  )rY   r„   r  rO   rO   rP   Ú	set_retry  s
   

ÿzConnectionPool.set_retryrT  c              	   ƒ   s®   �ˆj 4 I d H šB ˆjD ]'‰ ˆ j ‡ ‡fdd„‡fdd„¡I d H  ˆ j ‡ fdd„‡fdd„¡I d H  qˆjD ]‰ ˆ  ˆ¡ q7W d   ƒI d H  d S 1 I d H sPw   Y  d S )Nc                      s   ˆ   dˆ d¡ˆ ¡ ¡S rW  )r  rY  rZ  rO   )r  rT  rO   rP   rÀ   '  s    ÿz1ConnectionPool.re_auth_callback.<locals>.<lambda>c                    ó
   ˆ   | ¡S rW   ©Ú_mock©rÄ   r£   rO   rP   rÀ   *  ó   
 c                      rÏ   rW   )r  rO   )r  rO   rP   rÀ   -  rÑ   c                    r  rW   r  r!  r£   rO   rP   rÀ   -  r"  )rw   rä  r„   rÊ   ræ  rV  rU  rO   )r  rY   rT  rP   Úre_auth_callback#  s   €


üÿ
ÿ.õzConnectionPool.re_auth_callbackrÄ   c                 Ã   s   �dS )z
        Dummy functions, needs to be passed as error callback to retry object.
        :param error:
        :return:
        NrO   )rY   rÄ   rO   rO   rP   r   2  s   €zConnectionPool._mockc                 C   sX   t  ¡ }t| ƒ|t< | ¡ }| ¡ }tjj|t< tj	j|t< t
| jƒ|ft
| jƒ|fgS )zD
        Returns a connection count (both idle and in use).
        )r   Úbuild_base_attributesr   r   rŽ   r   rð  r¾  r   rñ  r  rä  ræ  )rY   Ú
attributesÚfree_connections_attributesÚin_use_connections_attributesrO   rO   rP   Úget_connection_count:  s   ÿÿþz#ConnectionPool.get_connection_countr\  rW   r]  )r„   r/   r¼   N)(rJ   rK   rL   r^  Úclassmethodr   rÜ  r'  râ  re  rU   r
   r”   r˜   Ú	frozensetrè  r²   r÷  r¡   r`  rø  r%   r  r  r  r  r  r  rÇ   r  r  r  r    r#  r9   r   r   r=  Údictr(  rO   rO   rO   rP   rÝ  Ì  sH    0ýþ
ýÿ	
ý4	

c                
       s|   e Zd ZdZddeejfdedee	 de
e de
ej f‡ fdd	„Zed
gddd�d‡ fdd„	ƒZdef‡ fdd„Z‡  ZS )ÚBlockingConnectionPoola  
    A blocking connection pool::

        >>> from redis.asyncio import Redis, BlockingConnectionPool
        >>> client = Redis.from_pool(BlockingConnectionPool())

    It performs the same function as the default
    :py:class:`~redis.asyncio.ConnectionPool` implementation, in that,
    it maintains a pool of reusable connections that can be shared by
    multiple async redis clients.

    The difference is that, in the event that a client tries to get a
    connection from the pool when all of connections are in use, rather than
    raising a :py:class:`~redis.ConnectionError` (as the default
    :py:class:`~redis.asyncio.ConnectionPool` implementation does), it
    blocks the current `Task` for a specified number of seconds until
    a connection becomes available.

    Use ``max_connections`` to increase / decrease the pool size::

        >>> pool = BlockingConnectionPool(max_connections=10)

    Use ``timeout`` to tell it either how many seconds to wait for a connection
    to become available, or to block forever:

        >>> # Block forever.
        >>> pool = BlockingConnectionPool(timeout=None)

        >>> # Raise a ``ConnectionError`` after five seconds if a connection is
        >>> # not available.
        >>> pool = BlockingConnectionPool(timeout=5)
    é2   é   rÇ  r)   rÊ  Úqueue_classc                    s,   t ƒ jd||dœ|¤Ž t ¡ | _|| _d S )N)rÊ  rÇ  rO   )rk  r˜   r�   Ú	ConditionÚ
_conditionr)   )rY   rÇ  r)   rÊ  r/  rã  rl  rO   rP   r˜   r  s   þý

zBlockingConnectionPool.__init__rù  rú  rû  rü  Nc              
   �   sv  �t  ¡ }zi| j4 I dH šU t| jƒ4 I dH š6 | j | j¡I dH  t| jƒt| j	ƒ }t  ¡ }t
ƒ  ¡ }t| jƒt| j	ƒ }||k}	W d  ƒI dH  n1 I dH sSw   Y  W d  ƒI dH  n1 I dH shw   Y  W n tjy€ }
 ztdƒ|
‚d}
~
ww z)|  |¡I dH  |	r™t| t  ¡ | d�I dH  tt| ƒt  ¡ | d�I dH  |W S  tyº   |  |¡I dH  ‚ w )z@Gets a connection from the pool, blocking until one is availableNzNo connection available.rþ  )rì  r   )r   r  r1  r  r)   r*  rø  r  rä  ræ  rk  r  r�   r;   r6   r  r,   r-   r   r,  r  )rY   r  r  r  Ústart_time_acquiredr  r	  rT   r
  r  Úerrrl  rO   rP   r  ‚  sL   €
ÿ

ÿ
*õ(ÿ€
€ÿ
þ
þþz%BlockingConnectionPool.get_connectionrT   c              	   ƒ   s^   �| j 4 I dH š tƒ  |¡I dH  | j  ¡  W d  ƒI dH  dS 1 I dH s(w   Y  dS )z)Releases the connection back to the pool.N)r1  rk  r  ÚnotifyrX   rl  rO   rP   r  ±  s
   €.þzBlockingConnectionPool.releaserW   )rJ   rK   rL   r^  re  r�   Ú	LifoQueuer”   r
   r<  r   rU   ÚQueuer˜   r%   r  r  r~  rO   rO   rl  rP   r,  P  s,    #ûþýüûý*r,  )�r�   rŽ   Úenumrä   rŒ   Úsysr   rc  rµ   Úabcr   Ú	itertoolsr   Útypesr   Útypingr   r   r   r   r	   r
   r   r   r   r   r   r   r   Úurllib.parser   r   r   r   Úobservability.attributesr   r   r   r   r   Úutilsr   r›  r   r   r   Ú
auth.tokenr    rƒ   r!   r"   Úeventr#   r$   r%   r&   Úversion_infor)   r  Ú$redis.asyncio.observability.recorderr*   r+   r,   r-   r.   Úredis.asyncio.retryr/   Úredis.backoffr0   Úredis.connectionr1   Úredis.credentialsr2   r3   Úredis.exceptionsr4   r5   r6   r7   r8   r9   r:   r;   Úredis.observability.metricsr<   Úredis.typingr=   Úredis.utilsr>   r?   Ú_parsersr@   rA   rB   rC   rD   r@  rD  rA  ÚSYM_LFr?  ÚEnumrI   rN   rŠ   rË  rQ   rS   r^   rb  rU   re  r  rš  r²  r½  r`  r¿  rÆ  r”   r<  rÈ  r'  rM   rÉ  rÛ  rÜ  rÝ  r,  rO   rO   rO   rP   Ú<module>   s²   
 <
(
     g9S]õÿ
5   