
    Ii                        % 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
  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#  \RH                  S	:  a  S S
K J%r&  OS S
K&J%r&  S SK'J(r(  S SK)J*r*  S SK+J,r,  S SK-J.r.J/r/  S SK0J1r1J2r2J3r3J4r4J5r5J6r6J7r7  S SK8J9r9  S SK:J;r;J<r<J=r=  SSK>J?r?J@r@JArAJBrBJCrC  SrDSrESrFSrGSrH " S S\R                  5      rJ\JR                  rL\\\B\C\A4      \MS'   \;(       a  \ArNO\BrN " S S\5      rO " S S\5      rP\\O\P4   rQ " S S 5      rR " S! S"\R5      rS " S# S$\S5      rT " S% S&5      rU " S' S(\R5      rVS)rWS*\\X   4S+ jrY\" \Z\[\[\Y\Y\Z\Z\Y\[S,.	5      r\\\]\S-\^4   4   \MS.'    " S/ S0\S1S29r_S3\]S*\_4S4 jr`\" S5S6S79ra " S8 S65      rb " S9 S:\b5      rcg);    N)abstractmethod)chain)MappingProxyType)AnyCallableIterableListMappingOptionalProtocolSetTupleType	TypedDictTypeVarUnion)ParseResultparse_qsunquoteurlparse   )format_error_message)      r   )timeout)Retry)	NoBackoff)DEFAULT_RESP_VERSION)CredentialProvider"UsernamePasswordCredentialProvider)AuthenticationError$AuthenticationWrongNumberOfArgsErrorConnectionError	DataError
RedisErrorResponseErrorTimeoutError)
EncodableT)HIREDIS_AVAILABLEget_lib_versionstr_if_bytes)
BaseParserEncoder_AsyncHiredisParser_AsyncRESP2Parser_AsyncRESP3Parser   *   $s   
   
    c                   "    \ rS rSr\" 5       rSrg)	_SentinelF    N)__name__
