
    ng\j                    F   % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
Jr  S SKJr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJrJ r J!r!J"r"  SSK#J$r$J%r%J&r&J'r'J(r(  SS	K)J*r*J+r+  \*(       a  S SK,r,S S
K,J-r-J.r.J/r/  OSr,Sr.Sr-Sr/SSK0J1r1  SSK2J3r3J4r4  SSK5J6r6J7r7  SSK)J8r8J9r9  \Rt                  S:  a  S SK J;r<  OS SK<J;r<  S SK=J>r>J?r?J@r@JArAJBrB  S SKCJDrD  S SKEJFrF  S SKGJHrHJIrI  S SKJJKrKJLrLJMrMJNrNJOrOJPrPJQrQJRrR  S SKSJTrT  S SKUJVrV  S SKWJXrXJYrYJZrZJ[r[  SSK\J]r]J^r^J_r_J`r`  SSKaJbrbJcrcJdrdJereJfrf  SrgSrhSriSrjSrk\\\e\f\d4      \lS '   \Y(       a  \drmO\frm " S! S"\5      rn " S# S$\5      ro\\n\o4   rp " S% S&5      rq " S' S(\q5      rr " S) S*\r5      rs " S+ S,5      rt " S- S.\q5      ruS/rvS0\\w   4S1 jrxS2 ry\" \z\{\{\z\x\x\z\z\x\y\y\z\{\z\xS3.5      r|\\}\S4\~4   4   \lS5'    " S6 S7\S8S99rS:\}S0\4S; jr\" S<S=S>9r " S? S@\
5      r " SA S=\5      r " SB SC\5      rg)D    N)ABC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deprecated_function)
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)CredentialProvider"UsernamePasswordCredentialProvider)AuthenticationError$AuthenticationWrongNumberOfArgsErrorConnectionError	DataErrorMaxConnectionsError
RedisErrorResponseErrorTimeoutError)CloseReason)
EncodableT)DEFAULT_RESP_VERSIONHIREDIS_AVAILABLESENTINELstr_if_bytes)DEFAULT_SOCKET_CONNECT_TIMEOUTDEFAULT_SOCKET_READ_SIZEDEFAULT_SOCKET_TIMEOUT$get_default_socket_keepalive_options)
BaseParserEncoder_AsyncHiredisParser_AsyncRESP2Parser_AsyncRESP3Parser   *   $s   
   
    DefaultParserc                       \ rS rSrSS jrSrg)ConnectCallbackProtocolu   c                     g N self
