
    h                     :   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mZmZ d dlmZmZmZm Z  ddl!m"Z" e"rd dl#Z#d d	l#m$Z$m%Z%m&Z& ndZ#dZ%dZ$dZ&dd
l'm(Z( ddl)m*Z*m+Z+ ddl!m,Z,m-Z- ej.        dk    rd dl m/Z0 nd dl0m/Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 d dl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA d dlBmCZC d dlDmEZEmFZFmGZG ddlHmIZImJZJmKZKmLZLmMZM dZNdZOdZPdZQdZR G d dejS                  ZTeTjU        ZVeeeLeMeKf                  eWd<   eEreKZXneLZX G d d e          ZY G d! d"e          ZZeeYeZf         Z[ G d# d$          Z\ G d% d&e\          Z] G d' d(e]          Z^ G d) d*          Z_ G d+ d,e\          Z`d-Zad.eeb         fd/Zcd0 Zd eeeefefececeeeeecededefd1          Zgeehed2eif         f         eWd3<    G d4 d5ed67          Zjd8ehd.ejfd9Zk ed:d;<          Zl G d= d;          Zm G d> d?em          ZndS )@    N)abstractmethod)chain)MappingProxyType)AnyCallableIterableListMappingOptionalProtocolSetTupleType	TypedDictTypeVarUnion)ParseResultparse_qsunquoteurlparse   )SSL_AVAILABLE)
SSLContext
TLSVersionVerifyFlags)TokenInterface)!AsyncAfterConnectionReleasedEventEventDispatcher)deprecated_args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                   "    e Zd Z e            ZdS )	_SentinelN)__name__
__module____qualname__objectsentinel r<   X/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/redis/asyncio/connection.pyr>   r>   R   s        vxxHHHr<   r>   DefaultParserc                       e Zd ZddZdS )ConnectCallbackProtocol
connectionAbstractConnectionc                     d S NrD   selfrI   s     rE   __call__z ConnectCallbackProtocol.__call__a   s      r<   NrI   rJ   r?   r@   rA   rO   rD   r<   rE   rH   rH   `   s        ======r<   rH   c                       e Zd ZddZdS )AsyncConnectCallbackProtocolrI   rJ   c                 
   K   d S rL   rD   rM   s     rE   rO   z%AsyncConnectCallbackProtocol.__call__e   s
        r<   NrP   rQ   rD   r<   rE   rS   rS   d   s        CCCCCCr<   rS   c            .          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de	e
ef         dee
         dee         dee         dede	eef         de
de
dedee         dededee
         dee
         dee
         dee
         dee         dee         dee         dee         d ee         d!ee         f,d"Zefd#efd$Zd% Zd& Zed'             Zed(             Z d) Z!d* Z"dee         d+dfd,Z#d- Z$	 dUd/ed0efd1Z%d2 Z&d3 Z'ed4             Z(ed+e
fd5            Z)d6e*d+e
fd7Z+d8 Z,dVd9Z-dWd/ed+dfd:Z.dXd;ed+dfd<Z/d= Z0d> Z1d? Z2d@e3e4         d+dfdAZ5	 dWd@e	e4e
e3e4         f         d/ed+dfdBZ6dCedDed+dfdEZ7dF Z8	 	 dYd.ddGdHedIee         dJedKee         fdLZ9dCe:d+e;e4         fdMZ<dNe3e3e:                  d+e;e4         fdOZ=dP Z>dQ Z?dRe@fdSZAdT ZBdS )ZrJ   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   )rV   r\   r]   r^   r`   ra   encodingencoding_errorsdecode_responsesparser_classsocket_read_sizerb   rX   rY   rZ   rW   retryr_   encoder_classr[   rg   event_dispatcherrV   r\   r]   r^   r`   ra   rr   rs   rt   ru   rv   rb   rX   rY   rZ   rW   rw   r_   rx   r[   rg   ry   c                   |s|r|t          d          |t                      | _        n|| _        || _        || _        || _        || _        || _        || _        || _	        || _
        ||}|| _        || _        |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| _#        d | _$        d| _%        	 tM          |          }n/# tN          $ r
 tP          }Y ntR          $ r tU          d          w xY w|dk     s|d	k    rtU          d
          || _+        d S # |dk     s|d	k    rtU          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  Fzprotocol must be an integerr   r!   zprotocol must be either 2 or 3),r,   r   _event_dispatcherrV   rX   rY   rZ   r[   r\   rW   r]   r^   r`   SENTINELappendr/   socketr#   asynciora   r$   r%   rw   copydeepcopyupdate_supported_errorsrb   rc   re   r_   rh   ri   rn   
