
    )Jf                        U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZmZmZ ej        dk    rd dl m Z! nd dl!m Z! d d	l"m#Z# d d
l$m%Z% d dl&m'Z'm(Z( d dl)m*Z* d dl+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9m:Z:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@mAZA dZBdZCdZDdZEdZF G d dejG                  ZHeHjI        ZJeee@eAe?f                  eKd<   e9re?ZLne@ZL G d de'          ZM G d de'          ZNeeMeNf         ZO G d d           ZP G d! d"eP          ZQ G d# d$eQ          ZR G d% d&          ZS G d' d(eP          ZTd)ZUd*eeV         fd+ZW eeXeYeYeWeWeXeXeWd,          ZZee[ed-e\f         f         eKd.<    G d/ d0e(d12          Z]d3e[d*e]fd4Z^ ed5d67          Z_ G d8 d6          Z` G d9 d:e`          ZadS );    N)abstractmethod)chain)MappingProxyType)AnyCallableIterableListMappingOptionalSetTupleTypeTypeVarUnion)ParseResultparse_qsunquoteurlparse)      r   )timeout)Retry)	NoBackoff)Protocol	TypedDict)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                   "    e Zd Z e            ZdS )	_SentinelN)__name__
__module____qualname__objectsentinel r3   [/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/redis/asyncio/connection.pyr5   r5   B   s        vxxHHHr3   r5   DefaultParserc                       e Zd ZddZdS )ConnectCallbackProtocol
connectionAbstractConnectionc                     d S Nr;   selfr@   s     r<   __call__z ConnectCallbackProtocol.__call__Q   s    r3   Nr@   rA   r6   r7   r8   rF   r;   r3   r<   r?   r?   P   (             r3   r?   c                       e Zd ZddZdS )AsyncConnectCallbackProtocolr@   rA   c                 
   K   d S rC   r;   rD   s     r<   rF   z%AsyncConnectCallbackProtocol.__call__V   s      r3   NrG   rH   r;   r3   r<   rK   rK   U   rI   r3   rK   c            ,       D   e Zd ZdZdZdddddedddedddd	 e            dddedd
dde	e
ef         dee
         dee         dee         dede	eef         de
de
dedee         dededee
         dee
         dee
         dee
         dee         dee         dee         dee         d ee         f*d!Zd" Zed#             Zed$             Zd% Zd& Zdee         d'dfd(Zd) Zed*             Z ed'e
fd+            Z!ed,e"d'e
fd-            Z#dFd.Z$dGd/ed'dfd0Z%d1 Z&d2 Z'd3 Z(d4e)e*         d'dfd5Z+	 dHd4e	e*e
e)e*         f         d7ed'dfd8Z,d9e-d:e-d'dfd;Z.d< Z/	 	 dId6dd=d>ed?ee         d@edAee         fdBZ0d9e1d'e2e*         fdCZ3dDe)e)e1                  d'e2e*         fdEZ4dS )JrA   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*   )rN   rT   rU   rV   rX   rY   encodingencoding_errorsdecode_responsesparser_classsocket_read_sizerZ   rP   rQ   rR   rO   retryrW   encoder_classrS   r_   rN   rT   rU   rV   rX   rY   rj   rk   rl   rm   rn   rZ   rP   rQ   rR   rO   ro   rW   rp   rS   r_   c                f   |s|r|t          d          || _        || _        || _        || _        || _        || _        || _        || _        ||}|| _	        || _
        |t          u rg }|rX|                    t                     |                    t          j                   |                    t           j                   || _        |s|rX|s"t%          t'                      d          | _        nt+          j        |          | _        | j                            |           n!t%          t'                      d          | _        || _        d| _         ||||	          | _        || _        d | _        d | _        || _        |                     |
           g | _         d| _!        	 tE          |          }n/# tF          $ r
 tH          }Y ntJ          $ r tM          d          w xY w|dk     s|dk    rtM          d	          || _'        d S # |dk     s|dk    rtM          d	          || _'        w xY w)
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"   rN   rP   rQ   rR   rS   rT   rO   rU   rV   rX   SENTINELappendr%   socketr   asynciorY   r   r   ro   copydeepcopyupdate_supported_errorsrZ   r[   r]   rW   r`   ra   rf   
set_parserrc   rd   int	TypeErrorr   
ValueErrorr!   r_   )rE   rN   rT   rU   rV   rX   rY   rj   rk   rl   rm   rn   rZ   rP   rQ   rR   rO   ro   rW   rp   rS   r_   ps                          r<   __init__zAbstractConnection.__init__}   s~   2  	 	&9&E+   & &#6   ,!)%3"&<# 0X%%N 	8!!,///!!&.111!!'"6777, 		/N 		/ 2"9;;22

 "]511