connections     S/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/redis/asyncio/connection.py__call__ ConnectCallbackProtocol.__call__v   s    #rP   rW   NrZ   AbstractConnection__name__
__module____qualname____firstlineno__r\   __static_attributes__rW   rP   r[   rS   rS   u   s    =rP   rS   c                       \ rS rSrSS jrSrg)AsyncConnectCallbackProtocoly   c                    #    g 7frV   rW   rX   s     r[   r\   %AsyncConnectCallbackProtocol.__call__z   s        rW   Nr^   r`   rW   rP   r[   rg   rg   y   s    CrP   rg   c            3          \ rS rSrSrSr\" SS/SS9SS	\\S
\	SSS
\
\SS	\	\	\	S	S	S	\S	S	SS	S.S\\-  S\S	-  S\S	-  S\S	-  S\S\\-  S\S\S\S\\   S\S\S\S	-  S\\-  S	-  S\\-  S	-  S\\-  S	-  S\S	-  S\S	-  S\S	-  S \\   S!\S	-  S"\S	-  S#\S$\S	-  40S% jj5       r\4S&\4S' jjrS( rS) r\ S* 5       r!\"S+ 5       r#S, r$S- r%S\\   S.S	4S/ jr&S0 r' SaS1\S2\4S3 jjr(S4 r)S5 r*S6 r+\ S7 5       r,\ S.\4S8 j5       r-S9\.S.\4S: jr/S; r0SbS< jr1ScS1\S.S	4S= jjr2    SdS>\S?\3\4   S@\3\   SA\S.S	4
SB jjr5SC r6SD r7SE r8SF\9\:   S.S	4SG jr; ScSF\<\:\\9\:   4   S1\S.S	4SH jjr=SI\SJ\S.S	4SK jr>\?" SLSMSNSO9S.\4SP j5       r@S.\4SQ jrA  SeSS
SR.SS\ST\3\   SU\SV\3\   4SW jjjrBSI\CS.\D\:   4SX jrESY\9\9\C      S.\D\:   4SZ jrFS[ rGS\ rHS]\I4S^ jrJS_ rKS`rLg	)fr_      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__rq   rr   zbUse 'driver_info' parameter instead. lib_name and lib_version will be removed in a future version.)args_to_warnreasonr   NFutf-8strictT)rn   rt   ru   rv   rx   ry   encodingencoding_errorsdecode_responsesparser_classsocket_read_sizerz   rp   rq   rr   driver_inforo   retryrw   encoder_classrs   r   legacy_responsesevent_dispatcherrn   rt   ru   rv   rx   ry   r   r   r   r   r   rz   rp   r   ro   r   rw   r   rs   r   r   r   c                   U(       d  U(       a  Ub  [        S5      eUc  [        5       U l        OUU l        Xl        Xl        [        UX5      U l        UU l        X l        UU l	        X0l
        Uc  UnX@l        XPl        U[        L a  / nU(       aS  UR                  [        5        UR                  [         R"                  5        UR                  [$        R                  5        X`l        U(       d  U(       aX  U(       d  [)        [+        5       S5      U l        O[.        R0                  " U5      U l        U R,                  R3                  U5        O[)        [+        5       S5      U l        Xl        SU l        U" XxU	5      U l        UU l        SU l        SU l        Xl         / U l!        SU l"        SU l#        SU l$         [K        U5      nUS:  d  US	:  a  [M        S
5      e UU l*        UU l+        U
[X        :w  aA  U RT                  S	:X  a  U
[Z        :X  a  [\        n
O U RT                  S:X  a  U
[\        :X  a  [Z        n
U R_                  U
5        g! [N         a	    [P        n N}[R         a    [M        S5      ef = f)a	  
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. Explicit None disables CLIENT SETINFO.
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  Fr   r*   zprotocol must be either 2 or 3zprotocol must be an integer)0r9   r'   _event_dispatcherrn   rp   r%   r   rs   rt   ro   ru   rv   rx   rB   appendr=   socketr,   asynciory   r2   r3   r   copydeepcopyupdate_supported_errorsrz   r{   r}   rw   r   r   r   r   r   _re_auth_token_should_reconnectintr8   	TypeErrorr@   
ValueErrorr   r   rJ   rK   rL   
set_parser)rY   rn   rt   ru   rv   rx   ry   r   r   r   r   r   rz   rp   rq   rr   r   ro   r   rw   r   rs   r   r   r   ps                             r[   __init__AbstractConnection.__init__   s+   ^ &9&E+  #%4%6D"%5D"& /{HR#6   ,!)%3"&<# 0X%N!!,/!!&..1!!'"6"67,N"9;2
 "]]51
JJ..~>y{A.DJ%:"(*$X@PQ"47;7;!1NP"8<!&	HHA 1uA%&FGG  0..}}!l6G&G0!#8I(I0%  	%$A 	A!"?@@	As   <I
 
I1I1	_warningsc                     [        U SS 5      (       a@  UR                  SU < 3[        U S9   [        R                  " 5         U R                  5         g g ! [         a     g f = f)Nr   zunclosed Connection )source)getattrwarnResourceWarningr   get_running_loop_closeRuntimeError)rY   r   s     r[   __del__AbstractConnection.__del__  se     4D))NN&th/  ((* *   s   %A 
A! A!c                 x    U R                   (       a)  U R                   R                  5         S=U l         U l        gg)zB
Internal method to silently close the connection without waiting
N)r   closer   rY   s    r[   r   AbstractConnection._close(  s.     <<LL *..DL4< rP   c                     SR                  S U R                  5        5       5      nSU R                  R                   SU R                  R                   SU S3$ )N,c              3   4   #    U  H  u  pU S U 3v   M     g7f)=NrW   ).0kvs      r[   	<genexpr>.AbstractConnection.__repr__.<locals>.<genexpr>1  s     H5GTQ1QCj5Gs   <.(z)>)joinrepr_pieces	__class__rb   ra   )rY   	repr_argss     r[   __repr__AbstractConnection.__repr__0  sQ    HHHT5E5E5GHI	4>>,,-Qt~~/F/F.GqSUVVrP   c                     g rV   rW   r   s    r[   r   AbstractConnection.repr_pieces4      rP   c                 H    U R                   S L=(       a    U R                  S L$ rV   )r   r   r   s    r[   is_connectedAbstractConnection.is_connected8  s    ||4'DDLL,DDrP   c                     [         R                  " U5      nX R                  ;  a  U R                  R                  U5        gg)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
WeakMethodr   r   )rY   callbackwms      r[   register_connect_callback,AbstractConnection.register_connect_callback<  s9     ),,,##**2. -rP   c                      U R                   R                  [        R                  " U5      5        g! [         a     gf = f)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)r   remover   r   r   )rY   r   s     r[   deregister_connect_callback.AbstractConnection.deregister_connect_callbackH  s8    	##**7+=+=h+GH 		s   /2 
??returnc                 .    U" U R                   S9U l        g)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)r   r   )rY   r   s     r[   r   AbstractConnection.set_parserS  s     $T5K5KLrP   c                 h   ^ #    T R                   R                  U 4S jU 4S jSS9I Sh  vN   g N7f)z5Connects to the Redis server if not already connectedc                  $   > T R                  SSS9$ )NTF)check_healthretry_socket_connect)connect_check_healthr   s   r[   <lambda>,AbstractConnection.connect.<locals>.<lambda>`  s    D--! . rP   c                 "   > TR                  XS9$ N)errorfailure_count
disconnect)r   r   rY   s     r[   r   r   c  s     *9 *rP   Twith_failure_countN)r   call_with_retryr   s   `r[   connectAbstractConnection.connect[  s8      jj((  $ ) 
 	
 	
s   '202r   r   c                 j  ^ ^	#    T R                   (       a  g Sm	U	U 4S jn U(       a(  T R                  R                  U 4S jUSS9I S h  vN   OT R                  5       I S h  vN     T R                  (       d  T R!                  US9I S h  vN   OO[        R"                  " T R                  5      (       a  T R                  T 5      I S h  vN OT R                  T 5        T R(                   Vs/ s H  of" 5       (       d  M  UPM     snT l        T R(                   HB  nU" 5       nU" T 5      nU(       d  M  [*        R,                  " U5      (       d  M8  UI S h  vN   MD     g  GN GN! [        R
                   a    e [        R                  [        R                  4 aR    [        S5      n[        [        T SS 5      [        T SS 5      [        T SS 5      [        T SS 5      UT	S	S
9I S h  vN    Ue[         ae  n[        T R                  U5      5      n[        [        T SS 5      [        T SS 5      [        T SS 5      [        T SS 5      UT	S	S
9I S h  vN    UeS nAf[         a  n[        U5      UeS nAff = f GN GN! [$         a    T R'                  5       I S h  vN    e f = fs  snf  GNV7f)Nr   c                 &   > UmTR                  XS9$ r   r   )r   r   actual_retry_attemptsrY   s     r[   failure_callbackAAbstractConnection.connect_check_health.<locals>.failure_callbackq  s    $1!???LLrP   c                  $   > T R                  5       $ rV   )_connectr   s   r[   r   9AbstractConnection.connect_check_health.<locals>.<lambda>y  s    DMMOrP   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   )r   r   r   r   r   CancelledErrorr   r,   r=   r1   r   OSErrorr8   _error_message	Exceptionrw   on_connect_check_healthiscoroutinefunctionr;   r   r   inspectisawaitable)
rY   r   r   r   eexcrefr   taskr   s
   `        @r[   r   'AbstractConnection.connect_check_healthi  s}      !	M
$	0#jj00+$'+ 1    mmo%%<	**222MMM
 2243J3JKK 11$777006 372I2I"S2I3SU32I"S**CuHD>Dt++D11

	 +q &%% 	 4 45 	;<A$&tVT:#D&$7%,T64%@")$"=4!   G 	 3 3A 67A$&tVT:#D&$7%,T64%@")$"=4!   G 	0!#&C/	0 N 8  	//###	 #T
 s   J3)E* 
E$E* J3E* #E'$E* (J3*#J I=J J39J J J "J30J+J+	+J38J3J3J0	J3$E* 'E* *BI:+G.,I:<AIIII:)I55I::J3=J  J J( J#!J((	J3c                     SU l         g )NTr   r   s    r[   mark_for_reconnect%AbstractConnection.mark_for_reconnect  s
    !%rP   c                     U R                   $ rV   r  r   s    r[   should_reconnect#AbstractConnection.should_reconnect  s    %%%rP   c                     SU l         g )NFr  r   s    r[   reset_should_reconnect)AbstractConnection.reset_should_reconnect  s
    !&rP   c                    #    g 7frV   rW   r   s    r[   r   AbstractConnection._connect       rk   c                     g rV   rW   r   s    r[   _host_errorAbstractConnection._host_error  r   rP   	exceptionc                 6    [        U R                  5       U5      $ rV   )r)   r  )rY   r  s     r[   r  !AbstractConnection._error_message  s    #D$4$4$6	BBrP   c                     U R                   $ rV   )r   r   s    r[   get_protocolAbstractConnection.get_protocol  s    }}rP   c                 >   #    U R                  SS9I Sh  vN   g N7f)z=Initialize the connection, authenticate and select a databaseTr  N)r  r   s    r[   
on_connectAbstractConnection.on_connect  s     ***===s   c                 
  #    U R                   R                  U 5        U R                   nS nU R                  (       d"  U R                  (       d  U R                  (       aK  U R                  =(       d     [        U R                  U R                  5      nUR                  5       I S h  vN nU(       Ga0  U R                  S;  Ga  [        U R                   [        5      (       aK  U R                  [        5        UR                  U R                   l        U R                   R                  U 5        [        U5      S:X  a  SUS   /nU R                  " SU R                  S/UQ7SS06I S h  vN   U R                  5       I S h  vN nUR!                  S	5      [#        U R                  5      :w  a3  UR!                  S
5      [#        U R                  5      :w  a  [%        S5      eGOU(       aR  U R                  " S/UQ7SS06I S h  vN    U R                  5       I S h  vN n[)        U5      S:w  a  [+        S5      eOU R                  S;  a  [        U R                   [        5      (       aK  U R                  [        5        UR                  U R                   l        U R                   R                  U 5        U R                  SU R                  US9I S h  vN   U R                  5       I S h  vN nU R,                  (       aT  U R                  SSU R,                  US9I S h  vN   [)        U R                  5       I S h  vN 5      S:w  a  [%        S5      eSnSnU R.                  (       aL  U R.                  R0                  (       a1  U R                  SSSU R.                  R0                  US9I S h  vN   SnU R.                  (       aL  U R.                  R2                  (       a1  U R                  SSSU R.                  R2                  US9I S h  vN   SnU R4                  (       a#  U R                  SU R4                  US9I S h  vN   [7        [9        Xx/5      5       H  n	 U R                  5       I S h  vN   M     U R4                  (       a1  [)        U R                  5       I S h  vN 5      S:w  a  [%        S5      eg g  GN GNZ GNE GN GN! [&         a:    U R                  SUS   SS9I S h  vN    U R                  5       I S h  vN  n GNf = f GNB GN- GN GN GNr GN N N! [:         a     M  f = f N7f)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)r   r&  rs   ro   rt   r5   get_credentials_asyncr   
isinstancerK   r   rL   EXCEPTION_CLASSESlensend_commandread_responsegetr   r8   r7   rC   r6   rp   r   formatted_namerr   rn   rangesumr<   )
rY   r   parser	auth_argscred_providerresponseauth_responselib_name_sentlib_version_sent_s
             r[   r  *AbstractConnection.on_connect_check_health  s    %	##(( T5dmmT]]S  ,AACCI h6$,,(9:: 12171I1I.''-9~"&	!5	 ##1:IN   "//11H||H%T]]);;AT]]#A$ &&<== ##FKYKUKKK;&*&8&8&: : M*d2)*HII 3 ]](*$,,(9:: 12171I1I.''-##GT]]#VVV!//11H ##  )	 $    $"4"4"6674?%&ABB   0 0 ? ?##  //) $    !M 0 0 < <##  ,,) $     $ 77##HdggL#QQQ sM<=>A((*** ? 77$"4"4"6674?%&899 @ I D 2 L !;7 ;
 ''	"E'RRR&*&8&8&: : :;$ W1 7 R
 +   7sU  B#T>%R?&CT>(S)T> SBT>ST>S SS  B3T>TT>+T,4T> T!T>=T>A1T>/T!0AT>T$5T>T'T> T+3T)4T+8-T>%T<&T>T>T>T>S !T/S20TT	TT>TT>T>T>T>!T>$T>'T>)T++
T95T>8T99T>nowaitr   r   health_check_failedc           
        #    [         R                  " 5       c;  U R                  R                  5         U R	                  5         U R                  5         g [        U R                  5       ISh  vN   U R                  R                  5         U R	                  5         U R                  (       d   SSS5      ISh  vN   g U R                  R                  5         U(       d"  U R                  R                  5       I Sh  vN   SU l        SU l	        SSS5      ISh  vN   U(       a  U(       a  [        R                   nO[        R"                  nUb_  X0R$                  R'                  5       :  aB  [)        [+        U SS5      [+        U SS5      [+        U SS5      [+        U SS5      UUS9I Sh  vN   [-        UUS9I Sh  vN   g[-        [        R.                  S9I Sh  vN   g GNx GN/ N! [         a     Nf = f! SU l        SU l	        f = f N! , ISh  vN  (       d  f       GN	= f! [         R                   a    [        SU R                   35      Sef = f N N N7f)z!Disconnects from the Redis serverNz#Timed out closing connection after r   r   )r   r   r   r   r   r   )close_reasonr   )rI  )r   current_taskr   on_disconnectr  r   async_timeoutrv   r   r   r   wait_closedr  r   r=   r>   HEALTHCHECK_FAILEDERRORr   get_retriesr1   r   r-   APPLICATION_CLOSE)rY   rF  r   r   rG  rI  s         r[   r   AbstractConnection.disconnectD  s     !)LL&&('')KKM	$T%@%@AA**,++-(( BAA
(LL&&( ""ll66888 $(DL#'DL! BA, "*==*00(]ZZ=S=S=U-U(#*4#> 'fd ;)0vt)D&-dFD&A$#0   +)   
 +(::  W B 9  $(DL#'DL! BAAA" ## 	5d6Q6Q5RS	
s  AI%H. .G&/H. 2=H/H. :G);H. ?I%>G.?G, G.HH. HH. "BI%.I/I% I!I% I#!I%&H. )H. ,G..
G;8G>:G;;G>>HHH. H+HH+&H. )I%+H. ..II%!I%#I%c                    #    U R                  SSS9I Sh  vN   [        U R                  5       I Sh  vN 5      S:w  a  [        S5      eg N5 N7f)z Send PING, expect PONG in returnPINGFr  NPONGz#Bad response from PING health check)r7  rC   r8  r8   r   s    r[   
_send_pingAbstractConnection._send_ping  sP     U;;;d00223v=!"GHH > 	<2s   AAAAAAc                 @   #    U R                  XSS9I Sh  vN   g N7f)z Function to call when PING failsT)r   r   rG  Nr   )rY   r   r   s      r[   _ping_failedAbstractConnection._ping_failed  s%     oo$  
 	
 	
   c                   #    U R                   (       aj  [        R                  " 5       R                  5       U R                  :  a8  U R
                  R                  U R                  U R                  SS9I Sh  vN   ggg N7f)z3Check the health of the connection with a PING/PONGTr   N)	rz   r   r   timer{   r   r   rV  rY  r   s    r[   r   AbstractConnection.check_health  sr      &&((*//1D4J4JJ**,,!2!2t -    K 's   A5B7A?8Bcommandc                    #    U R                   R                  U5        U R                   R                  5       I S h  vN   g  N7frV   )r   
writelinesdrain)rY   r_  s     r[   _send_packed_command'AbstractConnection._send_packed_command  s-     (ll  """s   9AAAc                   #    U R                   (       d  U R                  SS9I S h  vN   U(       a  U R                  5       I S h  vN    [        U[        5      (       a  UR                  5       n[        U[        5      (       a  U/nU R                  (       a9  [        R                  " U R                  U5      U R                  5      I S h  vN   g U R                  R                  U5        U R                  R                  5       I S h  vN   g  N N NG N! [        R                   a%    U R                  SS9I S h  vN    [        S5      S e[          ax  nU R                  SS9I S h  vN    [#        UR$                  5      S:X  a  SUR$                  S   pTOUR$                  S   nUR$                  S   n['        S	U S
U S35      UeS nAf[(         a    U R                  SS9I S h  vN    e f = f7f)NFr  TrF  zTimeout writing to socketr   UNKNOWNr   zError z while writing to socket. r   )r   r   r   r4  strencodebytesru   r   wait_forrc  r   ra  rb  r=   r   r  r6  argsr8   BaseException)rY   r_  r   r
  err_noerrmsgs         r[   send_packed_command&AbstractConnection.send_packed_command  s       +++???##%%%	'3''!..*'5))")""&&--g68K8K   ''0ll((*** @%
 +## 	F///...:;E 		///...166{a!*AFF1I! :6(!D  	
 ///...	s   $G6DG6DG6BD DD G68D 
DD G6G6D D &G3>E?G3G+E.,A GG3+G.,G33G6rl  kwargsc                 z   #    U R                  U R                  " U6 UR                  SS5      S9I Sh  vN   g N7f)z+Pack and send a command to the Redis serverr   Tr  N)rp  pack_commandr9  )rY   rl  rr  s      r[   r7  AbstractConnection.send_command  s=     &&t$6::nd3S ' 
 	
 	
s   1;9;z8.0.0zUse can_read() insteadcan_read_destructive)versionr   namec                    #     U R                   R                  5       I Sh  vN $  N! [         aH  nU R                  SS9I Sh  vN    U R	                  5       n[        SU SUR                   35      eSnAff = f7fz=Check the socket to see if there's data loaded in the buffer.NTrf  Error while reading from z: r   can_readr  r   r  r8   rl  rY   r
  
host_errors      r[   rv  'AbstractConnection.can_read_destructive  st     
	V..0000 	V///...))+J!$=j\AFF8"TUU	V<   A=( &( A=( 
A:A5A0A55A::A=c                    #     U R                   R                  5       I Sh  vN $  N! [         aH  nU R                  SS9I Sh  vN    U R	                  5       n[        SU SUR                   35      eSnAff = f7frz  r|  r~  s      r[   r}  AbstractConnection.can_read  st     	V..0000 	V///...))+J!$=j\AFF8"TUU	Vr  )disconnect_on_errorpush_requestdisable_decodingr,   r  r  c                .  #    U[         R                  :X  a  SnOUb  UOU R                  nU R                  5       n UbV  U R                  S;   aF  [        U5       ISh  vN   U R                  R                  XS9I Sh  vN nSSS5      ISh  vN   OUbF  [        U5       ISh  vN   U R                  R                  US9I Sh  vN nSSS5      ISh  vN   OTU R                  S;   a"  U R                  R                  XS9I Sh  vN nO"U R                  R                  US9I Sh  vN n U R                  (       a6  [        R                   " 5       R#                  5       U R                  -   n	Xl        ['        W[(        5      (       a  USeU$  GN5 GN GN
! , ISh  vN  (       d  f       N= f GN N N! , ISh  vN  (       d  f       N= f N N! [        R                   a3    Ub   gU(       a  U R                  SS9I Sh  vN    [        SU 35      e[         a?  nU(       a  U R                  SS9I Sh  vN    [        SU S	UR                   35      eSnAf[         a!    U(       a  U R                  SS9I Sh  vN    e f = f7f)
a  Read the response from a previously sent command.

``timeout`` semantics:
- ``None`` (default): fall back to ``self.socket_timeout``.
- ``math.inf``: block indefinitely with no timeout. Used by PubSub
  blocking reads (``listen()`` / ``get_message(timeout=None)`` /
  ``parse_response(block=True)``) where the configured
  ``socket_timeout`` must not abort the read.
- ``float``: apply that timeout in seconds for this single read.

TODO(next-major): replace the ``math.inf`` opt-in with a SENTINEL
default for ``timeout``. After that change, ``timeout=None`` will
mean "no timeout, block until a response arrives" (matching the
long-standing PubSub docstring contract) and the SENTINEL default
will be the value that falls back to ``self.socket_timeout``.
That swap is a breaking change, so it must wait for a major
release. Until then, callers that need an indefinitely blocking
read pass ``math.inf`` explicitly.
N)3r*   )r  r  )r  Trf  zTimeout reading from r{  z : )mathinfru   r  r   rL  r   r8  r   r=   r   r  r8   rl  rm  rz   r   r]  r{   r4  r<   )
rY   r  r,   r  r  read_timeoutr  r@  r
  	next_times
             r[   r8   AbstractConnection.read_response  sO    B dhhL&-&97t?R?RL%%'
%	'DMMX,E(66%)\\%?%?)9 &@ &  H 766 )(66%)\\%?%?)9 &@ &  H 766 (*!%!;!;%5 "< "  "&!;!;%5 "< " . %%002779D<V<VVI%."h..$W 7  7666
 7  7666
 ## 	E""ooTo222!6zlCDD 	W"ooTo222!$=j\QVVH"UVV 	 #ooTo222	sa  9J"G FG "F?F FG FG JG 'F6(G +F=F9	F=G F;G J,G 
GG JG ,G-G 1A"JG FG F3"F%#F3/G 2J3G 9F=;G =GGGG JG G J2J4JHJ*I$I I$$&J
JJJc           	         / n[        US   [        5      (       a   e[        US   [        5      (       a1  [        US   R	                  5       R                  5       5      USS -   nO+SUS   ;   a"  [        US   R                  5       5      USS -   n[        R                  [        [        [        U5      5      R	                  5       [        45      nU R                  n[        U R                  R                  U5       H  n[        U5      n[        U5      U:  d  Xd:  d  [        U[        5      (       ab  [        R                  U[        [        U5      R	                  5       [        45      nUR!                  U5        UR!                  U5        [        nM  [        R                  U[        [        U5      R	                  5       [        U[        45      nM     UR!                  U5        U$ )z2Pack a series of arguments into the Redis protocolr   r   N    )r4  floatrh  tupleri  split	SYM_EMPTYr   SYM_STARr6  SYM_CRLFr   mapr}   
memoryview
SYM_DOLLARr   )rY   rl  outputbuffbuffer_cutoffarg
arg_lengths          r[   rt  AbstractConnection.pack_command;  s    d1gu----d1gs##a)//12T!"X=DT!W_a)DH4D~~xSY)>)>)@(KL++t||**D1C SJD	M)-c:.. ~~:s:'='='?J d#c" ~~"J..0  	! 24 	drP   commandsc                    / n/ nSnU R                   nU H  nU R                  " U6  H  n[        U5      nXE:  d  X:  d  [        U[        5      (       a/  U(       a$  UR                  [        R                  U5      5        Sn/ nX:  d  [        U[        5      (       a  UR                  U5        M  UR                  U5        XH-  nM     M     U(       a$  UR                  [        R                  U5      5        U$ )z.Pack multiple commands into the Redis protocolr   )r   rt  r6  r4  r  r   r  r   )	rY   r  r  piecesbuffer_lengthr  cmdchunkchunklens	            r[   pack_commands AbstractConnection.pack_commandsi  s      ++C**C0u:!1/!%44innV&<=$%MF+z%/L/LMM%(MM%(!-M! 1 & MM)..01rP   c                 F    [        U R                  R                  5      S:H  $ )zCheck if the socket is emptyr   )r6  r   _bufferr   s    r[   _socket_is_empty#AbstractConnection._socket_is_empty  s    4<<''(A--rP   c                    #    U R                  5       (       d/  U R                  SS9I S h  vN   U R                  5       (       d  M.  g g  N7f)NT)r  )r  r8  r   s    r[   process_invalidation_messages0AbstractConnection.process_invalidation_messages  s?     ''))$$$$777 ''))7s   (A
AA
A
tokenc                     Xl         g rV   )r   rY   r  s     r[   set_re_auth_token$AbstractConnection.set_re_auth_token  s    #rP   c                   #    U R                   bl  U R                  SU R                   R                  S5      U R                   R                  5       5      I S h  vN   U R	                  5       I S h  vN   S U l         g g  N% N7fNr,  oid)r   r7  try_get	get_valuer8  r   s    r[   re_authAbstractConnection.re_auth  s}     *####++E2##--/  
 $$&&&"&D +
 's$   ABA=B/A?0B?B)r   r   r   r   r   r   r   r   r   rp   rs   rn   r   r}   rz   r   r{   rt   r   rw   r   ry   rx   rv   ru   ro   )TTr   NT)FNNF)FN)Mra   rb   rc   rd   __doc__	__slots__r(   rF   rD   rB   rQ   rE   rI   rh  r   r  boollistobjectr   rH   r$   r2   ConnectCallbackTr4   r'   r   warningsr   r   r   r   r   r   propertyr   r   r   r   r   r   r  r  r  r   r  rm  r  r#  r&  r  r   r  r   rV  rY  r   r	   rj  rc  r   rp  r7  r   rv  r}  r8  r?   r
   rt  r  r  r  r#   r  r  re   rW   rP   r[   r_   r_      s   :I:  -0H #'=/M!&(0'!&)6 8'("&(0+32:#"6:'.9=#!%375q& #Iq& *	q&
 q& !&q& q& vq& q& q& q& :&q& q&  %q& 4Zq&  ,%!q&" 6\D(#q&$  &(4/%q&& *'q&( t|)q&* -t3+q&, G}-q&. 0$6/q&0 *1q&2 3q&4 *D05q&
q&f (0   /W   E E
/	MtJ'7 MD M
 GKK K?CKZ&&'   S  C C# C>q:$ q:$ q:j %)'+$)@@ 	"@  }	@
 "@ 
@DI
#(5/ #d #
 QU'UC%89'IM'	'R
 
s 
t 
  8?UVD VV	V 	V "'#'S
 %)',SS %S
 "S tnSj,* ,e ,\hx
/C&D e <.8$~ $'rP   r_   c                      ^  \ rS rSrSrSSS\SS.S\S	\\-  S
\S\	\\\
-  4   \-  S-  S\4
U 4S jjjrS rS\	4S jrS rS\4S jrSrU =r$ )
Connectioni  z4Manages TCP communication to and from a Redis server	localhosti  Tr   )r   r   socket_keepalivesocket_keepalive_optionssocket_typer   r   r  r  Nr  c                   > Xl         [        U5      U l        X0l        U[        L a
  [        5       nU=(       d    0 U l        XPl        [        TU ]$  " S0 UD6  g)ai  
Initialize a TCP connection.

Parameters
----------
socket_keepalive : bool
    If `True`, TCP keepalive is enabled for TCP socket connections.
socket_keepalive_options : Mapping[int, int | bytes] | object | None
    Mapping of TCP keepalive socket option constants to values, for
    example `{socket.TCP_KEEPIDLE: 30}`. If left unspecified, redis-py
    uses TCP keepalive defaults when `socket_keepalive` is enabled:
    idle 30 seconds, interval 5 seconds, and 3 probes. Platform-specific
    options that are not available are skipped. Pass `None` or `{}` to
    avoid setting additional TCP keepalive options.
NrW   )
r   r   r   r  rB   rG   r  r  superr   )rY   r   r   r  r  r  rr  r   s          r[   r   Connection.__init__  sO    2 	I	 0#x/'K'M$(@(FB%&"6"rP   c                     SU R                   4SU R                  4SU R                  4/nU R                  (       a  UR	                  SU R                  45        U$ )Nr   r   rn   rp   )r   r   rn   rp   r   rY   r  s     r[   r   Connection.repr_pieces  sM    499%		':T477OLMM=$*:*:;<rP   r   c                 4    U R                   U R                  S.$ )Nr   r   r  r   s    r[   _connection_arguments Connection._connection_arguments  s    		49955rP   c                   #    [        U R                  5       ISh  vN   [        R                  " S0 U R	                  5       D6I Sh  vN u  pSSS5      ISh  vN   WU l        WU l        UR                  R                  S5      nU(       a  UR                  [        R                  [        R                  S5         U R                  (       as  UR                  [        R                  [        R                  S5        U R                   R#                  5        H%  u  pEUR                  [        R$                  XE5        M'     ggg GN) N N! , ISh  vN  (       d  f       GN= f! [&        [(        4 a    UR+                  5         e f = f7f)zCreate a TCP socket connectionNr   r   rW   )rL  rv   r   open_connectionr  r   r   	transportget_extra_info
setsockoptr   IPPROTO_TCPTCP_NODELAYr  
SOL_SOCKETSO_KEEPALIVEr  itemsSOL_TCPr  r   r   )rY   readerwritersockr   r   s         r[   r   Connection._connect  s(     !<!<==#*#:#: $,,.$ NF >= ..x8OOF..0B0BAF((OOF$5$5v7J7JAN $ = = C C E= !F )	  > >===  Y'  	sp   FEF(EE	EFE
A#F?BE' FE
FE$EE$F'"F		Fc                 8    U R                    SU R                   3$ )N:r  r   s    r[   r  Connection._host_error  s    ))Adii[))rP   )r   r   r   r   r  r  r  )ra   rb   rc   rd   r  rB   rh  r   r  r   rj  r  r   r   r  r   r  re   __classcell__r   s   @r[   r  r    s    :
  !%NV #  # Ci	 #
  # #*#sU{*:";f"Dt"K #  #  #D6w 60*S * *rP   r  c                     ^  \ rS rSrSr            SS\\   S\\   S\\\R                  4   S\\
S      S\\
S      S	\\   S
\\   S\\   S\S\\   S\\   S\\   4U 4S jjjrS\4U 4S jjr\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrU =r$ )SSLConnectioni  zManages 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)
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                    > [         (       d  [        S5      e[        UUUUUUUUU	U
UUS9U l        [        TU ]  " S0 UD6  g )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ciphersrt   rW   )r   r;   RedisSSLContextr~   r  r   )rY   r  r  r  r  r  r  r  r  r  r  r  r  rr  r   s                 r[   r   SSLConnection.__init__  sY      }CDD,;!#!9!9!-'!-
 	"6"rP   r   c                 ^   > [         TU ]  5       nU R                  R                  5       US'   U$ )Nssl)r  r  r~   r9  )rY   rr  r   s     r[   r  #SSLConnection._connection_arguments  s-    .0((,,.urP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  SSLConnection.keyfile      '''rP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  SSLConnection.certfile      (((rP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  SSLConnection.cert_reqs  s    )))rP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  "SSLConnection.include_verify_flags!      444rP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  "SSLConnection.exclude_verify_flags%  r  rP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  SSLConnection.ca_certs)  r  rP   c                 .    U R                   R                  $ rV   )r~   r   r   s    r[   r   SSLConnection.ca_data-  r  rP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  SSLConnection.check_hostname1  s    ...rP   c                 .    U R                   R                  $ rV   )r~   r  r   s    r[   r  SSLConnection.min_version5  s    +++rP   )r~   )NNrequiredNNNNNTNNN)ra   rb   rc   rd   r  r   rh  r   r  
VerifyModer
   r  r!   r   r   r  r  r  r  r  r  r  r  r   r  r  re   r  r  s   @r[   r  r    s    &*&*4>FJFJ&*%)%)#'04%)&*!#c]!# sm!# S#..01	!#
 #+40A+B"C!# #+40A+B"C!# sm!# c]!# c]!# !!# "*-!# c]!# sm!# !#Fw 
 ( ( ) ) * * 5 5 5 5 ) ) ( ( / / , ,rP   r  c                       \ rS rSrSr            SS\\   S\\   S\\\\R                  4      S\\
S      S	\\
S      S
\\   S\\   S\\   S\S\\   S\\   S\\   4S jjrS\4S jrSrg)r  i:  )r  r  r  r  r  r  r   r  contextr  r  r  rt   Nr  r  r  r  r  r  r  r   r  r  r  r  rt   c                    [         (       d  [        S5      eXl        X l        Uc  [        R
                  nO\[        U[        5      (       aG  [        R
                  [        R                  [        R                  S.nX=;  a  [        SU 35      eX   nX0l
        X@l        XPl        X`l        Xpl        Xl        U R                  [        R
                  :w  a  U	OSU l        Xl        Xl        Xl        S U l        g )Nr  )noneoptionalr  z+Invalid SSL Certificate Requirements Flag: F)r   r;   r  r  r  	CERT_NONEr4  rh  CERT_OPTIONALCERT_REQUIREDr  r  r  r  r   r  r  r  r  rt   r"  )rY   r  r  r  r  r  r  r   r  r  r  r  rt   	CERT_REQSs                 r[   r   RedisSSLContext.__init__K  s     }CDD I	3''----I
 ) A)M  ",I"$8!$8! "nn=N5 	 ' -1rP   r   c                    U R                   (       Gd  [        R                  " 5       nU R                  Ul        U R                  Ul        U R                  (       a(  U R                   H  nU=R                  U-  sl        M     U R                  (       a)  U R                   H  nU=R                  U) -  sl        M     U R                  (       d  U R                  (       a/  UR                  U R                  U R                  U R                  S9  U R                  (       d"  U R                  (       d  U R                  (       a/  UR!                  U R                  U R                  U R                  S9  U R"                  b  U R"                  Ul        U R&                  b  UR)                  U R&                  5        Xl         U R                   $ )N)r  r  rt   )cafilecapathcadata)r"  r  create_default_contextr  r  verify_moder  verify_flagsr  r  r  load_cert_chainrt   r  r   r  load_verify_locationsr  minimum_versionr  set_ciphers)rY   r"  flags      r[   r9  RedisSSLContext.getz  s@   |||002G%)%8%8G""&..G(( 55D((D0( 6(( 55D((TE1( 6}}''!]] LL!]] ( 
 }}--==dll .  +*.*:*:'||'##DLL1"L||rP   )r  r   r  r  r  r  r  r"  r  r  r  r  rt   )NNNNNNNNFNNN)ra   rb   rc   rd   r  r   rh  r   r  r   r
   r  r!   r   r    r9  re   rW   rP   r[   r  r  :  s   I$ "&"&:>BFBF"&!%!%$,0!%"&-2#-2 3--2 E#s~~"567	-2
 't,='>?-2 't,='>?-2 3--2 #-2 #-2 -2 j)-2 #-2 3--2^Z rP   r  c                   x   ^  \ rS rSrSrSS.S\4U 4S jjjrS\\\\	\\
4   4      4S jrS	 rS\4S
 jrSrU =r$ )UnixDomainSocketConnectioni  z4Manages UDS communication to and from a Redis server pathr<  c                2   > Xl         [        TU ]  " S0 UD6  g )NrW   )r<  r  r   )rY   r<  rr  r   s      r[   r   #UnixDomainSocketConnection.__init__  s    	"6"rP   r   c                     SU R                   4SU R                  4/nU R                  (       a  UR                  SU R                  45        U$ )Nr<  rn   rp   )r<  rn   rp   r   r  s     r[   r   &UnixDomainSocketConnection.repr_pieces  sB    499%dgg7MM=$*:*:;<rP   c                 H  #    [        U R                  5       IS h  vN   [        R                  " U R                  S9I S h  vN u  pS S S 5      IS h  vN   WU l        WU l        U R                  5       I S h  vN   g  Nc N? N/! , IS h  vN  (       d  f       ND= f N%7f)Nr;  )rL  rv   r   open_unix_connectionr<  r   r   r&  )rY   r  r  s      r[   r   #UnixDomainSocketConnection._connect  sq      !<!<==#*#?#?TYY#OONF >=oo	 >O >=== 	 sb   B"B B""BBB	B"B%B":B ;B"BB"BBBB"c                     U R                   $ rV   r;  r   s    r[   r  &UnixDomainSocketConnection._host_error  s    yyrP   )r   r   r<  )ra   rb   rc   rd   r  rh  r   r	   r   r   r   r   r   r  re   r  r  s   @r[   r9  r9    sS    :&( # # #XeCsCx,@&AB  S  rP   r9  )0FFALSENNOr   c                     U b  U S:X  a  g [        U [        5      (       a  U R                  5       [        ;   a  g[	        U 5      $ )Nr:  F)r4  rh  upperFALSE_STRINGSr  )values    r[   to_boolrO    s7    }%%++-="@;rP   c                 "   U R                  SS5      R                  SS5      n/ nUR                  S5       HU  nUR                  5       n[        [        U5      (       d  [        SU 35      eUR                  [        [        U5      5        MW     U$ )N[r:  ]r   zInvalid ssl verify flag: )replacer  striphasattrr"   r   r   r   )rN  verify_flags_strr1  r6  s       r[   parse_ssl_verify_flagsrW    s     }}S"-55c2>L &&s+zz|{D))8?@@GK67	 ,
 rP   )rn   ru   rv   r   r  rx   max_connectionsrz   r  r  r  r  r,   r   r   .URL_QUERY_ARGUMENT_PARSERSc                   b    \ rS rSr% \\S'   \\S'   \\   \S'   \\S'   \\S'   \\S'   \\S'   S	r	g
)ConnectKwargsi  ro   rt   connection_classr   r   rn   r<  rW   N)
ra   rb   rc   rd   rh  __annotations__r   r_   r   re   rW   rP   r[   r[  r[    s,    MM-..
I
IG
IrP   r[  F)totalurlc                 j   [        U 5      n0 n[        UR                  5      R                  5        HZ  u  p4U(       d  M  [	        U5      S:  d  M  [        US   5      n[        R                  U5      nU(       a   U" U5      X#'   MV  XRU'   M\     UR                  (       a  [        UR                  5      US'   UR                  (       a  [        UR                  5      US'   UR                  S:X  a4  UR                  (       a  [        UR                  5      US'   [        US'   U$ UR                  S	;   a  UR                  (       a  [        UR                  5      US
'   UR                   (       a  [#        UR                   5      US'   UR                  (       a8  SU;  a2   [#        [        UR                  5      R%                  SS5      5      US'   UR                  S:X  a	  [(        US'   U$ Sn[        SU S35      e! [        [        4 a    [        SU S35      ef = f! [&        [        4 a     Naf = f)Nr   zInvalid value for 'z' in connection URL.ro   rt   unixr<  r\  )redisredissr   r   rn   /r:  rc  zredis://, rediss://, unix://z5Redis URL must specify one of the following schemes ())r   r   queryr  r6  r   rY  r9  r   r   ro   rt   schemer<  r9  hostnamer   r   rS  AttributeErrorr  )r_  parsedrr  rx  
value_listrN  r=  valid_schemess           r[   	parse_urlrm    s   "3-FF$V\\288::#j/A-JqM*E/33D9FW#)%=FL  %t ; $V__5z$V__5z }};;$V[[1F6N%?!"2 M/ 
-	-??$V__5F6N;; -F6N ;;4v-"76;;#7#?#?R#HIt ==H$)6F%& M 7CM?RST
 	
G ":. W$':4&@T%UVVW6 #J/ s   ;
G<1H < HH21H2_CPConnectionPool)boundc                   4   \ rS rSr\S 5       r\SS j5       r\\" S/SSS	9 SS
\\	   S\
S\
SS4S jj5       5       r\SS j5       r\SS j5       r\SS\SS4S jj5       r\SS j5       r\SS j5       r\S\SS4S j5       r\S\\\\4      4S j5       rSrg)ConnectionPoolInterfacei  c                     g rV   rW   r   s    r[   r#  $ConnectionPoolInterface.get_protocol   r   rP   r   Nc                     g rV   rW   r   s    r[   resetConnectionPoolInterface.reset$  r   rP   *)Use get_connection() without args instead5.3.0r   r   rw  command_namekeysoptionsr_   c                    #    g 7frV   rW   )rY   r|  r}  r~  s       r[   get_connection&ConnectionPoolInterface.get_connection(  s
      	rk   c                     g rV   rW   r   s    r[   get_encoder#ConnectionPoolInterface.get_encoder3  r   rP   c                    #    g 7frV   rW   rX   s     r[   releaseConnectionPoolInterface.release7  r  rk   inuse_connectionsc                    #    g 7frV   rW   )rY   r  s     r[   r   "ConnectionPoolInterface.disconnect;  r  rk   c                    #    g 7frV   rW   r   s    r[   acloseConnectionPoolInterface.aclose?  r  rk   c                     g rV   rW   )rY   r   s     r[   	set_retry!ConnectionPoolInterface.set_retryC  r   rP   r  c                    #    g 7frV   rW   r  s     r[   re_auth_callback(ConnectionPoolInterface.re_auth_callbackG  r  rk   c                     g)4
Returns a connection count (both idle and in use).
NrW   r   s    r[   get_connection_count,ConnectionPoolInterface.get_connection_countK  s    
 	rP   rW   r  rV   )r   rI   )rZ   r_   r   Nr  r   r2   r   N)ra   rb   rc   rd   r   r#  rv  r(   r   rh  r   r  r  r  r  r   r  r  r#   r  r
   r   r   dictr  re   rW   rP   r[   rr  rr    s:       U: -1$SM9<IL	 
     $ $       N t   d5d+;&<  rP   rr  c                   X   \ rS rSrSr\S\\   S\S\4S j5       r	\
S4S\\   S	\\   4S
 jjr\" 1 Sk5      rS rS rS rS'S jrS\4S jr\" S/SSS9S(S j5       rS rS rS rS\4S jrS\4S jrS)S\4S jjrS rS'S jr S*S  jr!S!\"4S" jr#S#\$4S$ jr%S\&\'\\(4      4S% jr)S&r*g)+ro  iS  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                 J    [        U5      nUR                  U5        U " S0 UD6$ )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.
rW   )rm  update)r  r_  rr  url_optionss       r[   from_urlConnectionPool.from_urlb  s&    V  nk"}V}rP   Nr\  rX  c                    U=(       d    Sn[        U[        5      (       a  US:  a  [        S5      eXl        X0l        X l        / U l        [        5       U l        U R                  R                  S[        5      U l        [        R                  " 5       U l        U R                  R                  SS 5      U l        U R                  c  [!        5       U l        g g )Nd   r   z,"max_connections" must be a positive integerr   r   )r4  r   r   r\  connection_kwargsrX  _available_connectionsset_in_use_connectionsr9  rI   r   r   Lockr   r   r'   )rY   r\  rX  r  s       r[   r   ConnectionPool.__init__  s     *0S/3//?Q3FKLL 0!2.@B#<?E !3377Q\\^
!%!7!7!;!;<NPT!U!!)%4%6D" *rP   >   rt   ro   r  rs   c                 z   SR                  U R                  R                  5        VVs/ s H  u  pU SXR                  ;   a  SOU 3PM     snn5      nSU R                  R
                   SU R                  R                   SU R                  R
                   SU R                  R                   SU S3$ s  snnf )	Nr   r   z
<REDACTED>r   r   z(<r   z)>)>)r   r  r  SENSITIVE_REPR_KEYSr   rb   ra   r\  )rY   r   r   conn_kwargss       r[   r   ConnectionPool.__repr__  s    hh !2288::DA #Qq,D,D'D|!LM:
 ))*!DNN,C,C+D&&112!D4I4I4R4R3S}D"	
s   $B7
c                 :    U R                   R                  SS5      $ )z
Returns:
    The RESP protocol version, or ``None`` if the protocol is not specified,
    in which case the server default will be used.
r   N)r  r9  r   s    r[   r#  ConnectionPool.get_protocol  s     %%))*d;;rP   c                    [        U S5      (       a  [        U S5      (       a  [        U R                  5      n[        U R                  5      nUS:  d  US:  aK  [	        U 5      nSSKJn  US:  a  U" U[        R                  U* S9  US:  a  U" U[        R                  U* S9  / U l        [        R                  " 5       U l        g )Nr  r  r   r.   	pool_nameconnection_statecounter)rU  r6  r  r  r   redis.observability.recorderr.   r   IDLEUSEDr   WeakSetrY   
idle_countin_use_countr  sync_record_connection_counts        r[   rv  ConnectionPool.reset  s     4122w'8
 8
 T889Jt778LA~!1)$/	 >0"+)8)=)=!+
  !#0"+)8)=)=!- ')##*??#4 rP   c                 r    [        U S5      (       a  [        U S5      (       d  g[        U R                  5      n[        U R                  5      nUS:  d  US:  aM  [	        U 5      nSSKJn  US:  a  U" U[        R                  U* S9  US:  a  U" U[        R                  U* S9  ggg! [         a     gf = f)zCClean up connection pool and record metrics when garbage collected.r  r  Nr   r  r  )rU  r6  r  r  r   r  r.   r   r  r  r  r  s        r[   r   ConnectionPool.__del__  s    	4!9::'+C C T889Jt778LA~!1)$/	 >0"+)8)=)=!+
  !#0"+)8)=)=!- $ "2&  		s   "B) BB) )
B65B6c                 l    U R                   =(       d"    [        U R                  5      U R                  :  $ )z;Return True if a connection can be retrieved from the pool.)r  r6  r  rX  r   s    r[   can_get_connection!ConnectionPool.can_get_connection  s1     '' D4++,t/C/CC	
rP   rx  ry  rz  r{  c                 x  #    U R                    ISh  vN   [        U R                  5      [        U R                  5      -   n[        R
                  " 5       nU R                  5       n[        U R                  5      [        U R                  5      -   nXt:  nSSS5      ISh  vN   [        U 5      n	W(       a"  [        U	[        R                  SS9I Sh  vN   OB[        U	[        R                  SS9I Sh  vN   [        U	[        R                  SS9I Sh  vN    U R                  W5      I Sh  vN   U(       a(  [        U [        R
                  " 5       W-
  S9I Sh  vN   U$  GNU N! , ISh  vN  (       d  f       N= f N N Nr NZ N-! [         a    U R                  W5      I Sh  vN    e f = f7f)z(Get a connected connection from the poolNr   r  r   connection_poolduration_seconds)r   r6  r  r  r]  	monotonicget_available_connectionr   r.   r   r  r  ensure_connectionr/   rm  r  )
rY   r|  r}  r~  connections_beforestart_time_createdrZ   connections_after
is_createdr  s
             r[   r  ConnectionPool.get_connection  s     :::!$T%@%@!AC((E " "&!1668J #D$?$? @3((D ! +?J : "$'	)#!0!5!5   *#!0!5!5  
 *#!0!5!5  	((4443$(%)^^%58J%J  
 Y ::: 
 5  	,,z***	s   F:E(F:B E-F:"E+#2F:F!F:7F	8 F:FF:F 2F3.F !F"F 'F:+F:-F3E64F F:	F:F:F F F7/F20F77F:c                     U R                   R                  5       nU R                  R                  U5        U$ ! [         aB    [        U R                  5      U R
                  :  a  [        S5      SeU R                  5       n Nhf = f)zCGet a connection from the pool, without making sure it is connectedzToo many connectionsN)	r  pop
IndexErrorr6  r  rX  r:   make_connectionaddrX   s     r[   r  'ConnectionPool.get_available_connectionD  s}    	04488:J
 	  $$Z0  	04++,0D0DD)*@AtK--/J	0s   9 A	BBc                     U R                   nU R                  UR                  SS5      UR                  SS5      UR                  SS5      S9$ )z,Return an encoder based on encoding settingsr   r   r   r   r   F)r   r   r   )r  r   r9  )rY   rr  s     r[   r  ConnectionPool.get_encoderO  sQ    ''!!ZZ
G4"JJ'8(C#ZZ(:EB " 
 	
rP   c                 :    U R                   " S0 U R                  D6$ )z=Create a new connection.  Can be overridden by child classes.rW   )r\  r  r   s    r[   r  ConnectionPool.make_connectionX  s     $$>t'='=>>rP   rZ   c                   #    UR                  5       I Sh  vN    UR                  5       I Sh  vN (       a  [        S5      Seg N/ N! [        [        [        4 a_    UR                  5       I Sh  vN    UR                  5       I Sh  vN    UR                  5       I Sh  vN  (       a  [        S5      Se gf = f7f)z8Ensure that the connection object is connected and validNzConnection has datazConnection not ready)r   r}  r8   r=   r  r   rX   s     r[   r   ConnectionPool.ensure_connection^  s       """
	H((***%&;<$F + 	# +w7 	H'')))$$&&&((***%&<=4G +	Hsf   CACA
 AA
 CA
 
(B>2A53B>BB>$B'%B>;C=B>>Cc                   #    U R                   R                  U5        UR                  5       (       a  UR                  5       I Sh  vN   U R                  R                  U5        U R                  R                  [        U5      5      I Sh  vN   [        U 5      n[        U[        R                  SS9I Sh  vN   [        U[        R                  SS9I Sh  vN   g N NT N* N7f)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   rZ   r  s      r[   r  ConnectionPool.releasen  s      	  ''
3&&(('')))##**:6$$33-j9
 	
 	

 "$'	%,11
 	
 	

 &,11
 	
 	
 *	
	

	
sI   AC(C AC(C"+C(9C$: C(C&C("C($C(&C(r  c                    #    U(       a!  [        U R                  U R                  5      nOU R                  n[        R                  " S U 5       SS06I Sh  vN n[        S U 5       S5      nU(       a  Ueg N!7f)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              3   @   #    U  H  oR                  5       v   M     g 7frV   r   )r   rZ   s     r[   r   ,ConnectionPool.disconnect.<locals>.<genexpr>  s     D*##%%s   return_exceptionsTNc              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7frV   )r4  rm  )r   rs     r[   r   r    s     Dt!z!]'CAAts   (	()r   r  r  r   gathernext)rY   r  connectionsrespr  s        r[   r   ConnectionPool.disconnect  s{      8=++T-E-E9K 55K^^DD
"
 

 DtDdKI 
s   AA;A9"A;c                    #    U R                    ISh  vN   U R                   H  nUR                  5         M     SSS5      ISh  vN   g N8 N! , ISh  vN  (       d  f       g= f7f)z,
Mark all active connections for reconnect.
N)r   r  r  )rY   conns     r[   'update_active_connections_for_reconnect6ConnectionPool.update_active_connections_for_reconnect  s;      :::00'') 1 :::::sC   A*AA*$AA*AA*A*A'AA'#A*c                 @   #    U R                  5       I Sh  vN   g N7f)z-Close the pool, disconnecting all connectionsNr   r   s    r[   r  ConnectionPool.aclose  s     oor[  c                 h    U R                    H	  nXl        M     U R                   H	  nXl        M     g rV   )r  r   r  )rY   r   r  s      r[   r  ConnectionPool.set_retry  s,    //DJ 0,,DJ -rP   r  c                   ^ ^^#    T R                    IS h  vN   T R                   H\  mTR                  R                  UU4S jU 4S j5      I S h  vN   TR                  R                  U4S jU 4S j5      I S h  vN   M^     T R                   H  mTR                  T5        M     S S S 5      IS h  vN   g  N Nk NA N! , IS h  vN  (       d  f       g = f7f)Nc                  d   > T R                  STR                  S5      TR                  5       5      $ r  )r7  r  r  )r  r  s   r[   r   1ConnectionPool.re_auth_callback.<locals>.<lambda>  s'    D--e 4eoo6GrP   c                 &   > TR                  U 5      $ rV   _mockr   rY   s    r[   r   r    s    $**U"3rP   c                  $   > T R                  5       $ rV   )r8  )r  s   r[   r   r    s    D..0rP   c                 &   > TR                  U 5      $ rV   r  r  s    r[   r   r    s    

5@QrP   )r   r  r   r   r  r  )rY   r  r  s   ``@r[   r  ConnectionPool.re_auth_callback  s     :::33jj00 4	   jj0002Q   4 00&&u- 1 :: :::sh   CB<C8CB>+C>C ?,C+C6C7C>C CCC
CCCr   c                    #    g7f)z_
Dummy functions, needs to be passed as error callback to retry object.
:param error:
:return:
NrW   )rY   r   s     r[   r  ConnectionPool._mock  s
      	rk   c                 p   [         R                  " 5       n[        U 5      U[        '   UR	                  5       nUR	                  5       n[
        R                  R                  U[        '   [
        R                  R                  U[        '   [        U R                  5      U4[        U R                  5      U4/$ )r  )r   build_base_attributesr   r   r   r   r  rN  r   r  r6  r  r  )rY   
attributesfree_connections_attributesin_use_connections_attributess       r[   r  #ConnectionPool.get_connection_count  s     &;;=
5B45H
12&0oo&7#(2(9%   && 	$$>?   && 	&&@A
 ,,-/JK))*,IJ
 	
rP   )r  r   r  r   r\  r  r   rX  r  rV   r  r  )+ra   rb   rc   rd   r  classmethodr   rn  rh  r  r  r_   r   r   r   	frozensetr  r   r#  rv  r   r  r  r(   r  r  r  r  r  r  r   r  r  r  r#   r  r;   r  r
   r  r  r  re   rW   rP   r[   ro  ro  S  s.    ,d3i ,c , , ,` 6@)-7127 "#7. $	

<5>>
D 
 U:
2
2h	
?H2D H 
(: 
6$ .* .N . 
d5d+;&< 
rP   c            
          ^  \ rS rSrSrSS\\R                  4S\S\	\
   S\\   S\\R                     4U 4S	 jjjr\" S
/SSS9SU 4S jj5       rS\4U 4S jjrSrU =r$ )BlockingConnectionPooli  a  
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      rX  r,   r\  queue_classc                 l   > [         TU ]  " SUUS.UD6  [        R                  " 5       U l        X l        g )N)r\  rX  rW   )r  r   r   	Condition
_conditionr,   )rY   rX  r,   r\  r	  r  r   s         r[   r   BlockingConnectionPool.__init__  s>     	 	
-+	
  	

 "++-rP   rx  ry  rz  r{  c                 Z  >#    [         R                  " 5       n U R                   ISh  vN   [        U R                  5       ISh  vN   U R                  R                  U R                  5      I Sh  vN   [        U R                  5      [        U R                  5      -   n[         R                  " 5       n[        TU ]-  5       n[        U R                  5      [        U R                  5      -   nX:  n	SSS5      ISh  vN   SSS5      ISh  vN    U R                  W5      I Sh  vN   W	(       a(  [!        U [         R                  " 5       W-
  S9I Sh  vN   [#        [%        U 5      [         R                  " 5       U-
  S9I Sh  vN   U$  GNi GNN GN$ N! , ISh  vN  (       d  f       N= f N! , ISh  vN  (       d  f       N= f! [        R                   a  n
[        S5      U
eSn
A
ff = f N N Ns! [&         a    U R)                  W5      I Sh  vN    e f = f7f)z@Gets a connection from the pool, blocking until one is availableNzNo connection available.r  )r  r  )r]  r  r  rL  r,   rk  r  r6  r  r  r  r  r   r=   r8   r  r/   r0   r   rm  r  )rY   r|  r}  r~  start_time_acquiredr  r  rZ   r  r  errr   s              r[   r  %BlockingConnectionPool.get_connection  s     #nn.	G(66//2243J3JKKK),T-H-H)IC00M *& *.)9&!&!A!CJ(+D,G,G(H300L )% "3!GJ 76 '"	((4443$(%)^^%58J%J  
 .'-!%!14G!G  
 ? '6K 7666 ' ## 	G!"<=3F	G
 5
  	,,z***	s(  H+G FG F:F	F:)F5F6BF7F:FF:G F8G H ,G<-.H G>0H H H H+G F:FF:F5	$F'%F5	1F:8G :G GGG H+G G9(G44G99H+<H >H  H H( H#!H((H+rZ   c                    >#    U R                    ISh  vN   [        TU ]	  U5      I Sh  vN   U R                   R                  5         SSS5      ISh  vN   g NF N1 N	! , ISh  vN  (       d  f       g= f7f)z)Releases the connection back to the pool.N)r  r  r  notify)rY   rZ   r   s     r[   r  BlockingConnectionPool.release@  sH     ???'/*---OO""$ #??- #???sT   A;AA;A!AA!
A;AA;A!A;!A8'A*(A84A;)r  r,   rV   )ra   rb   rc   rd   r  r  r   	LifoQueuer   r   r  r   r_   Queuer   r(   r  r  re   r  r  s   @r[   r  r    s    F  "#%5?+2+<+< % 12	
 '--(   U:
(
(T%(: % %rP   r  )r   r   r  r  r   sysr]  r  r   abcr   r   	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!   r"   
auth.tokenr#   r   r$   r%   eventr&   r'   r(   r)   version_infor,   rL  $redis.asyncio.observability.recorderr-   r.   r/   r0   r1   redis.asyncio.retryr2   redis.backoffr3   redis.credentialsr4   r5   redis.exceptionsr6   r7   r8   r9   r:   r;   r<   r=   redis.observability.metricsr>   redis.typingr?   redis.utilsr@   rA   rB   rC   	_defaultsrD   rE   rF   rG   _parsersrH   rI   rJ   rK   rL   r  r  r  SYM_LFr  r]  rQ   rS   rg   r  r_   r  r  r  r9  rM  r  rO  rW  r   r  rY  rh  r  r[  rm  rn  rr  ro  r  rW   rP   r[   <module>r-     sm        
    #  "    B A  777
CJJK ' 9 F 9 z!06  & # T	 	 	 4 #    
		 E+->@SSTU U'M%M>h >D8 D 02NNO Z' Z'zG*# G*TP,J P,fZ Zz!3 0 /htn  CS"'##!$%$:$:#C GC#v+)>$>? *IU 23 2= 2j e+,1c 1hI
, I
Xe%^ e%rP   