set_parserrk   rl   _re_auth_token_should_reconnectint	TypeErrorr&   
ValueErrorr+   rg   )rN   rV   r\   r]   r^   r`   ra   rr   rs   rt   ru   rv   rb   rX   rY   rZ   rW   rw   r_   rx   r[   rg   ry   ps                           rE   __init__zAbstractConnection.__init__   s   4  	 	&9&E+   #%4%6%6D""%5D"& &#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"8<!&		%HAA 	% 	% 	%$AAA 	A 	A 	A!"?@@@	A 1uuA%&FGGG$DMMM 1uuA%&FGGG$DM$$$$s*   G$ #H7 $H5H7 7HH7 7$I	_warningsc                     t          | dd           r[|                    d| t          |            	 t          j                     |                                  d S # t          $ r Y d S w xY wd S )Nri   zunclosed Connection )source)getattrwarnResourceWarningr   get_running_loop_closeRuntimeError)rN   r   s     rE   __del__zAbstractConnection.__del__   s     4D)) 
	NN/t//    (***   
	 
	s   'A 
A*)A*c                 f    | j         r)| j                                          dx| _         | _        dS dS )zR
        Internal method to silently close the connection without waiting
        N)ri   closerh   rN   s    rE   r   zAbstractConnection._close   s>     < 	/L   *..DL4<<<	/ 	/r<   c                     d                     d |                                 D                       }d| j        j         d| j        j         d| dS )N,c              3   *   K   | ]\  }}| d | V  dS )=NrD   .0kvs      rE   	<genexpr>z.AbstractConnection.__repr__.<locals>.<genexpr>   s0      HHTQjjQjjHHHHHHr<   <.(z)>)joinrepr_pieces	__class__r@   r?   )rN   	repr_argss     rE   __repr__zAbstractConnection.__repr__   sY    HHHHT5E5E5G5GHHHII	V4>,VVt~/FVVVVVVr<   c                     d S rL   rD   r   s    rE   r   zAbstractConnection.repr_pieces      r<   c                 &    | j         d uo| j        d uS rL   )rh   ri   r   s    rE   is_connectedzAbstractConnection.is_connected  s    |4'DDL,DDr<   c                 x    t          j        |          }|| j        vr| j                            |           dS dS )a^  
        Register a callback to be called when the connection is established either
        initially or reconnected.  This allows listeners to issue commands that
        are ephemeral to the connection, for example pub/sub subscription or
        key tracking.  The callback must be a _method_ and will be kept as
        a weak reference.
        N)weakref
WeakMethodrk   r   )rN   callbackwms      rE   register_connect_callbackz,AbstractConnection.register_connect_callback	  sG     ))T,,,#**2..... -,r<   c                     	 | j                             t          j        |                     dS # t          $ r Y dS w xY w)z
        De-register a previously registered callback.  It will no-longer receive
        notifications on connection events.  Calling this is not required when the
        listener goes away, since the callbacks are kept as weak methods.
        N)rk   remover   r   r   )rN   r   s     rE   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
        )rv   N)rn   rj   )rN   ru   s     rE   r   zAbstractConnection.set_parser   s     $|T5KLLLr<   c                 B   K   |                      d           d{V  dS )z5Connects to the Redis server if not already connectedTcheck_healthN)connect_check_healthr   s    rE   connectzAbstractConnection.connect(  s5      ''T':::::::::::r<   Tr   retry_socket_connectc                    K    j         rd S 	 |r( j                             fd fd           d {V  n                                  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 )Nc                  ,                                      S rL   )_connectr   s   rE   <lambda>z9AbstractConnection.connect_check_health.<locals>.<lambda>4  s    DMMOO r<   c                 ,                                     S rL   
disconnecterrorrN   s    rE   r   z9AbstractConnection.connect_check_health.<locals>.<lambda>4  s    4??;L;L r<   zTimeout connecting to serverr   c                 &    g | ]} |            |S rD   rD   )r   refs     rE   
<listcomp>z;AbstractConnection.connect_check_health.<locals>.<listcomp>T  s#    "S"S"S3SSUU"S3"S"S"Sr<   )r   rw   call_with_retryr   r   CancelledErrorr   r#   r/   OSErrorr+   _error_message	Exceptionr_   on_connect_check_healthiscoroutinefunctionr-   r   rk   inspectisawaitable)rN   r   r   eexcr   r   tasks   `       rE   r   z'AbstractConnection.connect_check_health,  s       	F	0# &j00++++-L-L-L-L          mmoo%%%%%%%% 	 	 	 45 	? 	? 	?=>>> 	: 	: 	:!$"5"5a"8"8999 	0 	0 	0!#&&C/	0	* 	222MMMMMMMMMM
 243JKK7$11$7777777770066 	 	 	//#########	 #T"S$2I"S"S"S* 	 	CsuuH8D>>D +D11 






		 	s2   AA AC"B77CCCA-E &E1c                     d| _         d S )NTr   r   s    rE   mark_for_reconnectz%AbstractConnection.mark_for_reconnect[  s    !%r<   c                     | j         S rL   r   r   s    rE   should_reconnectz#AbstractConnection.should_reconnect^  s    %%r<   c                 
   K   d S rL   rD   r   s    rE   r   zAbstractConnection._connecta  s      r<   c                     d S rL   rD   r   s    rE   _host_errorzAbstractConnection._host_errore  r   r<   	exceptionc                 F    t          |                                 |          S rL   )r    r   )rN   r   s     rE   r   z!AbstractConnection._error_messagei  s    #D$4$4$6$6	BBBr<   c                     | j         S rL   )rg   r   s    rE   get_protocolzAbstractConnection.get_protocoll  s
    }r<   c                 B   K   |                      d           d{V  dS )z=Initialize the connection, authenticate and select a databaseTr   N)r   r   s    rE   
