
    (ph                     R   S SK Jr  S SKJr  S SKJr  S SKJ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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Jr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/  S SK0J1r1   S SK2r2S	r3\\Rj                  0r6\3(       a<  \7" \2S5      (       a  S\6\2Rp                  '   S\6\2Rr                  '   OS\6\2Rt                  '   \
Rv                  \6;  a  S\6\
Rv                  '   \<" \6R{                  5       5      r>\1(       aj  S SK?r?\" \?R                  5      rA\A\" S5      :  rB\A\" S5      :  rC\A\" S5      :  rD\C(       d!  S\?R                  -  rE\R                  " \E5        S	rG\C(       d  S
rGSrHSrISrJSrKSrL\M" 5       rN " S S\M5      rO " S S\M5      rP " S S\M5      rQ " S S\P5      rR " S S \P5      rS\1(       a  \SrTO\RrT " S! S"\M5      rU " S# S$\U5      rV " S% S&\U5      rWS'rXS( rY\Z\Z\Y\Y\[\[\YS).r\ " S* S+\M5      r] " S, S-\]5      r^g! \4 a    S
r3 GNf = f).    )unicode_literals)StrictVersion)chain)timeN)xrangeimapunicodelong	nativestr
basestring	iteritems	LifoQueueEmptyFullurlparseparse_qsrecv	recv_intounquoteBlockingIOErrorsendallshutdownssl_wrap_socket)AuthenticationError$AuthenticationWrongNumberOfArgsErrorBusyLoadingErrorChildDeadlockedErrorConnectionError	DataErrorExecAbortErrorInvalidResponseNoPermissionErrorNoScriptErrorReadOnlyError
RedisErrorResponseErrorTimeoutError)HIREDIS_AVAILABLETFSSLWantReadError   iz0.1.3z0.1.4z1.0.0z`redis-py works best with hiredis >= 0.1.4. You're running hiredis %s. Please consider upgrading.   *   $s   
    zConnection closed by server.c                   .    \ rS rSrSrS rS rSS jrSrg)	Encoder_   z=Encode strings to bytes-like and decode bytes-like to stringsc                 (    Xl         X l        X0l        g Nencodingencoding_errorsdecode_responses)selfr4   r5   r6   s       C/var/www/html/venv/lib/python3.13/site-packages/redis/connection.py__init__Encoder.__init__b   s     . 0r-   c                 .   [        U[        [        45      (       a  U$ [        U[        5      (       a  [	        S5      e[        U[
        5      (       a  [        U5      R                  5       nOm[        U[        [        45      (       a  [        U5      R                  5       nO8[        U[        5      (       d#  [        U5      R                  n[	        SU-  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.zLInvalid input of type: '%s'. Convert to a bytes, string, int or float first.)
isinstancebytes
memoryviewboolr   floatreprencodeintr
   strr   type__name__r	   r4   r5   )r7   valuetypenames      r8   rB   Encoder.encodeg   s    eeZ011Lt$$ A B Bu%%K&&(ET{++J%%'EE:..E{++H ACKL M MeW%%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)r6   r<   r>   tobytesr=   decoder4   r5   )r7   rG   forces      r8   rL   Encoder.decode}   sQ      E%,,%''T]]D4H4HIr-   )r6   r4   r5   N)F)	rF   
__module____qualname____firstlineno____doc__r9   rB   rL   __static_attributes__ r-   r8   r/   r/   _   s    C1
,r-   r/   c                   :    \ rS rSr\\\\\S.\\\	\
\\S.rS rSrg)
BaseParser   )zmax number of clients reachedz(Client sent AUTH, but no password is setzinvalid passwordz,wrong number of arguments for 'auth' commandz,wrong number of arguments for 'AUTH' command)ERR	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lenr<   dictgetr&   )r7   response
error_codeexception_classs       r8   parse_errorBaseParser.parse_error   s|    ^^C(+
///J! 3 45H"44Z@O/400"1"5"5h"N"8,,X&&r-   rT   N)rF   rO   rP   rQ   r   r   r   r    r   r#   r$   r"   rc   rj   rS   rT   r-   r8   rV   rV      s=     .=8K 3 5 5
 $#!!%#',	'r-   rV   c                   X    \ 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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)r7   socketrr   rs   s       r8   r9   SocketBuffer.__init__   s/    
 0,zz|r-   c                 4    U R                   U R                  -
  $ r2   )rw   rx   r7   s    r8   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                   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
settimeoutr   r<   r=   rd   r   SERVER_CLOSED_CONNECTION_ERRORwriters   ry   timeoutr'   NONBLOCKING_EXCEPTIONS#NONBLOCKING_EXCEPTION_ERROR_NUMBERSrf   	__class__errnoargs)r7   r}   r   raise_on_timeoutsockrr   bufmarkercustom_timeoutdatadata_lengthexalloweds                r8   _read_from_socketSocketBuffer._read_from_socket   s   zz00ll##$ 0 	5(DJJ(89dE**s4yA~)*HII		$!$i""k1"%%&/   3 34  ~~ 	"#@AA  3 34  & 		.
 :==bllBOG#G(;  3 34  "#%77#- . .		.  3 34 s=   B!D &G"7G% 	G"%7GG% GG""G% %%H
c                 Z    [        U R                  5      =(       d    U R                  USS9$ )NFr   r   )r?   r}   r   r7   r   s     r8   can_readSocketBuffer.can_read   s0    DKK  ;""749 # ;	;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 R                  U R                  :X  a  U R                  5         US S $ )Nr*   )	r}   r   rv   r   rx   readrd   rw   purge)r7   r}   r   s      r8   r   SocketBuffer.read   s    !KK""6KK#78$//*||  (3t9$ ??d000JJL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 R                  U R                  :X  a  U R                  5         US S $ )Nr   )
rv   r   rx   readlineendswithSYM_CRLFr   rd   rw   r   )r7   r   r   s      r8   r   SocketBuffer.readline   s    ll!||~--))""$HHT__%<<>D	 --)) 	3t9$ ??d000JJLCRyr-   c                     U R                   R                  S5        U R                   R                  5         SU l        SU l        g rp   )rv   r   truncaterw   rx   r|   s    r8   r   SocketBuffer.purge  s3    !r-   c                      U R                  5         U R                  R                  5         S U l        S U l        g ! [         a     Nf = fr2   )r   rv   close	Exceptionrq   r|   s    r8   r   SocketBuffer.close  sF    		JJLLL  
  	 	s   *; 
AA)rv   rq   rx   rw   rr   rs   )rF   rO   rP   rQ   r9   propertyr}   r   r   r   r   r   r   r   rS   rT   r-   r8   rm   rm      sD     4 4 (,X+/)5V;
"&r-   rm   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)PythonParseri"  zPlain Python parsing classc                 :    Xl         S U l        S U l        S U l        g r2   )rr   encoderrq   rv   r7   rr   s     r8   r9   PythonParser.__init__$  s     0
r-   c                 F     U R                  5         g ! [         a     g f = fr2   on_disconnectr   r|   s    r8   __del__PythonParser.__del__*  %    	  		    
  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   r7   
connections     r8   
on_connectPythonParser.on_connect0  sB    %%
#DJJ$($9$9$.$=$=? "))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    r8   r   PythonParser.on_disconnect8  s1    
<<#LL DLr-   c                 ^    U R                   =(       a    U R                   R                  U5      $ r2   )rv   r   r   s     r8   r   PythonParser.can_read@  s     ||> 5 5g >>r-   c                    U R                   R                  5       nU(       d  [        [        5      eUS S USS  p2US;  a  [	        SU-  5      eUS:X  a5  [        U5      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  o`R                  5       PM     nn[        U[        5      (       a  U R                  R                  U5      nU$ s  snf )
Nra   )   -   +   :r,   r+   zProtocol Error: %rr   r   r   r,   r   r+   )rv   r   r   r   r!   r   rj   r<   r
   rC   r   r   read_responser=   r   rL   )r7   rawbyterg   errorr}   is          r8   r   PythonParser.read_responseC  s;   ll##%!"@AARa#ab'h55!"6"<== 4< *H$$X.E %11
 LT\T\H~HT\]F|||((0HT\]F|6<VnEn**,nHEh&&||**84H Fs   ;E)rv   rq   r   rr   N)rF   rO   rP   rQ   rR   r9   r   r   r   r   r   rS   rT   r-   r8   r   r   "  s#     *?+r-   r   c                   J    \ rS rSrSrS rS rS rS rS r	\
S4S	 jrS
 rSrg)HiredisParseriq  z*Parser class for connections using Hiredisc                 t    [         (       d  [        S5      eXl        [        (       a  [	        U5      U l        g g )NzHiredis is not installed)r(   r%   rr   HIREDIS_USE_BYTE_BUFFER	bytearrayrv   r   s     r8   r9   HiredisParser.__init__s  s2      788 0""$%56DL #r-   c                 F     U R                  5         g ! [         a     g f = fr2   r   r|   s    r8   r   HiredisParser.__del__{  r   r   c                    UR                   U l         UR                  U l        [        U R                  S.n[
        (       d	  [        US'   UR                  R                  (       a  UR                  R                  US'   [        (       a  UR                  R                  US'   [        R                  " S0 UD6U l        SU l        g )N)protocolError
replyErrorr   r4   errorsFrT   )rq   rs   _socket_timeoutr!   rj    HIREDIS_SUPPORTS_CALLABLE_ERRORSr&   r   r6   r4    HIREDIS_SUPPORTS_ENCODING_ERRORSr5   hiredisReader_reader_next_response)r7   r   kwargss      r8   r   HiredisParser.on_connect  s    %%
)88,**
 0/#0F< ..!+!3!3!<!<F:++)11AAF8~~//#r-   c                 .    S U l         S U l        SU l        g NF)rq   r   r   r|   s    r8   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     r8   r   HiredisParser.can_read  sh    ||!"@AA%'"&,,"3"3"5D""e+,,W>C - E Er-   Tc                 J   U R                   nU[        Ln U(       a  UR                  U5        [        (       a]  [	        U R                   U R
                  5      nUS:X  a  [        [        5      eU R                  R                  U R
                  SU5        On[        U R                   U R                  5      n[        U[        5      (       a  [        U5      S:X  a  [        [        5      eU R                  R                  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R0                  < 35      eS nAff = f! U(       a  UR                  U R                  5        f f = fr   )rq   r   r   r   r   rv   r   r   r   feedr   rr   r<   r=   rd   r   ry   r   r'   r   r   rf   r   r   r   )	r7   r   r   r   r   bufflenbufferr   r   s	            r8   r   HiredisParser.read_from_socket  s   zz 0!	6(&&#DJJ=a<)*HII!!$,,7;djj$*?*?@!&%00CK14D)*HII!!&)    4 45  ~~ 	"#@AA  4 45  & 		.
 :==bllBOG#G(;  4 45  "#%77#- . .		.  4 45 s<   C.D) )&G:G= 4	G:=7G54G= G55G::G= =%H"c                    U R                   (       d  [        [        5      eU R                  SLa  U R                  nSU l        U$ U R                   R	                  5       nUSL a1  U R                  5         U R                   R	                  5       nUSL a  M1  [        (       d  [        U[        5      (       a  U R                  UR                  S   5      nOX[        U[        5      (       aC  U(       a<  [        US   [        5      (       a$  U R                  US   R                  S   5      US'   [        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   r   r<   r&   rj   r   list)r7   rg   s     r8   r   HiredisParser.read_response  s3   ||!"@AA e+**H"'DO<<$$&%!!#||((*H %
 0/(M22++HMM!,<=Hd++x{M::"..x{/?/?/BC h00N$''H8A;881+r-   )rv   r   r   rq   r   rr   N)rF   rO   rP   rQ   rR   r9   r   r   r   r   r   r   r   rS   rT   r-   r8   r   r   q  s0    07$&$
	 (0$ $6L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4S 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S jrS rSS jrS rS rS rSrg) 
Connectioni  z4Manages TCP communication to and from a Redis server	localhost  r   NFutf-8strict   c                    [         R                  " 5       U l        Xl        [	        U5      U l        X0l        UU l        UU l        X@l	        XPl
        U=(       d    UU l        Xpl        U=(       d    0 U l        Xl        Xl        UU l        SU l        [%        XU5      U l        S U l        U" US9U l        / U l        SU l        g Nr   )rr   ip  )osgetpidpidhostrC   portdbusernameclient_namepasswordrs   socket_connect_timeoutsocket_keepalivesocket_keepalive_optionssocket_typeretry_on_timeouthealth_check_intervalnext_health_checkr/   r   rq   _parser_connect_callbacks_buffer_cutoff)r7   r   r   r  r  rs   r  r  r  r  r	  r4   r5   r6   parser_classrr   r
  r  r  s                      r8   r9   Connection.__init__  s     99;	I	 & ,&<&N# 0(@(FB%& 0%:"!"x:JK
#5EF"$"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   rF   )r7   kv	repr_argss       r8   __repr__Connection.__repr__  sL    HH4;K;K;MN;M41A.;MNO	>>22I>> O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  appendr7   piecess     r8   r  Connection.repr_pieces  sS    TYYTYY477O

 MM=$*:*:;<r-   c                 F     U R                  5         g ! [         a     g f = fr2   )
disconnectr   r|   s    r8   r   Connection.__del__  s#    	OO 		r   c                 :    U R                   R                  U5        g r2   )r  r  )r7   callbacks     r8   register_connect_callback$Connection.register_connect_callback$  s    &&x0r-   c                     / U l         g r2   )r  r|   s    r8   clear_connect_callbacks"Connection.clear_connect_callbacks'  s
    "$r-   c                    U R                   (       a  g U R                  5       nXl          U R                  5         U R                   H  nU" U 5        M     g! [        R                   a    [	        S5      e[        R
                   a  n[        U R                  U5      5      eSnAff = f! [         a    U R                  5         e f = f)z5Connects to the Redis server if not already connectedNzTimeout connecting to server)rq   _connectry   r   r'   r   r   _error_messager   r%   r#  r  )r7   r   er&  s       r8   connectConnection.connect*  s    ::	:==?D 
	OO //HTN 0 ~~ 	?=>>|| 	:!$"5"5a"899	:  	OO	s"   A B+ 2B(	B##B(+C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                  (       am  UR                  [         R                  [         R                  S5        [        U 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[         R$                  " S5      e! [         R$                   a(  nUnUb  UR'                  5          SnAGMi   SnAGMp  SnAff = f)zCreate a TCP socket connectionNra   z)socket.getaddrinfo returned an empty list)ry   getaddrinfor   r   r  SOCK_STREAM
setsockoptIPPROTO_TCPTCP_NODELAYr  
SOL_SOCKETSO_KEEPALIVEr   r  r   r  r0  rs   r   r   )r7   errresfamilysocktypeproto	canonnamesocket_addressr   r  r  _s               r8   r-  Connection._connectB  sX   
 %%diiD<L<L&,&8&8:CAD>FeD!}}Vu= 2 2F4F4FJ ((OOF$5$5v7J7JAN )$*G*G H(:(:AA !I  ; ;< ^,  3 34/:< ?IllFGG << !#JJLL $!s   DFF=F88F=c           	         [        UR                  5      S:X  a0  SU R                  < SU R                  < SUR                  S   < S3$ SUR                  S   < SU R                  < SU R                  < SUR                  S   < S3	$ )	Nra   zError connecting to :. r   .Error z connecting to )rd   r   r   r   r7   	exceptions     r8   r.  Connection._error_messagej  sm     y~~!#DIIy~~a'8: : $
 "DIItyy)..:KM Mr-   c                 N   U R                   R                  U 5        U R                  (       d  U R                  (       a  U R                  (       a"  U R                  U R                  =(       d    S4nOU R                  4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 R                  SS9  U R                  5       n Nf = f)z=Initialize the connection, authenticate and select a database AUTHcheck_healthFrN  OKzInvalid Username or PasswordCLIENTSETNAMEzError setting client nameSELECTzInvalid DatabaseN)r  r   r  r  send_commandr   r   r   r   r  r   r  )r7   	auth_argsauth_responses      r8   r   Connection.on_connectt  s]   % ==DMM}}!]]DMM,?R@	!]],	 fEyEuE5 $ 2 2 4 '4/)*HII h	43C3CD++-.$6%&ABB 77h0++-.$6%&899 7 % 8 5
 !!&$--e!L $ 2 2 45s   E, ,5F$#F$c                 Z   U R                   R                  5         U R                  c  g [        R                  " 5       U R
                  :X  a$  [        U R                  [        R                  5        U R                  R                  5         SU l        g! [        R                   a     Nf = f)z!Disconnects from the Redis serverN)r  r   rq   r   r   r   r   ry   	SHUT_RDWRr   r   r|   s    r8   r#  Connection.disconnect  s{    ""$::	yy{dhh&V%5%56JJ 
 || 		s   A!B B*)B*c                    U R                   (       aS  [        5       U R                  :  a:   U R                  SSS9  [	        U R                  5       5      S:w  a  [        S5      eggg! [        [        4 aK    U R                  5         U R                  SSS9  [	        U R                  5       5      S:w  a  [        S5      e gf = f)z3Check the health of the connection with a PING/PONGPINGFrO  PONGz#Bad response from PING health checkN)	r
  r   r  rT  r   r   r   r'   r#  r|   s    r8   rN  Connection.check_health  s    %%$&43I3I*I
?!!&u!=T//12f<)=? ? = +J% $\2 ?!!!&u!=T//12f<)=? ? =?s   8A& &AC Cc                    U R                   (       d  U R                  5         U(       a  U R                  5          [        U[        5      (       a  U/nU H  n[        U R                   U5        M     g! [        R                   a    U R                  5         [        S5      e[        R                   aq  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 socketra   UNKNOWNr   rG  z while writing to socket. rF  N)rq   r0  rN  r<   rD   r   ry   r   r#  r'   r   rd   r   r   BaseException)r7   commandrN  itemr/  r   errmsgs          r8   send_packed_commandConnection.send_packed_command  s    zzLLN	'3''")

D)  ~~ 	<OO:;;|| 	3OO166{a )166!9vq	!#(&#2 3 3 	OO	s   7A2 2AD?4A,D  D?c                 ^    U R                  U R                  " U6 UR                  SS5      S9  g)z+Pack and send a command to the Redis serverrN  TrO  N)re  pack_commandrf   )r7   r   r   s      r8   rT  Connection.send_command  s1      !2!2D!9.4jj.N 	! 	Pr-   c                     U R                   nU(       d  U R                  5         U R                   nU R                  R                  U5      $ )z8Poll the socket to see if there's data that can be read.)rq   r0  r  r   )r7   r   r   s      r8   r   Connection.can_read  s5    zzLLN::D||$$W--r-   c           	      N    U R                   R                  5       nU R                  (       a  [        5       U R                  -   U l        [        U[         5      (       a  UeU$ ! [        R                   a8    U R	                  5         [        SU R                  < SU R                  < 35      e[        R                   aJ  nU R	                  5         [        SU R                  < SU R                  < SUR                  < 35      eSnAf[         a    U R	                  5         e f = f)z0Read the response from a previously sent commandzTimeout reading from rD  zError while reading from z : N)r  r   ry   r   r#  r'   r   r   r   r   r   ra  r
  r   r  r<   r&   )r7   rg   r/  s      r8   r   Connection.read_response  s    	||113H %%%)Vd.H.H%HD"h..N# ~~ 	7OO $		499 6 7 7|| 	BOO!#'99dii#A B B 	OO	s   A" "AD$ ADD$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   ra   N    )r<   r	   tuplerB   rb   	SYM_EMPTYr  SYM_STARrD   rd   r   r  r   r   r>   
SYM_DOLLARr  )r7   r   outputbuffbuffer_cutoffarg
arg_lengths          r8   rh  Connection.pack_command  sh    d1gw''a)//12T!"X=DT!W_a)DH4D~~xSY)>)>)@(KL++++T2C SJD	M)Z-G!#z22 ~~:s:'='='?JLd#c" ~~:s:'='='?sH./ 3 	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  rh  rd   r<   r>   r  rq  r  )	r7   commandsrt  r   buffer_lengthrv  cmdchunkchunklens	            r8   pack_commandsConnection.pack_commands  s    ++C**C0u:!1X5M%eZ88MM).."89$%MF+z%/L/LMM%(MM%(!-M 1  MM)..01r-   )r  r  r  rq   r  r  r   r
  r   r  r  r   r   r	  r  r  r  rs   r  r  T)r   )rF   rO   rP   rQ   rR   DefaultParserr9   r  r  r   r'  r*  r0  r-  r.  r   r#  rN  re  rT  r   r   rh  r  rS   rT   r-   r8   r   r     s    :'dq4 $T"'$!)E+e'(dT#8?1%0&HPM%:N?8P
.. Dr-   r   c                   >   ^  \ rS rSr   SU 4S jjrU 4S jrSrU =r$ )SSLConnectioni4  c                 v  > [         (       d  [        S5      e[        [        U ]  " S0 UD6  Xl        X l        Uc  [        R                  nO\[        U[        5      (       aG  [        R                  [        R                  [        R                  S.nX7;  a  [        SU-  5      eXs   nX0l        X@l        XPl        g )Nz$Python wasn't built with SSL support)noneoptionalrequiredz-Invalid SSL Certificate Requirements Flag: %srT   )ssl_availabler%   superr  r9   keyfilecertfilessl	CERT_NONEr<   r   CERT_OPTIONALCERT_REQUIRED	cert_reqsca_certscheck_hostname)	r7   ssl_keyfilessl_certfilessl_cert_reqsssl_ca_certsssl_check_hostnamer   	CERT_REQSr   s	           r8   r9   SSLConnection.__init__6  s     }CDDmT+5f5"$ MMMz22----I
 - C!"# # &4M&$0r-   c           	      H  > [         [        U ]  5       n[        [        S5      (       a  [        R
                  " 5       nU R                  Ul        U R                  Ul        U R                  (       a5  U R                  (       a$  UR                  U R                  U R                  S9  U R                  (       a  UR                  U R                  5        [        X!U R                  S9nU$ [        [        UU R                  U R                  U R                  U R                  S9nU$ )z Wrap the socket with SSL supportcreate_default_context)r  r  )server_hostname)r  r  r  r  )r  r  r-  hasattrr  r  r  r  verify_moder  r  load_cert_chainr  load_verify_locationsr   r   )r7   r   contextr   s      r8   r-  SSLConnection._connectQ  s    ]D243011002G%)%8%8G""&..G}}''04 ( >}}--dmm<"7$))LD  #3#'-1^^+/<<,0MM,0MM;D r-   )r  r  r  r  r  )NNr  NF)rF   rO   rP   rQ   r9   r-  rS   __classcell__r   s   @r8   r  r  4  s    6:8<$)16 r-   r  c                   J    \ rS rSrSSSSSSSSS\SSS4S	 jrS
 rS rS rSr	g)UnixDomainSocketConnectionij  rL  r   Nr   r   Fr   c                    [         R                  " 5       U l        Xl        X l        X0l        Xl        X@l        XPl        Xl	        Xl
        SU l        [        XgU5      U l        S U l        U
" US9U l        / U l        SU l        g r   )r   r   r   pathr  r  r  r  rs   r	  r
  r  r/   r   rq   r  r  r  )r7   r  r  r  r  rs   r4   r5   r6   r	  r  rr   r
  r  s                 r8   r9   #UnixDomainSocketConnection.__init__l  sx     99;	 & , 0%:"!"x:JK
#5EF"$"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  r  s     r8   r  &UnixDomainSocketConnection.repr_pieces  sG    TYY477O
 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_UNIXr4  r   rs   r0  r  )r7   r   s     r8   r-  #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$ )Nra   z!Error connecting to unix socket: rE  r   rF  rG  z connecting to unix socket: )rd   r   r  rH  s     r8   r.  )UnixDomainSocketConnection._error_message  sa     y~~!#INN1-/ / $
 "DIIy~~a/@B Br-   )r  r  r  rq   r  r  r   r
  r  r  r  r   r	  rs   r  )
rF   rO   rP   rQ   r  r9   r  r-  r.  rS   rT   r-   r8   r  r  j  s7    1td $w!)E"'+e'(d#,Br-   r  )0FFALSENNOc                     U b  U S:X  a  g [        U [        5      (       a  U R                  5       [        ;   a  g[	        U 5      $ )NrL  F)r<   r   upperFALSE_STRINGSr?   )rG   s    r8   to_boolr    s7    }%$$-)G;r-   )rs   r  r  r	  max_connectionsr
  r  c                   t    \ rS rSrSr\SS j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rg)ConnectionPooli  zGeneric connection poolNc                    [        U5      n0 n[        [        UR                  5      5       HR  u  pgU(       d  M  [	        U5      S:  d  M  [
        R                  U5      nU(       a   U" US   5      XV'   MK  US   XV'   MT     U(       a  UR                  (       a  [        UR                  5      OSn	UR                  (       a  [        UR                  5      OSn
UR                  (       a  [        UR                  5      OSnUR                   (       a  [        UR                   5      OSnOBUR                  =(       d    Sn	UR                  =(       d    Sn
UR                  nUR                   nUR"                  S:X  a  UR%                  U	U
U[&        S.5        OUR"                  S;   ax  UR%                  U[)        UR*                  =(       d    S5      U	U
S.5        S	U;  a&  U(       a   [)        UR-                  S
S5      5      US	'   UR"                  S:X  a	  [0        US'   OSR3                  S5      n[        SU-  5      e[)        UR                  S	U=(       d    S5      5      US	'   UR%                  U5        SU;   a3  [        R                  " [5        S5      5        UR7                  S5      US'   SU;   a3  [        R                  " [5        S5      5        UR7                  S5      US'   U " S0 UD6$ ! [        [        4 a'    [        R                  " [        SU-  5      5         GM  f = f! [.        [        4 a     GN8f = f)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]:[password]]@/path/to/socket.sock?db=0

Three URL schemes are supported:

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

There are several ways to specify a database number. The parse function
will return the first specified option:
    1. A ``db`` querystring option, e.g. redis://localhost?db=0
    2. If using the redis:// scheme, the path argument of the url, e.g.
       redis://localhost/0
    3. The ``db`` argument to this function.

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

The ``decode_components`` argument allows this function to work with
percent-encoded URLs. If this argument is set to ``True`` all ``%xx``
escapes will be replaced by their single-character equivalents after
the URL has been parsed. This only applies to the ``hostname``,
``path``, ``username`` and ``password`` components.

Any additional querystring arguments and keyword arguments will be
passed along to the ConnectionPool class's initializer. The querystring
arguments ``socket_connect_timeout`` and ``socket_timeout`` if supplied
are parsed as float values. The arguments ``socket_keepalive`` and
``retry_on_timeout`` are parsed to boolean values that accept
True/False, Yes/No values to indicate state. Invalid types cause a
``UserWarning`` to be raised. In the case of conflicting arguments,
querystring arguments always win.

r   z)Invalid value for `%s` in connection URL.Nunix)r  r  r  connection_class)redisredissr   )r   r   r  r  r  /rL  r  r  z, )zredis://z	rediss://zunix://z8Redis URL must specify one of the following schemes (%s)charsetz/"charset" is deprecated. Use "encoding" insteadr4   r   z5"errors" is deprecated. Use "encoding_errors" insteadr5   rT   )r   r   r   queryrd   URL_QUERY_ARGUMENT_PARSERSrf   	TypeError
ValueErrorwarningswarnUserWarningr  r   r  r  hostnameschemeupdater  rC   r   replaceAttributeErrorr  r  DeprecationWarningpop)clsurlr  decode_componentsr   url_optionsnamerG   parserr  r  r  r  valid_schemess                 r8   from_urlConnectionPool.from_url  s   \ sm$Xcii%89KDuUa377=,258,<) ).aK% : 03ws||,$H03ws||,$H(+7388$dD03ws||,$H||+tH||+tH88D||H ::$$$>	   ZZ.. CHH,-$$	   ;&4(+DLLb,A(BK% zzX%2?./ II&JKM ,.;< = =  bgA >?D 	k" MM,AC D!'I!6F:vMM,GI J(.

8(<F$%}V}E &z2  kG$N'  P '
3 s$   (K0'L* 02L'&L'*L>=L>c                     U=(       d    Sn[        U[        [        45      (       a  US:  a  [        S5      eXl        X0l        X l        [        R                  " 5       U l	        U R                  5         g)aa  
Create a connection pool. If max_connections is set, then this
object raises redis.ConnectionError when the pool's limit is reached.

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

Any additional keyword arguments are passed to the constructor of
connection_class.
l        r   z,"max_connections" must be a positive integerN)r<   rC   r
   r  r  connection_kwargsr  	threadingLock
_fork_lockreset)r7   r  r  r  s       r8   r9   ConnectionPool.__init__0  s]     *4W/C;77?Q;NKLL 0!2. $..*

r-   c           	          [        U 5      R                  < S[        U R                  " S0 U R                  D65      < S3$ )Nr  r  rT   )rE   rF   rA   r  r  r|   s    r8   r  ConnectionPool.__repr__O  s5    J&&@)?)?@A
 	
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    r8   r  ConnectionPool.resetU  s9    ^^%
$%!&(##&5  99;r-   c                    U R                   [        R                  " 5       :w  a  [        5       S-   nSn[        5       U:  a3  U R                  R                  S5      nU(       a  O[        5       U:  a  M3  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   F)	r   r   r   r   r  acquirer   r  release)r7   
timeout_atacquireds      r8   	_checkpidConnectionPool._checkpidf  s    F 88ryy{" !JH&:%??2259 &:% ***88ryy{*JJL'')# #" '')s   3C C-c                 f   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! [         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  r  r  r  
IndexErrormake_connectionr  addr0  r   r   r#  ra  r  r7   command_namekeysoptionsr   s        r8   get_connectionConnectionPool.get_connection  s    ZZ4!88<<>
 $$((4 	 
B&&(()*?@@ ) 3  4!113
4 Z" # B%%'""$&&(()*@AA ) B
  	 LL$		sX   B1BB1D . C B.+B1-B..B11
B?A
DD DD D0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 settingsr4   r   r5   r   r6   Fr3   )r  r/   rf   )r7   r   s     r8   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 connectionsra   rT   )r  r  r   r  r  r|   s    r8   r  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 poolra   N)
r  r  r  removeKeyErrorowns_connectionr  r  r  r#  r   s     r8   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  $ r2   )r   r   s     r8   r	  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  r  r   r  r  r#  )r7   inuse_connectionsconnectionsr   s       r8   r#  ConnectionPool.disconnect  s`     	ZZ #D$?$?$($<$<> #99)
%%' * ZZs   AA44
B)	r  r  r  r  r  r  r  r  r   r   r  )rF   rO   rP   rQ   rR   classmethodr  r   r9   r  r  r  r  r  r  r  r	  r#  rS   rT   r-   r8   r  r    sU    x xt )3D >
"4*l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.connection.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.exceptions.ConnectionError`` (as the default
``:py:class: ~redis.connection.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                 L   > X@l         X l        [        [        U ]  " SUUS.UD6  g )N)r  r  rT   )queue_classr   r  r  r9   )r7   r  r   r  r  r  r   s         r8   r9   BlockingConnectionPool.__init__  s5     '$d4 	!-+	!  	!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 r2   )	r  r  pool
put_nowaitr   _connectionsr   r   r   r|   s    r8   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.rT   )r  r  r  r  r   s     r8   r  &BlockingConnectionPool.make_connection=  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! [
         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.r  r  )r  r  rf   r   r   r   r  r0  r   r#  ra  r  r  s        r8   r  %BlockingConnectionPool.get_connectionC  s    	 
	>T4<<HJ --/J	 
B&&(()*?@@ ) =  	> ""<==	>( # B%%'""$&&(()*@AA ) B
  	LL$	s6   $B  C*  B  BA
C'#C* &C''C* *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  r	  r#  r  r  r   r   s     r8   r  BlockingConnectionPool.releasew  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  r  r#  r   s     r8   r#  !BlockingConnectionPool.disconnect  s(    ++J!!# ,r-   )r  r   r  r  r   )rF   rO   rP   rQ   rR   r   r   r9   r  r  r  r  r#  rS   r  r  s   @r8   r  r    s9    @ (*2",)	!02h*$ $r-   r  )_
__future__r   distutils.versionr   	itertoolsr   r   r   rt   r   ry   r  r  redis._compatr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   redis.exceptionsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   redis.utilsr(   r  r  ImportErrorEWOULDBLOCKr   r  r)   SSLWantWriteErrorSSLErrorr   rp  r  r   r   __version__hiredis_versionr   HIREDIS_SUPPORTS_BYTE_BUFFERr   msgr  r   rr  rs  r   rq  r   objectr   r/   rV   rm   r   r   r  r   r  r  r  r  r@   rC   r  r  r  rT   r-   r8   <module>r6     sz   ' +    	 	   ? ? ? ? ? ?
     *M
 U&&' # s&''DE+C,@,@AEF+C,A,AB<=+CLL9 
<<::8?'5BGGIJ #G$7$78O=11 % 	=11 ! 	=11 % (8:A:M:MNc"'"'
	!? 8%f %P '  'Fu6 upL: L^wJ wt !M M@ @F
3J 3l0B 0Bf / # ! C(V C(L
W$^ W$g&  Ms   H H&%H&