J..~>>>>y{{A..DJ%:"(*$}X@PQQ"47;7;!1%%%NP"		%HAA 	% 	% 	%$AAA 	A 	A 	A!"?@@@	A 1uuA%&FGGG$DMMM 1uuA%&FGGG$DM$$$$s*   )F9 8H 9G%
H G%%H $H0c                     d                     d |                                 D                       }| j        j         d| dS )N,c              3   *   K   | ]\  }}| d | V  dS )=Nr;   ).0kvs      r<   	<genexpr>z.AbstractConnection.__repr__.<locals>.<genexpr>   s0      HHTQjjQjjHHHHHHr3   <>)joinrepr_pieces	__class__r6   )rE   	repr_argss     r<   __repr__zAbstractConnection.__repr__   sJ    HHHHT5E5E5G5GHHHII	.)88I8888r3   c                     d S rC   r;   rE   s    r<   r   zAbstractConnection.repr_pieces       r3   c                 &    | j         d uo| j        d uS rC   )r`   ra   r   s    r<   is_connectedzAbstractConnection.is_connected   s    |4'DDL,DDr3   c                 x    t          j        |          }|| j        vr| j                            |           d S d S rC   )weakref
WeakMethodrc   ru   )rE   callbackwms      r<   _register_connect_callbackz-AbstractConnection._register_connect_callback   sE    ))T,,,#**2..... -,r3   c                     	 | j                             t          j        |                     d S # t          $ r Y d S w xY wrC   )rc   remover   r   r~   )rE   r   s     r<   _deregister_connect_callbackz/AbstractConnection._deregister_connect_callback   sQ    	#**7+=h+G+GHHHHH 	 	 	DD	s   ,0 
>>returnc                 2     || j                   | _        dS )z
        Creates a new instance of parser_class with socket size:
        _socket_read_size and assigns it to the parser for the connection
        :param parser_class: The required parser class
        )rn   N)rf   rb   )rE   rm   s     r<   r{   zAbstractConnection.set_parser   s     $|T5KLLLr3   c                 T   K    j         rdS 	  j                             fd fd           d{V  n# t          j        $ r  t
          j        t          j        f$ r t          d          t          $ r'}t           
                    |                    d}~wt          $ r}t          |          |d}~ww xY w	  j        s                                  d{V  nIt          j         j                  r                                 d{V n                                 n)# t          $ r                                   d{V   w xY wd  j        D              _         j        D ]5} |            } |           }|rt%          j        |          r| d{V  6dS )z5Connects to the Redis server if not already connectedNc                  ,                                      S rC   )_connectr   s   r<   <lambda>z,AbstractConnection.connect.<locals>.<lambda>   s     r3   c                 ,                                     S rC   
disconnect)errorrE   s    r<   r   z,AbstractConnection.connect.<locals>.<lambda>   s    t7H7H r3   zTimeout connecting to serverc                 &    g | ]} |            |S r;   r;   )r   refs     r<   
<listcomp>z.AbstractConnection.connect.<locals>.<listcomp>  s#    "S"S"S3SSUU"S3"S"S"Sr3   )r   ro   call_with_retryrw   CancelledErrorrv   r   r%   OSErrorr!   _error_message	ExceptionrW   
on_connectiscoroutinefunctionr#   r   rc   inspectisawaitable)rE   eexcr   r   tasks   `     r<   connectzAbstractConnection.connect   s]      	F	0*,,'''')H)H)H)H          % 	 	 	 45 	? 	? 	?=>>> 	: 	: 	:!$"5"5a"8"8999 	0 	0 	0!#&&C/	0	* 5oo'''''''''' 8?7R+8 8 5d--d333333333..t44 	 	 	//#########	 #T"S$2I"S"S"S* 	 	CsuuH8D>>D +D11 






		 	s/   '6 AB<8"BB<'B77B< A+D, ,&Ec                 
   K   d S rC   r;   r   s    r<   r   zAbstractConnection._connect  s      r3   c                     d S rC   r;   r   s    r<   _host_errorzAbstractConnection._host_error  r   r3   	exceptionc                     d S rC   r;   )rE   r   s     r<   r   z!AbstractConnection._error_message  r   r3   c                   K   | j                             |            | j         }d}| j        s| j        s| j        r5| j        pt          | j        | j                  }|                                }|r"| j        dvrt          | j         t                    rE| 
                    t                     |j        | j         _        | j                             |            t          |          dk    r