__module____qualname____firstlineno__objectsentinel__static_attributes__r8   r4   >/venv/lib/python3.13/site-packages/redis/asyncio/connection.pyr6   r6   F   s	    xHr4   r6   DefaultParserc                       \ rS rSrSS jrSrg)ConnectCallbackProtocolT   c                     g Nr8   self
connections     r@   __call__ ConnectCallbackProtocol.__call__U   s    #r4   r8   NrI   AbstractConnectionr9   r:   r;   r<   rJ   r?   r8   r4   r@   rC   rC   T   s    =r4   rC   c                       \ rS rSrSS jrSrg)AsyncConnectCallbackProtocolX   c                    #    g 7frF   r8   rG   s     r@   rJ   %AsyncConnectCallbackProtocol.__call__Y   s        r8   NrL   rN   r8   r4   r@   rP   rP   X   s    Cr4   rP   c            ,          \ rS rSrSrSrSSSSS\SSS\S	SSS
\" 5       SSS\	SSS.S\
\\4   S\\   S\\   S\\   S\S\
\\4   S\S\S\S\\   S\S\S\\   S\\   S\\   S\\   S\\   S\\   S\\	   S \\   S!\\   4*S" jj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#S- r$\S. 5       r%\S+\4S/ j5       r&S0\'S+\4S1 jr(SMS2 jr)SNS3\S+S4S4 jjr*S5 r+S6 r,S7 r-S8\.\/   S+S4S9 jr0 SOS8\
\/\\.\/   4   S;\S+S4S< jjr1S=\S>\S+S4S? jr2S@ r3  SPS:SSA.SB\SC\\   SD\SE\\   4SF jjjr4S=\5S+\6\/   4SG jr7SH\.\.\5      S+\6\/   4SI jr8SJ r9SK r:SLr;g)QrM   _   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__r   NFutf-8stricti   zredis-pyr   )rW   r]   r^   r_   ra   rb   encodingencoding_errorsdecode_responsesparser_classsocket_read_sizerc   rY   rZ   r[   rX   retryr`   encoder_classr\   rh   rW   r]   r^   r_   ra   rb   rs   rt   ru   rv   rw   rc   rY   rZ   r[   rX   rx   r`   ry   r\   rh   c                .   U(       d  U(       a  Ub  [        S5      eXl        Xl        Xl        Xl        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[*        R,                  " U5      U l        U R(                  R/                  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 R?                  U
5        / U l         SU l!         [E        U5      nUS:  d  US:  a  [M        S	5      eUU l'        g ! [F         a	    [H        n N1[J         a    [M        S5      ef = f! WS:  d  US:  a  [M        S	5      eUU l'        f = f)
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  zprotocol must be an integerr   r   zprotocol must be either 2 or 3)(r$   rW   rY   rZ   r[   r\   r]   rX   r^   r_   ra   SENTINELappendr'   socketr   asynciorb   r   r   rx   copydeepcopyupdate_supported_errorsrc   rd   rf   r`   ri   rj   ro   
set_parserrl   rm   int	TypeErrorr   
ValueErrorr#   rh   )rH   rW   r]   r^   r_   ra   rb   rs   rt   ru   rv   rw   rc   rY   rZ   r[   rX   rx   r`   ry   r\   rh   ps                          r@   __init__AbstractConnection.__init__   s   2 &9&E+  & &#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"		%HA 1uA%&FGG$DM  	%$A 	A!"?@@	A 1uA%&FGG$DMs$    G
 
G1G4 G11G4 4 H	_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)Nrj   zunclosed Connection )source)getattrwarnResourceWarningr   get_running_loop_closeRuntimeError)rH   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)rj   closeri   rH   s    r@   r   AbstractConnection._close   s.     <<LL *..DL4< r4   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)=Nr8   ).0kvs      r@   	<genexpr>.AbstractConnection.__repr__.<locals>.<genexpr>   s     H5GTQ1QCj5Gs   <.()>)joinrepr_pieces	__class__r:   r9   )rH   	repr_argss     r@   __repr__AbstractConnection.__repr__   sQ    HHHT5E5E5GHI	4>>,,-Qt~~/F/F.GqSUVVr4   c                     g rF   r8   r   s    r@   r   AbstractConnection.repr_pieces       r4   c                 H    U R                   S L=(       a    U R                  S L$ rF   )ri   rj   r   s    r@   is_connectedAbstractConnection.is_connected   s    ||4'DDLL,DDr4   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
WeakMethodrl   r~   )rH   callbackwms      r@   register_connect_callback,AbstractConnection.register_connect_callback   s9     ),,,##**2. -r4   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)rl   remover   r   r   )rH   r   s     r@   deregister_connect_callback.AbstractConnection.deregister_connect_callback  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
)rw   N)ro   rk   )rH   rv   s     r@   r   AbstractConnection.set_parser  s     $T5K5KLr4   c                    ^ #    T R                   (       a  g T R                  R                  U 4S jU 4S j5      I Sh  vN    T R                  (       d  T R                  5       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  o3" 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! [        R                   a    e [
        R                  [        R                  4 a    [        S5      e[         a  n[        T R                  U5      5      eSnAf[         a  n[        U5      UeSnAff = f GNa GN%! [         a    T R!                  5       I Sh  vN    e f = fs  snf  N7f)z5Connects to the Redis server if not already connectedNc                  $   > T R                  5       $ rF   )_connectr   s   r@   <lambda>,AbstractConnection.connect.<locals>.<lambda>  s    r4   c                 $   > TR                  5       $ rF   
disconnect)errorrH   s    r@   r   r     s    t7Hr4   zTimeout connecting to server)r   rx   call_with_retryr   CancelledErrorr   r   r'   OSErrorr#   _error_message	Exceptionr`   
on_connectiscoroutinefunctionr%   r   rl   inspectisawaitable)rH   eexcrefr   tasks   `     r@   connectAbstractConnection.connect  s    	0**,,')H  	**oo'''
 2243J3JKK 11$777006 372I2I"S2I3SU32I"S**CuHD>Dt++D11

	 +A %% 	 4 45 	?=>> 	:!$"5"5a"899 	0!#&C/	0 ( 8  	//###	 #T
 s   G>'E D?E $G (G	)G -G>.9G 'G(G =G>G7G7$+G>G>0G>5G<6	G>?E AGF((G5GGG>	G G G4,G/-G44	G>c                    #    g 7frF   r8   r   s    r@   r   AbstractConnection._connect?  s     rT   c                     g rF   r8   r   s    r@   _host_errorAbstractConnection._host_errorC  r   r4   	exceptionc                 6    [        U R                  5       U5      $ rF   )r   r   )rH   r   s     r@   r   !AbstractConnection._error_messageG  s    #D$4$4$6	BBr4   c                 	  #    U R                   R                  U 5        U R                   nSnU R                  (       d"  U R                  (       d  U R                  (       aC  U R                  =(       d     [        U R                  U R                  5      nUR                  5       nU(       Ga-  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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                  5      I Sh  vN   U R                  5       I Sh  vN nU R,                  (       aU  U R                  SSU R,                  5      I Sh  vN   [)        U R                  5       I Sh  vN 5      S:w  a  [%        S5      eU R.                  (       a&  U R                  SSSU R.                  5      I Sh  vN   U R0                  (       a&  U R                  SSSU R0                  5      I Sh  vN   U R2                  (       a$  U R                  SU R2                  5      I Sh  vN   S U R.                  U R0                  4 5        H  n U R                  5       I Sh  vN   M     U R2                  (       a1  [)        U R                  5       I Sh  vN 5      S:w  a  [%        S5      egg GN GN GN GNj! [&         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N GN GN GN GNR GN N N! [4         a     M  f = f N7f)z=Initialize the connection, authenticate and select a databaseN)r   2r{   defaultr   HELLOAUTHs   protoprotozInvalid RESP versioncheck_healthFr|   r   OKzInvalid Username or PasswordCLIENTSETNAMEzError setting client nameSETINFOzLIB-NAMEzLIB-VERSELECTc              3   6   #    U  H  o(       d  M  Uv   M     g 7frF   r8   )r   sents     r@   r   0AbstractConnection.on_connect.<locals>.<genexpr>  s     M#D4$$#Ds   
	zInvalid Database)rk   r   r\   rX   r]   r    get_credentialsrh   
isinstancer/   r   r0   EXCEPTION_CLASSESlensend_commandread_responsegetr   r#   r"   r+   r!   rY   rZ   r[   rW   r&   )rH   parser	auth_argscred_providerresponseauth_response_s          r@   r   AbstractConnection.on_connectJ  s    %	##(( T5dmmT]]S  &557I h6$,,(9:: 12171I1I.''-9~"&	!5	##GT]]FOYOOO!//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]];;;!//11H ##Hi9I9IJJJ$"4"4"6674?%&ABB ==##HiT]]SSS##HiDDTDTUUU77##Hdgg666 NDMM43C3C#DMA((*** N 77$"4"4"6674?%&899 @ y P1 L !;7 ;
 ''	"E'RRR&*&8&8&: : :;$ <1 K6
 TU 7
 +   7sA  ES-Q1S-5Q46BS-7Q78S-=Q= Q:Q= B4S-	S
S-!S"5S-S
S-4S5A	S->S?6S-5S64S-*S+&S-S%S&S*-S-S+S-4S-7S-:Q= =!SR!S7R:8S=S- SS-S-
S-S-S-S-S-S
S($S-'S((S-nowaitc                 t  #     [        U R                  5       ISh  vN   U R                  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   g N Nj N'! [         a     N1f = f! SU l	        SU l        f = f N.! , ISh  vN  (       d  f       g= f! [        R                   a    [        SU R                   35      Sef = f7f)z!Disconnects from the Redis serverNz#Timed out closing connection after )async_timeoutr_   rk   on_disconnectr   rj   r   wait_closedr   ri   r   r'   )rH   r   s     r@   r   AbstractConnection.disconnect  s     	$T%@%@AA**,(( BAA
(LL&&( ""ll66888 $(DL#'DL BAA 9  $(DL#'DL BAAA ## 	5d6Q6Q5RS	s   D8D CD -C-D CD D8 >CCC#C-1D <C+=D D8D D C
CCCCC((C-+D -D3C64D D D8D .D55D8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)r   r+   r   r#   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                  5       I Sh  vN   g N7f)z Function to call when PING failsNr   )rH   r   s     r@   _ping_failedAbstractConnection._ping_failed       oo   c                   #    U R                   (       ak  [        R                  " 5       R                  5       U R                  :  a9  U R
                  R                  U R                  U R                  5      I Sh  vN   ggg N7f)z3Check the health of the connection with a PING/PONGN)	rc   r   r   timerd   rx   r   r  r  r   s    r@   r   AbstractConnection.check_health  se      &&((*//1D4J4JJ**,,T__d>O>OPPP K ' Qs   A6B8B 9Bcommandc                    #    U R                   R                  U5        U R                   R                  5       I S h  vN   g  N7frF   )rj   
writelinesdrain)rH   r  s     r@   _send_packed_command'AbstractConnection._send_packed_command  s-     (ll  """s   9AAATr   c                   #    U R                   (       d  U R                  5       I S h  vN   O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)
NTr   zTimeout writing to socketr{   UNKNOWNr   zError z while writing to socket. r   )r   r   r   r   strencodebytesr^   r   wait_forr  rj   r  r  r'   r   r   r   argsr#   BaseException)rH   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   %G8DG8DG8BD DD G88D DD G8G8D D &G5 EG5G-E0.A GG5-G0.G55G8r  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)r#  pack_commandr   )rH   r  r%  s      r@   r   AbstractConnection.send_command  s=     &&t$6::nd3S ' 
 	
 	
s   1;9;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)z8Poll the socket to see if there's data that can be read.NTr  Error while reading from z: )rk   can_read_destructiver   r   r   r#   r  )rH   r   
host_errors      r@   r+  'AbstractConnection.can_read_destructive  st     	V::<<<< 	V///...))+J!$=j\AFF8"TUU	Vs<   A=( &( A=( 
A:A5A0A55A::A=)disconnect_on_errorpush_requestdisable_decodingr   r.  r/  c                ,  #    Ub  UOU R                   nU R                  5       n Uba  U R                  S;   aQ  [        (       dF  [	        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   O_U R                  S;   a-  [        (       d"  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N@ 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)
z0Read the response from a previously sent commandN)3r   )r0  r/  )r0  Tr  zTimeout reading from r*  z : )r^   r   rh   r)   r  rk   r   r   r'   r   r   r#   r  r   rc   r   r  rd   r   r&   )
rH   r0  r   r.  r/  read_timeoutr,  r   r   	next_times
             r@   r    AbstractConnection.read_response  sJ     #*"5w4;N;N%%'
)	(MMX-))(66%)\\%?%?)9 &@ &  H 766 )(66%)\\%?%?)9 &@ &  H 766 (*3D3D!%!;!;%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  "J-G FG F3F4F8G FG J	G F5G F<<F8=F<G F:G J7G 	G
G JG +G,G 0A"JG FG F2!F$"F2.G 1J2G 8F<:G <GGGG JG G J1J3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    )r   floatr  tupler  split	SYM_EMPTYr   SYM_STARr   SYM_CRLFrm   maprf   
memoryview
SYM_DOLLARr~   )rH   r  outputbuffbuffer_cutoffarg
arg_lengths          r@   r'  AbstractConnection.pack_commandD  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r4   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   )rm   r'  r   r   r?  r~   r;  r   )	rH   rG  rA  piecesbuffer_lengthrC  cmdchunkchunklens	            r@   pack_commands AbstractConnection.pack_commandsr  s      ++C**C0u:!1/!%44innV&<=$%MF+z%/L/LMM%(MM%(!-M! 1 & MM)..01r4   c                 F    [        U R                  R                  5      S:H  $ )zCheck if the socket is emptyr   )r   ri   _bufferr   s    r@   _socket_is_empty#AbstractConnection._socket_is_empty  s    4<<''(A--r4   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/  )rR  r   r   s    r@   process_invalidation_messages0AbstractConnection.process_invalidation_messages  s?     ''))$$$$777 ''))7s   (A
AA
A
)rm   rl   rk   ri   ro   rj   rY   r\   rW   rf   rc   rZ   r[   rd   r]   rh   r`   rx   rb   ra   r_   r^   rX   r   N)FT)FN)<r9   r:   r;   r<   __doc__	__slots__r}   rA   r*   r-   r   r  r   r   r8  boollistr6   r   r,   r   ConnectCallbackTr   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'  rN  rR  rU  r?   r8   r4   r@   rM   rM   _   sb   :I@  "&*.26!&19'!&)6 %'(%)",%4%6"&!%9='.<@"#/P% #s(OP% 3-	P%
 !P% !)P% P% dIo.P% P% P% P% :&P% P%  %P% c]P%  3-!P%" c]#P%$ 3-%P%& 'P%( %%56)P%* G}+P%, &&89-P%. 3-/P%d (0   /W   E E
