
     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 d dlmZ d dlmZmZ d dlmZmZmZ d d	lmZ d d
lmZ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+m,Z,m-Z- d dl.m/Z/ d dl0m1Z1m2Z2m3Z3m4Z4 	 d dl5Z5dZ6n# e7$ r dZ6Y nw xY we8ej9        iZ:e6r+ e;e5d          rde:e5j<        <   de:e5j=        <   n
de:e5j>        <    e?e:@                                          ZAe2rd dlBZBdZCdZDdZEdZFdZG eH            ZIdZJdZKdZLdZMeedZN G d d          ZO G d d          ZP G d  d!          ZQ G d" d#eP          ZR G d$ d%eP          ZSePeTd&<   e2reSZUneRZU G d' d(          ZV G d) d*          ZW G d+ d,          ZX G d- d.eX          ZY G d/ d0eY          ZZ G d1 d2eX          Z[d3Z\d4 Z]e^e_e_e]e]e`e^e^e]d5	Zad6 Zb G d7 d8          Zc G d9 d:ec          ZddS );    N)abstractmethod)SEEK_END)chain)EmptyFull	LifoQueue)time)OptionalUnion)parse_qsunquoteurlparse)	NoBackoff)CredentialProvider"UsernamePasswordCredentialProvider)AuthenticationError$AuthenticationWrongNumberOfArgsErrorBusyLoadingErrorChildDeadlockedErrorConnectionError	DataErrorExecAbortErrorInvalidResponseModuleErrorNoPermissionErrorNoScriptErrorReadOnlyError
RedisErrorResponseErrorTimeoutError)Retry)CRYPTOGRAPHY_AVAILABLEHIREDIS_AVAILABLEHIREDIS_PACK_AVAILABLEstr_if_bytesTFSSLWantReadError      *   $s   
    zConnection closed by server.z:Error loading the extension. Please check the server logs.z5Error unloading module: no such module with that namez/Error unloading module: operation not possible.z[Error unloading module: the module exports one or more module-side data types, can't unload)zxAUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?z(Client sent AUTH, but no password is setc                   &    e Zd ZdZd Zd ZddZdS )Encoderz=Encode strings to bytes-like and decode bytes-like to stringsc                 0    || _         || _        || _        d S Nencodingencoding_errorsdecode_responses)selfr0   r1   r2   s       L/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/redis/connection.py__init__zEncoder.__init___   s     . 0r*   c                    t          |t          t          f          r|S t          |t                    rt	          d          t          |t
          t          f          r"t          |                                          }n<t          |t                    s't          |          j        }t	          d| d          t          |t                    r |                    | j        | j                  }|S )z=Return a bytestring or bytes-like representation of the valuezNInvalid input of type: 'bool'. Convert to a bytes, string, int or float first.zInvalid input of type: 'z2'. Convert to a bytes, string, int or float first.)
isinstancebytes
memoryviewboolr   intfloatreprencodestrtype__name__r0   r1   )r3   valuetypenames      r4   r>   zEncoder.encoded   s    eeZ011 	Lt$$ 	5   U|,, 	KK&&((EEE3'' 	E{{+HC8 C C C   eS!! 	FLL0DEEEr*   Fc                     | j         s|r^t          |t                    r|                                }t          |t                    r |                    | j        | j                  }|S )z:Return a unicode string from the bytes-like representation)r2   r7   r9   tobytesr8   decoder0   r1   )r3   rB   forces      r4   rF   zEncoder.decode{   se      	JE 	J%,, (%'' JT]D4HIIr*   NF)rA   
__module____qualname____doc__r5   r>   rF    r*   r4   r,   r,   \   sL        CC1 1 1
  .     r*   r,   c                   N    e Zd Zdedededeeeeee	ee