d|d         g} | j        d| j        dg|R   d{V  |                                  d{V }|                    d          t#          | j                  k    r:|                    d	          t#          | j                  k    rt%          d
          nI|r | j        dg|R ddi d{V  	 |                                  d{V }nN# t&          $ rA |                     d|d         d           d{V  |                                  d{V }Y nw xY wt)          |          dk    rt+          d          n| j        dvrt          | j         t                    rE| 
                    t                     |j        | j         _        | j                             |            |                     d| j                   d{V  |                                  d{V }| j        r\|                     dd| j                   d{V  t)          |                                  d{V           dk    rt%          d          | j        r#|                     ddd| j                   d{V  | j        r#|                     ddd| j                   d{V  | j        r!|                     d| j                   d{V  d | j        | j        fD             D ]-}	 |                                  d{V  # t4          $ r Y *w xY w| j        r:t)          |                                  d{V           dk    rt%          d          dS dS )z=Initialize the connection, authenticate and select a databaseN)r*   2rr   defaultr   HELLOAUTHs   protoprotozInvalid RESP versioncheck_healthFrs   r   OKzInvalid Username or PasswordCLIENTSETNAMEzError setting client nameSETINFOzLIB-NAMEzLIB-VERSELECTc              3      K   | ]}||V  	d S rC   r;   )r   sents     r<   r   z0AbstractConnection.on_connect.<locals>.<genexpr>p  s'      MM4M$MMMMMMr3   zInvalid Database)rb   r   rS   rO   rT   r   get_credentialsr_   
isinstancer.   r{   r/   EXCEPTION_CLASSESlensend_commandread_responsegetr|   r!   r    r)   r   rP   rQ   rR   rN   r$   )rE   parser	auth_argscred_providerresponseauth_response_s          r<   r   zAbstractConnection.on_connect#  sV     %%%	# 	8 	8 	8( T5dmT]SS  &5577I  (	2h66$,(9:: . 1222171I.''---9~~""&	!5	#$#GT]FOYOOOOOOOOOO!//11111111H||H%%T]););;;A AT]##A$ A$ &&<===  	2#$#FKYKKKUKKKKKKKKK;&*&8&8&:&: : : : : : :7 ; ; ;
 ''	"E'RRRRRRRRR&*&8&8&:&: : : : : : :; M**d22)*HIII 3 ](**$,(9:: . 1222171I.''---##GT];;;;;;;;;!//11111111H  	C##Hi9IJJJJJJJJJ$"4"4"6"6666666774??%&ABBB = 	T##HiT]SSSSSSSSS 	V##HiDDTUUUUUUUUU7 	7##Hdg666666666 NMDM43C#DMMM 	 	A((**********     7 	:$"4"4"6"6666666774??%&8999	: 	:??s%   /G
 
AHHO33
P ?P nowaitc                 &  K   	 t          | j                  4 d{V  | j                                         | j        s	 ddd          d{V  dS 	 | j                                         |s| j                                         d{V  n# t          $ r Y nw xY wd| _	        d| _        n# d| _	        d| _        w xY w	 ddd          d{V  dS # 1 d{V swxY w Y   dS # t          j        $ r t          d| j                   dw xY w)z!Disconnects from the Redis serverNz#Timed out closing connection after )async_timeoutrV   rb   on_disconnectr   ra   closewait_closedr   r`   rw   r%   )rE   r   s     r<   r   zAbstractConnection.disconnectz  s!     	$T%@AA ( ( ( ( ( ( ( (**,,,( ( ( ( ( ( ( ( ( ( ( ( ( ( (
(L&&((( " 9"l66888888888   D $(DL#'DLL $(DL#'DL'''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( # 	 	 	Sd6QSS 	sj   C( "C C( :BB.
BB.BB.C.B>>CC( 
CC( "C#C( ((Dc                    K   |                      dd           d{V  t          |                                  d{V           dk    rt          d          dS )z Send PING, expect PONG in returnPINGFr   NPONGz#Bad response from PING health check)r   r)   r   r!   r   s    r<   
_send_pingzAbstractConnection._send_ping  sy      U;;;;;;;;;d002222222233v==!"GHHH >=r3   c                 >   K   |                                   d{V  dS )z Function to call when PING failsNr   )rE   r   s     r<   _ping_failedzAbstractConnection._ping_failed  .      oor3   c                    K   | j         r[t          j                                                    | j        k    r/| j                            | j        | j                   d{V  dS dS dS )z3Check the health of the connection with a PING/PONGN)	rZ   rw   get_running_looptimer[   ro   r   r   r   r   s    r<   r   zAbstractConnection.check_health  s~       &	Q(**//11D4JJJ*,,T_d>OPPPPPPPPPPP		Q 	QJJr3   commandc                 |   K   | j                             |           | j                                          d {V  d S rC   )ra   
writelinesdrain)rE   r   s     r<   _send_packed_commandz'AbstractConnection._send_packed_command  sH      (((l  """""""""""r3   Tr   c                   K   | j         s|                                  d {V  n|r|                                  d {V  	 t          |t                    r|                                }t          |t                    r|g}| j        r5t          j	        | 
                    |          | j                   d {V  d S | j                            |           | j                                         d {V  d S # t          j        $ r- |                     d           d {V  t          d          d t           $ rz}|                     d           d {V  t#          |j                  dk    rd|j        d         }}n|j        d         }|j        d         }t'          d| d| d	          |d }~wt(          $ r |                     d           d {V   w xY w)
NTr   zTimeout writing to socketrr   UNKNOWNr   Error z while writing to socket. .)r   r   r   r   strencodebytesrU   rw   wait_forr   ra   r   r   r%   r   r   r   argsr!   BaseException)rE   r   r   r   err_noerrmsgs         r<   send_packed_commandz&AbstractConnection.send_packed_command  s{        	&,,..         	&##%%%%%%%%%	'3'' +!..**'5)) $")" +&--g668K           ''000l((***********# 	F 	F 	F///.........:;;E 		 		 		///.........16{{a!*AF1I!DDD6DDD   	 	 	
 ///.........	s!   A;C: ?9C: :AG>A5F33+Gr   kwargsc                 |   K   |                       | j        | |                    dd                     d{V  dS )z+Pack and send a command to the Redis serverr   Tr   N)r   pack_commandr   )rE   r   r   s      r<   r   zAbstractConnection.send_command  sh      &&Dt$6::nd3S3S ' 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r3   c                    K   	 | j                                          d{V S # t          $ rO}|                     d           d{V  |                                 }t          d| d|j                   d}~ww xY w)z8Poll the socket to see if there's data that can be read.NTr   Error while reading from z: )rb   can_read_destructiver   r   r   r!   r   )rE   r   
host_errors      r<   r  z'AbstractConnection.can_read_destructive  s      	V::<<<<<<<<< 	V 	V 	V///.........))++J!"Tj"T"TAF"T"TUUU	Vs   # 
A<A
A77A<)disconnect_on_errorpush_requestdisable_decodingr   r  r  c                  K   ||n| j         }|                                 }	 |l| j        dv rct          s\t	          |          4 d{V  | j                            ||           d{V }ddd          d{V  n# 1 d{V swxY w Y   n|[t	          |          4 d{V  | j                            |           d{V }ddd          d{V  n# 1 d{V swxY w Y   nT| j        dv r*t          s#| j                            ||           d{V }n!| j                            |           d{V }n# t          j        $ r6 |Y dS |r| 	                    d           d{V  t          d|           t          $ r=}|r| 	                    d           d{V  t          d| d	|j                   d}~wt          $ r  |r| 	                    d           d{V   w xY w| j        r4t          j                                                    | j        z   }	|	| _        t%          |t&                    r|d|S )
z0Read the response from a previously sent commandN)3r   )r  r  )r  Tr   zTimeout reading from r   z : )rU   r   r_   r'   r   rb   r   rw   r%   r   r   r!   r   r   rZ   r   r   r[   r   r$   )
rE   r  r   r  r  read_timeoutr  r   r   	next_times
             r<   r   z AbstractConnection.read_response  s\      #*"5ww4;N%%''
)	(MX--) . )66        %)\%?%?)9 &@ & &            H                           )(66        %)\%?%?)9 &@ & &            H                           (**3D*!%!;!;%5L "< " "       "&!;!;%5 "< " "       # 	E 	E 	E"tt" 3ooTo222222222CzCCDDD 	W 	W 	W" 3ooTo222222222!"Uj"U"UQV"U"UVVV 	 	 	 # 3ooTo222222222	 % 	/0227799D<VVI%.D"h.. 	%$sf   'E 
#A?-E ?
B		E B	E ("C
E 
C&&E )C&*AE G59G58G-G5c           	         g }t          |d         t                    rJ t          |d         t                    rEt          |d                                                                                   |dd         z   }n<d|d         v r2t          |d                                                   |dd         z   }t                              t          t          t          |                                                    t          f          }| j        }t          | j        j        |          D ]}t          |          }t          |          |k    s||k    st          |t                    ryt                              |t          t          |                                          t          f          }|                    |           |                    |           t          }t                              |t          t          |                                          t          |t          f          }	|                    |           |S )z2Pack a series of arguments into the Redis protocolr   rr   N    )r   floatr   tupler   split	SYM_EMPTYr   SYM_STARr   SYM_CRLFrd   mapr]   
memoryview
SYM_DOLLARru   )rE   r   outputbuffbuffer_cutoffarg
arg_lengths          r<   r   zAbstractConnection.pack_command  s    d1gu-----d1gs## 	5a))//1122T!""X=DDT!W__a))DH4D~~xSYY)>)>)@)@(KLL+t|*D11 	 	C SJD		M))--c:.. . !~~:s:'='='?'?J  d###c""" ~~"J..00  	 	 	dr3   commandsc                    g }g }d}| j         }|D ]} | j        | D ]}t          |          }||k    s||k    st          |t                    r3|r-|                    t                              |                     d}g }||k    st          |t                    r|                    |           |                    |           ||z  }|r-|                    t                              |                     |S )z.Pack multiple commands into the Redis protocolr   )rd   r   r   r   r  ru   r  r   )	rE   r  r  piecesbuffer_lengthr  cmdchunkchunklens	            r<   pack_commandsz AbstractConnection.pack_commandsK  s%     + 	. 	.C**C0 . .u::!M11-//!%44 0  >innV&<&<===$%MFm++z%/L/L+MM%((((MM%(((!X-MM!.$  	2MM)..00111r3   r   N)FT)FN)5r6   r7   r8   __doc__	__slots__rt   r=   r(   r,   r   r   r|   r   r  boollistr5   r   r+   r   ConnectCallbackTr   r   r   r   r   propertyr   r   r   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r&   r	   r   r!  r;   r3   r<   rA   rA   ]   s       ::I@  "&*.26!&19'!&)6 %'(%)",%4_%6%6"&!%9='.<@"#/P% P% 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% P% P% P%d9 9 9   ^ E E XE/ / /
  MtJ'7 MD M M M M' ' 'R   ^ S    ^  #    ^U: U: U: U:n t     .I I I     Q Q Q#(5/ #d # # # #
 QU' 'UC%89'IM'	' ' ' 'R
 
