HEX
Server: LiteSpeed
System: Linux linux31.centraldnserver.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: salamatk (1501)
PHP: 8.1.33
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open
Upload Files
File: //lib/python3.6/site-packages/redis/__pycache__/connection.cpython-36.pyc
3

be�^���@s�ddlmZddlmZddlmZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1yddl2Z2d	Z3Wne4k
�r*d
Z3YnXeej5iZ6e3�rhe7e2d��r^de6e2j8<de6e2j9<n
de6e2j:<e
j;e6k�r~d3e6e
j;<e<e6j=��Z>e1�r�ddl?Z?ee?j@�ZAeAed�kZBeAed�kZCeAed�kZDeC�s�de?j@ZEejFeE�d	ZGeC�s�d
ZGdZHdZIdZJdZKdZLeM�ZNGdd�deM�ZOGdd�deM�ZPGdd�deM�ZQGdd�deP�ZRGdd �d eP�ZSe1�rdeSZTneRZTGd!d"�d"eM�ZUGd#d$�d$eU�ZVGd%d&�d&eU�ZWd4ZXd,d-�ZYeZeZeYeYe[e[eYd.�Z\Gd/d0�d0eM�Z]Gd1d2�d2e]�Z^dS)5�)�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�i?Bz0.1.3z0.1.4z1.0.0z`redis-py works best with hiredis >= 0.1.4. You're running hiredis %s. Please consider upgrading.�*�$s
�zConnection closed by server.c@s*eZdZdZdd�Zdd�Zd
dd�Zd	S)�Encoderz=Encode strings to bytes-like and decode bytes-like to stringscCs||_||_||_dS)N)�encoding�encoding_errors�decode_responses)�selfr.r/r0�r2� /usr/lib/python3.6/connection.py�__init__bszEncoder.__init__cCs�t|ttf�r|St|t�r&td��nTt|t�r>t|�j�}n<t|tt	f�rZt
|�j�}n t|t�szt|�j
}td|��t|t�r�|j|j|j�}|S)z=Return a bytestring or bytes-like representation of the valuezNInvalid input of type: 'bool'. Convert to a bytes, string, int or float first.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__rr.r/)r1�value�typenamer2r2r3r;gs





zEncoder.encodeFcCs:|js
|r6t|t�r|j�}t|t�r6|j|j|j�}|S)z:Return a unicode string from the bytes-like representation)r0r5r7�tobytesr6�decoder.r/)r1r@�forcer2r2r3rC}s


zEncoder.decodeN)F)r?�
__module__�__qualname__�__doc__r4r;rCr2r2r2r3r-_sr-c@s4eZdZeeeeed�eeee	ee
d�Zdd�ZdS)�
BaseParser)zmax number of clients reachedz(Client sent AUTH, but no password is setzinvalid passwordz,wrong number of arguments for 'auth' commandz,wrong number of arguments for 'AUTH' command)ZERRZ	EXECABORTZLOADINGZNOSCRIPTZREADONLYZNOAUTHZNOPERMcCs\|jd�d}||jkrT|t|�dd�}|j|}t|t�rL|j|t�}||�St|�S)zParse an error response� r�N)�split�EXCEPTION_CLASSES�lenr5�dict�getr%)r1�responseZ
error_codeZexception_classr2r2r3�parse_error�s