/	MtJ'7 MD M)V   S  C C# CU:nt  .I Q#(5/ #d #
 QU'UC%89'IM'	'R
 
s 
t 
V "'#'<
 %)',<< %<
 "< tn<|,* ,e ,\hx
/C&D e <.8r4   rM   c                      ^  \ rS rSrSrSSSSSS.S	\S
\\\4   S\S\	\
\\\\4   4      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  FNr   )hostportsocket_keepalivesocket_keepalive_optionssocket_typerc  rd  re  rf  rg  c                   > Xl         [        U5      U l        X0l        U=(       d    0 U l        XPl        [        TU ]  " S0 UD6  g Nr8   )rc  r   rd  re  rf  rg  superr   )rH   rc  rd  re  rf  rg  r%  r   s          r@   r   Connection.__init__  s>     	I	 0(@(FB%&"6"r4   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$ )Nrc  rd  rW   rY   )rc  rd  rW   rY   r~   rH   rI  s     r@   r   Connection.repr_pieces  sM    499%		':T477OLMM=$*:*:;<r4   r   c                 4    U R                   U R                  S.$ )Nrc  rd  rp  r   s    r@   _connection_arguments Connection._connection_arguments  s    		49955r4   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{   r8   )r  r_   r   open_connectionrq  ri   rj   	transportget_extra_info
setsockoptr   IPPROTO_TCPTCP_NODELAYre  
SOL_SOCKETSO_KEEPALIVErf  itemsSOL_TCPr   r   r   )rH   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:rp  r   s    r@   r   Connection._host_error  s    ))Adii[))r4   )ri   rj   rc  rd  re  rf  rg  )r9   r:   r;   r<   rY  r  r   r   r[  r   r
   r  r   r   rq  r   r   r?   __classcell__r   s   @r@   ra  ra    s    :
   $!&NR# # CHo	#
 # #+73c5j8I3I+J"K# # #"6w 60*S * *r4   ra  c                      ^  \ rS rSrSr        SS\\   S\\   S\S\\   S\\   S\S	\\R                     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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_ca_certsssl_ca_datassl_check_hostnamessl_min_versionssl_ciphersc	                 P   > [        UUUUUUUUS9U l        [        T
U ]  " S0 U	D6  g )N)keyfilecertfile	cert_reqsca_certsca_datacheck_hostnamemin_versionciphersr8   )RedisSSLContextrg   rj  r   )rH   r  r  r  r  r  r  r  r  r%  r   s             r@   r   SSLConnection.__init__  s<     -<!#!-'	-
 	"6"r4   r   c                 ^   > [         TU ]  5       nU R                  R                  5       US'   U$ )Nssl)rj  rq  rg   r   )rH   r%  r   s     r@   rq  #SSLConnection._connection_arguments  s-    .0((,,.ur4   c                 .    U R                   R                  $ rF   )rg   r  r   s    r@   r  SSLConnection.keyfile      '''r4   c                 .    U R                   R                  $ rF   )rg   r  r   s    r@   r  SSLConnection.certfile      (((r4   c                 .    U R                   R                  $ rF   )rg   r  r   s    r@   r  SSLConnection.cert_reqs  s    )))r4   c                 .    U R                   R                  $ rF   )rg   r  r   s    r@   r  SSLConnection.ca_certs  r  r4   c                 .    U R                   R                  $ rF   )rg   r  r   s    r@   r  SSLConnection.ca_data  r  r4   c                 .    U R                   R                  $ rF   )rg   r  r   s    r@   r  SSLConnection.check_hostname	  s    ...r4   c                 .    U R                   R                  $ rF   )rg   r  r   s    r@   r  SSLConnection.min_version  s    +++r4   )rg   )NNrequiredNNFNN)r9   r:   r;   r<   rY  r   r  r[  r  
TLSVersionr   r
   rq  r_  r  r  r  r  r  r  r  r?   r  r  s   @r@   r  r    s/    &*&*'&*%)#(48%)#c]# sm# 	#
 sm# c]# !# "#..1# c]# #0w 
 ( ( ) ) * * ) ) ( ( / / , ,r4   r  c                       \ rS rSrSr        SS\\   S\\   S\\   S\\   S\\   S	\S
\\R                     S\\   4S jjr
S\R                  4S jrSrg)r  i  )	r  r  r  r  r  contextr  r  r  Nr  r  r  r  r  r  r  r  c	                 Z   Xl         X l        Uc  [        R                  U l        Oa[        U[        5      (       aL  [        R                  [        R                  [        R                  S.n	X9;  a  [        SU 35      eX   U l        X@l
        XPl        X`l        Xpl        Xl        S U l        g )N)noneoptionalr  z+Invalid SSL Certificate Requirements Flag: )r  r  r  	CERT_NONEr  r   r  CERT_OPTIONALCERT_REQUIREDr%   r  r  r  r  r  r  )
rH   r  r  r  r  r  r  r  r  	CERT_REQSs
             r@   r   RedisSSLContext.__init__  s       ]]DN	3''----I
 ) A)M  '1DN ,&15r4   r   c                 \   U R                   (       Gd  [        R                  " 5       nU R                  Ul        U R                  Ul        U R                  (       a5  U R                  (       a$  UR                  U R                  U R                  S9  U R                  (       d  U R                  (       a$  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  )cafilecadata)r  r  create_default_contextr  r  verify_moder  r  load_cert_chainr  r  load_verify_locationsr  minimum_versionr  set_ciphers)rH   r  s     r@   r   RedisSSLContext.get@  s    |||002G%)%8%8G""&..G}}'''U}}--T]]4<<-X+*.*:*:'||'##DLL1"L||r4   )	r  r  r  r  r  r  r  r  r  )NNNNNFNN)r9   r:   r;   r<   rZ  r   r  r[  r  r  r   
SSLContextr   r?   r8   r4   r@   r  r    s    
I "&"&#'"&!%$04!%6#6 3-6 C=	6
 3-6 #6 6 cnn-6 #6BS^^ r4   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$ )UnixDomainSocketConnectioniQ  z4Manages UDS communication to and from a Redis server pathr  c                2   > Xl         [        TU ]  " S0 UD6  g ri  )r  rj  r   )rH   r  r%  r   s      r@   r   #UnixDomainSocketConnection.__init__T  s    	"6"r4   r   c                     SU R                   4SU R                  4/nU R                  (       a  UR                  SU R                  45        U$ )Nr  rW   rY   )r  rW   rY   r~   rm  s     r@   r   &UnixDomainSocketConnection.repr_piecesX  sB    499%dgg7MM=$*:*:;<r4   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  )r  r_   r   open_unix_connectionr  ri   rj   r   )rH   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                   $ rF   r  r   s    r@   r   &UnixDomainSocketConnection._host_errore  s    yyr4   )ri   rj   r  )r9   r:   r;   r<   rY  r  r   r   r   r   r   r   r   r   r?   r  r  s   @r@   r  r  Q  sS    :&( # # #XeCsCx,@&AB  S  r4   r  )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)r   r  upperFALSE_STRINGSr[  )values    r@   to_boolr  l  s7    }%%++-="@;r4   )	rW   r^   r_   re  ra   max_connectionsrc   r  r   .URL_QUERY_ARGUMENT_PARSERSc                   b    \ rS rSr% \\S'   \\S'   \\   \S'   \\S'   \\S'   \\S'   \\S'   S	r	g
)ConnectKwargsi  rX   r]   connection_classrc  rd  rW   r  r8   N)
r9   r:   r;   r<   r  __annotations__r   rM   r   r?   r8   r4   r@   r  r    s,    MM-..
I
IG
Ir4   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.rX   r]   unixr  r  )redisredissrc  rd  rW   /r  r  zredis://, rediss://, unix://z5Redis URL must specify one of the following schemes ())r   r   queryr|  r   r   r  r   r   r   rX   r]   schemer  r  hostnamerd  r   replaceAttributeErrorr  )r  parsedr%  name
value_listr  r   valid_schemess           r@   	parse_urlr    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%?!"0 M- 
-	-??$V__5F6N;; -F6N ;;4v-"76;;#7#?#?R#HIt ==H$)6F%& M 7CM?RST
 	
E ":. W$':4&@T%UVVW6 #J/ s   ;
G<1H < HH21H2_CPConnectionPool)boundc                       \ rS rSrSr\S\\   S\S\4S j5       r	\
S4S\\   S	\\   4S
 jjrS rS rS\4S jrS 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S jrSS jrSrg)r  i  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.

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.
r8   )r  update)r  r  r%  url_optionss       r@   from_urlConnectionPool.from_url  s&    V  nk"}V}r4   Nr  r  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        g )Nl        r   z,"max_connections" must be a positive integerry   )r   r   r   r  connection_kwargsr  _available_connectionsset_in_use_connectionsr   r-   ry   )rH   r  r  r  s       r@   r   ConnectionPool.__init__  sm     *2U/3//?Q3FKLL 0!2.@B#<?E !3377Qr4   c           
          SU R                   R                   SU R                   R                   SU R                  " S0 U R                  D6< S3$ )Nr   r   r   r   r8   )r   r:   r9   r  r  r   s    r@   r   ConnectionPool.__repr__  sN    ))*!DNN,C,C+D%%?(>(>?B"F	
r4   c                 F    / U l         [        R                  " 5       U l        g rF   )r  r   WeakSetr  r   s    r@   resetConnectionPool.reset  s    &(##*??#4 r4   c                 l    U R                   =(       d"    [        U R                  5      U R                  :  $ )z;Return True if a connection can be retrieved from the pool.)r  r   r  r  r   s    r@   can_get_connection!ConnectionPool.can_get_connection  s1     '' D4++,t/C/CC	
r4   c                    #    U R                  5       n U R                  U5      I Sh  vN   U$  N! [         a    U R                  U5      I Sh  vN    e f = f7f)z(Get a connected connection from the poolN)get_available_connectionensure_connectionr   release)rH   command_namekeysoptionsrI   s        r@   get_connectionConnectionPool.get_connection$  s\     224
	((444
  5 	,,z***	s1   A1 /1 A1 AAAA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
IndexErrorr   r  r  r#   make_connectionaddrG   s     r@   r  'ConnectionPool.get_available_connection/  s}    	04488:J
 	  $$Z0  	04++,0D0DD%&<=4G--/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 settingsrs   rq   rt   rr   ru   F)rs   rt   ru   )r  ry   r   )rH   r%  s     r@   get_encoderConnectionPool.get_encoder:  sQ    ''!!ZZ
G4"JJ'8(C#ZZ(:EB " 
 	
r4   c                 :    U R                   " S0 U R                  D6$ )z=Create a new connection.  Can be overridden by child classes.r8   )r  r  r   s    r@   r  ConnectionPool.make_connectionC  s    $$>t'='=>>r4   rI   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+  r#   r   r   rG   s     r@   r   ConnectionPool.ensure_connectionG  s       """
	H44666%&;<$F 7 	# 7) 	H'')))$$&&&44666%&<=4G 7	Hsf   B<AB<A
 AA
 B<A
 
#B9-A0.B9B	B9B" B96B<8B99B<c                 x   #    U R                   R                  U5        U R                  R                  U5        g7f)z(Releases the connection back to the poolN)r  r   r  r~   rG   s     r@   r  ConnectionPool.releaseW  s/      	  ''
3##**:6s   8:inuse_connectionsc                    #    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rF   r   )r   rI   s     r@   r   ,ConnectionPool.disconnect.<locals>.<genexpr>m  s     D*##%%s   return_exceptionsTNc              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7frF   )r   r   )r   rs     r@   r   r*  p  s     Dt!z!]'CAAts   (	()r   r  r  r   gathernext)rH   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                  5       I Sh  vN   g N7f)z-Close the pool, disconnecting all connectionsNr   r   s    r@   acloseConnectionPool.acloset  r  r  c                 h    U R                    H	  nXl        M     U R                   H	  nXl        M     g rF   )r  rx   r  )rH   rx   conns      r@   	set_retryConnectionPool.set_retryx  s,    //DJ 0,,DJ -r4   )r  r  r  r  ry   r  rX  rW  )rx   r   r   N)r9   r:   r;   r<   rY  classmethodr   r  r  r  ra  rM   r   r   r   r   r
  r[  r  r  r  r  r  r  r  r   r4  r8  r?   r8   r4   r@   r  r    s     ,d3i ,c , , ,` 6@)-R12R "#R$
5
D 
		
?H2D H 7(: 7$ , r4   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U 4S
 j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      r  r   r  queue_classc                 l   > [         TU ]  " SUUS.UD6  [        R                  " 5       U l        X l        g )N)r  r  r8   )rj  r   r   	Condition
_conditionr   )rH   r  r   r  r?  r  r   s         r@   r   BlockingConnectionPool.__init__  s>     	 	
-+	
  	

 "++-r4   c                   >#     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   [
        TU ]  5       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   U$  N N} NR N6! , ISh  vN  (       d  f       NK= f NB! , ISh  vN  (       d  f       NW= f! [        R                   a  n[        S5      UeSnAff = f Nl! [         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.)rB  r  r   r  r  rj  r  r   r'   r#   r  r   r  )rH   r  r  r  rI   errr   s         r@   r  %BlockingConnectionPool.get_connection  s     	G(66//2243J3JKKK!&!A!CJ 76 '	((444 '6K 7666 ' ## 	G!"<=3F	G
 5 	,,z***	s   E C- B/C- CB1C)B7 B3!B73C>B5?CC- CC- D (D)D .E /C- 1C3B75C7C	=C >C	
CC- C*CC*&C- )E *C- -DDDE D D=5D86D==E rI   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)rB  rj  r  notify)rH   rI   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;)rB  r   )r9   r:   r;   r<   rY  ra  r   	LifoQueuer   r   r   rM   Queuer   r  r  r?   r  r  s   @r@   r<  r<    sw    F  "!#5?+2+<+< # 12	
 '--(  $%(: % %r4   r<  )dr   r   enumr   r   r  sysr^  r   abcr   	itertoolsr   typesr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   urllib.parser   r   r   r   utilsr   version_infor   r  redis.asyncio.retryr   redis.backoffr   redis.connectionr   redis.credentialsr   r    redis.exceptionsr!   r"   r#   r$   r%   r&   r'   redis.typingr(   redis.utilsr)   r*   r+   _parsersr,   r-   r.   r/   r0   r<  r@  r=  SYM_LFr;  Enumr6   r>   r}   r  rA   rC   rP   r]  rM   ra  r  r  r  r  r[  r  r   r8  r  r  r=   r  r  r  r  r<  r8   r4   r@   <module>r_     s        
 
     "    B A ( z!06 % # 1 T   $ H H  
				   E+->@SSTU U'M%M>h >D8 D 02NNO w8 w8t6*# 6*r=,J =,@< <~!3 0 /htn  CS"'##!$%
C GC#v+)>$>? IU 13 1= 1h e+,x xvH%^ H%r4   