s 
t 
 
 
 
V V V "'#'<
 %)',< < << %<
 "< tn< < < <|,* ,e , , , ,\hx
/C&D e      r3   rA   c                        e Zd ZdZddddddded	eeef         d
edee	eeee
f         f                  def
 fdZd Zde	fdZd ZdefdZdedefdZ xZS )
Connectionz4Manages TCP communication to and from a Redis server	localhosti  FNr   )hostportsocket_keepalivesocket_keepalive_optionssocket_typer-  r.  r/  r0  r1  c                    || _         t          |          | _        || _        |pi | _        || _         t                      j        di | d S Nr;   )r-  r|   r.  r/  r0  r1  superr   )rE   r-  r.  r/  r0  r1  r   r   s          r<   r   zConnection.__init__m  sY     	II	 0(@(FB%&""6"""""r3   c                     d| j         fd| j        fd| j        fg}| j        r|                    d| j        f           |S )Nr-  r.  rN   rP   )r-  r.  rN   rP   ru   rE   r  s     r<   r   zConnection.repr_pieces~  sL    49%	':T47OL 	=MM=$*:;<<<r3   r   c                      | j         | j        dS )Nr-  r.  r8  r   s    r<   _connection_argumentsz Connection._connection_arguments  s    	49555r3   c                   K   t          | j                  4 d{V  t          j        di |                                  d{V \  }}ddd          d{V  n# 1 d{V swxY w Y   || _        || _        |j                            d          }|r|	                    t          j        t          j        d           	 | j        rk|	                    t          j        t          j        d           | j                                        D ](\  }}|	                    t          j        ||           'dS dS # t&          t(          f$ r |                                  w xY wdS )zCreate a TCP socket connectionNrv   rr   r;   )r   rV   rw   open_connectionr9  r`   ra   	transportget_extra_info
setsockoptrv   IPPROTO_TCPTCP_NODELAYr/  
SOL_SOCKETSO_KEEPALIVEr0  itemsSOL_TCPr   r}   r   )rE   readerwritersockr   r   s         r<   r   zConnection._connect  s      !<== 	 	 	 	 	 	 	 	#*#: $ $,,..$ $      NFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ..x88 	OOF.0BAFFF( >OOF$5v7JANNN $ = C C E E > >11====> >> > Y'    		 	s   -A
A&)A&A2D9 9'E c                 $    | j          d| j         S )N:r8  r   s    r<   r   zConnection._host_error  s    )))di)))r3   r   c                     |                                  }|j        sd| dS t          |j                  dk    rd| d|j        d          dS d|j        d          d| d|j        d          dS )	NzError connecting to z. Connection reset by peerrr   . r   r   r   z connecting to )r   r   r   rE   r   r  s      r<   r   zConnection._error_message  s     %%''
~ 	 Q*PPPP  A%%L*LL	q8ILLLL(* ( (: ( (>!$( ( (r3   )r6   r7   r8   r$  r   r   r|   r&  r   r
   r   r   r   r9  r   r   r   r   __classcell__r   s   @r<   r+  r+  j  s&       ::
   $!&NR# # # # CHo	#
 # #+73c5j8I3I+J"K# # # # # # #"  6w 6 6 6 6  0*S * * * * #        r3   r+  c                       e Zd ZdZ	 	 	 	 	 	 ddee         dee         dedee         d	ee         d
ef fdZdef fdZ	e
d             Ze
d             Ze
d             Ze
d             Ze
d             Ze
d             Z xZS )SSLConnectionzManages SSL connections to and from the Redis server(s).
    This class extends the Connection class, adding SSL functionality, and making
    use of ssl.SSLContext (https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
    NrequiredFssl_keyfilessl_certfilessl_cert_reqsssl_ca_certsssl_ca_datassl_check_hostnamec                 n    t          ||||||          | _         t                      j        di | d S )N)keyfilecertfile	cert_reqsca_certsca_datacheck_hostnamer;   )RedisSSLContextr^   r4  r   )	rE   rR  rS  rT  rU  rV  rW  r   r   s	           r<   r   zSSLConnection.__init__  sS     -<!#!--
 -
 -
 	""6"""""r3   r   c                     t                                                      }| j                                        |d<   |S )Nssl)r4  r9  r^   r   )rE   r   r   s     r<   r9  z#SSLConnection._connection_arguments  s5    ..00(,,..ur3   c                     | j         j        S rC   )r^   rY  r   s    r<   rY  zSSLConnection.keyfile      ''r3   c                     | j         j        S rC   )r^   rZ  r   s    r<   rZ  zSSLConnection.certfile      ((r3   c                     | j         j        S rC   )r^   r[  r   s    r<   r[  zSSLConnection.cert_reqs  s    ))r3   c                     | j         j        S rC   )r^   r\  r   s    r<   r\  zSSLConnection.ca_certs  re  r3   c                     | j         j        S rC   )r^   r]  r   s    r<   r]  zSSLConnection.ca_data  rc  r3   c                     | j         j        S rC   )r^   r^  r   s    r<   r^  zSSLConnection.check_hostname  s    ..r3   )NNrQ  NNF)r6   r7   r8   r$  r   r   r&  r   r
   r9  r)  rY  rZ  r[  r\  r]  r^  rM  rN  s   @r<   rP  rP    sq         &*&*'&*%)#(# #c]# sm# 	#
 sm# c]# !# # # # # #(w      
 ( ( X( ) ) X) * * X* ) ) X) ( ( X( / / X/ / / / /r3   rP  c                       e Zd ZdZ	 	 	 	 	 	 ddee         dee         dee         dee         dee         d	efd
Zdej	        fdZ
dS )r_  )rY  rZ  r[  r\  r]  contextr^  NFrY  rZ  r[  r\  r]  r^  c                 :   || _         || _        |t          j        | _        n\t          |t                    rGt          j        t          j        t          j        d}||vrt          d|           ||         | _        || _
        || _        || _        d | _        d S )N)noneoptionalrQ  z+Invalid SSL Certificate Requirements Flag: )rY  rZ  ra  	CERT_NONEr[  r   r   CERT_OPTIONALCERT_REQUIREDr#   r\  r]  r^  rk  )rE   rY  rZ  r[  r\  r]  r^  	CERT_REQSs           r<   r   zRedisSSLContext.__init__  s       ]DNN	3'' 
	2-- I
 	)) M)MM   'y1DN ,15r3   r   c                 >   | j         st          j                    }| j        |_        | j        |_        | j        r(| j        r!|                    | j        | j                   | j	        s| j
        r!|                    | j	        | j
                   || _         | j         S )N)rZ  rY  )cafilecadata)rk  ra  create_default_contextr^  r[  verify_moderZ  rY  load_cert_chainr\  r]  load_verify_locations)rE   rk  s     r<   r   zRedisSSLContext.get  s    | 	#022G%)%8G""&.G} V V'''UUU} Y Y--T]4<-XXX"DL|r3   )NNNNNF)r6   r7   r8   r%  r   r   r&  r   ra  