on_connectzAbstractConnection.on_connecto  s5      ***===========r<   c                   K   | j                             |            | j         }d }| j        s| j        s| j        r;| j        pt          | j        | j                  }|                                 d {V }|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di d {V  |                                  d {V }|                    d	          t#          | j                  k    r:|                    d
          t#          | j                  k    rt%          d          nK|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 )N)r   2r{   defaultr   HELLOAUTHr   Fs   protoprotozInvalid RESP versionr|   r   OKzInvalid Username or PasswordCLIENTSETNAMEzError setting client nameSETINFOzLIB-NAMEzLIB-VERSELECTc              3      K   | ]}||V  	d S rL   rD   )r   sents     rE   r   z=AbstractConnection.on_connect_check_health.<locals>.<genexpr>  s'      MM4M$MMMMMMr<   zInvalid Database)rj   r   r[   rW   r\   r(   get_credentials_asyncrg   
isinstancer7   r   r8   EXCEPTION_CLASSESlensend_commandread_responsegetr   r+   r*   r3   r)   rX   rY   rZ   rV   r.   )rN   r   parser	auth_argscred_providerresponseauth_response_s           rE   r   z*AbstractConnection.on_connect_check_healths  s     %%%	# 	D 	D 	D( T5dmT]SS  ,AACCCCCCCCI  ,	2h66$,(9:: . 1222171I.''---9~~""&	!5	 $$#1:  IN         "//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]#VVVVVVVVV!//11111111H  	C## )	 $          $"4"4"6"6666666774??%&ABBB = 	##) $           	## ) $          7 	R##HdgL#QQQQQQQQQ 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%   8G AHH+P
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_timeoutr^   rj   on_disconnectr   ri   r   wait_closedr   rh   r   r/   )rN   r   s     rE   r   zAbstractConnection.disconnect  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   r3   r   r+   r   s    rE   
_send_pingzAbstractConnection._send_ping  sy      U;;;;;;;;;d002222222233v==!"GHHH >=r<   c                 >   K   |                                   d{V  dS )z Function to call when PING failsNr   rN   r   s     rE   _ping_failedzAbstractConnection._ping_failed  .      oor<   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)	rb   r   r   timerc   rw   r   r  r  r   s    rE   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Jr<   commandc                 |   K   | j                             |           | j                                          d {V  d S rL   )ri   
writelinesdrain)rN   r  s     rE   _send_packed_commandz'AbstractConnection._send_packed_command  sH      (((l  """""""""""r<   c                   K   | j         s|                     d           d {V  |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)NFr   T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  ri   r  r  r/   r   r   r   argsr+   BaseException)rN   r  r   r   err_noerrmsgs         rE   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?A5F44+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   )rN   r  r   s      rE   r   zAbstractConnection.send_command5  sh      &&Dt$6::nd3S3S ' 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r<   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: )rj   can_read_destructiver   r   r   r+   r  )rN   r   
host_errors      rE   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         }|                                 }	 |e| j        dv r\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   nM| j        dv r#| 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 : )r]   r   rg   r  rj   r   r   r/   r   r   r+   r  r  rb   r   r  rc   r   r.   )
rN   r)  r#   r'  r(  read_timeoutr&  r   r   	next_times
             rE   r   z AbstractConnection.read_responseD  sK      #*"5ww4;N%%''