eieeeeeeeedZd ZdS )
BaseParserzmax number of clients reachedzinvalid passwordz,wrong number of arguments for 'auth' commandz,wrong number of arguments for 'AUTH' command)ERR	WRONGPASS	EXECABORTLOADINGNOSCRIPTREADONLYNOAUTHNOPERMc                 ,   |                     d          d         }|| j        v rb|t          |          dz   d         }| j        |         }t          |t                    r|                    |t                    } ||          S t          |          S )zParse an error response r      N)splitEXCEPTION_CLASSESlenr7   dictgetr   )r3   response
error_codeexception_classs       r4   parse_errorzBaseParser.parse_error   s    ^^C((+
///J! 3 5 56H"4Z@O/400 O"1"5"5h"N"N"?8,,,X&&&r*   N)rA   rI   rJ   r   r   r   MODULE_LOAD_ERRORr   MODULE_EXPORTS_DATA_TYPES_ERRORNO_SUCH_MODULE_ERROR MODULE_UNLOAD_NOT_POSSIBLE_ERRORNO_AUTH_SET_ERRORr   r   r   r   r   r[   rb   rL   r*   r4   rN   rN      s         ,_ 3!"F!"F{+[ +,k
  
" )##!!%#1 6	' 	' 	' 	' 	'r*   rN   c            	           e Zd Zdej        dedefdZdefdZdedfd	e	e         d
e
eef         de	e         defdZd
edefdZd	edefdZdefdZdefdZdeddfdZddZddZdS )SocketBuffersocketsocket_read_sizesocket_timeoutc                 `    || _         || _        || _        t          j                    | _        d S r.   )_sockrk   rl   ioBytesIO_buffer)r3   rj   rk   rl   s       r4   r5   zSocketBuffer.__init__   s,     
 0,z||r*   returnc                     | j                                         }| j                             dt                    }| j                             |           ||z
  S )z3
        Remaining unread length of buffer
        r   )rq   tellseekr   )r3   posends      r4   unread_byteszSocketBuffer.unread_bytes   sN     l!!l8,,#Syr*   NTlengthtimeoutraise_on_timeoutc                    | j         }| j        }d}|t          u}| j        }|                                }	|                    dt                     |r|                    |           	 	 | j                             |          }
t          |
t                    r't          |
          dk    rt          t                    |                    |
           t          |
          }||z  }|||k    r	 |                    |	           |r|                    | j                   dS dS # t           j        $ rH |rt%          d          Y |                    |	           |r|                    | j                   dS dS t&          $ r}t(                              |j        d          }|sD|j        |k    r9Y d }~|                    |	           |r|                    | j                   dS dS t          d|j                   d }~ww xY w# |                    |	           |r|                    | j                   w w xY wNr   TzTimeout reading from socketFz!Error while reading from socket: )rn   rk   SENTINELrq   rt   ru   r   
settimeoutrecvr7   r8   r\   r   SERVER_CLOSED_CONNECTION_ERRORwriterl   rj   rz   r    NONBLOCKING_EXCEPTIONS#NONBLOCKING_EXCEPTION_ERROR_NUMBERSr^   	__class__errnoargs)r3   ry   rz   r{   sockrk   markercustom_timeoutbufcurrent_posdatadata_lengthexalloweds                 r4   _read_from_socketzSocketBuffer._read_from_socket   s    z0 0lhhjjH 	%OOG$$$	5z'788dE** Js4yyA~~)*HIII		$!$ii+%%&6// HH[!!! 5 3444445 5 ~ 	 	 	 B"#@AAA HH[!!! 5 3444445 5 & 	Q 	Q 	Q
 :==blBOOG# G(;(;uuu HH[!!! 5 3444445 5 ""Obg"O"OPPP	Q HH[!!! 5 344445s=   (B	D' ' HH =	H-H3H ,HHH 4H?c                 r    t          |                                           p|                     |d          S )NFrz   r{   )r:   rx   r   r3   rz   s     r4   can_readzSocketBuffer.can_read   s@    D%%''(( 
D,B,Be -C -
 -
 	
r*   c                     |dz   }| j                             |          }|t          |          z
  }|r2|                     |           || j                             |          z  }|d d         S )Nr'   )rq   readr\   r   )r3   ry   r   missings       r4   r   zSocketBuffer.read   st    !|  ((3t99$ 	/""7+++DL%%g...DCRCyr*   c                 
   | j         }|                                }|                    t                    sE|                                  ||                                z  }|                    t                    E|d d         S )Nr   )rq   readlineendswithSYM_CRLFr   )r3   r   r   s      r4   r   zSocketBuffer.readline   st    l||~~--)) 	#""$$$CLLNN"D --)) 	#
 CRCyr*   c                 4    | j                                         S )z+
        Get current read position
        )rq   rt   r3   s    r4   get_poszSocketBuffer.get_pos  s     |  """r*   rv   c                 :    | j                             |           dS )zO
        Rewind the buffer to a specific position, to re-start reading
        N)rq   ru   )r3   rv   s     r4   rewindzSocketBuffer.rewind  s      	#r*   c                    |                                  }|dk    rdS |dk    r)| j                                        }|| d         |d|<   | j                            |           | j                            d           dS )zH
        After a successful read, purge the read part of buffer
        r   N)rx   rq   	getbuffertruncateru   )r3   unreadviews      r4   purgezSocketBuffer.purge  s     ""$$
 A::FA::<))++D &ND&Mf%%%!r*   c                 x    	 | j                                          n# t          $ r Y nw xY wd | _         d | _        d S r.   )rq   close	Exceptionrn   r   s    r4   r   zSocketBuffer.close'  sT    	L     	 	 	 D	 


s    
))rr   N)rA   rI   rJ   rj   r;   r<   r5   rx   r   r
   r   objectr:   r   r   r8   r   r   r   r   r   r   rL   r*   r4   ri   ri      s}       $m$7:$LQ$ $ $ $c     !%(0+/	-5 -5-5 uf}%-5 #4.	-5
 
-5 -5 -5 -5^
 
$ 
 
 
 

	3 	5 	 	 	 	%    # # # # ## $       &     r*   ri   c                   @    e Zd ZdZd Zd Zd Zd Zd ZddZ	dd	Z
d
S )PythonParserzPlain Python parsing classc                 >    || _         d | _        d | _        d | _        d S r.   )rk   encoderrn   rq   r3   rk   s     r4   r5   zPythonParser.__init__8  s#     0
r*   c                 R    	 |                                   d S # t          $ r Y d S w xY wr.   on_disconnectr   r   s    r4   __del__zPythonParser.__del__>  A    	      	 	 	DD	    
&&c                     |j         | _         t          | j         | j        |j                  | _        |j        | _        dS )zCalled when the socket connectsN)rn   ri   rk   rl   rq   r   r3   
connections     r4   
on_connectzPythonParser.on_connectD  s<    %
#J-z/H
 
 ")r*   c                 p    d| _         | j         | j                                         d| _        d| _        dS )z"Called when the socket disconnectsN)rn   rq   r   r   r   s    r4   r   zPythonParser.on_disconnectL  s7    
<#L   DLr*   c                 D    | j         o| j                             |          S r.   )rq   r   r   s     r4   r   zPythonParser.can_readT  s    |> 5 5g > >>r*   Fc                 
   | j         r| j                                         nd }	 |                     |          }| j                                          |S # t          $ r# | j         r| j                             |            w xY w)Ndisable_decoding)rq   r   _read_responser   BaseExceptionr   )r3   r   rv   results       r4   read_responsezPythonParser.read_responseW  s    (,>dl""$$$$	((:J(KKF L   M  	 	 	| )##C(((	s   A -Bc                      j                                         }|st          t                    |d d         |dd          }}|dk    rE|                    dd          }                     |          }t          |t                    r||S |dk    rn|dk    rt          |          S |dk    r|d	k    rd S |dk    r( j                             t          |                    }nP|d
k    r|d	k    rd S |d
k    r* fdt          t          |                    D             }nt          d|          du r j                            |          }|S )NrY      -utf-8replace)errors   +   :r)   s   -1r(   c                 <    g | ]}                                S )r   )r   ).0ir   r3   s     r4   
<listcomp>z/PythonParser._read_response.<locals>.<listcomp>  s;        ##5E#FF  r*   zProtocol Error: F)rq   r   r   r   rF   rb   r7   r;   r   ranger   r   )r3   r   rawbyter_   errors   ``    r4   r   zPythonParser._read_responsec  s   l##%% 	B!"@AAARaR#abb'h 4<<wyAAH$$X..E %11 
 LT\\T\\x== T\\h%//4T\\|((X77HHT\\h%//4T\\    s8}}--  HH
 ""<S"<"<===u$$|**844Hr*   NrH   )rA   rI   rJ   rK   r5   r   r   r   r   r   r   rL   r*   r4   r   r   5  s              * * *  ? ? ?
 
 
 
, , , , , ,r*   r   c                   D    e Zd ZdZd Zd Zd Zd Zd Ze	dfdZ
dd
ZdS )HiredisParserz*Parser class for connections using Hiredisc                 h    t           st          d          || _        t          |          | _        d S )NzHiredis is not installed)r#   r   rk   	bytearrayrq   r   s     r4   r5   zHiredisParser.__init__  s5      	97888 0 !122r*   c                 R    	 |                                   d S # t          $ r Y d S w xY wr.   r   r   s    r4   r   zHiredisParser.__del__  r   r   c                     |j         | _         |j        | _        t          | j        |j        j        d}|j        j        r|j        j        |d<   t          j
        di || _        d| _        d S )N)protocolError
replyErrorr   r0   FrL   )rn   rl   _socket_timeoutr   rb   r   r1   r2   r0   hiredisReader_reader_next_response)r3   r   kwargss      r4   r   zHiredisParser.on_connect  sz    %
)8,* (8
 
 . 	=!+!3!<F:~////#r*   c                 0    d | _         d | _        d| _        d S )NF)rn   r   r   r   s    r4   r   zHiredisParser.on_disconnect  s    
#r*   c                     | j         st          t                    | j        du r>| j                                         | _        | j        du r|                     |d          S dS )NFr   T)r   r   r   r   getsread_from_socketr   s     r4   r   zHiredisParser.can_read  sl    | 	B!"@AAA%''"&,"3"3"5"5D"e++,,Wu,UUUtr*   Tc                     | j         }|t          u}	 |r|                    |           | j                             | j                  }|dk    rt          t                    | j                            | j        d|           	 |r|                    | j	                   dS dS # t          j        $ r3 |rt          d          Y |r|                    | j	                   dS dS t          $ rm}t                              |j        d          }|s/|j        |k    r$Y d }~|r|                    | j	                   dS dS t          d|j                   d }~ww xY w# |r|                    | j	                   w w xY wr}   )rn   r   r   	recv_intorq   r   r   r   feedr   rj   rz   r    r   r   r^   r   r   r   )r3   rz   r{   r   r   bufflenr   r   s           r4   r   zHiredisParser.read_from_socket  s   z 0	6 )(((j**4<88G!||%&DEEELdlAw777   6 4555556 6 ~ 	 	 	 B"#@AAA  6 4555556 6 & 	Q 	Q 	Q
 :==blBOOG# G(;(;uuu  6 4555556 6 ""Obg"O"OPPP	Q  6 455556s<   A1B$ $ EE %	E.-EE ?EEE E=Fc                     | j         st          t                    | j        dur| j        }d| _        |S |r| j                             d          }n| j                                         }|du rN|                                  |r| j                             d          }n| j                                         }|du Nt          |t                    r|t          |t                    r%|r#t          |d         t                    r|d         |S )NFr   )r   r   r   r   r   r   r7   list)r3   r   r_   s      r4   r   zHiredisParser.read_response  s+   | 	B!"@AAA e++*H"'DO 	+|((//HH|((**H%!!### /<,,U33<,,.. % h00 	Nx&&		 8A;88	
 1+r*   NrH   )rA   rI   rJ   rK   r5   r   r   r   r   r   r   r   rL   r*   r4   r   r     s        003 3 3  $ $ $$ $ $
   (0$ 6 6 6 6<           r*   r   DefaultParserc                       e Zd Zd ZdS )HiredisRespSerializerc                 "   g }t          |d         t                    rEt          |d                                                                                   |dd         z   }n<d|d         v r2t          |d                                                   |dd         z   }	 |                    t          j        |                     nG# t          $ r: t          j
                    \  }}}t          |                              |          w xY w|S 2Pack a series of arguments into the Redis protocolr   rY   N    )r7   r?   tupler>   rZ   appendr   pack_command	TypeErrorsysexc_infor   with_traceback)r3   r   output_rB   	tracebacks         r4   packzHiredisRespSerializer.pack  s    d1gs## 	5a))//1122T!""X=DDT!W__a))DH4D	=MM'.t445555 	= 	= 	="%,..AuiE""11)<<<	= s    'C ADN)rA   rI   rJ   r   rL   r*   r4   r   r     s#            r*   r   c                       e Zd ZddZd ZdS )PythonRespSerializerrr   Nc                 "    || _         || _        d S r.   )_buffer_cutoffr>   )r3   buffer_cutoffr>   s      r4   r5   zPythonRespSerializer.__init__  s    +r*   c           	      \   g }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        |          D ]}t          |          }t          |          |k    s||k    st          |t                    ryt
                              |t          t          |                                          t          f          }|                    |           |                    |           t          }t
                              |t          t          |                                          t          |t          f          }	|                    |           |S r   )r7   r?   r   r>   rZ   	SYM_EMPTYjoinSYM_STARr\   r   r  mapr9   
SYM_DOLLARr   )r3   r   r   buffr  arg
arg_lengths          r4   r   zPythonRespSerializer.pack  s    d1gs## 	5a))//1122T!""X=DDT!W__a))DH4D~~xSYY)>)>)@)@(KLL+t{D)) 	 	C SJD		M))--c:.. . !~~:s:'='='?'?J  d###c""" ~~"J..00  	 	 	dr*   r   )rA   rI   rJ   r5   r   rL   r*   r4   r  r    s7           + + + + +r*   r  c                      e Zd ZdZdddedddeddddddddfdee         fd	Zd
 Z	e
d             Zd Zd Zd Zd Zd Zd Ze
d             Ze
d             Ze
d             Zd Zd Zd Zd Zd Zd!dZd Zd"dZd#dZd Zd  ZdS )$AbstractConnectionz0Manages communication to and from a Redis serverr   NFr   stricti   credential_providerc                    |s|r|t          d          t          j                    | _        || _        || _        || _        || _        || _        || _	        |t          u rg }|r|                    t                     || _        |s|rX|"t          t                      d          | _        nt#          j        |          | _        | j                            |           n!t          t                      d          | _        |
| _        d| _        || _        t/          |||          | _        d| _        |	| _        |                     |           g | _        d| _        |                     |          | _        dS )a2  
        Initialize a new Connection.
        To specify a retry policy for specific errors, first set
        `retry_on_error` to a list of the error/s to retry on, then set
        `retry` to a valid `Retry` object.
        To retry on TimeoutError, `retry_on_timeout` can also be set to `True`.
        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'rY   r   ip  ) r   osgetpidpiddbclient_namer  passwordusernameretry_on_timeoutr   r   r    retry_on_errorr!   r   retrycopydeepcopyupdate_supported_errorshealth_check_intervalnext_health_checkredis_connect_funcr,   r   rn   _socket_read_size
set_parser_connect_callbacksr  _construct_command_packer_command_packer)r3   r  r  r  r  r0   r1   r2   parser_classrk   r   r  r  r  r"  r  command_packers                    r4   r5   zAbstractConnection.__init__N  s   4  	 	&9&E+   9;;&#6    0X%%N 	0!!,///, 		/N 		/}"9;;22

 "]511
J..~>>>>y{{A..DJ%:"!""4x:JKK
!1%%%"$"#==nMMr*   c                     d                     d |                                 D                       }| j        j         d| dS )N,c                 "    g | ]\  }}| d | S )=rL   )r   kvs      r4   r   z/AbstractConnection.__repr__.<locals>.<listcomp>  s&    HHHTQjjQjjHHHr*   <>)r  repr_piecesr   rA   )r3   	repr_argss     r4   __repr__zAbstractConnection.__repr__  sJ    HHHHT5E5E5G5GHHHII	.)88I8888r*   c                     d S r.   rL   r   s    r4   r2  zAbstractConnection.repr_pieces      r*   c                 R    	 |                                   d S # t          $ r Y d S w xY wr.   )
disconnectr   r   s    r4   r   zAbstractConnection.__del__  s?    	OO 	 	 	DD	r   c                 r    ||S t           rt                      S t          | j        | j        j                  S r.   )r$   r   r  r  r   r>   )r3   packers     r4   r&  z,AbstractConnection._construct_command_packer  s:    M# 	R(***'(;T\=PQQQr*   c                 ^    | j                             t          j        |                     d S r.   )r%  r   weakref
WeakMethod)r3   callbacks     r4   register_connect_callbackz,AbstractConnection.register_connect_callback  s*    &&w'9('C'CDDDDDr*   c                     g | _         d S r.   )r%  r   s    r4   clear_connect_callbacksz*AbstractConnection.clear_connect_callbacks  s    "$r*   c                 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
        )rk   N)r#  _parser)r3   r(  s     r4   r$  zAbstractConnection.set_parser  s     $|T5KLLLr*   c                      j         rdS 	  j                             fd fd          }nQ# t          j        $ r t          d          t          $ r'}t                               |                    d}~ww xY w| _         	  j	         
                                 n 	                                n## t          $ r                                    w xY w j        D ]} |            }|r |            dS )z5Connects to the Redis server if not already connectedNc                  ,                                      S r.   )_connectr   s   r4   <lambda>z,AbstractConnection.connect.<locals>.<lambda>  s     r*   c                 .                         |           S r.   r8  )r   r3   s    r4   rG  z,AbstractConnection.connect.<locals>.<lambda>  s    tu7M7M r*   zTimeout connecting to server)rn   r  call_with_retryrj   rz   r    OSErrorr   _error_messager"  r   r   r8  r%  )r3   r   erefr>  s   `    r4   connectzAbstractConnection.connect  sV   : 	F	::--'''')M)M)M)M DD ~ 	? 	? 	?=>>> 	: 	: 	:!$"5"5a"8"8999	: 

	&.!!!! ''--- 	 	 	OO	 * 	 	CsuuH 	 	s!   !. 'A<"A77A<1B9 9 Cc                     d S r.   rL   r   s    r4   rF  zAbstractConnection._connect  r6  r*   c                     d S r.   rL   r   s    r4   _host_errorzAbstractConnection._host_error  r6  r*   c                     d S r.   rL   )r3   	exceptions     r4   rL  z!AbstractConnection._error_message  r6  r*   c                 B   | j                             |            | j        s| j        s| j        r| j        pt          | j        | j                  }|                                } | j        dg|R ddi 	 |                                 }nB# t          $ r5 |                     d|d         d           |                                 }Y nw xY wt          |          dk    rt          d          | j        rP|                     dd	| j                   t          |                                           dk    rt          d
          | j        rO|                     d| j                   t          |                                           dk    rt          d          dS dS )z=Initialize the connection, authenticate and select a databaseAUTHcheck_healthFr~   rW  OKzInvalid Username or PasswordCLIENTSETNAMEzError setting client nameSELECTzInvalid DatabaseN)rC  r   r  r  r  r   get_credentialssend_commandr   r   r%   r   r  r   r  )r3   cred_provider	auth_argsauth_responses       r4   r   zAbstractConnection.on_connect  s   %%% # 	J 	J 	J( T5dmT]SS  &5577I DfEyEEEuEEE5 $ 2 2 4 47 5 5 5
 !!&)B-e!LLL $ 2 2 4 45 M**d22)*HIII  	Ch	43CDDDD..0011T99%&ABBB 7 	:h000D..0011T99%&8999	: 	:99s   7B <C
Cc                 R   | j                                          | j        dS t          j                    | j        k    r6	 | j                            t          j                   n# t          $ r Y nw xY w	 | j        
                                 n# t          $ r Y nw xY wd| _        dS )z!Disconnects from the Redis serverN)rC  r   rn   r  r  r  shutdownrj   	SHUT_RDWRrK  r   r3   r   s     r4   r8  zAbstractConnection.disconnect
  s    ""$$$:F9;;$(""
##F$45555   	J 	 	 	D	


s$    $A% %
A21A26B 
BBc                     |                      dd           t          |                                           dk    rt          d          dS )z Send PING, expect PONG in returnPINGFrX  PONGz#Bad response from PING health checkN)r^  r%   r   r   r   s    r4   
_send_pingzAbstractConnection._send_ping  sQ    &u555**,,--77!"GHHH 87r*   c                 .    |                                   dS )z Function to call when PING failsNrI  )r3   r   s     r4   _ping_failedzAbstractConnection._ping_failed"  s    r*   c                     | j         r>t                      | j        k    r)| j                            | j        | j                   dS dS dS )z3Check the health of the connection with a PING/PONGN)r   r	   r!  r  rJ  ri  rk  r   s    r4   rW  zAbstractConnection.check_health&  sT    % 	K$&&43I*I*IJ&&t8IJJJJJ	K 	K*I*Ir*   Tc                 r   | j         s|                                  |r|                                  	 t          |t                    r|g}|D ]}| j                             |           dS # t          j        $ r$ |                                  t          d          t          $ rq}|                                  t          |j                  dk    rd|j        d         }}n|j        d         }|j        d         }t          d| d| d          d}~wt          $ r |                                   w xY w)	z2Send an already packed command to the Redis serverzTimeout writing to socketrY   UNKNOWNr   Error z while writing to socket. .N)rn   rO  rW  r7   r?   sendallrj   rz   r8  r    rK  r\   r   r   r   )r3   commandrW  itemrM  r   errmsgs          r4   send_packed_commandz&AbstractConnection.send_packed_command+  si   z 	LLNNN 	 	'3'' $") ) )
""4(((() )~ 	< 	< 	<OO:;;; 	W 	W 	WOO16{{a )16!9vq	!"U5"U"UF"U"U"UVVV 	 	 	OO	s   7A, ,;D6'A,D#D6c                 v    |                       | j        j        | |                    dd                     dS )z+Pack and send a command to the Redis serverrW  TrX  N)ru  r'  r   r^   )r3   r   r   s      r4   r^  zAbstractConnection.send_commandF  sJ      %D %t,ND99 	! 	
 	
 	
 	
 	
r*   c                    | j         }|s|                                  |                                 }	 | j                            |          S # t
          $ r3}|                                  t          d| d|j                   d}~ww xY w)z8Poll the socket to see if there's data that can be read.Error while reading from z: N)	rn   rO  rR  rC  r   rK  r8  r   r   )r3   rz   r   
host_errorrM  s        r4   r   zAbstractConnection.can_readM  s    z 	LLNNN%%''
	V<((111 	V 	V 	VOO!"Tj"T"TAF"T"TUUU	Vs   A 
B
.BB
c                    |                                  }	 | j                            |          }n# t          j        $ r' |                                  t          d|           t          $ r3}|                                  t          d| d|j	                   d}~wt          $ r |                                   w xY w| j        rt                      | j        z   | _        t          |t                    r||S )z0Read the response from a previously sent commandr   zTimeout reading from rx  z : N)rR  rC  r   rj   rz   r8  r    rK  r   r   r   r   r	   r!  r7   r   )r3   r   ry  r_   rM  s        r4   r   z AbstractConnection.read_response[  s.    %%''
	|11CS1TTHH~ 	E 	E 	EOOCzCCDDD 	 	 	OO!GJGGqvGG    	 	 	OO	 % 	I%)VVd.H%HD"h.. 	Ns   2 >C0.B#Cc                       | j         j        | S )r   )r'  r   re  s     r4   r   zAbstractConnection.pack_commandu  s    (t#($//r*   c                    g }g }d}| j         }|D ]} | j        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   )	r  r'  r   r\   r7   r9   r   r  r  )	r3   commandsr   piecesbuffer_lengthr  cmdchunkchunklens	            r4   pack_commandsz AbstractConnection.pack_commandsy  s(   + 	. 	.C2-2C8 . .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*   T)r   rH   ) rA   rI   rJ   rK   r   r   r
   r   r5   r4  r   r2  r   r&  r?  rA  r$  rO  rF  rR  rL  r   r8  ri  rk  rW  ru  r^  r   r   r   r  rL   r*   r4   r  r  K  s        66  "<@#AN AN  &&89!AN AN AN ANF9 9 9   ^  R R RE E E% % %M M M  B   ^   ^   ^&: &: &:P  $I I I  K K K
   6
 
 
V V V V   40 0 0    r*   r  c                   J     e Zd ZdZ	 	 	 	 	 	 	 d fd	Zd Zd	 Zd
 Zd Z xZ	S )
Connectionz4Manages TCP communication to and from a Redis server	localhost  NFr   c                     || _         t          |          | _        || _        |p|| _        || _        |pi | _        || _         t                      j	        di | d S NrL   )
hostr;   portrl   socket_connect_timeoutsocket_keepalivesocket_keepalive_optionssocket_typesuperr5   )
r3   r  r  rl   r  r  r  r  r   r   s
            r4   r5   zConnection.__init__  sn     	II	,&<&N# 0(@(FB%&""6"""""r*   c                     d| j         fd| j        fd| j        fg}| j        r|                    d| j        f           |S )Nr  r  r  r  )r  r  r  r  r   r3   r~  s     r4   r2  zConnection.repr_pieces  sL    49%	':T47OL 	=MM=$*:;<<<r*   c                    d}t          j        | j        | j        | j        t           j                  D ]<}|\  }}}}}d}	 t          j         |||          }|                    t           j        t           j        d           | j	        rk|                    t           j
        t           j        d           | j                                        D ]&\  }	}
|                    t           j        |	|
           '|                    | j                   |                    |           |                    | j                   |c S # t$          $ r#}|}||                                 Y d}~6d}~ww xY w||t%          d          )zCreate a TCP socket connectionNrY   z)socket.getaddrinfo returned an empty list)rj   getaddrinfor  r  r  SOCK_STREAM
setsockoptIPPROTO_TCPTCP_NODELAYr  
SOL_SOCKETSO_KEEPALIVEr  itemsr   r  rO  rl   rK  r   )r3   errresfamilysocktypeproto	canonnamesocket_addressr   r.  r/  r   s               r4   rF  zConnection._connect  s   
 %Ity$"2F4F
 
 	! 	!C BE>FHeYD!}VXu== 2F4FJJJ ( BOOF$5v7JANNN $ = C C E E B B1(:AqAAAA  ;<<< ^,,,  3444 ! ! !#JJLLL!
 ?IABBBs   C=E
E.E))E.c                 $    | j          d| j         S )N:)r  r  r   s    r4   rR  zConnection._host_error  s    )))di)))r*   c                 J   |                                  }t          |j                  dk    r5	 d| d|j        d          dS # t          $ r d|j        d          cY S w xY w	 d|j        d          d| d	|j        d          dS # t          $ r d|j        d          cY S w xY w)
NrY   zError connecting to z.                         r   rp  zConnection Error: ro  z connecting to . )rR  r\   r   AttributeErrorr3   rT  ry  s      r4   rL  zConnection._error_message  s    %%''
y~!##@.j . ."*. . . .! @ @ @?IN1,=?????@@:Y^A. : :!: :%.^A%6: : : " @ @ @?IN1,=?????@s#   A AA#!B B"!B")r  r  NNFNr   
rA   rI   rJ   rK   r5   r2  rF  rR  rL  __classcell__r   s   @r4   r  r    s        :: #!%# # # # # #(  'C 'C 'CR* * *@ @ @ @ @ @ @r*   r  c                   F     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z f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requiredFc                    t           st          d          || _        || _        |t          j        }nWt          |t                    rBt          j        t          j        t          j	        d}||vrt          d|           ||         }|| _
        || _        || _        || _        || _        || _        |	| _        |
| _        || _        || _         t)                      j        di | dS )ae  Constructor

        Args:
            ssl_keyfile: Path to an ssl private key. Defaults to None.
            ssl_certfile: Path to an ssl certificate. Defaults to None.
            ssl_cert_reqs: The string value for the SSLContext.verify_mode (none, optional, required). Defaults to "required".
            ssl_ca_certs: The path to a file of concatenated CA certificates in PEM format. Defaults to None.
            ssl_ca_data: Either an ASCII string of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates.
            ssl_check_hostname: If set, match the hostname during the SSL handshake. Defaults to False.
            ssl_ca_path: The path to a directory containing several CA certificates in PEM format. Defaults to None.
            ssl_password: Password for unlocking an encrypted private key. Defaults to None.

            ssl_validate_ocsp: If set, perform a full ocsp validation (i.e not a stapled verification)
            ssl_validate_ocsp_stapled: If set, perform a validation on a stapled ocsp response
            ssl_ocsp_context: A fully initialized OpenSSL.SSL.Context object to be used in verifying the ssl_ocsp_expected_cert
            ssl_ocsp_expected_cert: A PEM armoured string containing the expected certificate to be returned from the ocsp verification service.

        Raises:
            RedisError
        z$Python wasn't built with SSL supportN)noneoptionalr  z+Invalid SSL Certificate Requirements Flag: rL   )ssl_availabler   keyfilecertfilessl	CERT_NONEr7   r?   CERT_OPTIONALCERT_REQUIRED	cert_reqsca_certsca_dataca_pathcheck_hostnamecertificate_passwordssl_validate_ocspssl_validate_ocsp_stapledssl_ocsp_contextssl_ocsp_expected_certr  r5   )r3   ssl_keyfilessl_certfilessl_cert_reqsssl_ca_certsssl_ca_datassl_check_hostnamessl_ca_pathssl_passwordr  r  r  r  r   	CERT_REQSr   s                  r4   r5   zSSLConnection.__init__  s   H  	ECDDD"$ MMMs++ 
	5-- I
 I-- Q-QQ   &m4M&$""0$0!!2)B& 0&<#""6"""""r*   c                 "   t                                                      }t          j                    }| j        |_        | j        |_        | j        s| j        r'|	                    | j        | j        | j
                   | j        | j        | j        '|                    | j        | j        | j                   |                    || j                  }| j        du rt$          du rt'          d          | j        r| j        rt'          d          | j        rd	dl}d
dlm} | j        Y|j                            |j        j                  }|                    | j                   |                    | j                   n| j        }|                    || j                   |j                             |tC          j!                              }|"                                 |#                    | j        | j$        f           |%                                 |&                                 |S | j        du rOt$          rHd
dlm'}  ||| j        | j$        | j                  }	|	(                                r|S tS          d          |S )z Wrap the socket with SSL support)r  r  r  N)cafilecapathcadata)server_hostnameTFzcryptography is not installed.zKEither an OCSP staple or pure OCSP connection must be validated - not both.r   rY   )ocsp_staple_verifier)OCSPVerifierzocsp validation error)*r  rF  r  create_default_contextr  r  verify_moder  r  load_cert_chainr  r  r  r  load_verify_locationswrap_socketr  r  r"   r   r  OpenSSLocspr  r  SSLContextSSLv23_METHODuse_certificate_fileuse_privatekey_fileset_ocsp_client_callbackr  r  rj   request_ocsprO  r  do_handshakerc  r  is_validr   )r3   r   contextsslsockr  r  
staple_ctxconr  or   s             r4   rF  zSSLConnection._connect?  s   ww!!,..!%!4"n= 	DL 	##2 $    M%|'|'))}T\$, *    %%dDI%FF!T)).D.M.M=>>>) 	d.D 	   ) 	NNN222222 $,$[001JKK
//>>>..t|<<<<!2
//$d&A  
 +((V]__EECKKDI.///LLNNNN !T)).D)******WdiDMJJAzz|| ?%&=>>>r*   )NNr  NNFNNFFNN)rA   rI   rJ   rK   r5   rF  r  r  s   @r4   r  r    s            "'#@# @# @# @# @# @#DA A A A A A A A Ar*   r  c                   <     e Zd ZdZd	 fd	Zd Zd Zd Zd Z xZ	S )
UnixDomainSocketConnectionz4Manages UDS communication to and from a Redis server Nc                 V    || _         || _         t                      j        di | d S r  )pathrl   r  r5   )r3   r  rl   r   r   s       r4   r5   z#UnixDomainSocketConnection.__init__  s5    	,""6"""""r*   c                 p    d| j         fd| j        fg}| j        r|                    d| j        f           |S )Nr  r  r  )r  r  r  r   r  s     r4   r2  z&UnixDomainSocketConnection.repr_pieces  sC    49%dg7 	=MM=$*:;<<<r*   c                     t          j         t           j        t           j                  }|                    | j                   |                    | j                   |S )z&Create a Unix domain socket connection)rj   AF_UNIXr  r   rl   rO  r  )r3   r   s     r4   rF  z#UnixDomainSocketConnection._connect  sF    }V^V-?@@+,,,TYr*   c                     | j         S r.   )r  r   s    r4   rR  z&UnixDomainSocketConnection._host_error  s
    yr*   c                     |                                  }t          |j                  dk    rd| d|j        d          dS d|j        d          d| d|j        d          dS )NrY   z!Error connecting to unix socket: r  r   rp  ro  z connecting to unix socket: )rR  r\   r   r  s      r4   rL  z)UnixDomainSocketConnection._error_message  s     %%''
y~!##VJVV).QRBSVVV
6* 6 66 6!*!26 6 6r*   )r  Nr  r  s   @r4   r  r    s        ::# # # # # #
            r*   r  )0FFALSENNOc                     | | dk    rd S t          | t                    r|                                 t          v rdS t	          |           S )Nr  F)r7   r?   upperFALSE_STRINGSr:   )rB   s    r4   to_boolr    sI    }t% %++--="@"@u;;r*   )	r  rl   r  r  r  r  max_connectionsr   r  c                 \   |                      d          s9|                      d          s$|                      d          st          d          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        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<   |S )Nzredis://z	rediss://zunix://zRRedis URL must specify one of the following schemes (redis://, rediss://, unix://)r   zInvalid value for `z` in connection URL.r  r  unixr  connection_classr  r  r  /r  rediss)
startswith
ValueErrorr   r   queryr  r\   r   URL_QUERY_ARGUMENT_PARSERSr^   r   r  r  schemer  r  hostnamer  r;   r   r  r  )urlr   namerB   parsers        r4   	parse_urlr    su   z""
>>+&&
 >>)$$

 5
 
 	

 3--CF	**0022 
% 
%e 		%SZZ!^^E!H%%E/33D99F %W#)6%==F4LL!:. W W W$%U4%U%U%UVVVW  %t
| 3$S\22z
| 3$S\22z zV8 	/$SX..F6N%?!"" < 	3$S\22F6N8 	+ ]]F6N 8 	F**"738#4#4#<#<S"#E#EFFt"J/    :!!)6F%&Ms   C!!%D8H   HHc                   t    e Zd ZdZed             ZedfdZd Zd Z	d Z
d Zd	 Zd
 Zd Zd ZddZddZdS )ConnectionPoola  
    Create a connection pool. ``If max_connections`` is set, then this
    object raises :py:class:`~redis.exceptions.ConnectionError` when the pool's
    limit is reached.

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

    Any additional keyword arguments are passed to the constructor of
    ``connection_class``.
    c                 x    t          |          }d|v r|d         |d<   |                    |            | 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  rL   )r  update)clsr  r   url_optionss       r4   from_urlzConnectionPool.from_url	  sP    R  nn''.45G.HK*+k"""s}}V}}r*   Nc                     |pd}t          |t                    r|dk     rt          d          || _        || _        || _        t          j                    | _        | 	                                 d S )Nl        r   z,"max_connections" must be a positive integer)
r7   r;   r  r  connection_kwargsr  	threadingLock
_fork_lockreset)r3   r  r  r  s       r4   r5   zConnectionPool.__init__:  st     *2U/3// 	M?Q3F3FKLLL 0!2. $.**

r*   c           	      p    t          |           j         dt           | j        di | j                   dS )Nr0  r1  rL   )r@   rA   r=   r  r  r   s    r4   r4  zConnectionPool.__repr__P  sS    Dzz" I I*T*DDT-CDDEEI I I	
r*   c                     t          j                    | _        d| _        g | _        t                      | _        t          j                    | _	        d S )Nr   )
r  r  _lock_created_connections_available_connectionsset_in_use_connectionsr  r  r  r   s    r4   r  zConnectionPool.resetV  s@    ^%%
$%!&(##&55  9;;r*   c                 Z   | j         t          j                    k    r| j                            d          }|st
          	 | j         t          j                    k    r|                                  | j                                         d S # | j                                         w xY wd S )N   )rz   )r  r  r  r  acquirer   r  release)r3   acquireds     r4   	_checkpidzConnectionPool._checkpidg  s    F 8ry{{""..q.99H +***8ry{{**JJLLL'')))))'')))) #"s   0B B(c                    |                                   | j        5  	 | j                                        }n$# t          $ r |                                 }Y nw xY w| j                            |           ddd           n# 1 swxY w Y   	 |                                 	 |	                                rt          d          nb# t          t          f$ rN |                                 |                                 |	                                rt          d          Y nw xY wn$# t          $ r |                     |            w xY w|S )zGet a connection from the poolNConnection has dataConnection not ready)r%  r  r  pop
IndexErrormake_connectionr  addrO  r   r   rK  r8  r   r#  r3   command_namekeysoptionsr   s        r4   get_connectionzConnectionPool.get_connection  s   Z 	5 	54!8<<>>

 4 4 4!1133


4$((444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5	   
B&&(( A)*?@@@A#W- B B B%%'''""$$$&&(( B)*@AAAB BB
  	 	 	 LL$$$		 sb   B8BABABB	BD* ##C D* AD&#D* %D&&D* *!Ec                     | j         }t          |                    dd          |                    dd          |                    dd                    S )z,Return an encoder based on encoding settingsr0   r   r1   r  r2   Fr/   )r  r,   r^   )r3   r   s     r4   get_encoderzConnectionPool.get_encoder  sV    'ZZ
G44"JJ'8(CC#ZZ(:EBB
 
 
 	
r*   c                     | j         | j        k    rt          d          | xj         dz  c_          | j        di | j        S )zCreate a new connectionzToo many connectionsrY   rL   )r  r  r   r  r  r   s    r4   r+  zConnectionPool.make_connection  sR    $(<<<!"8999!!Q&!!$t$>>t'=>>>r*   c                    |                                   | j        5  	 | j                            |           n# t          $ r Y nw xY w|                     |          r| j                            |           n2| xj        dz  c_        |	                                 	 ddd           dS 	 ddd           dS # 1 swxY w Y   dS )z(Releases the connection back to the poolrY   N)
r%  r  r  removeKeyErrorowns_connectionr  r   r  r8  r   s     r4   r#  zConnectionPool.release  sI   Z 	 	(//
;;;;    
 ##J// +22:>>>>
 ))Q.))%%'''!	 	 	 	 	 	 	 	 ?	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s2   B99B9
AB9AAB99B= B=c                 "    |j         | j         k    S r.   )r  r   s     r4   r8  zConnectionPool.owns_connection  s    ~))r*   Tc                     |                                   | j        5  |rt          | j        | j                  }n| j        }|D ]}|                                 	 ddd           dS # 1 swxY w Y   dS )z
        Disconnects connections in the pool

        If ``inuse_connections`` is True, disconnect connections that are
        current in use, potentially by other threads. Otherwise only disconnect
        connections that are idle in the pool.
        N)r%  r  r   r  r  r8  )r3   inuse_connectionsconnectionsr   s       r4   r8  zConnectionPool.disconnect  s     	Z 		( 		(  :#/1I  #9) ( (
%%''''(		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		( 		(s   >A((A,/A,r  r!   rr   c                     | j                             d|i           | j        D ]	}||_        
| j        D ]	}||_        
d S )Nr  )r  r  r  r  r  )r3   r  conns      r4   	set_retryzConnectionPool.set_retry  s^    %%w&6777/ 	 	DDJJ, 	 	DDJJ	 	r*   r  )r  r!   rr   N)rA   rI   rJ   rK   classmethodr  r  r5   r4  r  r%  r1  r3  r+  r#  r8  r8  r?  rL   r*   r4   r  r    s          . . [.b  *4   ,
 
 
  "-* -* -*^  B
 
 