zBaseParser.parse_errorN)
r?rErFrrrrrr"r#r!rLrQr2r2r2r3rH�srHc@sXeZdZdd�Zedd��Zdedfdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)�SocketBuffercCs,||_||_||_tj�|_d|_d|_dS)Nr)�_sock�socket_read_size�socket_timeout�io�BytesIO�_buffer�
bytes_written�
bytes_read)r1�socketrTrUr2r2r3r4�s
zSocketBuffer.__init__cCs|j|jS)N)rYrZ)r1r2r2r3�length�szSocketBuffer.lengthNTc
CsB|j}|j}|j}|j|j�d}|tk	}�z�y||r>|j|�xht|j|�}	t|	t	�rjt
|	�dkrjtt��|j
|	�t
|	�}
|j|
7_||
7}|dk	r�||kr�q@dSWnztjk
r�|r�td��dStk
�r$}z<tj|jd�}|�r|j|k�rdStd|jf��WYdd}~XnXWd|�r<|j|j�XdS)NrTzTimeout reading from socketFrJz#Error while reading from socket: %s���)rSrTrX�seekrY�SENTINEL�
settimeoutrr5r6rMr�SERVER_CLOSED_CONNECTION_ERROR�writer[�timeoutr&�NONBLOCKING_EXCEPTIONS�#NONBLOCKING_EXCEPTION_ERROR_NUMBERSrO�	__class__�errno�argsrU)
r1r\rc�raise_on_timeout�sockrT�bufZmarker�custom_timeout�dataZdata_length�ex�allowedr2r2r3�_read_from_socket�s@

"zSocketBuffer._read_from_socketcCst|j�p|j|dd�S)NF)rcri)r8r\rp)r1rcr2r2r3�can_read�s
zSocketBuffer.can_readcCsn|d}||jkr"|j||j�|jj|j�|jj|�}|jt|�7_|j|jkrb|j�|dd�S)Nr)���)	r\rprXr^rZ�readrMrY�purge)r1r\rmr2r2r3rs�s
zSocketBuffer.readcCsx|j}|j|j�|j�}x*|jt�sD|j�|j|j�|j�}qW|jt|�7_|j|jkrl|j	�|dd�S)Nr)rr)
rXr^rZ�readline�endswith�SYM_CRLFrprMrYrt)r1rkrmr2r2r3ru�szSocketBuffer.readlinecCs&|jjd�|jj�d|_d|_dS)Nr)rXr^�truncaterYrZ)r1r2r2r3rt
s
zSocketBuffer.purgecCs<y|j�|jj�Wntk
r*YnXd|_d|_dS)N)rtrX�close�	ExceptionrS)r1r2r2r3ryszSocketBuffer.close)
r?rErFr4�propertyr\r_rprqrsrurtryr2r2r2r3rR�s
*rRc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�PythonParserzPlain Python parsing classcCs||_d|_d|_d|_dS)N)rT�encoderrSrX)r1rTr2r2r3r4$szPythonParser.__init__cCs&y|j�Wntk
r YnXdS)N)�
on_disconnectrz)r1r2r2r3�__del__*szPythonParser.__del__cCs(|j|_t|j|j|j�|_|j|_dS)zCalled when the socket connectsN)rSrRrTrUrXr})r1�
connectionr2r2r3�
on_connect0s

zPythonParser.on_connectcCs*d|_|jdk	r |jj�d|_d|_dS)z"Called when the socket disconnectsN)rSrXryr})r1r2r2r3r~8s


zPythonParser.on_disconnectcCs|jo|jj|�S)N)rXrq)r1rcr2r2r3rq@szPythonParser.can_readcs�jj�}|stt��|dd�|dd�}}|d
krDtd|��|dkrpt|�}�j|�}t|t�rl|�|S|dkrznn|dkr�t|�}n\|dkr�t	|�}|dkr�dS�jj
|�}n2|dkr�t	|�}|dkr�dS�fdd	�t|�D�}t|t��r�j
j|�}|S)
NrJ�-�+�:r+r*zProtocol Error: %rcsg|]}�j��qSr2)�
read_response)�.0�i)r1r2r3�
<listcomp>ksz.PythonParser.read_response.<locals>.<listcomp>)r�r�r�r+r*r]r])rXrurrar r
rQr5r	r<rsrr6r}rC)r1�rawZbyterP�errorr\r2)r1r3r�Cs:



zPythonParser.read_responseN)
r?rErFrGr4rr�r~rqr�r2r2r2r3r|"sr|c@sNeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	dfd
d�Z
dd�ZdS)�
HiredisParserz*Parser class for connections using HirediscCs$tstd��||_tr t|�|_dS)NzHiredis is not installed)r'r$rT�HIREDIS_USE_BYTE_BUFFER�	bytearrayrX)r1rTr2r2r3r4ss
zHiredisParser.__init__cCs&y|j�Wntk
r YnXdS)N)r~rz)r1r2r2r3r{szHiredisParser.__del__cCsd|j|_|j|_t|jd�}ts(t|d<|jjr<|jj	|d<t
rL|jj|d<tj
f|�|_d|_dS)N)Z
protocolError�
replyErrorr�r.�errorsF)rSrU�_socket_timeoutr rQ� HIREDIS_SUPPORTS_CALLABLE_ERRORSr%r}r0r.� HIREDIS_SUPPORTS_ENCODING_ERRORSr/�hiredis�Reader�_reader�_next_response)r1r��kwargsr2r2r3r��s
zHiredisParser.on_connectcCsd|_d|_d|_dS)NF)rSr�r�)r1r2r2r3r~�szHiredisParser.on_disconnectcCs@|jstt��|jdkr<|jj�|_|jdkr<|j|dd�SdS)NF)rcriT)r�rrar��gets�read_from_socket)r1rcr2r2r3rq�s

zHiredisParser.can_readTc	Cs(|j}|tk	}�z�y�|r"|j|�trXt|j|j�}|dkrDtt��|jj	|jd|�n:t
|j|j�}t|t
�s~t|�dkr�tt��|jj	|�dStjk
r�|r�td��dStk
�r
}z8tj|jd�}|r�|j|kr�dStd|jf��WYdd}~XnXWd|�r"|j|j�XdS)NrTzTimeout reading from socketFrJz#Error while reading from socket: %sr])rSr_r`r�rrXrrar�ZfeedrrTr5r6rMr[rcr&rdrerOrfrgrhr�)	r1rcrirjrlZbufflen�bufferrnror2r2r3r��s6
"zHiredisParser.read_from_socketcCs�|jstt��|jdk	r(|j}d|_|S|jj�}x|dkrP|j�|jj�}q4Wts�t|t�rr|j	|j
d�}n4t|t�r�|r�t|dt�r�|j	|dj
d�|d<t|t�r�|�n$t|t�r�|r�t|dt�r�|d�|S)NFr)r�rrar�r�r�r�r5r%rQrh�list)r1rPr2r2r3r��s,