%	'DMX,E,E(66        %)\%?%?)9 &@ & &            H                           )(66        %)\%?%?)9 &@ & &            H                           (**!%!;!;%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    D5 #A8&D5 8
BD5 BD5 !"CD5 
CD5 "C#AD5 5G'	9G'8F::-G'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   r{   N    )r   floatr  tupler  split	SYM_EMPTYr   SYM_STARr   SYM_CRLFrl   mapre   
memoryview
SYM_DOLLARr   )rN   r  outputbuffbuffer_cutoffarg
arg_lengths          rE   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r<   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   )rl   r"  r   r   r7  r   r3  r   )	rN   r>  r9  piecesbuffer_lengthr;  cmdchunkchunklens	            rE   pack_commandsz AbstractConnection.pack_commands  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r<   c                 <    t          | j        j                  dk    S )zCheck if the socket is emptyr   )r   rh   _bufferr   s    rE   _socket_is_emptyz#AbstractConnection._socket_is_empty  s    4<'((A--r<   c                    K   |                                  s2|                     d           d {V  |                                  0d S d S )NT)r(  )rH  r   r   s    rE   process_invalidation_messagesz0AbstractConnection.process_invalidation_messages  sm      '')) 	8$$$$777777777 '')) 	8 	8 	8 	8 	8r<   tokenc                     || _         d S rL   )r   )rN   rK  s     rE   set_re_auth_tokenz$AbstractConnection.set_re_auth_token  s    #r<   c                    K   | j         o|                     d| j                             d          | j                                                    d {V  |                                  d {V  d | _         d S d S Nr   oid)r   r   try_get	get_valuer   r   s    rE   re_authzAbstractConnection.re_auth  s      *###++E22#--//        
 $$&&&&&&&&&"&D +*r<   )TTr   NT)F)FN)Cr?   r@   rA   __doc__	__slots__r~   rF   r2   r5   r   r  r   r   r0  boollistr>   r   r4   r$   ConnectCallbackTr'   r   r   warningsr   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r  r  r   r   r  r  r  r   r%  r   r0   r	   r"  rE  rH  rJ  r   rM  rS  rD   r<   rE   rJ   rJ   k   s       ::I@  "&*.26!&19'!&)6 %'(%)",%4_%6%6"&!%9='.<@"#6:1X% X% X% #s(OX% 3-	X%
 !X% !)X% X% dIo.X% X% X% X% :&X% X%  %X% c]X%  3-!X%" c]#X%$ 3-%X%& 'X%( %%56)X%* G}+X%, &&89-X%. 3-/X%0 #?31X% X% X% X%t (0       / / /W W W   ^ E E XE
/ 
/ 
/	 	 	MtJ'7 MD M M M M; ; ;
 GK- - -?C- - - -^& & && & &   ^ S    ^C C# C C C C  > > > >j: j:$ j:$ j: j: j: j:X t     .I I I     Q Q Q#(5/ #d # # # #
 QU' 'UC%89'IM'	' ' ' 'R
 
s 
t 
 
 
 
V V V "'#'8
 %)',8 8 88 %8
 "8 tn8 8 8 8t,* ,e , , , ,\hx
/C&D e    <. . .8 8 8$~ $ $ $ $' ' ' ' 'r<   rJ   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 xZS )
Connectionz4Manages TCP communication to and from a Redis server	localhosti  FNr   )hostportsocket_keepalivesocket_keepalive_optionssocket_typer`  ra  rb  rc  rd  c                    || _         t          |          | _        || _        |pi | _        || _         t                      j        di | d S NrD   )r`  r   ra  rb  rc  rd  superr   )rN   r`  ra  rb  rc  rd  r   r   s          rE   r   zConnection.__init__  sY     	II	 0(@(FB%&""6"""""r<   c                     d| j         fd| j        fd| j        fg}| j        r|                    d| j        f           |S )Nr`  ra  rV   rX   )r`  ra  rV   rX   r   rN   r@  s     rE   r   zConnection.repr_pieces  sL    49%	':T47OL 	=MM=$*:;<<<r<   r   c                      | j         | j        dS )Nr`  ra  rk  r   s    rE   _connection_argumentsz Connection._connection_arguments  s    	49555r<   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 connectionNr   r{   rD   )r  r^   r   open_connectionrl  rh   ri   	transportget_extra_info
setsockoptr   IPPROTO_TCPTCP_NODELAYrb  
SOL_SOCKETSO_KEEPALIVErc  itemsSOL_TCPr   r   r   )rN   readerwritersockr   r   s         rE   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:rk  r   s    rE   r   zConnection._host_error  s    )))di)))r<   )r?   r@   rA   rV  r  r   r   rX  r   r
   r  r   r   rl  r   r   __classcell__r   s   @rE   r^  r^    s       ::
   $!&NR# # # # CHo	#
 # #+73c5j8I3I+J"K# # # # # # #"  6w 6 6 6 6  0*S * * * * * * * *r<   r^  c                       e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddee         dee         deeej        f         dee	d	                  d