? ? ?  ** * *( ( ( ((     r*   r  c                   J     e Zd ZdZddeef fd	Zd Zd Zd Z	d Z
d	 Z xZS )
BlockingConnectionPoola  
    Thread-safe blocking connection pool::

        >>> from redis.client import Redis
        >>> client = Redis(connection_pool=BlockingConnectionPool())

    It performs the same function as the default
    :py:class:`~redis.ConnectionPool` implementation, in that,
    it maintains a pool of reusable connections that can be shared by
    multiple redis clients (safely across threads if required).

    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.ConnectionPool` implementation does), it
    makes the client wait ("blocks") 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      c                 \    || _         || _         t                      j        d||d| d S )N)r  r  rL   )queue_classrz   r  r5   )r3   r  rz   r  rF  r  r   s         r4   r5   zBlockingConnectionPool.__init__  sS     ' 	
-+	
 	
  	
 	
 	
 	
 	
r*   c                     |                      | j                  | _        	 	 | j                            d            n# t          $ r Y nw xY w-g | _        t          j                    | _        d S r.   )	rF  r  pool
put_nowaitr   _connectionsr  r  r  r   s    r4   r  zBlockingConnectionPool.reset.  s    $$T%9::			$$T****   	  9;;s   = 
A
	A
c                 ^     | j         di | j        }| j                            |           |S )zMake a fresh connection.rL   )r  r  rJ  r   r   s     r4   r+  z&BlockingConnectionPool.make_connectionF  s:    *T*DDT-CDD
  ,,,r*   c                 `   |                                   d}	 | j                            d| j                  }n# t          $ r t          d          w xY w||                                 }	 |                                 	 |                                rt          d          nb# t
          t          f$ rN |
                                 |                                 |                                rt          d          Y nw xY wn$# t          $ r |                     |            w xY w|S )a7  
        Get a connection, blocking for ``self.timeout`` until a connection
        is available from the pool.

        If the connection returned is ``None`` then creates a new connection.
        Because we use a last-in first-out queue, the existing connections
        (having been returned to the pool after the initial ``None`` values
        were added) will be returned before ``None`` values. This means we only
        create new connections when we need to, i.e.: the actual number of
        connections will only increase in response to demand.
        NT)blockrz   zNo connection available.r'  r(  )r%  rH  r^   rz   r   r   r+  rO  r   rK  r8  r   r#  r-  s        r4   r1  z%BlockingConnectionPool.get_connectionL  sz    	 
	>T4<HHJJ 	> 	> 	> ""<===	> --//J	   
B&&(( A)*?@@@A#W- B B B%%'''""$$$&&(( B)*@AAAB BB
  	 	 	LL$$$	
 s:   !: A.D
 #B' &D
 'ADD
 DD
 
!D+c                    |                                   |                     |          s0|                                 | j                            d           dS 	 | j                            |           dS # t
          $ r Y dS w xY w)z)Releases the connection back to the pool.N)r%  r8  r8  rH  rI  r   r   s     r4   r#  zBlockingConnectionPool.release  s     	##J// 	
 !!###I  &&&F	I  ,,,,, 	 	 	 DD	s   A7 7