zHiredisParser.read_responseN)r?rErFrGr4rr�r~rqr_r�r�r2r2r2r3r�qs&r�c@s�eZdZdZddddddddddddded	dddfd
d�Zdd
�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd d!�Zd/d#d$�Zd%d&�Zd0d'd(�Zd)d*�Zd+d,�Zd-d.�ZdS)1�
Connectionz4Manages TCP communication to and from a Redis serverZ	localhosti�rNFzutf-8�stricticCs�tj�|_||_t|�|_||_||_||_||_	||_
|p>||_||_|pNi|_
|	|_|
|_||_d|_t|||
�|_d|_||d�|_g|_d|_dS)Nr)rTip)�os�getpid�pid�hostr<�port�db�username�client_name�passwordrU�socket_connect_timeout�socket_keepalive�socket_keepalive_options�socket_type�retry_on_timeout�health_check_interval�next_health_checkr-r}rS�_parser�_connect_callbacks�_buffer_cutoff)r1r�r�r�r�rUr�r�r�r�r�r.r/r0�parser_classrTr�r�r�r2r2r3r4�s(



zConnection.__init__cCs(djdd�|j�D��}d|jj|fS)N�,cSsg|]\}}d||f�qS)z%s=%sr2)r��k�vr2r2r3r�sz'Connection.__repr__.<locals>.<listcomp>z%s<%s>)�join�repr_piecesrfr?)r1Z	repr_argsr2r2r3�__repr__szConnection.__repr__cCs6d|jfd|jfd|jfg}|jr2|jd|jf�|S)Nr�r�r�r�)r�r�r�r��append)r1�piecesr2r2r3r�szConnection.repr_piecescCs&y|j�Wntk
r YnXdS)N)�
disconnectrz)r1r2r2r3rszConnection.__del__cCs|jj|�dS)N)r�r�)r1�callbackr2r2r3�register_connect_callback$sz$Connection.register_connect_callbackcCs
g|_dS)N)r�)r1r2r2r3�clear_connect_callbacks'sz"Connection.clear_connect_callbackscCs�|jr
dSy|j�}WnNtjk
r4td��Yn2tjk
rd}zt|j|���WYdd}~XnX||_y|j�Wnt	k
r�|j
��YnXx|jD]}||�q�WdS)z5Connects to the Redis server if not already connectedNzTimeout connecting to server)rS�_connectr[rcr&r�r�_error_messager�r$r�r�)r1rj�er�r2r2r3�connect*s  zConnection.connectcCsd}x�tj|j|j|jtj�D]�}|\}}}}}d}y�tj|||�}|jtjtjd�|j	r�|jtj
tjd�x&t|j
�D]\}	}
|jtj|	|
�qzW|j|j�|j|�|j|j�|Stjk
r�}z|}|dk	r�|j�WYdd}~XqXqW|dk	�r|�tjd��dS)zCreate a TCP socket connectionNrJz)socket.getaddrinfo returned an empty list)r[Zgetaddrinfor�r�r��SOCK_STREAMZ
setsockoptZIPPROTO_TCPZTCP_NODELAYr�Z
SOL_SOCKETZSO_KEEPALIVErr�r`r�r�rUr�ry)r1�err�resZfamilyZsocktype�protoZ	canonnameZsocket_addressrjr�r��_r2r2r3r�Bs.

zConnection._connectcCsJt|j�dkr&d|j|j|jdfSd|jd|j|j|jdfSdS)NrJzError connecting to %s:%s. %s.rz!Error %s connecting to %s:%s. %s.)rMrhr�r�)r1�	exceptionr2r2r3r�js
zConnection._error_messagecCs�|jj|�|js|jr�|jr0|j|jp*df}n|jf}|jd|�ddi�y|j�}Wn.tk
r�|jd|jdd�|j�}YnXt|�dkr�td��|j	r�|jdd	|j	�t|j��dkr�t
d
��|jr�|jd|j�t|j��dkr�t
d��d
S)z=Initialize the connection, authenticate and select a database��AUTH�check_healthF)r�ZOKzInvalid Username or PasswordZCLIENTZSETNAMEzError setting client nameZSELECTzInvalid DatabaseN)r�)r�r�r�r��send_commandr�rr
rr�rr�)r1Z	auth_argsZ
auth_responser2r2r3r�ts*zConnection.on_connectcCsd|jj�|jdkrdSy*tj�|jkr6t|jtj�|jj	�Wntj
k
rXYnXd|_dS)z!Disconnects from the Redis serverN)r�r~rSr�r�r�rr[Z	SHUT_RDWRryr�)r1r2r2r3r��s

zConnection.disconnectcCs�|jr�t�|jkr�y*|jddd�t|j��dkr:td��WnFttfk
r�|j�|jddd�t|j��dkr~td��YnXdS)z3Check the health of the connection with a PING/PONGZPINGF)r�ZPONGz#Bad response from PING health checkN)	r�rr�r�r
r�rr&r�)r1r2r2r3r��s
zConnection.check_healthTcCs�|js|j�|r|j�y.t|t�r,|g}x|D]}t|j|�q2WWn�tjk
rn|j�t	d��Yn�tj
k
r�}zR|j�t|j�dkr�d|jd}}n|jd}|jd}t
d||f��WYdd}~Xntk
r�|j��YnXdS)z2Send an already packed command to the Redis serverzTimeout writing to socketrJZUNKNOWNrz%Error %s while writing to socket. %s.N)rSr�r�r5r=rr[rcr�r&r�rMrhr�
BaseException)r1Zcommandr��itemr�rg�errmsgr2r2r3�send_packed_command�s.



zConnection.send_packed_commandcOs |j|j|�|jdd�d�dS)z+Pack and send a command to the Redis serverr�T)r�N)r��pack_commandrO)r1rhr�r2r2r3r��szConnection.send_commandcCs$|j}|s|j�|j}|jj|�S)z8Poll the socket to see if there's data that can be read.)rSr�r�rq)r1rcrjr2r2r3rq�s
zConnection.can_readcCs�y|jj�}Wn�tjk
r@|j�td|j|jf��Yn`tjk
r�}z&|j�t	d|j|j|j
f��WYdd}~Xntk
r�|j��YnX|jr�t
�|j|_t|t�r�|�|S)z0Read the response from a previously sent commandzTimeout reading from %s:%sz#Error while reading from %s:%s : %sN)r�r�r[rcr�r&r�r�r�rrhr�r�rr�r5r%)r1rPr�r2r2r3r��s$$
zConnection.read_responsecGsg}t|dt�r4t|dj�j��|dd�}n(d|dkr\t|dj��|dd�}tjttt	|��j�t
f�}|j}x�t|j
j|�D]|}t	|�}t	|�|ks�||ks�t|t�r�tj|tt|�j�t
f�}|j|�|j|�t
}q�tj|tt|�j�t
|t
f�}q�W|j|�|S)z2Pack a series of arguments into the Redis protocolrrJN� )r5r�tupler;rK�	SYM_EMPTYr��SYM_STARr=rMrwr�rr}r7�
SYM_DOLLARr�)r1rh�outputZbuff�
buffer_cutoff�argZ
arg_lengthr2r2r3r��s*"