SSLContextr   r;   r3   r<   r_  r_    s        I "&"&#'"&!%$6 6#6 3-6 C=	6
 3-6 #6 6 6 6 6:
S^ 
 
 
 
 
 
r3   r_  c                        e Zd ZdZdddef fdZdeeeeee	f         f                  fdZ
d Zdefd	Zd
edefdZ xZS )UnixDomainSocketConnectionz4Manages UDS communication to and from a Redis server pathr  c                H    || _          t                      j        di | d S r3  )r  r4  r   )rE   r  r   r   s      r<   r   z#UnixDomainSocketConnection.__init__(  s-    	""6"""""r3   r   c                 p    d| j         fd| j        fg}| j        r|                    d| j        f           |S )Nr  rN   rP   )r  rN   rP   ru   r6  s     r<   r   z&UnixDomainSocketConnection.repr_pieces,  sC    49%dg7 	=MM=$*:;<<<r3   c                   K   t          | j                  4 d {V  t          j        | j                   d {V \  }}d d d           d {V  n# 1 d {V swxY w Y   || _        || _        |                                  d {V  d S )Nr~  )r   rV   rw   open_unix_connectionr  r`   ra   r   )rE   rE  rF  s      r<   r   z#UnixDomainSocketConnection._connect2  sJ      !<== 	P 	P 	P 	P 	P 	P 	P 	P#*#?TY#O#O#OOOOOOONFF	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Poos   $A
A Ac                     | j         S rC   r~  r   s    r<   r   z&UnixDomainSocketConnection._host_error9  s
    yr3   r   c                     |                                  }t          |j                  dk    rd| d|j        d          dS d|j        d          d| d|j        d          dS )Nrr   z!Error connecting to unix socket: rK  r   r   r   z connecting to unix socket: )r   r   r   rL  s      r<   r   z)UnixDomainSocketConnection._error_message<  s     %%''