BBc                 j    |                                   | j        D ]}|                                 dS )z(Disconnects all connections in the pool.N)r%  rJ  r8  r   s     r4   r8  z!BlockingConnectionPool.disconnect  sC    + 	$ 	$J!!####	$ 	$r*   )rA   rI   rJ   rK   r  r   r5   r  r+  r1  r#  r8  r  r  s   @r4   rB  rB    s         F #
 
 
 
 
 
"  0  2 2 2h  *$ $ $ $ $ $ $r*   rB  )er  r   ro   r  rj   r   r  r<  abcr   r   	itertoolsr   queuer   r   r   r	   typingr
   r   urllib.parser   r   r   redis.backoffr   redis.credentialsr   r   redis.exceptionsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    redis.retryr!   redis.utilsr"   r#   r$   r%   r  r  ImportErrorBlockingIOErrorEWOULDBLOCKr   hasattrr&   SSLWantWriteErrorSSLErrorr   r/  r   r   r  r
  r   r  r   r   r   rc   re   rf   rd   rg   r,   rN   ri   r   r   __annotations__r   r   r  r  r  r  r  r  r  r;   r<   r   r  r  r  rB  rL   r*   r4   <module>ra     s     				 				  



                        ( ( ( ( ( ( ( ( ( (       " " " " " " " " 4 4 4 4 4 4 4 4 4 4 # # # # # # T T T T T T T T                                 "                 JJJMM   MMM (78I&J # >ws&'' >DE+C,@AEF+C,ABB<=+CL9BGGIIJJ  NNN
	!? 688P N #T     ':0C  & & & & & & & &R%' %' %' %' %' %' %' %'PE E E E E E E EPZ Z Z Z Z: Z Z Zzj j j j jJ j j jZ     !!MM M       $0 0 0 0 0 0 0 0fJ J J J J J J JZ
\@ \@ \@ \@ \@# \@ \@ \@~I I I I IJ I I IX$ $ $ $ $!3 $ $ $N /   # !
 
 6 6 6r} } } } } } } }@^$ ^$ ^$ ^$ ^$^ ^$ ^$ ^$ ^$ ^$s   B   B*)B*