
    Ri              
       f   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
JrJr  S SKJr  S SKJr  S SKJrJrJr  S SKJr  S SKJrJr  S S	KJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(  S S
K)J*r*  S SK+J,r,J-r-J.r.   S SK/r/Sr0\2\Rf                  0r4\0(       a<  \5" \/S5      (       a  S\4\/Rl                  '   S\4\/Rn                  '   OS\4\/Rp                  '   \9" \4Ru                  5       5      r;\-(       a  S SK<r<Sr=Sr>Sr?Sr@SrA\B" 5       rCSrDSrESrFSrG\\S.rH " S S5      rI " S S5      rJ " S S5      rK " S  S!\J5      rL " S" S#\J5      rM\-(       a  \MrNO\LrN " S$ S%5      rO " S& S'\O5      rP " S( S)\O5      rQS*rRS+ rS\T\U\U\S\S\V\T\T\SS,.	rWS- rX " S. S/5      rY " S0 S1\Y5      rZg! \1 a    Sr0 GN%f = f)2    N)chain)EmptyFull	LifoQueue)time)Optional)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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                   .    \ rS rSrSrS rS rSS jrSrg)	EncoderT   z=Encode strings to bytes-like and decode bytes-like to stringsc                 (    Xl         X l        X0l        g Nencodingencoding_errorsdecode_responses)selfr-   r.   r/   s       b/var/www/html/backend/Backoffice_Marketplace/venv/lib/python3.13/site-packages/redis/connection.py__init__Encoder.__init__W   s     . 0r&   c                    [        U[        [        45      (       a  U$ [        U[        5      (       a  [	        S5      e[        U[
        [        45      (       a  [        U5      R                  5       nO9[        U[        5      (       d$  [        U5      R                  n[	        SU S35      e[        U[        5      (       a&  UR                  U R                  U R                  5      nU$ )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__r-   r.   )r0   valuetypenames      r1   r<   Encoder.encode\   s    eeZ011Lt$$5  U|,,K&&(EE3''E{++H*8* 5B C  eS!!LL0D0DEEr&   c                     U R                   (       d  U(       a`  [        U[        5      (       a  UR                  5       n[        U[        5      (       a&  UR                  U R                  U R                  5      nU$ )z:Return a unicode string from the bytes-like representation)r/   r5   r7   tobytesr6   decoder-   r.   )r0   r@   forces      r1   rE   Encoder.decodes   sQ      E%,,%''T]]D4H4HIr&   )r/   r-   r.   NF)	r?   
__module____qualname____firstlineno____doc__r2   r<   rE   __static_attributes__ r&   r1   r(   r(   T   s    C1
.r&   r(   c                   T    \ rS rSrS\S\S\S\\\\	\\
\\\0\E\\\\\\\S.rS rSrg	)

BaseParser}   z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                    UR                  S5      S   nX R                  ;   aS  U[        U5      S-   S nU R                  U   n[        U[        5      (       a  UR                  U[        5      nU" U5      $ [        U5      $ )zParse an error response r      N)splitEXCEPTION_CLASSESlenr5   dictgetr   )r0   response
error_codeexception_classs       r1   parse_errorBaseParser.parse_error   s|    ^^C(+
///J! 3 56H"44Z@O/400"1"5"5h"N"8,,X&&r&   rN   N)r?   rI   rJ   rK   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^   re   rM   rN   r&   r1   rP   rP   }   sf     ,_ 3!"F!"F{+[ +,k
  
" )##!!%#16	'r&   rP   c                   d    \ rS rSrS r\S 5       rS\S4S jrS r	S r
S	 rS
 rS rS rS rSrg)SocketBuffer   c                 x    Xl         X l        X0l        [        R                  " 5       U l        SU l        SU l        g Nr   )_socksocket_read_sizesocket_timeoutioBytesIO_bufferbytes_written
bytes_read)r0   socketrr   rs   s       r1   r2   SocketBuffer.__init__   s/    
 0,zz|r&   c                 4    U R                   U R                  -
  $ r+   )rw   rx   r0   s    r1   lengthSocketBuffer.length   s    !!DOO33r&   NTc                 "   U R                   nU R                  nU R                  nUR                  U R                  5        SnU[
        Ln U(       a  UR                  U5         U R                   R                  U5      n	[        U	[        5      (       a  [        U	5      S:X  a  [        [        5      eUR                  U	5        [        U	5      n
U =R                  U
-  sl        Xz-  nUb  X:  a  M   U(       a  UR                  U R                  5        gg! [        R                    a8    U(       a  [#        S5      e U(       a  UR                  U R                  5        gg[$         a|  n[&        R)                  UR*                  S5      nU(       d8  UR,                  U:X  a(   S nAU(       a  UR                  U R                  5        gg[        SUR.                   35      eS nAff = f! U(       a  UR                  U R                  5        f f = fNr   TzTimeout reading from socketFz!Error while reading from socket: )rq   rr   rv   seekrw   SENTINEL
settimeoutrecvr5   r6   r_   r   SERVER_CLOSED_CONNECTION_ERRORwriters   ry   timeoutr   NONBLOCKING_EXCEPTIONS#NONBLOCKING_EXCEPTION_ERROR_NUMBERSra   	__class__errnoargs)r0   r}   r   raise_on_timeoutsockrr   bufmarkercustom_timeoutdatadata_lengthexalloweds                r1   _read_from_socketSocketBuffer._read_from_socket   s   zz00ll##$ 0	5(zz'78dE**s4yA~)*HII		$!$i""k1"%%&/  3 34  ~~ 	"#@AA  3 34  & 	Q
 :==bllBOG#G(;  3 34  "$EbggY"OPP	Q  3 34 s=   B&D &G&<G) !	G&*7G!!G) 	G!!G&&G) )%Hc                 Z    [        U R                  5      =(       d    U R                  USS9$ )NFr   r   )r8   r}   r   r0   r   s     r1   can_readSocketBuffer.can_read   s/    DKK  
D$:$:e %; %
 	
r&   c                 *   US-   nXR                   :  a  U R                  XR                   -
  5        U R                  R                  U R                  5        U R                  R                  U5      nU =R                  [        U5      -  sl        US S $ )Nr#   )r}   r   rv   r   rx   readr_   )r0   r}   r   s      r1   r   SocketBuffer.read   sr    !KK""6KK#78$//*||  (3t9$CRyr&   c                    U R                   nUR                  U R                  5        UR                  5       nUR	                  [
        5      (       dW  U R                  5         UR                  U R                  5        UR                  5       nUR	                  [
        5      (       d  MW  U =R                  [        U5      -  sl        US S $ )Nr   )rv   r   rx   readlineendswithSYM_CRLFr   r_   )r0   r   r   s      r1   r   SocketBuffer.readline   s    ll!||~--))""$HHT__%<<>D	 --)) 	3t9$CRyr&   c                     U R                   $ )z
Get current read position
rx   r|   s    r1   get_posSocketBuffer.get_pos   s     r&   c                     Xl         g)z?
Rewind the buffer to a specific position, to re-start reading
Nr   )r0   poss     r1   rewindSocketBuffer.rewind   s	     r&   c                    U R                   U R                  -
  nUS:  a  gUS:  a"  U R                  R                  5       nX!* S USU& U R                  R	                  U5        Xl         SU l        U R                  R                  S5        g)z8
After a successful read, purge the read part of buffer
r   N)rw   rx   rv   	getbuffertruncater   )r0   unreadviews      r1   purgeSocketBuffer.purge  s     ##doo5
 A:A:<<))+D ND&Mf%#!r&   c                      S=U l         U l        U R                  R                  5         S U l        S U l        g ! [         a     Nf = frp   )rw   rx   rv   close	Exceptionrq   r|   s    r1   r   SocketBuffer.close  sL    		344DLL  
  	 	s   (9 
AA)rv   rq   rx   rw   rr   rs   )r?   rI   rJ   rK   r2   propertyr}   r   r   r   r   r   r   r   r   r   rM   rN   r&   r1   rm   rm      sN     4 4 (,XPT '5R

	*r&   rm   c                   J    \ rS rSrSrS rS rS rS rS r	SS jr
SS	 jrS
rg)PythonParseri*  zPlain Python parsing classc                 :    Xl         S U l        S U l        S U l        g r+   )rr   encoderrq   rv   r0   rr   s     r1   r2   PythonParser.__init__-  s     0
r&   c                 F     U R                  5         g ! [         a     g f = fr+   on_disconnectr   r|   s    r1   __del__PythonParser.__del__3  %    	  		    
  c                     UR                   U l         [        U R                   U R                  UR                  5      U l        UR
                  U l        g)zCalled when the socket connectsN)rq   rm   rr   rs   rv   r   r0   
connections     r1   
on_connectPythonParser.on_connect9  sA    %%
#JJ--z/H/H
 "))r&   c                 |    SU l         U R                  b!  U R                  R                  5         SU l        SU l        g)z"Called when the socket disconnectsN)rq   rv   r   r   r|   s    r1   r   PythonParser.on_disconnectA  s1    
<<#LL DLr&   c                 ^    U R                   =(       a    U R                   R                  U5      $ r+   )rv   r   r   s     r1   r   PythonParser.can_readI  s     ||> 5 5g >>r&   c                     U R                   R                  5       n U R                  US9nU R                   R                  5         U$ ! [         a    U R                   R                  U5        e f = f)Ndisable_decoding)rv   r   _read_responser   BaseExceptionr   )r0   r   r   results       r1   read_responsePythonParser.read_responseL  sj    ll""$	((:J(KF
 LL M  	LL$	s   A 'A.c                    U R                   R                  5       nU(       d  [        [        5      eUS S USS  pCUS;  a  [	        SU< 35      eUS:X  a:  UR                  SSS9nU R                  U5      n[        U[        5      (       a  UeU$ US:X  a  OUS	:X  a  [        U5      nOtUS
:X  a.  [        U5      nUS:X  a  g U R                   R                  U5      nO@US:X  a:  [        U5      nUS:X  a  g [        U5       Vs/ s H  nU R                  US9PM     nn[        U[        5      (       a   USL a  U R                  R                  U5      nU$ s  snf )Nr\   )   -   +   :r%   r$   zProtocol Error: r   utf-8replace)errorsr   r   r%   r   r$   r   F)rv   r   r   r   r   rE   re   r5   r9   r   ranger   r6   r   )r0   r   rawbyterb   errorr}   is           r1   r   PythonParser._read_responseW  sd   ll##%!"@AARa#ab'h55!$4SG"<== 4<wyAH$$X.E %11
 LT\T\8}HT\]F|||((0HT\]F| v&A ##5E#F&   h&&+;u+D||**84Hs   E)rv   rq   r   rr   NrH   )r?   rI   rJ   rK   rL   r2   r   r   r   r   r   r   rM   rN   r&   r1   r   r   *  s(     *?	.r&   r   c                   N    \ rS rSrSrS rS rS rS rS r	\
S4S	 jrSS
 jrSrg)HiredisParseri  z*Parser class for connections using Hiredisc                 \    [         (       d  [        S5      eXl        [        U5      U l        g )NzHiredis is not installed)r    r   rr   	bytearrayrv   r   s     r1   r2   HiredisParser.__init__  s'      788 0 !12r&   c                 F     U R                  5         g ! [         a     g f = fr+   r   r|   s    r1   r   HiredisParser.__del__  r   r   c                 D   UR                   U l         UR                  U l        [        U R                  UR
                  R                  S.nUR
                  R                  (       a  UR
                  R                  US'   [        R                  " S0 UD6U l        SU l        g )N)protocolError
replyErrorr   r-   FrN   )rq   rs   _socket_timeoutr   re   r   r.   r/   r-   hiredisReader_reader_next_response)r0   r   kwargss      r1   r   HiredisParser.on_connect  s    %%
)88,** ((88
 ..!+!3!3!<!<F:~~//#r&   c                 .    S U l         S U l        SU l        g )NF)rq   r   r   r|   s    r1   r   HiredisParser.on_disconnect  s    
#r&   c                     U R                   (       d  [        [        5      eU R                  SL a>  U R                   R	                  5       U l        U R                  SL a  U R                  USS9$ g)NFr   T)r   r   r   r   getsread_from_socketr   s     r1   r   HiredisParser.can_read  s_    ||!"@AA%'"&,,"3"3"5D""e+,,Wu,UUr&   Tc                 ^   U R                   nU[        Ln U(       a  UR                  U5        U R                   R                  U R                  5      nUS:X  a  [        [        5      eU R                  R                  U R                  SU5         U(       a  UR                  U R                  5        gg! [        R                   a8    U(       a  [        S5      e U(       a  UR                  U R                  5        gg[         a|  n[        R                  UR                   S5      nU(       d8  UR"                  U:X  a(   S nAU(       a  UR                  U R                  5        gg[        SUR$                   35      eS nAff = f! U(       a  UR                  U R                  5        f f = fr   )rq   r   r   	recv_intorv   r   r   r   feedr   ry   r   r   r   r   ra   r   r   r   )r0   r   r   r   r   bufflenr   r   s           r1   r   HiredisParser.read_from_socket  sZ   zz 0	6(jj**4<<8G!|%&DEELLdllAw7   4 45  ~~ 	"#@AA  4 45  & 	Q
 :==bllBOG#G(;  4 45  "$EbggY"OPP	Q  4 45 s<   A9B4 4&FF ?	F7E??F 'E??FF %F,c                 Z   U R                   (       d  [        [        5      eU R                  SLa  U R                  nSU l        U$ U(       a  U R                   R	                  S5      nOU R                   R	                  5       nUSL aT  U R                  5         U(       a  U R                   R	                  S5      nOU R                   R	                  5       nUSL a  MT  [        U[        5      (       a  Ue[        U[        5      (       a$  U(       a  [        US   [        5      (       a  US   eU$ )NFr   )r   r   r   r   r   r   r5   list)r0   r   rb   s      r1   r   HiredisParser.read_response  s    ||!"@AA e+**H"'DO||((/H||((*H%!!#<<,,U3<<,,. % h00Nx&&8A;881+r&   )rv   r   r   rq   r   rr   NrH   )r?   rI   rJ   rK   rL   r2   r   r   r   r   r   r   r   rM   rN   r&   r1   r   r     s/    03$$
 (0$ 6< r&   r   c                       \ rS rSrSrSSSSSSSSSS\SS	S\S
SSSSSS4S\\   4S jjr	S r
S rS rS rS rS rS rS rS rS rS rS rS rS rS rS#S jrS rS$S jrS%S jrS  rS! rS"rg)&
Connectioni  z4Manages TCP communication to and from a Redis server	localhosti  r   NFr   strict   credential_providerc                 D   U(       d  U(       a  Ub  [        S5      e[        R                  " 5       U l        Xl        [        U5      U l        X0l        UU l        UU l	        X@l
        UU l        XPl        U=(       d    UU l        Xpl        U=(       d    0 U l        Xl        Xl        U[$        L a  / nU
(       a  UR'                  [(        5        Xl        U(       d  U(       aT  Uc  [-        [/        5       S5      U l        O[2        R4                  " U5      U l        U R0                  R7                  U5        O[-        [/        5       S5      U l        UU l        SU l        UU l        [?        XU5      U l         SU l!        UU l"        U RG                  U5        / U l$        SU l%        g)a  
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`.
N'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\   r   p  )&r   osgetpidpidhostr9   portdbclient_namer
  passwordusernamers   socket_connect_timeoutsocket_keepalivesocket_keepalive_optionssocket_typeretry_on_timeoutr   appendr   retry_on_errorr   r   retrycopydeepcopyupdate_supported_errorshealth_check_intervalnext_health_checkredis_connect_funcr(   r   rq   _socket_read_size
set_parser_connect_callbacks_buffer_cutoff)r0   r  r  r  r  rs   r  r  r  r  r  r  r-   r.   r/   parser_classrr   r"  r  r  r  r$  r
  s                          r1   r2   Connection.__init__  sX   @ &9&E+  99;	I	&#6   ,&<&N# 0(@(FB%& 0X%N!!,/,N}"9;2
 "]]51
JJ..~>y{A.DJ%:"!""4x:JK
!1%"$"r&   c           	          SR                  U R                  5        VVs/ s H  u  pU SU 3PM     snn5      nU R                  R                   SU S3$ s  snnf )N,=<>)joinrepr_piecesr   r?   )r0   kv	repr_argss       r1   __repr__Connection.__repr__M  sZ    HHT5E5E5GH5GTQ1QCj5GHI	..))*!I;a88 Is   A
c                     SU R                   4SU R                  4SU R                  4/nU R                  (       a  UR	                  SU R                  45        U$ )Nr  r  r  r  )r  r  r  r  r  r0   piecess     r1   r1  Connection.repr_piecesQ  sM    499%		':T477OLMM=$*:*:;<r&   c                 F     U R                  5         g ! [         a     g f = fr+   )
disconnectr   r|   s    r1   r   Connection.__del__W  s#    	OO 		r   c                 b    U R                   R                  [        R                  " U5      5        g r+   )r'  r  weakref
WeakMethod)r0   callbacks     r1   register_connect_callback$Connection.register_connect_callback]  s!    &&w'9'9('CDr&   c                     / U l         g r+   )r'  r|   s    r1   clear_connect_callbacks"Connection.clear_connect_callbacks`  s
    "$r&   c                 .    U" U R                   S9U l        g)z
Creates a new instance of parser_class with socket size:
_socket_read_size and assigns it to the parser for the connection
:param parser_class: The required parser class
)rr   N)r%  _parser)r0   r)  s     r1   r&  Connection.set_parserc  s     $T5K5KLr&   c                   ^  T R                   (       a  g T R                  R                  U 4S jU 4S j5      nUT l          T R                  c  T R                  5         OT R                  T 5         T R                   H  nU" 5       nU(       d  M  U" T 5        M     g! [        R                   a    [        S5      e[         a  n[        T R                  U5      5      eSnAff = f! [         a    T R                  5         e f = f)z5Connects to the Redis server if not already connectedNc                  $   > T R                  5       $ r+   )_connectr|   s   r1   <lambda>$Connection.connect.<locals>.<lambda>q  s    r&   c                 &   > TR                  U 5      $ r+   r<  )r   r0   s    r1   rM  rN  q  s    tu7Mr&   zTimeout connecting to server)rq   r  call_with_retryry   r   r   OSErrorr   _error_messager$  r   r   r<  r'  )r0   r   erefrA  s   `    r1   connectConnection.connectk  s    ::	:::--')MD 

	&&.! ''- **CuHx +) ~~ 	?=>> 	:!$"5"5a"899	:  	OO	s)   $B C' C' (C$CC$'Dc                 `   Sn[         R                  " U R                  U R                  U R                  [         R
                  5       GH  nUu  p4pVnSn [         R                   " X4U5      nUR                  [         R                  [         R                  S5        U R                  (       ar  UR                  [         R                  [         R                  S5        U R                  R                  5        H%  u  pUR                  [         R                  X5        M'     UR                  U R                  5        UR!                  U5        UR                  U R"                  5        Us  $    Ub  Ue[%        S5      e! [$         a(  nUnUb  UR'                  5          SnAGMY   SnAGM`  SnAff = f)zCreate a TCP socket connectionNr\   z)socket.getaddrinfo returned an empty list)ry   getaddrinfor  r  r  SOCK_STREAM
setsockoptIPPROTO_TCPTCP_NODELAYr  
SOL_SOCKETSO_KEEPALIVEr  itemsr   r  rV  rs   rR  r   )r0   errresfamilysocktypeproto	canonnamesocket_addressr   r2  r3  _s               r1   rL  Connection._connect  sX   
 %%IItyy$"2"2F4F4F
C BE>FeD!}}Vu= 2 2F4F4FJ ((OOF$5$5v7J7JAN $ = = C C E(:(:AA !F  ; ;< ^,  3 341
> ?IABB  !#JJLL $!s   DE;;
F-F((F-c                 d     U R                    SU R                   3nU$ ! [         a    Sn U$ f = f)N:r   )r  r  AttributeError)r0   
host_errors     r1   _host_errorConnection._host_error  sC    	& II;a		{3J   	&%J	&s    //c                 X   U R                  5       n[        UR                  5      S:X  a   SU SUR                  S    S3$  SUR                  S    SU S	UR                  S    S3$ ! [         a    SUR                  S    3s $ f = f! [         a    SUR                  S    3s $ f = f)
Nr\   zError connecting to z.                         r   .zConnection Error: Error z connecting to . )rn  r_   r   rl  )r0   	exceptionrm  s      r1   rS  Connection._error_message  s     %%'
y~~!#@-j\ :"*+1. .
@Y^^A./!l"Y^^A%6$7q:	 " @+INN1,=+>??@ " @+INN1,=+>??@s#   A( %B
 (BB
B)(B)c                 h   U R                   R                  U 5        U R                  (       d"  U R                  (       d  U R                  (       a  U R                  =(       d     [        U R                  U R                  5      nUR                  5       nU R                  " S/UQ7SS06   U R                  5       n[        U5      S:w  a  [        S5      eU R                  (       aE  U R                  SS	U R                  5        [        U R                  5       5      S:w  a  [        S
5      eU R                  (       aE  U R                  SU R                  5        [        U R                  5       5      S:w  a  [        S5      egg! [         a'    U R                  SUS   SS9  U R                  5       n Nf = f)z=Initialize the connection, authenticate and select a databaseAUTHcheck_healthFr   rx  OKzInvalid Username or PasswordCLIENTSETNAMEzError setting client nameSELECTzInvalid DatabaseN)rH  r   r
  r  r  r   get_credentialssend_commandr   r   r!   r   r  r   r  )r0   cred_provider	auth_argsauth_responses       r1   r   Connection.on_connect  sq   % ##(( T5dmmT]]S  &557I fEyEuE5 $ 2 2 4 M*d2)*HII h	43C3CDD..01T9%&ABB 77h0D..01T9%&899 : % 8 5
 !!&)B-e!L $ 2 2 45s   )F   .F10F1c                 r   U R                   R                  5         U R                  c  g[        R                  " 5       U R
                  :X  a*   U R                  R                  [        R                  5         U R                  R                  5         SU l        g! [         a     N/f = f! [         a     N$f = f)z!Disconnects from the Redis serverN)rH  r   rq   r  r  r  shutdownry   	SHUT_RDWRrR  r   )r0   r   s     r1   r<  Connection.disconnect  s    ""$::99;$(("

##F$4$45	JJ 
  
  		s$   )B 7B) 
B&%B&)
B65B6c                 t    U R                  SSS9  [        U R                  5       5      S:w  a  [        S5      eg)z Send PING, expect PONG in returnPINGFry  PONGz#Bad response from PING health checkN)r  r!   r   r   r|   s    r1   
_send_pingConnection._send_ping  s<    &u5**,-7!"GHH 8r&   c                 $    U R                  5         g)z Function to call when PING failsNrP  )r0   r   s     r1   _ping_failedConnection._ping_failed  s    r&   c                     U R                   (       aJ  [        5       U R                  :  a1  U R                  R	                  U R
                  U R                  5        ggg)z3Check the health of the connection with a PING/PONGN)r"  r   r#  r  rQ  r  r  r|   s    r1   rx  Connection.check_health  sA    %%$&43I3I*IJJ&&t8I8IJ +J%r&   c                 v   U R                   (       d  U R                  5         U(       a  U R                  5          [        U[        5      (       a  U/nU H  nU R                   R                  U5        M      g! [        R                   a    U R                  5         [        S5      e[         ao  nU R                  5         [        UR                  5      S:X  a  SUR                  S   peOUR                  S   nUR                  S   n[        SU SU S35      eSnAf[         a    U R                  5         e f = f)	z2Send an already packed command to the Redis serverzTimeout writing to socketr\   UNKNOWNr   rr  z while writing to socket. rq  N)rq   rV  rx  r5   r=   sendallry   r   r<  r   rR  r_   r   r   r   )r0   commandrx  itemrT  r   errmsgs          r1   send_packed_commandConnection.send_packed_command  s    zzLLN	'3''")

""4(  ~~ 	<OO:;; 	WOO166{a )166!9vq	!F5'1KF8ST"UVV 	OO	s   <A7 78D8/A*DD8c                 ^    U R                  U R                  " U6 UR                  SS5      S9  g)z+Pack and send a command to the Redis serverrx  Try  N)r  pack_commandra   )r0   r   r   s      r1   r  Connection.send_command6  s0      t$6::nd3S 	! 	
r&   c                    U R                   nU(       d  U R                  5         U R                  5       n U R                  R	                  U5      $ ! [
         a0  nU R                  5         [        SU SUR                   35      eSnAff = f)z8Poll the socket to see if there's data that can be read.Error while reading from z: N)	rq   rV  rn  rH  r   rR  r<  r   r   )r0   r   r   rm  rT  s        r1   r   Connection.can_read<  sy    zzLLN%%'
	V<<((11 	VOO!$=j\AFF8"TUU	Vs   A 
B
+BB
c                    U R                  5       n U R                  R                  US9nU R                  (       a  [        5       U R                  -   U l        [        U[        5      (       a  UeU$ ! [        R                   a    U R                  5         [        SU 35      e[         a0  nU R                  5         [        SU SUR                   35      eSnAf[         a    U R                  5         e f = f)z0Read the response from a previously sent commandr   zTimeout reading from r  z : N)rn  rH  r   ry   r   r<  r   rR  r   r   r   r"  r   r#  r5   r   )r0   r   rm  rb   rT  s        r1   r   Connection.read_responseJ  s     %%'
	||11CS1TH %%%)Vd.H.H%HD"h..N# ~~ 	EOO!6zlCDD 	OO!+J<3qvvhG   	OO	s   A1 1;C6,+CC6c           	         / n[        US   [        5      (       a1  [        US   R                  5       R	                  5       5      USS -   nO+SUS   ;   a"  [        US   R	                  5       5      USS -   n[
        R                  [        [        [        U5      5      R                  5       [        45      nU R                  n[        U R                  R                  U5       H  n[        U5      n[        U5      U:  d  Xd:  d  [        U[        5      (       ab  [
        R                  U[        [        U5      R                  5       [        45      nUR                  U5        UR                  U5        [        nM  [
        R                  U[        [        U5      R                  5       [        U[        45      nM     UR                  U5        U$ )z2Pack a series of arguments into the Redis protocolr   r\   N    )r5   r=   tupler<   r]   	SYM_EMPTYr0  SYM_STARr_   r   r(  mapr   r7   
SYM_DOLLARr  )r0   r   outputbuffbuffer_cutoffarg
arg_lengths          r1   r  Connection.pack_commandd  sn    d1gs##a)//12T!"X=DT!W_a)DH4D~~xSY)>)>)@(KL++t||**D1C SJD	M)-c:.. ~~:s:'='='?J d#c" ~~"J..0  	! 24 	dr&   c                    / n/ nSnU R                   nU H  nU R                  " U6  H  n[        U5      nXE:  d  X:  d  [        U[        5      (       a(  UR                  [        R                  U5      5        Sn/ nX:  d  [        U[        5      (       a  UR                  U5        M  UR                  U5        XH-  nM     M     U(       a$  UR                  [        R                  U5      5        U$ )z.Pack multiple commands into the Redis protocolr   )r(  r  r_   r5   r7   r  r  r0  )	r0   commandsr  r9  buffer_lengthr  cmdchunkchunklens	            r1   pack_commandsConnection.pack_commands  s    ++C**C0u:!1/!%44MM).."89$%MF+z%/L/LMM%(MM%(!-M 1 $ MM)..01r&   )r(  r'  rH  rq   r%  r  r
  r  r   r"  r  r#  r  r  r  r$  r  r  r  r  r  r  rs   r  r  T)r   rH   ) r?   rI   rJ   rK   rL   r   DefaultParserr   r   r2   r5  r1  r   rB  rE  r&  rV  rL  rn  rS  r   r<  r  r  rx  r  r  r   r   r  r  rM   rN   r&   r1   r  r    s    : #!% "<@/M#. &&89/M#^9E%MB'CR@*&:P$IK
6
V4+Zr&   r  c                   T   ^  \ rS rSrSr            SU 4S jjrU 4S jrSrU =r$ )SSLConnectioni  zManages SSL connections to and from the Redis server(s).
This class extends the Connection class, adding SSL functionality, and making
use of ssl.SSLContext (https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
c                   > [         (       d  [        S5      e[        TU ]  " S0 UD6  Xl        X l        Uc  [        R                  nO\[        U[        5      (       aG  [        R                  [        R                  [        R                  S.nX>;  a  [        SU 35      eX   nX0l        X@l        XPl        Xpl        X`l        Xl        Xl        Xl        Xl        Xl        g)a  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optionalrequiredz+Invalid SSL Certificate Requirements Flag: rN   )ssl_availabler   superr2   keyfilecertfilessl	CERT_NONEr5   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_cert)r0   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                  r1   r2   SSLConnection.__init__  s    H }CDD"6""$ MMMs++----I
 - A-Q  &4M&$""0$0!!2)B& 0&<#r&   c                   > [         T
U ]  5       n[        R                  " 5       nU R                  Ul        U R
                  Ul        U R                  (       d  U R                  (       a/  UR                  U R                  U R                  U R                  S9  U R                  c  U R                  c  U R                  b/  UR                  U R                  U R                  U R                  S9  UR                  XR                   S9nU R"                  SL a  [$        SL a  ['        S5      eU R(                  (       a  U R"                  (       a  ['        S5      eU R(                  (       Ga,  S	SKnS
SKJn  U R0                  cf  UR2                  R5                  UR2                  R6                  5      nUR9                  U R                  5        UR;                  U R                  5        OU R0                  nUR=                  XPR>                  5        UR2                  RA                  U[B        RB                  " 5       5      nURE                  5         URG                  U R                   U RH                  45        URK                  5         URM                  5         U$ U R"                  SL a[  [$        (       aP  S
SKJ'n  U" X0R                   U RH                  U R                  5      n	U	RQ                  5       (       a  U$ [S        S5      eU$ )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   r\   )ocsp_staple_verifier)OCSPVerifierzocsp validation error)*r  rL  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  ry   request_ocsprV  r  do_handshaker  r  is_validr   )r0   r   contextsslsockr  r  
staple_ctxconr  or   s             r1   rL  SSLConnection._connect  sJ   w!,,.!%!4!4"nn==DLL##22 $  MM%||'||'))}}T\\$,, *  %%dII%F!!T).D.M=>>))d.D.D  )))2 $$,$[[001J1JK
//>..t||<!22
//$&A&A
 ++((V]]_ECKKDII./LLNN !!T).D.D*WiiDMMJAzz||%&=>>r&   )r  r  r  r  r  r  r  r  r  r  r  r  )NNr  NNFNNFFNN)	r?   rI   rJ   rK   rL   r2   rL  rM   __classcell__r   s   @r1   r  r    sA       "'#A=FA Ar&   r  c                   `    \ rS rSrSSSSSSSSS\\SSSSSS4S	\\   4S
 jjrS r	S r
S rSrg)UnixDomainSocketConnectioni<   r   Nr   r  Fr	  r
  c                    U(       d  U(       a  Ub  [        S5      e[        R                  " 5       U l        Xl        X l        Xl        UU l        X@l        X0l	        XPl
        Xl        U
[        L a  / n
U	(       a  U
R                  [        5        Xl        U R                  (       aT  Uc  [!        [#        5       S5      U l        O[&        R(                  " U5      U l        U R$                  R+                  U
5        O[!        [#        5       S5      U l        Xl        SU l        UU l        [3        XgU5      U l        SU l        Xl        U R;                  U5        / U l        SU l        g)a  
Initialize a new UnixDomainSocketConnection.
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`.
Nr  r\   r   r  ) r   r  r  r  pathr  r  r
  r  r  rs   r  r   r  r   r  r   r   r  r  r   r!  r"  r#  r$  r(   r   rq   r%  r&  r'  r(  )r0   r  r  r  r  rs   r-   r.   r/   r  r  r)  rr   r"  r  r  r$  r
  s                     r1   r2   #UnixDomainSocketConnection.__init__=  s"   6 &9&E+  99;	&#6   , 0X%N!!,/,}"9;2
 "]]51
JJ..~>y{A.DJ%:"!""4x:JK
!1%"$"r&   c                     SU R                   4SU R                  4/nU R                  (       a  UR                  SU R                  45        U$ )Nr  r  r  )r  r  r  r  r8  s     r1   r1  &UnixDomainSocketConnection.repr_pieces  sB    499%dgg7MM=$*:*:;<r&   c                     [         R                   " [         R                  [         R                  5      nUR                  U R                  5        UR                  U R                  5        U$ )z&Create a Unix domain socket connection)ry   AF_UNIXrZ  r   rs   rV  r  )r0   r   s     r1   rL  #UnixDomainSocketConnection._connect  sC    }}V^^V-?-?@++,TYYr&   c                     [        UR                  5      S:X  a   SU R                   SUR                  S    S3$ SUR                  S    SU R                   SUR                  S    S3$ )Nr\   z!Error connecting to unix socket: rs  r   rq  rr  z connecting to unix socket: )r_   r   r  )r0   rt  s     r1   rS  )UnixDomainSocketConnection._error_message  su     y~~!#6tyykINNSTDUCVVWXX *++G99+R	q 12!5r&   )r(  r'  rq   r%  r  r
  r  r   r"  r#  r  r  r  r$  r  r  r  rs   r  )r?   rI   rJ   rK   r   r  r   r   r2   r1  rL  rS  rM   rN   r&   r1   r  r  <  s^      "<@%C#$ &&89%C#J	r&   r  )0FFALSENNOc                     U b  U S:X  a  g [        U [        5      (       a  U R                  5       [        ;   a  g[	        U 5      $ )Nr  F)r5   r=   upperFALSE_STRINGSr8   )r@   s    r1   to_boolr    s7    }%%++-="@;r&   )	r  rs   r  r  r  r  max_connectionsr"  r  c                    U R                  S5      (       d7  U R                  S5      (       d!  U R                  S5      (       d  [        S5      e[        U 5      n 0 n[        U R                  5      R                  5        HZ  u  p#U(       d  M  [        U5      S:  d  M  [        US   5      n[        R                  U5      nU(       a   U" U5      X'   MV  X1U'   M\     U R                  (       a  [        U R                  5      US'   U R                  (       a  [        U R                  5      US	'   U R                  S
:X  a4  U R                  (       a  [        U R                  5      US'   [        US'   U$ U R                   (       a  [        U R                   5      US'   U R"                  (       a  [%        U R"                  5      US'   U R                  (       a8  SU;  a2   [%        [        U R                  5      R'                  SS5      5      US'   U R                  S:X  a	  [*        US'   U$ ! [        [        4 a    [        SU S35      ef = f! [(        [        4 a     NPf = f)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_PARSERSra   	TypeErrorr  r  schemer  r  hostnamer  r9   r   rl  r  )urlr   namer@   parsers        r1   	parse_urlr     s   z"">>+&&>>)$$5
 	

 3-CF		*0025SZ!^E!H%E/33D9FW#)%=FL  %t 3 ||$S\\2z
||$S\\2z zzV88$SXX.F6N%?!"& M! <<$S\\2F6N88 ]F6N 88F*"7388#4#<#<S"#EFt ::!)6F%&MC ":. W$':4&@T%UVVW6 #J/ s   
H(1I ( IIIc                   z    \ rS rSrSr\S 5       r\S4S jrS r	S r
S rS	 rS
 rS rS rS rSS jrSS jrSrg)ConnectionPooli  a  
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                 f    [        U5      nSU;   a  US   US'   UR                  U5        U " S0 UD6$ )a1  
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  rN   )r   update)clsr  r   url_optionss       r1   from_urlConnectionPool.from_url  s?    R  n'.45G.HK*+k"}V}r&   Nc                     U=(       d    Sn[        U[        5      (       a  US:  a  [        S5      eXl        X0l        X l        [        R                  " 5       U l        U R                  5         g )Nl        r   z,"max_connections" must be a positive integer)
r5   r9   r  r  connection_kwargsr  	threadingLock
_fork_lockreset)r0   r  r  r*  s       r1   r2   ConnectionPool.__init__+  sY     *2U/3//?Q3FKLL 0!2. $..*

r&   c           	      ~    [        U 5      R                   S[        U R                  " S0 U R                  D65       S3$ )Nr.  r/  rN   )r>   r?   r;   r  r*  r|   s    r1   r5  ConnectionPool.__repr__A  s@    Dz""#T**DT-C-CDEFaI	
r&   c                     [         R                  " 5       U l        SU l        / U l        [        5       U l        [        R                  " 5       U l	        g rp   )
r+  r,  _lock_created_connections_available_connectionsset_in_use_connectionsr  r  r  r|   s    r1   r.  ConnectionPool.resetG  s9    ^^%
$%!&(##&5  99;r&   c                 r   U R                   [        R                  " 5       :w  au  U R                  R	                  SS9nU(       d  [
        e U R                   [        R                  " 5       :w  a  U R                  5         U R                  R                  5         g g ! U R                  R                  5         f = f)N   )r   )r  r  r  r-  acquirer   r.  release)r0   acquireds     r1   	_checkpidConnectionPool._checkpidX  s    F 88ryy{"..q.9H***88ryy{*JJL'') # '')s   3B B6c                 r   U R                  5         U R                      U R                  R                  5       nU R                  R                  U5        SSS5         WR                  5          UR                  5       (       a  [        S5      e U$ ! [         a    U R                  5       n Ntf = f! , (       d  f       Nc= f! [        [        4 aD    UR                  5         UR                  5         UR                  5       (       a  [        S5      e U$ f = f! [         a    U R                  W5        e f = f)zGet a connection from the poolNConnection has dataConnection not ready)r>  r3  r5  pop
IndexErrormake_connectionr7  addrV  r   r   rR  r<  r   r<  r0   command_namekeysoptionsr   s        r1   get_connectionConnectionPool.get_connection  s%   ZZ4!88<<>
 $$((4 	 
B&&(()*?@@ ) 3  4!113
4 Z" $W- B%%'""$&&(()*@AA ) B
  	 LL$		sX   B1BB1D . C B.+B1-B..B11
B?ADD DD D6c                     U R                   n[        UR                  SS5      UR                  SS5      UR                  SS5      S9$ )z,Return an encoder based on encoding settingsr-   r   r.   r  r/   Fr,   )r*  r(   ra   )r0   r   s     r1   get_encoderConnectionPool.get_encoder  sF    ''ZZ
G4"JJ'8(C#ZZ(:EB
 	
r&   c                     U R                   U R                  :  a  [        S5      eU =R                   S-  sl         U R                  " S0 U R                  D6$ )zCreate a new connectionzToo many connectionsr\   rN   )r4  r  r   r  r*  r|   s    r1   rE  ConnectionPool.make_connection  sM    $$(<(<<!"899!!Q&!$$>t'='=>>r&   c                    U R                  5         U R                      U R                  R                  U5        U R                  U5      (       a  U R                  R                  U5        O/U =R                  S-  sl        UR                  5          SSS5        g SSS5        g! [         a     Nwf = f! , (       d  f       g= f)z(Releases the connection back to the poolr\   N)
r>  r3  r7  removeKeyErrorowns_connectionr5  r  r4  r<  r   s     r1   r<  ConnectionPool.release  s    ZZ((//
; ##J//++22:>
 ))Q.)%%'! Z ? Z    Zs.   B5B%AB5%
B2/B51B22B55
Cc                 4    UR                   U R                   :H  $ r+   )r  r   s     r1   rU  ConnectionPool.owns_connection  s    ~~))r&   c                 
   U R                  5         U R                     U(       a!  [        U R                  U R                  5      nOU R                  nU H  nUR                  5         M     SSS5        g! , (       d  f       g= f)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>  r3  r   r5  r7  r<  )r0   inuse_connectionsconnectionsr   s       r1   r<  ConnectionPool.disconnect  s`     	ZZ #//1I1I #99)
%%' * ZZs   AA44
Bc                     U R                   R                  SU05        U R                   H	  nXl        M     U R                   H	  nXl        M     g )Nr  )r*  r$  r5  r  r7  )r0   r  conns      r1   	set_retryConnectionPool.set_retry  sE    %%w&67//DJ 0,,DJ -r&   )	r5  r4  r-  r7  r3  r  r*  r  r  r  )r  r   returnN)r?   rI   rJ   rK   rL   classmethodr'  r  r2   r5  r.  r>  rK  rN  rE  r<  rU  r<  r_  rM   rN   r&   r1   r"  r"    s\     . .b  *4,
"-*^B
?**((r&   r"  c                   V   ^  \ rS rSrSrSS\\4U 4S jjrS rS r	S r
S	 rS
 rSrU =r$ )BlockingConnectionPooli  a  
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                 D   > X@l         X l        [        TU ]  " SUUS.UD6  g )N)r  r  rN   )queue_classr   r  r2   )r0   r  r   r  rh  r*  r   s         r1   r2   BlockingConnectionPool.__init__  s2     ' 	
-+	
  	
r&   c                     U R                  U R                  5      U l          U R                  R                  S 5        M  ! [         a     Of = f/ U l        [        R                  " 5       U l        g r+   )	rh  r  pool
put_nowaitr   _connectionsr  r  r  r|   s    r1   r.  BlockingConnectionPool.reset  sf    $$T%9%9:			$$T*   
  99;s   A   
AAc                 t    U R                   " S0 U R                  D6nU R                  R                  U5        U$ )zMake a fresh connection.rN   )r  r*  rm  r  r   s     r1   rE  &BlockingConnectionPool.make_connection7  s5    **DT-C-CD
  ,r&   c                     U R                  5         Sn U R                  R                  SU R                  S9nUc  U R                  5       n UR                  5          UR                  5       (       a  [        S5      e U$ ! [         a    [        S5      ef = f! [
        [        4 aD    UR                  5         UR                  5         UR                  5       (       a  [        S5      e U$ f = f! [         a    U R                  U5        e f = f)a  
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)blockr   zNo connection available.rA  rB  )r>  rk  ra   r   r   r   rE  rV  r   rR  r<  r   r<  rG  s        r1   rK  %BlockingConnectionPool.get_connection=  s    	 
	>T4<<HJ --/J	 
B&&(()*?@@ ) =  	> ""<==	>( $W- B%%'""$&&(()*@AA ) B
  	LL$	s6   $B  C0  B  BAC-)C0 ,C--C0 0Dc                     U R                  5         U R                  U5      (       d,  UR                  5         U R                  R	                  S5        g U R                  R	                  U5        g! [
         a     gf = f)z)Releases the connection back to the pool.N)r>  rU  r<  rk  rl  r   r   s     r1   r<  BlockingConnectionPool.releaseq  sm     	##J//
 !!#II  &	II  , 	 	s   A0 0
A=<A=c                 j    U R                  5         U R                   H  nUR                  5         M     g)z(Disconnects all connections in the pool.N)r>  rm  r<  r   s     r1   r<  !BlockingConnectionPool.disconnect  s(    ++J!!# ,r&   )rm  r  rk  rh  r   )r?   rI   rJ   rK   rL   r  r   r2   r.  rE  rK  r<  r<  rM   r  r  s   @r1   rd  rd    s;    F #
"02h*$ $r&   rd  )[r  r   rt   r  ry   r+  r?  	itertoolsr   queuer   r   r   r   typingr   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  ImportErrorBlockingIOErrorEWOULDBLOCKr   hasattrr"   SSLWantWriteErrorSSLErrorr  rI  r   r   r  r  r   r  r   objectr   rg   ri   rj   rh   rk   r(   rP   rm   r   r   r  r  r  r  r  r  r9   r:   r  r  r   r"  rd  rN   r&   r1   <module>r     s     	 	     ( (   4 4 # T    "  O OM (78I8I&J #s&''DE+C,@,@AEF+C,A,AB<=+CLL9BGGIJ 
	!? 8P N #T     ':0C & &R%' %'PB BJ[: [|jJ jZ !M Mq qhJJ JZ\ \~ / # !
 6r} }@^$^ ^$I.  Ms   F$ $F0/F0