y~!##VJVV).QRBSVVV
6* 6 66 6!*!26 6 6r3   )r6   r7   r8   r$  r   r   r   r   r   r|   r   r   r   r   r   rM  rN  s   @r<   r|  r|  %  s        ::&( # # # # # # # # #XeCsCx,@&AB         S     #        r3   r|  )0FFALSENNOr   c                     | | dk    rd S t          | t                    r|                                 t          v rdS t	          |           S )Nr}  F)r   r   upperFALSE_STRINGSr&  )values    r<   to_boolr  N  sI    }t% %++--="@"@u;;r3   )rN   rU   rV   r/  rX   max_connectionsrZ   rW  .URL_QUERY_ARGUMENT_PARSERSc                   b    e Zd ZU eed<   eed<   ee         ed<   eed<   eed<   eed<   eed<   dS )	ConnectKwargsrO   rT   connection_classr-  r.  rN   r  N)r6   r7   r8   r   __annotations__r   rA   r|   r;   r3   r<   r  r  d  sX         MMMMMM-....
III
IIIGGG
IIIIIr3   r  F)totalurlc                    t          |           }i }t          |j                                                  D ]\  }}|rt	          |          dk    rnt          |d                   }t                              |          }|r8	  ||          ||<   [# t          t          f$ r t          d| d          w xY w|||<   |j
        rt          |j
                  |d<   |j        rt          |j                  |d<   |j        dk    r)|j        rt          |j                  |d<   t          |d<   n|j        d	v r|j        rt          |j                  |d
<   |j        rt#          |j                  |d<   |j        rUd|vrQ	 t#          t          |j                                      dd                    |d<   n# t&          t          f$ r Y nw xY w|j        dk    r
t(          |d<   nd}t          d| d          |S )Nr   zInvalid value for `z` in connection URL.rO   rT   unixr  r  )redisredissr-  r.  rN   /r}  r  zredis://, rediss://, unix://z5Redis URL must specify one of the following schemes ())r   r   queryrC  r   r   r  r   r}   r~   rO   rT   schemer  r|  hostnamer.  r|   replaceAttributeErrorrP  )r  parsedr   name
value_listr  r   valid_schemess           r<   	parse_urlr  n  sU   "3--FF$V\2288:: 
% 
%j 		%#j//A--JqM**E/33D99F %W#)6%==F4LL!:. W W W$%U4%U%U%UVVVW  %t 6$V_55z 6$V_55z }; 	2$V[11F6N%?!""	-	-	-? 	6$V_55F6N; 	. --F6N ; 	4v--"76;#7#7#?#?R#H#HIIt"J/    =H$$)6F%&6TMTTT
 
 	
 Ms   B%B88F; ;GG_CPConnectionPool)boundc                       e Zd ZdZedee         dedefd            Ze	dfdee
         dee         fd	Zd
 Zd ZdefdZd Zd Zd Zde