zConnection.pack_commandc	Cs�g}g}d}|j}x�|D]�}x||j|�D]n}t|�}||ksN||ksNt|t�rf|jtj|��d}g}||ksxt|t�r�|j|�q(|j|�||7}q(WqW|r�|jtj|��|S)z.Pack multiple commands into the Redis protocolr)r�r�rMr5r7r�r�r�)	r1Zcommandsr�r�Z
buffer_lengthr��cmd�chunkZchunklenr2r2r3�
pack_commandss&


zConnection.pack_commands)T)r)r?rErFrG�
DefaultParserr4r�r�rr�r�r�r�r�r�r�r�r�r�rqr�r�r�r2r2r2r3r��s2
(
'


"r�cs*eZdZd�fdd�	Z�fdd�Z�ZS)	�
SSLConnectionN�requiredFcs�tstd��tt|�jf|�||_||_|dkr:tj}n8t	|t
�rrtjtjtjd�}||krjtd|��||}||_
||_||_dS)Nz$Python wasn't built with SSL support)ZnoneZoptionalr�z-Invalid SSL Certificate Requirements Flag: %s)�
ssl_availabler$�superr�r4�keyfile�certfile�sslZ	CERT_NONEr5rZ
CERT_OPTIONALZ
CERT_REQUIRED�	cert_reqs�ca_certs�check_hostname)r1Zssl_keyfileZssl_certfileZ
ssl_cert_reqsZssl_ca_certs�ssl_check_hostnamer�Z	CERT_REQS)rfr2r3r46s&

