HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python311/lib/python3.11/site-packages/redis/__pycache__/connection.cpython-311.pyc
�

$�;f���
���ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZddl
m
Z
ddlmZmZmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%dd	l&m'Z'dd
l(m)Z)m*Z*m+Z+	ddl,Z,dZ-n
#e.$rdZ-YnwxYwe/ej0iZ1e-r+e2e,d
��rde1e,j3<de1e,j4<n
de1e,j5<e6e1�7����Z8e*rGddl9Z9ee9j:��Z;e;ed��kZ<e;ed��kZ=e;ed��kZ>dZ?e=sdZ?dZ@dZAdZBdZCdZDeE��ZFdZGdZHdZIdZJGd�d��ZKGd�d��ZLGd�d ��ZMGd!�d"eL��ZNGd#�d$eL��ZOe*reOZPneNZPGd%�d&��ZQGd'�d(eQ��ZRGd)�d*eQ��ZSd+ZTd,�ZUeVeWeWeUeUeXeVeVeUd-�	ZYd.�ZZGd/�d0��Z[Gd1�d2e[��Z\dS)3�N)�chain)�Empty�Full�	LifoQueue)�time)�parse_qs�unquote�urlparse)�Version)�	NoBackoff)�AuthenticationError�$AuthenticationWrongNumberOfArgsError�BusyLoadingError�ChildDeadlockedError�ConnectionError�	DataError�ExecAbortError�InvalidResponse�ModuleError�NoPermissionError�
NoScriptError�
ReadOnlyError�
RedisError�
ResponseError�TimeoutError)�Retry)�CRYPTOGRAPHY_AVAILABLE�HIREDIS_AVAILABLE�str_if_bytesTF�SSLWantReadError�z0.1.3z0.1.4z1.0.0�*�$s
�zConnection 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 unloadc�&�eZdZdZd�Zd�Zdd�ZdS)�Encoderz=Encode strings to bytes-like and decode bytes-like to stringsc�0�||_||_||_dS�N��encoding�encoding_errors�decode_responses)�selfr*r+r,s    �C/opt/alt/python311/lib/python3.11/site-packages/redis/connection.py�__init__zEncoder.__init__Zs�� ��
�.��� 0����r$c���t|ttf��r|St|t��rt	d���t|t
tf��r"t|�����}n<t|t��s't|��j}t	d|�d����t|t��r |�|j|j
��}|S)z=Return a bytestring or bytes-like representation of the valuezNInvalid input of type: 'bool'. Convert to a bytes, string, int or float first.zInvalid 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+)r-�value�typenames   r.r8zEncoder.encode_s����e�e�Z�0�1�1�	��L�
��t�
$�
$�	��5���
����U�|�
,�
,�	���K�K�&�&�(�(�E�E��E�3�'�'�	��E�{�{�+�H��C�8�C�C�C���
��e�S�!�!�	F��L�L����0D�E�E�E��r$Fc���|js|r^t|t��r|���}t|t��r |�|j|j��}|S)z:Return a unicode string from the bytes-like representation)r,r1r3�tobytesr2�decoder*r+)r-r<�forces   r.r@zEncoder.decodevse��� �	J�E�	J��%��,�,�
(��
�
�����%��'�'�
J����T�]�D�4H�I�I���r$N�F)r;�
__module__�__qualname__�__doc__r/r8r@�r$r.r&r&WsL������C�C�1�1�1�
���.�����r$r&c�L�eZdZdededededeeeeee	ee
ei	eee
eeed�Zd�ZdS)	�
BaseParserzmax 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)�ERR�	EXECABORT�LOADING�NOSCRIPT�READONLY�NOAUTH�NOPERMc�,�|�d��d}||jvrb|t|��dzd�}|j|}t|t��r|�|t��}||��St
|��S)zParse an error response� r�N)�split�EXCEPTION_CLASSES�lenr1�dict�getr)r-�response�
error_code�exception_classs    r.�parse_errorzBaseParser.parse_error�s����^�^�C�(�(��+�
���/�/�/���J���!� 3� 5� 5�6�H�"�4�Z�@�O��/�4�0�0�
O�"1�"5�"5�h�
�"N�"N��"�?�8�,�,�,��X�&�&�&r$N)r;rCrDrr
r�MODULE_LOAD_ERRORr�MODULE_EXPORTS_DATA_TYPES_ERROR�NO_SUCH_MODULE_ERROR� MODULE_UNLOAD_NOT_POSSIBLE_ERRORrrrrrrTr[rFr$r.rHrH�s�������
,�_�6�8K�� 3�
!�"F�
!�"F��{�+�[� �+�,�k�
�"$�#�!�!�%�#�/���4	'�	'�	'�	'�	'r$rHc�V�eZdZd�Zed���Zdedfd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)�SocketBufferc�|�||_||_||_tj��|_d|_d|_dS�Nr)�_sock�socket_read_size�socket_timeout�io�BytesIO�_buffer�
bytes_written�
bytes_read)r-�socketrerfs    r.r/zSocketBuffer.__init__�s9����
� 0���,����z�|�|����������r$c� �|j|jz
Sr()rjrk�r-s r.�lengthzSocketBuffer.length�s���!�D�O�3�3r$NTc���|j}|j}|j}|�|j��d}|t
u}	|r|�|��	|j�|��}	t|	t��r't|	��dkrtt���|�
|	��t|	��}
|xj|
z
c_||
z
}|�||kr��	|r|�|j��dSdS#tj$r3|rt#d���Y|r|�|j��dSdSt$$rm}t&�|jd��}|s/|j|kr$Yd}~|r|�|j��dSdStd|j�����d}~wwxYw#|r|�|j��wwxYw�NrTzTimeout reading from socketF���z!Error while reading from socket: )rdreri�seekrj�SENTINEL�
settimeout�recvr1r2rUr�SERVER_CLOSED_CONNECTION_ERROR�writerfrl�timeoutr�NONBLOCKING_EXCEPTIONS�#NONBLOCKING_EXCEPTION_ERROR_NUMBERSrW�	__class__�errno�args)
r-rory�raise_on_timeout�sockre�buf�marker�custom_timeout�data�data_length�ex�alloweds
             r.�_read_from_socketzSocketBuffer._read_from_socket�sP���z���0���l������#�$�$�$��� ��0��	5��
)�����(�(�(�
��z���'7�8�8���d�E�*�*�J�s�4�y�y�A�~�~�)�*H�I�I�I��	�	�$����!�$�i�i���"�"�k�1�"�"��+�%���%�&�6�/�/����
5����� 3�4�4�4�4�4�
5�
5���~�	�	�	��
B�"�#@�A�A�A���
5����� 3�4�4�4�4�4�
5�
5�&�	Q�	Q�	Q�
:�=�=�b�l�B�O�O�G�#�
���G�(;�(;��u�u�u��
5����� 3�4�4�4�4�4�
5�
5�"�"O�b�g�"O�"O�P�P�P�����	Q������
5����� 3�4�4�4�4�
5���s<�B0D
�
 G�-G�	G�-F?�G�(F?�?G�G�G&c�X�t|j��p|�|d���S)NF�ryr)r4ror��r-rys  r.�can_readzSocketBuffer.can_read�s5���D�K� � �
�D�$:�$:��e�%;�%
�%
�	
r$c�d�|dz}||jkr|�||jz
��|j�|j��|j�|��}|xjt
|��z
c_|j|jkr|���|dd�S)Nr!���)	ror�rirsrk�readrUrj�purge)r-ror�s   r.r�zSocketBuffer.read�s����!����D�K����"�"�6�D�K�#7�8�8�8�����$�/�*�*�*��|� � ��(�(�����3�t�9�9�$����?�d�0�0�0��J�J�L�L�L��C�R�C�y�r$c���|j}|�|j��|���}|�t
��s\|���|�|j��|���}|�t
���\|xjt|��z
c_|j|jkr|�	��|dd�S)Nr�)
rirsrk�readline�endswith�SYM_CRLFr�rUrjr�)r-r�r�s   r.r�zSocketBuffer.readline�s����l�������!�!�!��|�|�~�~���-�-��)�)�	"��"�"�$�$�$��H�H�T�_�%�%�%��<�<�>�>�D�	�-�-��)�)�	"�	
���3�t�9�9�$����?�d�0�0�0��J�J�L�L�L��C�R�C�y�r$c��|j�d��|j���d|_d|_dSrc)rirs�truncaterjrkrns r.r�zSocketBuffer.purges?������!������������������r$c��	|���|j���n#t$rYnwxYwd|_d|_dSr()r�ri�close�	Exceptionrdrns r.r�zSocketBuffer.closesa��		��J�J�L�L�L��L��� � � � ���	�	�	�
�D�
	���������
�
�
s�-0�
=�=)
r;rCrDr/�propertyrortr�r�r�r�r�r�rFr$r.rara�s�����������4�4��X�4�(,�X�PT�'5�'5�'5�'5�R
�
�
�
���"���&�������r$rac�8�eZdZdZd�Zd�Zd�Zd�Zd�Zd
d�Z	d	S)�PythonParserzPlain Python parsing classc�>�||_d|_d|_d|_dSr()re�encoderrdri�r-res  r.r/zPythonParser.__init__ s#�� 0��������
�����r$c�R�	|���dS#t$rYdSwxYwr(��
on_disconnectr�rns r.�__del__zPythonParser.__del__&�A��	���� � � � � ���	�	�	��D�D�	������
&�&c��|j|_t|j|j|j��|_|j|_dS)zCalled when the socket connectsN)rdrarerfrir��r-�
connections  r.�
on_connectzPythonParser.on_connect,s<���%��
�#��J��-�z�/H�
�
���"�)����r$c�p�d|_|j� |j���d|_d|_dS)z"Called when the socket disconnectsN)rdrir�r�rns r.r�zPythonParser.on_disconnect4s7����
��<�#��L��� � � ��D�L�����r$c�D�|jo|j�|��Sr()rir�r�s  r.r�zPythonParser.can_read<s���|�>��� 5� 5�g� >� >�>r$Fc������j���}|stt���|dd�|dd�}}|dvrt	d|�����|dkrE|�dd���}��|��}t|t��r|�|S|dkrn�|d	krt|��}nq|d
kr2t|��}|dkrdS�j�	|��}n9|dkr3t|��}|dkrdS��fd
�t|��D��}t|t��r�dur�j�|��}|S)NrR)�-�+�:r#r"zProtocol Error: r��utf-8�replace)�errorsr�r�r#rrr"c�<��g|]}��������S)��disable_decoding)�
read_response)�.0�ir�r-s  ��r.�
<listcomp>z.PythonParser.read_response.<locals>.<listcomp>gs;��������"�"�4D�"�E�E���r$F)
rir�rrwrr@r[r1r5r��ranger2r�)r-r��raw�byterX�errorros``     r.r�zPythonParser.read_response?s������l�#�#�%�%���	B�!�"@�A�A�A��R�a�R��#�a�b�b�'�h���5�5�5�!�"<�S�"<�"<�=�=�=��4�<�<����w�y��A�A�H��$�$�X�.�.�E��%��1�1�
���
�L�
�T�\�\��
�T�\�\��8�}�}�H�H�
�T�\�\���]�]�F���|�|��t��|�(�(��0�0�H�H�
�T�\�\���]�]�F���|�|��t�������v������H��h��&�&�	5�+;�u�+D�+D��|�*�*�8�4�4�H��r$NrB)
r;rCrDrEr/r�r�r�r�r�rFr$r.r�r�sy������ � �������*�*�*����?�?�?�.�.�.�.�.�.r$r�c�D�eZdZdZd�Zd�Zd�Zd�Zd�Ze	dfd�Z
dd
�ZdS)
�
HiredisParserz*Parser class for connections using Hiredisc�z�tstd���||_trt	|��|_dSdS)NzHiredis is not installed)rrre�HIREDIS_USE_BYTE_BUFFER�	bytearrayrir�s  r.r/zHiredisParser.__init__ssG�� �	9��7�8�8�8� 0���"�	7�$�%5�6�6�D�L�L�L�	7�	7r$c�R�	|���dS#t$rYdSwxYwr(r�rns r.r�zHiredisParser.__del__{r�r�c��|j|_|j|_t|jd�}t
s
t|d<|jjr|jj	|d<tr|jj|d<tj
di|��|_d|_dS)N)�
protocolError�
replyErrorr�r*r�FrF)rdrf�_socket_timeoutrr[� HIREDIS_SUPPORTS_CALLABLE_ERRORSrr�r,r*� HIREDIS_SUPPORTS_ENCODING_ERRORSr+�hiredis�Reader�_reader�_next_response)r-r��kwargss   r.r�zHiredisParser.on_connect�s����%��
�)�8���,��*�
�
��0�	1�#0�F�<� ���.�	=�!+�!3�!<�F�:��+�	B�)�1�A�F�8���~�/�/��/�/���#����r$c�0�d|_d|_d|_dS)NF)rdr�r�rns r.r�zHiredisParser.on_disconnect�s����
����#����r$c���|jstt���|jdur>|j���|_|jdur|�|d���SdS)NFr�T)r�rrwr��gets�read_from_socketr�s  r.r�zHiredisParser.can_read�sl���|�	B�!�"@�A�A�A���%�'�'�"&�,�"3�"3�"5�"5�D���"�e�+�+��,�,�W�u�,�U�U�U��tr$Tc��|j}|tu}	|r|�|��tr[|j�|j��}|dkrt
t���|j�	|jd|��nu|j�
|j��}t|t��rt|��dkrt
t���|j�	|��	|r|�|j��dSdS#t j$r3|rt%d���Y|r|�|j��dSdSt&$rm}t(�|jd��}|s/|j|kr$Yd}~|r|�|j��dSdSt
d|j�����d}~wwxYw#|r|�|j��wwxYwrq)rdrtrur��	recv_intorirrwr��feedrvrer1r2rUr�rlryrrzr{rWr|r}r~)	r-ryrr�r��bufflen�bufferr�r�s	         r.r�zHiredisParser.read_from_socket�sJ���z�� ��0�� 	6��
)�����(�(�(�&�

*��*�.�.�t�|�<�<���a�<�<�)�*H�I�I�I���!�!�$�,��7�;�;�;�;������)>�?�?��!�&�%�0�0�J�C��K�K�1�4D�4D�)�*H�I�I�I���!�!�&�)�)�)���
6����� 4�5�5�5�5�5�
6�
6���~�	�	�	��
B�"�#@�A�A�A���
6����� 4�5�5�5�5�5�
6�
6�&�	Q�	Q�	Q�
:�=�=�b�l�B�O�O�G�#�
���G�(;�(;��u�u�u��
6����� 4�5�5�5�5�5�
6�
6�"�"O�b�g�"O�"O�P�P�P�����	Q������
6����� 4�5�5�5�5�
6���s<�C.D!�! G�G�"	G�+-G�G�<G�G�G�G:Fc���|jstt���|jdur|j}d|_|S|j���}|dur1|���|j���}|du�1ts�t|t��r!|�	|j
d��}n[t|t��rF|rDt|dt��r)|�	|dj
d��|d<t|t��r|�t|t��r%|r#t|dt��r|d�|S)NFr)r�rrwr�r�r�r�r1rr[r~�list)r-r�rXs   r.r�zHiredisParser.read_response�s����|�	B�!�"@�A�A�A���e�+�+��*�H�"'�D���O��<�$�$�&�&���%����!�!�#�#�#��|�(�(�*�*�H��%���
0�	D��(�M�2�2�
D��+�+�H�M�!�,<�=�=����8�T�*�*�
D��
D��x��{�M�:�:�
D�
#�.�.�x��{�/?��/B�C�C�����h��0�0�	��N��x��&�&�	��	��8�A�;��8�8�	�
�1�+���r$NrB)r;rCrDrEr/r�r�r�r�rtr�r�rFr$r.r�r�ps�������0�0�7�7�7����$�$�$�&$�$�$�
���(0�$�#6�#6�#6�#6�J$�$�$�$�$�$r$r�c���eZdZdZddddddddddgddded	dddddfd
�Zd�Zd�Zd
�Zd�Z	d�Z
d�Zd�Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd d�Zd�Zd!d�Zd"d�Zd�Zd�ZdS)#�
Connectionz4Manages TCP communication to and from a Redis server�	localhosti�rNFr��strict�c���tj��|_||_t	|��|_||_||_||_||_	||_
|p||_||_|pi|_
|	|_|
|_|
r|�t"��||_|rX|�"t't)��d��|_nt-j|��|_|j�|��n!t't)��d��|_||_d|_||_t9||
|��|_d|_||_|� |��g|_!d|_"dS)a2
        Initialize a new Connection.
        To specify a retry policy for specific errors, first set
        `retry_on_error` to a list of the error/s to retry on, then set
        `retry` to a valid `Retry` object.
        To retry on TimeoutError, `retry_on_timeout` can also be set to `True`.
        NrRr�p)#�os�getpid�pid�hostr5�port�db�username�client_name�passwordrf�socket_connect_timeout�socket_keepalive�socket_keepalive_options�socket_type�retry_on_timeout�appendr�retry_on_errorrr�retry�copy�deepcopy�update_supported_erros�health_check_interval�next_health_check�redis_connect_funcr&r�rd�_socket_read_size�
set_parser�_connect_callbacks�_buffer_cutoff)r-r�r�r�r�rfr�r�r�r�r�r�r*r+r,�parser_classrer�r�r�r�r�s                      r.r/zConnection.__init__�sh��>�9�;�;�����	���I�I��	���� ��
�&��� ��
�,���&<�&N���#� 0���(@�(F�B��%�&��� 0����	0��!�!�,�/�/�/�,����		/��}�"�9�;�;��2�2��
�
�"�]�5�1�1��
��J�-�-�n�=�=�=�=��y�{�{�A�.�.�D�J�%:��"�!"���"4����x��:J�K�K�����
�!1�������%�%�%�"$���"����r$c��d�d�|���D����}|jj�d|�d�S)N�,c�"�g|]\}}|�d|����
S)�=rF)r��k�vs   r.r�z'Connection.__repr__.<locals>.<listcomp>=s&��H�H�H�T�Q���j�j�Q�j�j�H�H�Hr$�<�>)�join�repr_piecesr|r;)r-�	repr_argss  r.�__repr__zConnection.__repr__<sJ���H�H�H�H�T�5E�5E�5G�5G�H�H�H�I�I�	��.�)�8�8�I�8�8�8�8r$c��d|jfd|jfd|jfg}|jr|�d|jf��|S)Nr�r�r�r�)r�r�r�r�r��r-�piecess  r.rzConnection.repr_pieces@sL���4�9�%���	�':�T�4�7�O�L����	=��M�M�=�$�*:�;�<�<�<��
r$c�R�	|���dS#t$rYdSwxYwr()�
disconnectr�rns r.r�zConnection.__del__Fs?��	��O�O��������	�	�	��D�D�	���r�c�^�|j�tj|����dSr()r�r��weakref�
WeakMethod)r-�callbacks  r.�register_connect_callbackz$Connection.register_connect_callbackLs*����&�&�w�'9�(�'C�'C�D�D�D�D�Dr$c��g|_dSr()r�rns r.�clear_connect_callbacksz"Connection.clear_connect_callbacksOs��"$����r$c�2�||j���|_dS)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
        )reN)r��_parser)r-r�s  r.r�zConnection.set_parserRs��$�|�T�5K�L�L�L����r$c����jrdS	�j��fd��fd���}nQ#tj$rtd���t$r'}t��|�����d}~wwxYw|�_	�j	���
��n��	���n##t$r�����wxYw�j
D]}|��}|r|����dS)z5Connects to the Redis server if not already connectedNc�,������Sr()�_connectrns�r.�<lambda>z$Connection.connect.<locals>.<lambda>`s����
�
���r$c�.����|��Sr(�r
)r�r-s �r.rz$Connection.connect.<locals>.<lambda>`s���t���u�7M�7M�r$zTimeout connecting to server)rdr��call_with_retryrlryr�OSErrorr�_error_messager�r�rr
r�)r-r��e�refrs`    r.�connectzConnection.connectZsV����:�	��F�	:��:�-�-�'�'�'�'�)M�)M�)M�)M���D�D���~�	?�	?�	?��=�>�>�>��	:�	:�	:�!�$�"5�"5�a�"8�"8�9�9�9�����	:������
�
	��&�.����!�!�!�!��'�'��-�-�-����	�	�	��O�O�����	�����*�	�	�C��s�u�u�H��
��������	�	s!�!.�'A<�"A7�7A<�1B9�9 Cc��d}tj|j|j|jtj��D�]<}|\}}}}}d}	tj|||��}|�tjtjd��|j	rk|�tj
tjd��|j�
��D]&\}	}
|�tj|	|
���'|�|j��|�|��|�|j��|cS#t$$r#}|}|�|���Yd}~��6d}~wwxYw|�|�t%d���)zCreate a TCP socket connectionNrRz)socket.getaddrinfo returned an empty list)rl�getaddrinfor�r�r��SOCK_STREAM�
setsockopt�IPPROTO_TCP�TCP_NODELAYr��
SOL_SOCKET�SO_KEEPALIVEr��itemsrur�r"rfrr�)r-�err�res�family�socktype�proto�	canonname�socket_addressr�rr�_s            r.rzConnection._connect{s���
���%��I�t�y�$�"2�F�4F�
�
�	!�	!�C�BE�>�F�H�e�Y���D�
!��}�V�X�u�=�=������ 2�F�4F��J�J�J��(�B��O�O�F�$5�v�7J�A�N�N�N� $� =� C� C� E� E�B�B���1�����(:�A�q�A�A�A�A����� ;�<�<�<����^�,�,�,����� 3�4�4�4�������
!�
!�
!����#��J�J�L�L�L����������
!����
�?��I��A�B�B�Bs�C=E�
E.�E)�)E.c	�V�t|j��dkrB	d|j�d|j�d|jd�d�S#t$rd|jd��cYSwxYw	d|jd�d	|j�d|j�d
|jd�d�	S#t$rd|jd��cYSwxYw)NrRzError connecting to �:z.                         r�.zConnection Error: �Error z connecting to �. )rUr~r�r��AttributeError�r-�	exceptions  r.rzConnection._error_message�s8���y�~���!�#�#�
@�.�d�i�.�.�$�)�.�.�"���*�.�.�.�.��!�
@�
@�
@�?�I�N�1�,=�?�?�?�?�?�
@����
@�E�Y�^�A�.�E�E��y�E�E�#'�9�E�E�09��q�0A�E�E�E���"�
@�
@�
@�?�I�N�1�,=�?�?�?�?�?�
@���s!� ;�A�A�.B�B(�'B(c��|j�|��|js|jr�|jr|j|jpdf}n|jf}|jdg|�Rddi�	|���}nA#t$r4|�d|jd���|���}YnwxYwt|��dkrtd���|j	rP|�dd	|j	��t|�����dkrtd
���|jrO|�d|j��t|�����dkrtd���d
Sd
S)z=Initialize the connection, authenticate and select a database��AUTH�check_healthF�r?�OKzInvalid Username or Password�CLIENT�SETNAMEzError setting client name�SELECTzInvalid DatabaseN)rr�r�r��send_commandr�rrr
r�rr�)r-�	auth_args�
auth_responses   r.r�zConnection.on_connect�s��������%�%�%��=�	J�D�M�	J��}�
-�!�]�D�M�,?�R�@�	�	�!�]�,�	�
�D��f�E�y�E�E�E�u�E�E�E�
5� $� 2� 2� 4� 4�
�
��7�
5�
5�
5�
�!�!�&�$�-�e�!�L�L�L� $� 2� 2� 4� 4�
�
�
�

5�����M�*�*�d�2�2�)�*H�I�I�I���	C����h�	�4�3C�D�D�D��D�.�.�0�0�1�1�T�9�9�%�&A�B�B�B��7�	:����h���0�0�0��D�.�.�0�0�1�1�T�9�9�%�&8�9�9�9�	:�	:�9�9s�A0�0;B.�-B.c�R�|j���|j�dStj��|jkr6	|j�tj��n#t$rYnwxYw	|j�
��n#t$rYnwxYwd|_dS)z!Disconnects from the Redis serverN)rr�rdr�r�r��shutdownrl�	SHUT_RDWRrr�)r-r~s  r.r
zConnection.disconnect�s�����"�"�$�$�$��:���F�
�9�;�;�$�(�"�"�
��
�#�#�F�$4�5�5�5�5���
�
�
���
����	��J���������	�	�	��D�	������
�
�
s$�$A%�%
A2�1A2�6B�
B�Bc��|�dd���t|�����dkrtd���dS)z Send PING, expect PONG in return�PINGFr@�PONGz#Bad response from PING health checkN)rErr�rrns r.�
_send_pingzConnection._send_ping�sQ�����&�u��5�5�5���*�*�,�,�-�-��7�7�!�"G�H�H�H�8�7r$c�.�|���dS)z Function to call when PING failsNr)r-r�s  r.�_ping_failedzConnection._ping_failed�s���������r$c��|jr>t��|jkr)|j�|j|j��dSdSdS)z3Check the health of the connection with a PING/PONGN)r�rr�r�rrNrPrns r.r?zConnection.check_health�sT���%�	K�$�&�&�4�3I�*I�*I��J�&�&�t���8I�J�J�J�J�J�	K�	K�*I�*Ir$Tc�r�|js|���|r|���	t|t��r|g}|D]}|j�|���dS#tj$r$|���td���t$rq}|���t|j��dkrd|jd}}n|jd}|jd}td|�d|�d����d}~wt$r|����wxYw)	z2Send an already packed command to the Redis serverzTimeout writing to socketrR�UNKNOWNrr7z while writing to socket. r6N)rdr"r?r1r9�sendallrlryr
rrrUr~r�
BaseException)r-�commandr?�itemr r}�errmsgs       r.�send_packed_commandzConnection.send_packed_command�si���z�	��L�L�N�N�N��	 �������	��'�3�'�'�
$�"�)���
)�
)���
�"�"�4�(�(�(�(�
)�
)���~�	<�	<�	<��O�O�����:�;�;�;��	W�	W�	W��O�O�����1�6�{�{�a��� )�1�6�!�9�v�����q�	�������!�"U�5�"U�"U�F�"U�"U�"U�V�V�V������	�	�	��O�O�����	���s�7A,�,;D6�'A,D�#D6c�l�|�|j|�|�dd�����dS)z+Pack and send a command to the Redis serverr?Tr@N)rY�pack_commandrW)r-r~r�s   r.rEzConnection.send_commandsF��� � ��D��t�$�6�:�:�n�d�3S�3S�	!�	
�	
�	
�	
�	
r$c�p�|j}|s|���|j�|��S)z8Poll the socket to see if there's data that can be read.)rdr"rr�)r-ryr�s   r.r�zConnection.can_reads4���z���	��L�L�N�N�N��|�$�$�W�-�-�-r$c� �	|j�d|j��}n#t$rd}YnwxYw	|j�|���}n�#t
j$r'|���td|�����t$r3}|���td|�d|j�����d}~wt$r|����wxYw|j
rt��|j
z|_t!|t"��r|�|S)z0Read the response from a previously sent commandr5r�r�zTimeout reading from zError while reading from z : N)r�r�r9rr�rlryr
rrrr~rUr�rr�r1r)r-r��hosterrrXr s     r.r�zConnection.read_response&sX��	#���0�0�T�Y�0�0�G�G���	#�	#�	#�"�G�G�G�	#����
	��|�1�1�CS�1�T�T�H�H���~�	B�	B�	B��O�O�����@�w�@�@�A�A�A��	X�	X�	X��O�O����!�"V�g�"V�"V�a�f�"V�"V�W�W�W������	�	�	��O�O�����	�����%�	I�%)�V�V�d�.H�%H�D�"��h�
�.�.�	��N��s#��#�#�A�>C�.B/�/#Cc	�f�g}t|dt��rEt|d��������|dd�z}n<d|dvr2t|d�����|dd�z}t
�ttt|�������tf��}|j
}t|jj|��D�]}t|��}t|��|ks||kst|t��ryt
�|tt|�����tf��}|�|��|�|��t}��t
�|tt|�����t|tf��}��	|�|��|S)z2Pack a series of arguments into the Redis protocolrrRN� )r1r9�tupler8rS�	SYM_EMPTYr�SYM_STARrUr�r��mapr�r3�
SYM_DOLLARr�)r-r~�output�buff�
buffer_cutoff�arg�
arg_lengths       r.r[zConnection.pack_command@s������d�1�g�s�#�#�	5���a����)�)�/�/�1�1�2�2�T�!�"�"�X�=�D�D�
�T�!�W�_�_���a������)�)�D����H�4�D��~�~�x��S��Y�Y���)>�)>�)@�)@�(�K�L�L���+�
��t�|�*�D�1�1�	�	�C��S���J��D�	�	�M�)�)��
�-�-��c�:�.�.�.�!�~�~��:�s�:���'=�'=�'?�'?��J�����
�
�d�#�#�#��
�
�c�"�"�"���� �~�~��"��J���.�.�0�0� �� �
�	�	���	�
�
�d�����
r$c��g}g}d}|j}|D]�}|j|�D]�}t|��}||ks||kst|t��r1|�t�|����d}g}||kst|t��r|�|����|�|��||z
}����|r-|�t�|����|S)z.Pack multiple commands into the Redis protocolr)r�r[rUr1r3r�rbr)	r-�commandsrfr�
buffer_lengthrh�cmd�chunk�chunklens	         r.�
pack_commandszConnection.pack_commandsms�������
��+�
��	.�	.�C�*��*�C�0�
.�
.���u�:�:��!�M�1�1��-�/�/�!�%��4�4�0��M�M�)�.�.��"8�"8�9�9�9�$%�M��F��m�+�+�z�%��/L�/L�+��M�M�%�(�(�(�(��M�M�%�(�(�(�!�X�-�M�M�
.�"�	2��M�M�)�.�.��0�0�1�1�1��
r$�T)rrB)r;rCrDrE�
DefaultParserr/rrr�rrr�r"rrr�r
rNrPr?rYrEr�r�r[rqrFr$r.r�r��s�������:�:��
����#��!%����� ��"�������-B#�B#�B#�B#�H9�9�9�������E�E�E�%�%�%�M�M�M����B'C�'C�'C�R@�@�@�$%:�%:�%:�N���$I�I�I����K�K�K�
����6
�
�
�.�.�.�.�����4+�+�+�Z����r$r�c�D��eZdZdZ											d�fd�	Z�fd�Z�xZS)�
SSLConnectionz�Manages SSL connections to and from the Redis server(s).
    This class extends the Connection class, adding SSL functionality, and making
    use of ssl.SSLContext (https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
    N�requiredFc����tstd���t��jdi|��||_||_|�
tj}nWt|t��rBtjtj
tjd�}
||
vrtd|�����|
|}||_||_
||_||_||_||_|	|_|
|_||_dS)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_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�optionalrvz+Invalid SSL Certificate Requirements Flag: rF)�
ssl_availabler�superr/�keyfile�certfile�ssl�	CERT_NONEr1r9�
CERT_OPTIONAL�
CERT_REQUIRED�	cert_reqs�ca_certs�ca_path�check_hostname�certificate_password�ssl_validate_ocsp�ssl_validate_ocsp_stapled�ssl_ocsp_context�ssl_ocsp_expected_cert)r-�ssl_keyfile�ssl_certfile�
ssl_cert_reqs�ssl_ca_certs�ssl_check_hostname�ssl_ca_path�ssl_passwordr�r�r�r�r��	CERT_REQSr|s              �r.r/zSSLConnection.__init__�s���D�	E��C�D�D�D������"�"�6�"�"�"�"���$��
�� ��M�M�M�
�
�s�
+�
+�
	5��
��-��-���I�
�I�-�-� �Q�-�Q�Q����&�m�4�M�&���$��
�"���0���$0��!�!2���)B��&� 0���&<��#�#�#r$c���t�����}tj��}|j|_|j|_|js|jr'|�	|j|j|j
���|j�|j�!|�
|j|j���|�||j���}|jdurt"durt%d���|jr|jrt%d���|j�rd	dl}d
dlm}|j�Y|j�|jj��}|�|j��|�|j��n|j}|�||j��|j�|tAj ����}|�!��|�"|j|j#f��|�$��|�%��|S|jdurOt"rHd
dlm&}|||j|j#|j��}	|	�'��r|StQd
���|S)z Wrap the socket with SSL support)r}r|r�N)�cafile�capath)�server_hostnameTFzcryptography is not installed.zKEither an OCSP staple or pure OCSP connection must be validated - not both.rrR)�ocsp_staple_verifier)�OCSPVerifierzocsp validation error))r{rr~�create_default_contextr�r��verify_moder}r|�load_cert_chainr�r�r��load_verify_locations�wrap_socketr�r�rrr��OpenSSL�ocspr�r��SSL�Context�
SSLv23_METHOD�use_certificate_file�use_privatekey_file�set_ocsp_client_callbackr�r�rl�request_ocspr"r��do_handshakerIr��is_validr)r-r��context�sslsockr�r��
staple_ctx�conr��or|s          �r.rzSSLConnection._connect�s�����w�w���!�!���,�.�.��!%�!4���"�n����=�	�D�L�	��#�#������2�
$�
�
�
�
�=�$���(@��)�)���t�|�)�T�T�T��%�%�d�D�I�%�F�F���!�T�)�)�.D��.M�.M��=�>�>�>��)�	�d�.D�	�����
��)�	��N�N�N�2�2�2�2�2�2��$�,�$�[�0�0���1J�K�K�
��/�/��
�>�>�>��.�.�t�|�<�<�<�<�!�2�
��/�/�$��+�
�
�
��+�(�(��V�]�_�_�E�E�C��������K�K���D�I�.�/�/�/��������L�L�N�N�N��N��!�T�)�)�.D�)�*�*�*�*�*�*���W�d�i���D�M�J�J�A��z�z�|�|�
?���%�&=�>�>�>��r$)NNrvNFNNFFNN)r;rCrDrEr/r�
__classcell__�r|s@r.ruru�s������������ �� ����"'��#�>=�>=�>=�>=�>=�>=�@<�<�<�<�<�<�<�<�<r$ruc�H�eZdZdddddddddgedddddfd�Zd	�Zd
�Zd�ZdS)�UnixDomainSocketConnectionr=rNr�r�Fr�c��tj��|_||_||_||_||_||_||_|	|_	|	r|
�
t��|
|_|jrX|�"tt��d��|_nt!j|��|_|j�|
��n!tt��d��|_|
|_d|_||_t-|||��|_d|_||_|�|��g|_d|_dS)aB
        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`.
        NrRrr�)r�r�r��pathr�r�r�r�rfr�r�rr�rrr�r�r�r�r�r�r�r&r�rdr�r�r�r�)r-r�r�r�r�rfr*r+r,r�r�r�rer�r�r�r�s                 r.r/z#UnixDomainSocketConnection.__init__s4��4�9�;�;�����	���� ��
�&��� ��
�,��� 0����	0��!�!�,�/�/�/�,�����		/��}�"�9�;�;��2�2��
�
�"�]�5�1�1��
��J�-�-�n�=�=�=�=��y�{�{�A�.�.�D�J�%:��"�!"���"4����x��:J�K�K�����
�!1�������%�%�%�"$���"����r$c�p�d|jfd|jfg}|jr|�d|jf��|S)Nr�r�r�)r�r�r�r�r
s  r.rz&UnixDomainSocketConnection.repr_piecesKsH��
�T�Y��
�4�7�O�
����	=��M�M�=�$�*:�;�<�<�<��
r$c��tjtjtj��}|�|j��|�|j��|S)z&Create a Unix domain socket connection)rl�AF_UNIXr%rurfr"r�)r-r�s  r.rz#UnixDomainSocketConnection._connectTsF���}�V�^�V�-?�@�@������+�,�,�,����T�Y�����r$c��t|j��dkrd|j�d|jd�d�Sd|jd�d|j�d|jd�d�S)NrRz!Error connecting to unix socket: r8rr6r7z connecting to unix socket: )rUr~r�r:s  r.rz)UnixDomainSocketConnection._error_message[s����y�~���!�#�#�X�t�y�X�X�I�N�ST�DU�X�X�X�X�5����*�5�5��9�5�5� )��q� 1�5�5�5�
r$)r;rCrDrsr/rrrrFr$r.r�r�s������������� ����"������#8#�8#�8#�8#�t������	�	�	�	�	r$r�)�0�F�FALSE�N�NOc��|�|dkrdSt|t��r|���tvrdSt	|��S)Nr=F)r1r9�upper�
FALSE_STRINGSr4)r<s r.�to_boolr�jsI���}������t��%�����%�+�+�-�-�=�"@�"@��u���;�;�r$)	r�rfr�r�r�r��max_connectionsr�r�c���t|��}i}t|j�����D]�\}}|r�t	|��dkrnt|d��}t�|��}|r8	||��||<�[#ttf$rtd|�d����wxYw|||<��|j
rt|j
��|d<|jrt|j��|d<|jdkr)|j
rt|j
��|d<t|d<n�|jd	vr�|jrt|j��|d
<|jrt#|j��|d<|j
rUd|vrQ	t#t|j
���d
d����|d<n#t&tf$rYnwxYw|jdkr
t(|d<ntd���|S)NrzInvalid value for `z` in connection URL.r�r��unixr��connection_class)�redis�redissr�r�r��/r=r�zRRedis URL must specify one of the following schemes (redis://, rediss://, unix://))r
r�queryr+rUr	�URL_QUERY_ARGUMENT_PARSERSrW�	TypeError�
ValueErrorr�r��schemer�r��hostnamer�r5r�r9ru)�urlr��namer<�parsers     r.�	parse_urlr�sB��
�3�-�-�C�
�F���	�*�*�0�0�2�2�
%�
%���e��		%�S��Z�Z�!�^�^��E�!�H�%�%�E�/�3�3�D�9�9�F��
%�W�#)�6�%�=�=�F�4�L�L��!�:�.�W�W�W�$�%U�4�%U�%U�%U�V�V�V�W���� %��t���
�|�3�$�S�\�2�2��z��
�|�3�$�S�\�2�2��z���z�V����8�	/�$�S�X�.�.�F�6�N�%?��!�"�"�	��*�	*�	*��<�	3�$�S�\�2�2�F�6�N��8�	+� ���]�]�F�6�N��8�	��F�*�*�
�"�7�3�8�#4�#4�#<�#<�S�"�#E�#E�F�F��t����"�J�/�
�
�
���
�����:��!�!�)6�F�%�&���
5�
�
�	
�
�Ms�B�%B8�8F;�;G�Gc�l�eZdZdZed���Zedfd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zdd�ZdS)�ConnectionPoola�
    Create a connection pool. ``If max_connections`` is set, then this
    object raises :py:class:`~redis.exceptions.ConnectionError` when the pool's
    limit is reached.

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

    Any additional keyword arguments are passed to the constructor of
    ``connection_class``.
    c�x�t|��}d|vr|d|d<|�|��|di|��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://` 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�rF)r��update)�clsr�r��url_optionss    r.�from_urlzConnectionPool.from_url�sP��R ��n�n����'�'�.4�5G�.H�K�*�+��
�
�k�"�"�"��s�}�}�V�}�}�r$Nc���|pd}t|t��r|dkrtd���||_||_||_t
j��|_|�	��dS)Nlrz,"max_connections" must be a positive integer)
r1r5r�r��connection_kwargsr��	threading�Lock�
_fork_lock�reset)r-r�r�r�s    r.r/zConnectionPool.__init__�st��*�4�W���/�3�/�/�	M�?�Q�3F�3F��K�L�L�L� 0���!2���.���$�.�*�*����
�
�����r$c	�p�t|��j�dt|jdi|j�����d�S)NrrrF)r:r;r7r�r�rns r.rzConnectionPool.__repr__sS���D�z�z�"�
I�
I��*�T�*�D�D�T�-C�D�D�E�E�
I�
I�
I�	
r$c��tj��|_d|_g|_t��|_tj��|_	dSrc)
r�r��_lock�_created_connections�_available_connections�set�_in_use_connectionsr�r�r�rns r.r�zConnectionPool.resets@���^�%�%��
�$%��!�&(��#�#&�5�5�� ��9�;�;����r$c�Z�|jtj��kr�|j�d���}|st
�	|jtj��kr|���|j���dS#|j���wxYwdS)N�)ry)r�r�r�r��acquirerr��release)r-�acquireds  r.�	_checkpidzConnectionPool._checkpids���F�8�r�y�{�{�"�"���.�.�q�.�9�9�H��
+�*�*�
*��8�r�y�{�{�*�*��J�J�L�L�L���'�'�)�)�)�)�)����'�'�)�)�)�)����#�"s�0B
�
B(c��|���|j5	|j���}n$#t$r|���}YnwxYw|j�|��ddd��n#1swxYwY	|���	|�	��rtd���nb#ttf$rN|���|���|�	��rtd���YnwxYwn$#t$r|�|���wxYw|S)zGet a connection from the poolN�Connection has data�Connection not ready)r�r�r��pop�
IndexError�make_connectionr��addr"r�rrr
rUr��r-�command_name�keys�optionsr�s     r.�get_connectionzConnectionPool.get_connectionNs���������
�Z�	5�	5�
4�!�8�<�<�>�>�
�
���
4�
4�
4�!�1�1�3�3�
�
�
�
4�����$�(�(��4�4�4�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5�	���� � � �

B��&�&�(�(�A�)�*?�@�@�@�A��#�W�-�
B�
B�
B��%�%�'�'�'��"�"�$�$�$��&�&�(�(�B�)�*@�A�A�A�B�B�
B������
�	�	�	�
�L�L��$�$�$��		�����sb�B�8�B�A�B�A�B�B�	B�D*�##C�D*�AD&�#D*�%D&�&D*�*!Ec��|j}t|�dd��|�dd��|�dd�����S)z,Return an encoder based on encoding settingsr*r�r+r�r,Fr))r�r&rW)r-r�s  r.�get_encoderzConnectionPool.get_encoderosV���'����Z�Z�
�G�4�4�"�J�J�'8�(�C�C�#�Z�Z�(:�E�B�B�
�
�
�	
r$c��|j|jkrtd���|xjdz
c_|jdi|j��S)zCreate a new connectionzToo many connectionsrRrF)r�r�rr�r�rns r.r�zConnectionPool.make_connectionxsR���$��(<�<�<�!�"8�9�9�9��!�!�Q�&�!�!�$�t�$�>�>�t�'=�>�>�>r$c��|���|j5	|j�|��n#t$rYnwxYw|�|��r|j�|��n2|xjdzc_|�	��	ddd��dS	ddd��dS#1swxYwYdS)z(Releases the connection back to the poolrRN)
r�r�r��remove�KeyError�owns_connectionr�r�r�r
r�s  r.r�zConnectionPool.releasesI��������
�Z�	�	�
��(�/�/�
�;�;�;�;���
�
�
���
����
�#�#�J�/�/�
��+�2�2�:�>�>�>�>�
�)�)�Q�.�)�)��%�%�'�'�'��!	�	�	�	�	�	�	�	�?�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s2�B9�9�B9�
A�B9�A�AB9�9B=�B=c�"�|j|jkSr()r�r�s  r.r�zConnectionPool.owns_connection�s���~���)�)r$Tc���|���|j5|rt|j|j��}n|j}|D]}|����	ddd��dS#1swxYwYdS)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�rr�r�r
)r-�inuse_connections�connectionsr�s    r.r
zConnectionPool.disconnect�s���	
������
�Z�		(�		(� �
:�#��/��1I�����#�9��)�
(�
(�
��%�%�'�'�'�'�
(�		(�		(�		(�		(�		(�		(�		(�		(�		(�		(�		(�		(����		(�		(�		(�		(�		(�		(s�>A(�(A,�/A,rr)r;rCrDrE�classmethodr�r�r/rr�r�r�r�r�r�r�r
rFr$r.r�r��s����������.�.��[�.�b *�4�����,
�
�
����"-*�-*�-*�^���B
�
�
�?�?�?����**�*�*�(�(�(�(�(�(r$r�c�J��eZdZdZddeef�fd�	Zd�Zd�Zd�Z	d�Z
d	�Z�xZS)
�BlockingConnectionPoola
    Thread-safe blocking connection pool::

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

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

    The difference is that, in the event that a client tries to get a
    connection from the pool when all of connections are in use, rather than
    raising a :py:class:`~redis.ConnectionError` (as the default
    :py:class:`~redis.ConnectionPool` implementation does), it
    makes the client wait ("blocks") for a specified number of seconds until
    a connection becomes available.

    Use ``max_connections`` to increase / decrease the pool size::

        >>> pool = BlockingConnectionPool(max_connections=10)

    Use ``timeout`` to tell it either how many seconds to wait for a connection
    to become available, or to block forever:

        >>> # Block forever.
        >>> pool = BlockingConnectionPool(timeout=None)

        >>> # Raise a ``ConnectionError`` after five seconds if a connection is
        >>> # not available.
        >>> pool = BlockingConnectionPool(timeout=5)
    �2�c�\��||_||_t��jd||d�|��dS)N)r�r�rF)�queue_classryr{r/)r-r�ryr�r	r�r|s      �r.r/zBlockingConnectionPool.__init__�sS���'�����������	
�-�+�	
�	
� �	
�	
�	
�	
�	
r$c���|�|j��|_		|j�d��n#t$rYnwxYw�-g|_t
j��|_dSr()	r	r��pool�
put_nowaitr�_connectionsr�r�r�rns r.r�zBlockingConnectionPool.reset�s���$�$�T�%9�:�:��	�	�
��	�$�$�T�*�*�*�*���
�
�
���
����	�����9�;�;����s�=�
A
�	A
c�^�|jdi|j��}|j�|��|S)zMake a fresh connection.rF)r�r�r
r�r�s  r.r�z&BlockingConnectionPool.make_connection�s:��*�T�*�D�D�T�-C�D�D�
��� � ��,�,�,��r$c�R�|���d}	|j�d|j���}n#t$rtd���wxYw|�|���}	|���	|���rtd���n[#t
$rN|�	��|���|���rtd���YnwxYwn$#t$r|�|���wxYw|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)�blockryzNo connection available.r�r�)r�rrWryrrr�r"r�r
rUr�r�s     r.r�z%BlockingConnectionPool.get_connection�su��	
�������
�	>�����T�4�<��H�H�J�J���	>�	>�	>�"�"<�=�=�=�	>�������-�-�/�/�J�	���� � � �

B��&�&�(�(�A�)�*?�@�@�@�A��"�
B�
B�
B��%�%�'�'�'��"�"�$�$�$��&�&�(�(�B�)�*@�A�A�A�B�B�
B������
�	�	�	��L�L��$�$�$��	����
�s:�!:�A�.D�#B'�&D�'AC?�<D�>C?�?D�!D$c��|���|�|��s0|���|j�d��dS	|j�|��dS#t
$rYdSwxYw)z)Releases the connection back to the pool.N)r�r�r
rrrr�s  r.r�zBlockingConnectionPool.release1s���	
�������#�#�J�/�/�	�

�!�!�#�#�#��I� � ��&�&�&��F�	��I� � ��,�,�,�,�,���	�	�	�
�D�D�	���s�A7�7
B�Bc�j�|���|jD]}|����dS)z(Disconnects all connections in the pool.N)r�r
r
r�s  r.r
z!BlockingConnectionPool.disconnectFsC���������+�	$�	$�J��!�!�#�#�#�#�	$�	$r$)
r;rCrDrEr�rr/r�r�r�r�r
r�r�s@r.rr�s����������F��#��
�
�
�
�
�
�"���0���2�2�2�h���*$�$�$�$�$�$�$r$r)]r�r}rgr�rlr�r�	itertoolsr�queuerrrr�urllib.parserr	r
�packaging.versionr�
redis.backoffr�redis.exceptionsr
rrrrrrrrrrrrrr�redis.retryr�redis.utilsrrrr~rz�ImportError�BlockingIOError�EWOULDBLOCKr{�hasattrr �SSLWantWriteError�SSLErrorrar�rzr��__version__�hiredis_versionr��HIREDIS_SUPPORTS_BYTE_BUFFERr�r�rcrer�rbrw�objectrtr\r^r_r]r&rHrar�r�rsr�rur�r�r�r5r6r�r�r�r�rrFr$r.�<module>r%sf����������	�	�	�	�	�	�	�	�
�
�
�
���������������(�(�(�(�(�(�(�(�(�(�������4�4�4�4�4�4�4�4�4�4�%�%�%�%�%�%�#�#�#�#�#�#�����������������������������������"������O�O�O�O�O�O�O�O�O�O���J�J�J��M�M�������M�M�M������U�&�'�#��>��w�s�&�'�'�>�DE�+�C�,@�A�EF�+�C�,A�B�B�<=�+�C�L�9���B�G�G�I�I�J�J���(��N�N�N��g�g�1�2�2�O�'6�'�'�'�:J�:J�'J�$�#2�g�g�g�6F�6F�#F� �'6�'�'�'�:J�:J�'J�$�"��'�(�"'����
�
����	�!?���6�8�8��S��N��#W� �� �&�&�&�&�&�&�&�&�R$'�$'�$'�$'�$'�$'�$'�$'�Ns�s�s�s�s�s�s�s�lP�P�P�P�P�:�P�P�P�f|�|�|�|�|�J�|�|�|�~�!�!�M�M� �M�S�S�S�S�S�S�S�S�lB�B�B�B�B�J�B�B�B�JT�T�T�T�T��T�T�T�n/�
������#����� �!�
�
��1�1�1�hv(�v(�v(�v(�v(�v(�v(�v(�r^$�^$�^$�^$�^$�^�^$�^$�^$�^$�^$s�<B�B
�B