ee	d	                  dee         dee         de
dee         de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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requiredTssl_keyfilessl_certfilessl_cert_reqsssl_include_verify_flagsssl.VerifyFlagsssl_exclude_verify_flagsssl_ca_certsssl_ca_datassl_check_hostnamessl_min_versionssl_ciphersc                     t           st          d          t          |||||||||	|

  
        | _         t	                      j        di | d S )N$Python wasn't built with SSL support)
keyfilecertfile	cert_reqsinclude_verify_flagsexclude_verify_flagsca_certsca_datacheck_hostnamemin_versionciphersrD   )r   r-   RedisSSLContextrf   rg  r   )rN   r  r  r  r  r  r  r  r  r  r  r   r   s               rE   r   zSSLConnection.__init__  sw      	ECDDD,;!#!9!9!-'-
 -
 -
 	""6"""""r<   r   c                     t                                                      }| j                                        |d<   |S )Nssl)rg  rl  rf   r   )rN   r   r   s     rE   rl  z#SSLConnection._connection_arguments>  s5    ..00(,,..ur<   c                     | j         j        S rL   )rf   r  r   s    rE   r  zSSLConnection.keyfileC      ''r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  zSSLConnection.certfileG      ((r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  zSSLConnection.cert_reqsK  s    ))r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  z"SSLConnection.include_verify_flagsO      44r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  z"SSLConnection.exclude_verify_flagsS  r  r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  zSSLConnection.ca_certsW  r  r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  zSSLConnection.ca_data[  r  r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  zSSLConnection.check_hostname_  s    ..r<   c                     | j         j        S rL   )rf   r  r   s    rE   r  zSSLConnection.min_versionc  s    ++r<   )
NNr  NNNNTNN)r?   r@   rA   rV  r   r  r   r  
VerifyModer	   rX  r   r   r
   rl  r\  r  r  r  r  r  r  r  r  r  r}  r~  s   @rE   r  r    s!         &*&*4>FJFJ&*%)#'04%)# #c]# sm# S#.01	#
 #+40A+B"C# #+40A+B"C# sm# c]# !# "*-# c]# # # # # #>w      
 ( ( X( ) ) X) * * X* 5 5 X5 5 5 X5 ) ) X) ( ( X( / / X/ , , X, , , , ,r<   r  c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddee         dee         deeeej        f                  dee	d                  d	ee	d                  d
ee         dee         de
dee         dee         fdZdefdZdS )r  )r  r  r  r  r  r  r  contextr  r  r  NFr  r  r  r  r  r  r  r  r  r  r  c                    t           st          d          || _        || _        |t          j        }nWt          |t                    rBt          j        t          j        t          j	        d}||vrt          d|           ||         }|| _
        || _        || _        || _        || _        | j
        t          j        k    r|nd| _        |	| _        |
| _        d | _        d S )Nr  )noneoptionalr  z+Invalid SSL Certificate Requirements Flag: F)r   r-   r  r  r  	CERT_NONEr   r  CERT_OPTIONALCERT_REQUIREDr  r  r  r  r  r  r  r  r  )rN   r  r  r  r  r  r  r  r  r  r  	CERT_REQSs               rE   r   zRedisSSLContext.__init__w  s      	ECDDD II	3'' 
	--- I
 	)) M)MM   "),I"$8!$8! "n==NN5 	 '-1r<   r   c                 .   | j         st          j                    }| j        |_        | j        |_        | j        r| j        D ]}|xj        |z  c_        | j        r| j        D ]}|xj        | z  c_        | j	        r(| j
        r!|                    | j	        | j
                   | j        s| j        r!|                    | j        | j                   | j        | j        |_        | j        |                    | j                   || _         | j         S )N)r  r  )cafilecadata)r  r  create_default_contextr  r  verify_moder  verify_flagsr  r  r  load_cert_chainr  r  load_verify_locationsr  minimum_versionr  set_ciphers)rN   r  flags      rE   r   zRedisSSLContext.get  s>   | 	#022G%)%8G""&.G( 1 5 1 1D((D0(((( 2 5 2 2D((TE1(((} V V'''UUU} Y Y--T]4<-XXX+*.*:'|'##DL111"DL|r<   )
NNNNNNNFNN)r?   r@   rA   rW  r   r  r   r  r  r	   rX  r   r   r   r   rD   r<   rE   r  r  h  s       I  "&"&:>BFBF"&!%$,0!%)2 )2#)2 3-)2 E#s~"567	)2
 't,='>?)2 't,='>?)2 3-)2 #)2 )2 j))2 #)2 )2 )2 )2VZ      r<   r  c                   x     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 xZS )
UnixDomainSocketConnectionz4Manages UDS communication to and from a Redis server pathr  c                H    || _          t                      j        di | d S rf  )r  rg  r   )rN   r  r   r   s      rE   r   z#UnixDomainSocketConnection.__init__  s-    	""6"""""r<   r   c                 p    d| j         fd| j        fg}| j        r|                    d| j        f           |S )Nr  rV   rX   )r  rV   rX   r   ri  s     rE   r   z&UnixDomainSocketConnection.repr_pieces  sC    49%dg7 	=MM=$*:;<<<r<   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  r^   r   open_unix_connectionr  rh   ri   r   )rN   rx  ry  s      rE   r   z#UnixDomainSocketConnection._connect  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 rL   r  r   s    rE   r   z&UnixDomainSocketConnection._host_error  s
    yr<   )r?   r@   rA   rV  r  r   r   r   r   r   r   r   r   r}  r~  s   @rE   r  r    s        ::&( # # # # # # # # #XeCsCx,@&AB         S        r<   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_STRINGSrX  )values    rE   to_boolr    sI    }t% %++--="@"@u;;r<   c                 T   |                      dd                               dd          }g }|                    d          D ]e}|                                }t          t          |          st          d|           |                    t          t          |                     f|S )N[r  ]r   zInvalid ssl verify flag: )replacer2  striphasattrr   r   r   r   )r  verify_flags_strr  r  s       rE   parse_ssl_verify_flagsr    s     }}S"--55c2>>L &&s++ 8 8zz||{D)) 	A???@@@GK667777r<   )rV   r]   r^   rb  r`   max_connectionsrb   r  r  r  r#   .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 )	ConnectKwargsrW   r\   connection_classr`  ra  rV   r  N)r?   r@   rA   r  __annotations__r   rJ   r   rD   r<   rE   r  r    sX         MMMMMM-....
III
IIIGGG
IIIIIr<   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.rW   r\   unixr  r  )redisredissr`  ra  rV   /r  r  zredis://, rediss://, unix://z5Redis URL must specify one of the following schemes ())r   r   queryrv  r   r   r  r   r   r   rW   r\   schemer  r  hostnamera  r   r  AttributeErrorr  )r  parsedr   name
value_listr  r   valid_schemess           rE   	parse_urlr    sW   "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%& 7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 edgdd          d$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 Zd&dZd'dZd efd!Zd"ef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.
    :py:class:`~redis.SSLConnection` can be used for SSL enabled connections.

    Any additional keyword arguments are passed to the constructor of
    ``connection_class``.
    clsr  r   c                 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.
        rD   )r  update)r  r  r   url_optionss       rE   from_urlzConnectionPool.from_urlL  s4    V  nnk"""s}}V}}r<   Nr  r  c                    |pd}t          |t                    r|dk     rt          d          || _        || _        || _        g | _        t                      | _        | j        	                    dt                    | _        t          j                    | _        | j        	                    dd           | _        | j        t!                      | _        d S d S )Nl        r   z,"max_connections" must be a positive integerrx   ry   )r   r   r   r  connection_kwargsr  _available_connectionsset_in_use_connectionsr   r5   rx   r   Lockrm   r}   r   )rN   r  r  r  s       rE   r   zConnectionPool.__init__{  s     *2U/3// 	M?Q3F3FKLLL 0!2.@B#<?EE !377QQ\^^
!%!7!;!;<NPT!U!U!)%4%6%6D""" *)r<   c                     d                     d | j                                        D                       }d| j        j         d| j        j         d| j        j         d| j        j         d| dS )Nr   c                 "    g | ]\  }}| d | S )r   rD   r   s      rE   r   z+ConnectionPool.__repr__.<locals>.<listcomp>  s&    VVVtq!1

q

VVVr<   r   r   z(<r   z)>)>)r   r  rv  r   r@   r?   r  )rN   conn_kwargss     rE   r   zConnectionPool.__repr__  s    hhVVt7M7S7S7U7UVVVWW") " "DN,C " "&1" "484I4R" "" " "	
r<   c                 D    g | _         t          j                    | _        d S rL   )r  r   WeakSetr  r   s    rE   resetzConnectionPool.reset  s     &(##*?#4#4   r<   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    rE   can_get_connectionz!ConnectionPool.can_get_connection  s+     ' D4+,,t/CC	
r<   *)Use get_connection() without args instead5.3.0args_to_warnreasonversionc                 &  K   | j         4 d {V  	 |                                 }	 |                     |           d {V  n*# t          $ r |                     |           d {V   w xY w	 d d d           d {V  n# 1 d {V swxY w Y   |S rL   )rm   get_available_connectionensure_connectionr  release)rN   command_namekeysoptionsrI   s        rE   get_connectionzConnectionPool.get_connection  sP      : 	 	 	 	 	 	 	 	:6688J,,Z8888888888    ll:......... 9		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s(   B AB 'A**B  
B
B
c                    	 | j                                         }nQ# t          $ rD t          | j                  | j        k    rt          d          d|                                 }Y nw xY w| j                            |           |S )zCGet a connection from the pool, without making sure it is connectedzToo many connectionsN)	r  pop
IndexErrorr   r  r  r+   make_connectionaddrM   s     rE   r  z'ConnectionPool.get_available_connection  s    	0488::JJ 	0 	0 	04+,,0DDD%&<==4G--//JJJ	0 	 $$Z000s    AA*)A*c                     | j         }|                     |                    dd          |                    dd          |                    dd                    S )z,Return an encoder based on encoding settingsrr   rp   rs   rq   rt   F)rr   rs   rt   )r  rx   r   )rN   r   s     rE   get_encoderzConnectionPool.get_encoder  s\    '!!ZZ
G44"JJ'8(CC#ZZ(:EBB " 
 
 	
r<   c                 &     | j         di | j        S )z=Create a new connection.  Can be overridden by child classes.rD   )r  r  r   s    rE   r  zConnectionPool.make_connection  s    $t$>>t'=>>>r<   rI   c                   K   |                                  d{V  	 |                                 d{V rt          d          ddS # t          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   r   rM   s     rE   r  z ConnectionPool.ensure_connection  s,       """""""""
	H4466666666 G%&;<<$FG Gw7 	H 	H 	H'')))))))))$$&&&&&&&&&4466666666 H%&<==4GH H H	Hs   *A
 
A5CCc                 (  K   | j                             |           |                                r|                                 d{V  | j                            |           | j                            t          |                     d{V  dS )z(Releases the connection back to the poolN)	r  r   r   r   r  r   r}   dispatch_asyncr   rM   s     rE   r  zConnectionPool.release  s       	 ''
333&&(( 	*'')))))))))#**:666$33-j99
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r<   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 rL   r   )r   rI   s     rE   r   z,ConnectionPool.disconnect.<locals>.<genexpr>  s.      DD*j##%%DDDDDDr<   return_exceptionsTNc              3   D   K   | ]}t          |t                    |V  d S rL   )r   r  )r   rs     rE   r   z,ConnectionPool.disconnect.<locals>.<genexpr>  s1      DD!z!]'C'CDADDDDDDr<   )r   r  r  r   gathernext)rN   r!  connectionsrespr   s        rE   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	 	r<   c                    K   | j         4 d{V  | j        D ]}|                                 	 ddd          d{V  dS # 1 d{V swxY w Y   dS )z<
        Mark all active connections for reconnect.
        N)rm   r  r   )rN   conns     rE   'update_active_connections_for_reconnectz6ConnectionPool.update_active_connections_for_reconnect   s       : 	* 	* 	* 	* 	* 	* 	* 	*0 * *''))))*	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   A
AAc                 >   K   |                                   d{V  dS )z-Close the pool, disconnecting all connectionsNr   r   s    rE   aclosezConnectionPool.aclose  r  r<   rw   r$   c                 J    | j         D ]	}||_        
| j        D ]	}||_        
d S rL   )r  rw   r  )rN   rw   r,  s      rE   	set_retryzConnectionPool.set_retry  sB    / 	 	DDJJ, 	 	DDJJ	 	r<   rK  c                 f   K    j         4 d {V   j        D ]Qj                            fd fd           d {V  j                            fd fd           d {V  R j        D ]                               	 d d d           d {V  d S # 1 d {V swxY w Y   d S )Nc                  |                          d                    d                                                    S rO  )r   rQ  rR  )r,  rK  s   rE   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>  s4    D--e 4 4eoo6G6G  r<   c                 .                         |           S rL   _mockr   s    rE   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>  s    $**U"3"3 r<   c                  ,                                      S rL   )r   )r,  s   rE   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>  s    D..00 r<   c                 .                         |           S rL   r5  r   s    rE   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>  s    

5@Q@Q r<   )rm   r  rw   r   r  rM  )rN   rK  r,  s   ``@rE   re_auth_callbackzConnectionPool.re_auth_callback  s     : 	. 	. 	. 	. 	. 	. 	. 	.3 	 	j00     4333	         j0000002Q2Q2Q2Q          0 . .&&u----.	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   A9B  
B*-B*r   c                 
   K   dS )z
        Dummy functions, needs to be passed as error callback to retry object.
        :param error:
        :return:
        NrD   r
  s     rE   r6  zConnectionPool._mock!  s       	r<   rL   rU  rT  )rw   r$   r   N)!r?   r@   rA   rV  classmethodr   r  r  r  r^  rJ   r   r   r   r   r  rX  r  r   r  r  r  r  r  r  r   r-  r/  r1  r   r9  r-   r6  rD   r<   rE   r  r  =  s         ,d3i ,c , , , , [,` 6@)-7 7127 "#7 7 7 7,
 
 