zSSLConnection.__init__cs�tt|�j�}ttd�rrtj�}|j|_|j|_|j	rN|j
rN|j|j	|j
d�|jr`|j
|j�t|||jd�}ntt||j|j
|j	|jd�}|S)z Wrap the socket with SSL support�create_default_context)r�r�)Zserver_hostname)r�r�r�r�)r�r�r��hasattrr�r�r�r�Zverify_moder�r�Zload_cert_chainr�Zload_verify_locationsrr�)r1rj�context)rfr2r3r�Qs$


zSSLConnection._connect)NNr�NF)r?rErFr4r��
__classcell__r2r2)rfr3r�4sr�c
@sHeZdZdddddddddedddf
dd	�Zd
d�Zdd
�Zdd�ZdS)�UnixDomainSocketConnectionr�rNzutf-8r�FicCsptj�|_||_||_||_|
|_||_||_|	|_	||_
d|_t|||�|_
d|_|
|d�|_g|_d|_dS)Nr)rTip)r�r�r��pathr�r�r�r�rUr�r�r�r-r}rSr�r�r�)r1r�r�r�r�rUr.r/r0r�r�rTr�r�r2r2r3r4ls
z#UnixDomainSocketConnection.__init__cCs.d|jfd|jfg}|jr*|jd|jf�|S)Nr�r�r�)r�r�r�r�)r1r�r2r2r3r��s
z&UnixDomainSocketConnection.repr_piecescCs,tjtjtj�}|j|j�|j|j�|S)z&Create a Unix domain socket connection)r[ZAF_UNIXr�r`rUr�r�)r1rjr2r2r3r��sz#UnixDomainSocketConnection._connectcCsBt|j�dkr"d|j|jdfSd|jd|j|jdfSdS)NrJz(Error connecting to unix socket: %s. %s.rz+Error %s connecting to unix socket: %s. %s.)rMrhr�)r1r�r2r2r3r��s
z)UnixDomainSocketConnection._error_message)r?rErFr�r4r�r�r�r2r2r2r3r�js	r��0�F�FALSE�N�NOcCs6|dks|dkrdSt|t�r.|j�tkr.dSt|�S)Nr�F)r5r�upper�
FALSE_STRINGSr8)r@r2r2r3�to_bool�s
r�)rUr�r�r��max_connectionsr�r�c@sveZdZdZeddd��Zedfdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zddd�ZdS)�ConnectionPoolzGeneric connection poolNFc
KsBt|�}i}x�tt|j��D]t\}}|rt|�dkrtj|�}|r�y||d�||<Wq�ttfk
r�t	j
td|��Yq�Xq|d||<qW|r�|jr�t
|j�nd}	|jr�t
|j�nd}
|jr�t
|j�nd}|jr�t
|j�nd}n |jp�d}	|jp�d}
|j}|j}|jdk�r,|j|	|
|td��n�|jdk�r�|j|t|j�pJd�|	|
d	��d
|k�r�|�r�yt|jdd��|d
<Wnttfk
�r�YnX|jdk�r�t|d
<ndjd�}
td|
��t|jd
|�p�d��|d
<|j|�d|k�rt	j
td��|jd�|d<d|k�r8t	j
td��|jd�|d<|f|�S)a
        Return a connection pool configured from the given URL.

        For example::

            redis://[[username]:[password]]@localhost:6379/0
            rediss://[[username]:[password]]@localhost:6379/0
            unix://[[username]:[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.

        rz)Invalid value for `%s` in connection URL.NZunix)r�r�r��connection_class�redis�redissi�)r�r�r�r�r��/r�r�z, �redis://�	rediss://�unix://z8Redis URL must specify one of the following schemes (%s)�charsetz/"charset" is deprecated. Use "encoding" insteadr.r�z5"errors" is deprecated. Use "encoding_errors" insteadr/)r�r�)r�r�r�)rrrZqueryrM�URL_QUERY_ARGUMENT_PARSERSrO�	TypeError�
ValueError�warnings�warn�UserWarningr�rr�r��hostname�scheme�updater�r<r��replace�AttributeErrorr�r��DeprecationWarning�pop)�clsZurlr�Zdecode_componentsr�Zurl_options�namer@�parserr�r�r�rZ
valid_schemesr2r2r3�from_url�sl.








zConnectionPool.from_urlcKsP|pd}t|ttf�s |dkr(td��||_||_||_tj�|_	|j
�dS)a�
        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.
        r)�rz,"max_connections" must be a positive integerNl)r5r<r	rr��connection_kwargsr��	threading�Lock�
_fork_lock�reset)r1r�r�rr2r2r3r40s

zConnectionPool.__init__cCs dt|�jt|jf|j��fS)Nz%s<%s>)r>r?r:r�r)r1r2r2r3r�OszConnectionPool.__repr__cCs,tj�|_d|_g|_t�|_tj�|_	dS)Nr)
rr�_lock�_created_connections�_available_connections�set�_in_use_connectionsr�r�r�)r1r2r2r3rUs

zConnectionPool.resetc
Csr|jtj�krnt�d}d}x t�|kr<|jjd�}|rPqW|sFt�z|jtj�kr^|j�Wd|jj�XdS)N�F)	r�r�r�rr�acquirerr�release)r1Z
timeout_atZacquiredr2r2r3�	_checkpidfs#
zConnectionPool._checkpidc Os�|j�|j�>y|jj�}Wntk
r:|j�}YnX|jj|�WdQRXyV|j�y|j	�rnt
d��Wn4t
k
r�|j�|j�|j	�r�t
d��YnXWn tk
r�|j
|��YnX|S)zGet a connection from the poolNzConnection has datazConnection not ready)rrrr�
IndexError�make_connectionr�addr�rqrr�r�r)r1�command_name�keys�optionsr�r2r2r3�get_connection�s*
zConnectionPool.get_connectioncCs,|j}t|jdd�|jdd�|jdd�d�S)z,Return an encoder based on encoding settingsr.zutf-8r/r�r0F)r.r/r0)rr-rO)r1r�r2r2r3�get_encoder�s