fdZde
fdZddefdZddZddZdS )r  a  
    Create a connection pool. ``If max_connections`` is set, then this
    object raises :py:class:`~redis.ConnectionError` when the pool's
    limit is reached.

    By default, TCP connections are created unless ``connection_class``
    is specified. Use :py:class:`~redis.UnixDomainSocketConnection` for
    unix sockets.

    Any additional keyword arguments are passed to the constructor of
    ``connection_class``.
    clsr  r   c                 Z    t          |          }|                    |            | di |S )a  
        Return a connection pool configured from the given URL.

        For example::

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

        Three URL schemes are supported:

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

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

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

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

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

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

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

        All querystring options are cast to their appropriate Python types.
        Boolean arguments can be specified with string values "True"/"False"
        or "Yes"/"No". Values that cannot be properly cast cause a
        ``ValueError`` to be raised. Once parsed, the querystring arguments
        and keyword arguments are passed to the ``ConnectionPool``'s
        class initializer. In the case of conflicting arguments, querystring
        arguments always win.
        r;   )r  update)r  r  r   url_optionss       r<   from_urlzConnectionPool.from_url  s4    V  nnk"""s}}V}}r3   Nr  r  c                 
   |pd}t          |t                    r|dk     rt          d          || _        || _        || _        g | _        t                      | _        | j        	                    dt                    | _        d S )Nl        r   z,"max_connections" must be a positive integerrp   )r   r|   r~   r  connection_kwargsr  _available_connectionsset_in_use_connectionsr   r,   rp   )rE   r  r  r  s       r<   r   zConnectionPool.__init__  s     *2U/3// 	M?Q3F3FKLLL 0!2.@B#<?EE !377QQr3   c                 F    | j         j         d | j        di | j        dS )Nr   r   r;   )r   r6   r  r  r   s    r<   r   zConnectionPool.__repr__  sF    ~& E E%%??(>??E E E	
r3   c                 :    g | _         t                      | _        d S rC   )r  r  r  r   s    r<   resetzConnectionPool.reset  s    &(##&55   r3   c                 J    | j         pt          | j                  | j        k     S )z;Return True if a connection can be retrieved from the pool.)r  r   r  r  r   s    r<   can_get_connectionz!ConnectionPool.can_get_connection  s+     ' D4+,,t/CC	
r3   c                   K   	 | j                                         }nQ# t          $ rD t          | j                  | j        k    rt          d          d|                                 }Y nw xY w| j                            |           	 | 	                    |           d{V  n*# t          $ r |                     |           d{V   w xY w|S )zGet a connection from the poolzToo many connectionsN)r  pop
IndexErrorr   r  r  r!   make_connectionaddensure_connectionr   release)rE   command_namekeysoptionsr@   s        r<   get_connectionzConnectionPool.get_connection  s     	0488::JJ 	0 	0 	04+,,0DDD%&<==4G--//JJJ	0 	 $$Z000	((4444444444 	 	 	,,z*********	 s    AA,+A,
B& &'Cc                     | j         }|                     |                    dd          |                    dd          |                    dd                    S )z,Return an encoder based on encoding settingsrj   rh   rk   ri   rl   F)rj   rk   rl   )r  rp   r   )rE   r   s     r<   get_encoderzConnectionPool.get_encoder  s\    '!!ZZ
G44"JJ'8(CC#ZZ(:EBB " 
 
 	
r3   c                 &     | j         di | j        S )z=Create a new connection.  Can be overridden by child classes.r;   )r  r  r   s    r<   r  zConnectionPool.make_connection   s    $t$>>t'=>>>r3   r@   c                   K   |                                  d{V  	 |                                 d{V rt          d          ddS # t          t          f$ rb |                                 d{V  |                                  d{V  |                                 d{V rt          d          dY dS w xY w)z8Ensure that the connection object is connected and validNzConnection has datazConnection not ready)r   r  r!   r   r   rD   s     r<   r  z ConnectionPool.ensure_connection$  s*       """""""""
	H4466666666 G%&;<<$FG G) 	H 	H 	H'')))))))))$$&&&&&&&&&4466666666 H%&<==4GH H H	Hs   *A
 
A/B=<B=c                 r   K   | j                             |           | j                            |           dS )z(Releases the connection back to the poolN)r  r   r  ru   rD   s     r<   r  zConnectionPool.release4  s<       	 ''
333#**:66666r3   Tinuse_connectionsc                    K   |rt          | j        | j                  }n| j        }t          j        d |D             ddi d{V }t          d |D             d          }|r|dS )z
        Disconnects connections in the pool

        If ``inuse_connections`` is True, disconnect connections that are
        current in use, potentially by other tasks. Otherwise only disconnect
        connections that are idle in the pool.
        c              3   >   K   | ]}|                                 V  d S rC   r   )r   r@   s     r<   r   z,ConnectionPool.disconnect.<locals>.<genexpr>J  s.      DD*j##%%DDDDDDr3   return_exceptionsTNc              3   D   K   | ]}t          |t                    |V  d S rC   )r   r   )r   rs     r<   r   z,ConnectionPool.disconnect.<locals>.<genexpr>M  s1      DD!z!]'C'CDADDDDDDr3   )r   r  r  rw   gathernext)rE   r  connectionsrespr   s        r<   r   zConnectionPool.disconnect;  s        	68=+T-E9 9KK 5K^DDDDD