5 5 5
D 
 
 
 
 _U:  

 
 
 

	 	 	
 
 
? ? ?H2D H H H H 
(: 
 
 
 
 $    ,* * *          .N . . . .      r<   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 ed	gd
d          d 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
    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  rD   )rg  r   r   	Condition
_conditionr#   )rN   r  r#   r  r@  r  r   s         rE   r   zBlockingConnectionPool.__init__L  sW     	 	
-+	
 	
  	
 	
 	

 "+--r<   r  r  r	  r
  Nc                 R  K   	 | j         4 d{V  t          | j                  4 d{V  | j                             | j                   d{V  t                                                      }ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   n'# t          j        $ r}t          d          |d}~ww xY w	 | 
                    |           d{V  |S # t          $ r |                     |           d{V   w xY w)z@Gets a connection from the pool, blocking until one is availableNzNo connection available.)rC  r  r#   r  r  rg  r  r   r/   r+   r  r  r  )rN   r  r  r  rI   errr   s         rE   r  z%BlockingConnectionPool.get_connection\  s     	G D D D D D D D D(66 D D D D D D D D/2243JKKKKKKKKK!&!A!A!C!CJD D D D D D D D D D D D D D D D D D D D D D D D D D DD D D D D D D D D D D D D D D D D D D D D D D D D D D # 	G 	G 	G!"<==3F	G	((444444444 	 	 	,,z*********	sj   B: B(AB3B(
B	B(B	B(B: (
B22B: 5B26B: :C	CC"C? ?'D&rI   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)rC  rg  r  notify)rN   rI   r   s     rE   r  zBlockingConnectionPool.releases  s	     ? 	% 	% 	% 	% 	% 	% 	% 	%''//*---------O""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   AA%%
A/2A/rL   )r?   r@   rA   rV  r^  r   	LifoQueuer   r   r0  r   rJ   Queuer   r   r  r  r}  r~  s   @rE   r=  r=  *  s        F  "#%5?+2+<  % 12	
 '-(       _U:  
     
$%(: % % % % % % % % % %r<   r=  )or   r   enumr   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   r  r   r   r   
auth.tokenr   eventr   r   r   r    version_infor#   r  redis.asyncio.retryr$   redis.backoffr%   redis.connectionr&   redis.credentialsr'   r(   redis.exceptionsr)   r*   r+   r,   r-   r.   r/   redis.typingr0   redis.utilsr1   r2   r3   _parsersr4   r5   r6   r7   r8   r4  r8  r5  SYM_LFr3  Enumr>   rC   r~   r  rF   rH   rS   rZ  rJ   r^  r  r  r  r  rX  r  r  r   r0  r  r  rB   r  r  r  r  r=  rD   r<   rE   <module>r_     s        



               " " " " " "                              B A A A A A A A A A A A ! ! ! ! ! ! JJJ77777777777
CJJK ' ' ' ' ' ' F F F F F F F F 9 9 9 9 9 9 9 9 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 > > >D D D D D8 D D D 02NNO r	' r	' r	' r	' r	' r	' r	' r	'j6* 6* 6* 6* 6*# 6* 6* 6*rL, L, L, L, L,J L, L, L,^N N N N N N N Nb    !3   0 /htn       CSBR"'##!$%$:$: C C GC#v+)>$>?   "    IU    23 2= 2 2 2 2j ge+,,,j j j j j j j jZM% M% M% M% M%^ M% M% M% M% M%r<   