zConnectionPool.get_encodercCs0|j|jkrtd��|jd7_|jf|j�S)zCreate a new connectionzToo many connectionsrJ)rr�rr�r)r1r2r2r3r!�szConnectionPool.make_connectioncCsv|j�|j�^y|jj|�Wntk
r4YnX|j|�rN|jj|�n|jd8_|j	�dSWdQRXdS)z(Releases the connection back to the poolrJN)
rrr�remove�KeyError�owns_connectionrr�rr�)r1r�r2r2r3r�s
zConnectionPool.releasecCs|j|jkS)N)r�)r1r�r2r2r3r*�szConnectionPool.owns_connectionTc
CsN|j�|j�6|r$t|j|j�}n|j}x|D]}|j�q0WWdQRXdS)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)rrrrrr�)r1Zinuse_connectionsZconnectionsr�r2r2r3r��s

zConnectionPool.disconnect)NF)T)r?rErFrG�classmethodrr�r4r�rrr&r'r!rr*r�r2r2r2r3r��sz6!	r�csReZdZdZddeef�fdd�	Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Z�ZS)�BlockingConnectionPoola6
    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�cs,||_||_tt|�jf||d�|��dS)N)r�r�)�queue_classrcr�r,r4)r1r�rcr�r/r)rfr2r3r4szBlockingConnectionPool.__init__cCsP|j|j�|_x,y|jjd�Wqtk
r6PYqXqWg|_tj�|_dS)N)	r/r��pool�
put_nowaitr�_connectionsr�r�r�)r1r2r2r3r%szBlockingConnectionPool.resetcCs|jf|j�}|jj|�|S)zMake a fresh connection.)r�rr2r�)r1r�r2r2r3r!=sz&BlockingConnectionPool.make_connectioncOs�|j�d}y|jjd|jd�}Wntk
r>td��YnX|dkrP|j�}yV|j�y|j�rltd��Wn4tk
r�|j	�|j�|j�r�td��YnXWn t
k
r�|j|��YnX|S)a7
        Get a connection, blocking for ``self.timeout`` until a connection
        is available from the pool.

        If the connection returned is ``None`` then creates a new connection.
        Because we use a last-in first-out queue, the existing connections
        (having been returned to the pool after the initial ``None`` values
        were added) will be returned before ``None`` values. This means we only
        create new connections when we need to, i.e.: the actual number of
        connections will only increase in response to demand.
        NT)�blockrczNo connection available.zConnection has datazConnection not ready)rr0rOrcrrr!r�rqr�r�r)r1r#r$r%r�r2r2r3r&Cs,

z%BlockingConnectionPool.get_connectioncCsT|j�|j|�s*|j�|jjd�dSy|jj|�Wntk
rNYnXdS)z)Releases the connection back to the pool.N)rr*r�r0r1r)r1r�r2r2r3rws
zBlockingConnectionPool.releasecCs$|j�x|jD]}|j�qWdS)z(Disconnects all connections in the pool.N)rr2r�)r1r�r2r2r3r��sz!BlockingConnectionPool.disconnect)
r?rErFrGr�r
r4rr!r&rr�r�r2r2)rfr3r,�s 
4r,i���)r�r�r�r�r�)_Z
__future__rZdistutils.versionr�	itertoolsrrrgrVr�r[rrZ
redis._compatrrrr	r
rrr
rrrrrrrrrrrZredis.exceptionsrrrrrrrr r!r"r#r$r%r&Zredis.utilsr'r�r��ImportErrorZEWOULDBLOCKrer�r(ZSSLWantWriteErrorZSSLErrorr�r�r$rdr��__version__Zhiredis_versionr�ZHIREDIS_SUPPORTS_BYTE_BUFFERr��msgrr�r�r�rwr�ra�objectr_r-rHrRr|r�r�r�r�r�r�r�r9r<rr�r,r2r2r2r3�<module>s�T@



	


(#xOzE63	H