"
 
 
 
 
 
 
 
 DDtDDDdKK 	I	 	r3   c                 >   K   |                                   d{V  dS )z-Close the pool, disconnecting all connectionsNr   r   s    r<   aclosezConnectionPool.acloseQ  r   r3   ro   r   c                 J    | j         D ]	}||_        
| j        D ]	}||_        
d S rC   )r  ro   r  )rE   ro   conns      r<   	set_retryzConnectionPool.set_retryU  sB    / 	 	DDJJ, 	 	DDJJ	 	r3   r#  r"  )ro   r   r   N)r6   r7   r8   r$  classmethodr   r  r   r  r+  rA   r   r|   r   r   r  r&  r  r  r  r  r  r  r   r  r  r;   r3   r<   r  r    s         ,d3i ,c , , , , [,` 6@)-R R12R "#R R R R$
 
 
) ) )
D 
 
 
 
  $
 
 
? ? ?H2D H H H H 7(: 7 7 7 7 $    ,            r3   c            
            e Zd ZdZddeej        fdedee         de	e
         de	ej                 f fdZ fd	Zd
e
f fdZ xZS )BlockingConnectionPoola  
    A blocking connection pool::

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

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

    The difference is that, in the event that a client tries to get a
    connection from the pool when all of connections are in use, rather than
    raising a :py:class:`~redis.ConnectionError` (as the default
    :py:class:`~redis.asyncio.ConnectionPool` implementation does), it
    makes 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                 ~     t                      j        d||d| t          j                    | _        || _        d S )N)r  r  r;   )r4  r   rw   	Condition
_conditionr   )rE   r  r   r  r  r  r   s         r<   r   zBlockingConnectionPool.__init__~  sW     	 	
-+	
 	
  	
 	
 	

 "+--r3   c                   K   	 t          | j                  4 d{V  | j        4 d{V  | j                            | j                   d{V   t                      j        |g|R i | d{V cddd          d{V  cddd          d{V  S # 1 d{V swxY w Y   	 ddd          d{V  dS # 1 d{V swxY w Y   dS # t          j        $ r}t          d          |d}~ww xY w)z@Gets a connection from the pool, blocking until one is availableNzNo connection available.)
r   r   r  r   r  r4  r  rw   r%   r!   )rE   r  r  r  errr   s        r<   r  z%BlockingConnectionPool.get_connection  s     	G$T\22 X X X X X X X X? X X X X X X X X/2243JKKKKKKKKK!7!7!Wt!W!W!Ww!W!WWWWWWWX X X X X X X X X X X X XX X X X X X X X X X X X X XX X X X X X X X X X X X X X XX X X X X X X X X X X X X X X X X X X X X X X X X X X X X X # 	G 	G 	G!"<==3F	Gsd   C B?AB5B?C 
B$	$B?'B$	(B?,C ?
C		C C	C C6!C11C6r@   c                    K   | j         4 d{V  t                                          |           d{V  | j                                          ddd          d{V  dS # 1 d{V swxY w Y   dS )z)Releases the connection back to the pool.N)r  r4  r  notify)rE   r@   r   s     r<   r  zBlockingConnectionPool.release  s	     ? 	% 	% 	% 	% 	% 	% 	% 	%''//*---------O""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   AA%%
A/2A/)r6   r7   r8   r$  r+  rw   	LifoQueuer|   r   r   rA   Queuer   r  r  rM  rN  s   @r<   r  r  \  s         F  "!#5?+2+<  # 12	
 '-(      G G G G G%(: % % % % % % % % % %r3   r  )brw   rx   enumr   rv   ra  sysr   abcr   	itertoolsr   typesr   typingr   r   r   r	   r
   r   r   r   r   r   r   urllib.parser   r   r   r   version_infor   r   redis.asyncio.retryr   redis.backoffr   redis.compatr   r   redis.connectionr   redis.credentialsr   r   redis.exceptionsr   r    r!   r"   r#   r$   r%   redis.typingr&   redis.utilsr'   r(   r)   _parsersr+   r,   r-   r.   r/   r  r  r  SYM_LFr  Enumr5   r:   rt   r  r=   r?   rK   r(  rA   r+  rP  r_  r|  r  r&  r  r|   r  r  r   r9   r  r  r  r  r  r;   r3   r<   <module>r     s        



 



              " " " " " "                          B A A A A A A A A A A A z!!0000000666666 % % % % % % # # # # # # , , , , , , , , 1 1 1 1 1 1 T T T T T T T T                  $ # # # # # H H H H H H H H H H              
		    	     E+->@SSTU U U U &'MM%M    h   
    8   
 02NNO J J J J J J J JZK K K K K# K K K\5/ 5/ 5/ 5/ 5/J 5/ 5/ 5/p2 2 2 2 2 2 2 2j# # # # #!3 # # #L /htn     CSBR"'##!$%	 	C C GC#v+)>$>?       IU    13 1= 1 1 1 1h ge+,,,t t t t t t t tn@% @% @% @% @%^ @% @% @% @% @%r3   