HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/redis/asyncio/__pycache__/connection.cpython-39.pyc
a

��b&�
@s|UddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZmZmZmZmZmZmZmZmZmZmZddlmZmZmZm Z ddl!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'm(Z(dd	l)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8dd
l9m:Z:m;Z;ddl<m=Z=m>Z>dZ?e=�rlddl?Z?e@ejAejBdejCdejDdiZEeFeE�G��ZHd
ZIdZJdZKdZLdZMdZNGdd�dejO�ZPePjQZRdZSdZTdZUdZVGdd�de(dd�ZWGdd�d�ZXeeYeeeZeeYeeZfffZ[Gdd �d �Z\Gd!d"�d"�Z]Gd#d$�d$e\�Z^Gd%d&�d&e\�Z_eee^e_fe`d'<e=�rve_Zane^ZaGd(d)�d)e'�ZbGd*d+�d+e'�ZceebecfZdGd,d-�d-�ZeGd.d/�d/ee�ZfGd0d1�d1�ZgGd2d3�d3ee�Zhd4Zieejd5�d6d7�Zkeelememekekelelekd8��ZneeYed9eoffe`d:<Gd;d<�d<e(dd�ZpeYepd=�d>d?�Zqed@dAdB�ZrGdCdA�dA�ZsGdDdE�dEes�ZtdS)F�N)�chain)�MappingProxyType)�Any�Callable�Iterable�List�Mapping�Optional�Set�Tuple�Type�TypeVar�Union)�ParseResult�parse_qs�unquote�urlparse)�Retry)�	NoBackoff)�Protocol�	TypedDict)�AuthenticationError�$AuthenticationWrongNumberOfArgsError�BusyLoadingError�ChildDeadlockedError�ConnectionError�	DataError�ExecAbortError�InvalidResponse�ModuleError�NoPermissionError�
NoScriptError�
ReadOnlyError�
RedisError�
ResponseError�TimeoutError)�
EncodableT�EncodedT)�HIREDIS_AVAILABLE�str_if_bytes��*�$s
�
�zConnection closed by server.c@seZdZe�ZdS)�	_SentinelN)�__name__�
__module__�__qualname__�object�sentinel�r5r5�</usr/lib/python3.9/site-packages/redis/asyncio/connection.pyr/Nsr/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@sJeZdZUeegefed<eegefed<eeed<eeed<dS)�_HiredisReaderArgs�
protocolError�
replyError�encoding�errorsN)r0r1r2r�str�	Exception�__annotations__r	r5r5r5r6r7]s
r7F)�totalc@sHeZdZdZdZeeed�dd�Zee	d�dd�Z
deed�d	d
�ZdS)
�Encoderz=Encode strings to bytes-like and decode bytes-like to strings�r:�encoding_errors�decode_responsescCs||_||_||_dS�NrA)�selfr:rBrCr5r5r6�__init__iszEncoder.__init__)�value�returncCstt|t�r|�|j|j�St|ttf�r,|St|ttf�rXt|t	�rLt
d��t|���S|jj
}t
d|�d���dS)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: z1. Convert to a bytes, string, int or float first.N)�
isinstancer<�encoder:rB�bytes�
memoryview�int�float�boolr�repr�	__class__r0)rErG�typenamer5r5r6rJns

�
�zEncoder.encodeFcCsF|js
|rBt|t�r$|�|j|j�St|t�rB|���|j|j�S|S)z:Return a unicode string from the bytes-like representation)rCrIrK�decoder:rBrL�tobytes)rErG�forcer5r5r6rS�s


zEncoder.decodeN)F)r0r1r2�__doc__�	__slots__r<rOrFr&r'rJrSr5r5r5r6r@ds
r@c@s�eZdZUdZdZdededededeee	e
e	ee	ee	i	e
eeeeed�Zeed	<ed
�dd�Zd
d�Zeed�dd�Zdd�Zdd�dd�Zeed�dd�Zd ee e!ede"e!fd�dd�Z#dS)!�
BaseParser�Plain Python parsing class��_stream�_buffer�
_read_sizezmax 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	EXECABORTZLOADINGZNOSCRIPTZREADONLYZNOAUTHZNOPERM�EXCEPTION_CLASSES��socket_read_sizecCsd|_d|_||_dSrDrZ�rEr`r5r5r6rF�szBaseParser.__init__cCs$z|��WntyYn0dSrD)�
on_disconnectr=�rEr5r5r6�__del__�szBaseParser.__del__)�responserHcCs\|�d�d}||jvrT|t|�dd�}|j|}t|t�rL|�|t�}||�St|�S)zParse an error response� r�N)�splitr^�lenrI�dict�getr$)rEreZ
error_codeZexception_classr5r5r6�parse_error�s


zBaseParser.parse_errorcCs
t��dSrD��NotImplementedErrorrcr5r5r6rb�szBaseParser.on_disconnect�
Connection��
connectioncCs
t��dSrDrm�rErqr5r5r6�
on_connect�szBaseParser.on_connect��timeoutrHc�s
t��dSrDrm�rErur5r5r6�can_read�szBaseParser.can_readFN��disable_decodingrHc�s
t��dSrDrm)rEryr5r5r6�
read_response�szBaseParser.read_response)F)$r0r1r2rVrWrrr�MODULE_LOAD_ERRORr�MODULE_EXPORTS_DATA_TYPES_ERROR�NO_SUCH_MODULE_ERROR� MODULE_UNLOAD_NOT_POSSIBLE_ERRORrrr!r"r r^�ExceptionMappingTr>rMrFrdr<r$rlrbrsrNrOrwrr&rrzr5r5r5r6rX�s<
����rXc@s�eZdZdZejeeed�dd�Z	e
dd��Zdedfeee
edefeed	�d
d�Zeed�d
d�Zeed�dd�Zed�dd�Zdd�Zdd�ZdS)�SocketBufferz�Async-friendly re-impl of redis-py's SocketBuffer.

    TODO: We're currently passing through two buffers,
        the asyncio.StreamReader and this. I imagine we can reduce the layers here
        while maintaining compliance with prior art.
    )�
stream_readerr`�socket_timeoutcCs,||_||_||_t��|_d|_d|_dS�Nr)r[r`r��io�BytesIOr\�
bytes_written�
bytes_read)rEr�r`r�r5r5r6rF�s
zSocketBuffer.__init__cCs|j|jSrD)r�r�rcr5r5r6�length�szSocketBuffer.lengthNT)r�ru�raise_on_timeoutrHc

�s�|j}|dus|jdur td��|�|j�d}|tur<|n|j}z�t�|�4IdH�*|j�	|j
�IdH}Wd�IdHq�1IdHs�0Yt|t�r�t
|�dkr�tt��|�|�t
|�}|j|7_||7}|dur�||kr�qDWdStjtjf�y|�rtd��YdSt�y�}zJt�|jd�}	|�s\|j|	k�r\WYd}~dStd|j����WYd}~n
d}~00dS)N�Buffer is closed.rT�Timeout reading from socketF����!Error while reading from socket: )r\r[r#�seekr��SENTINELr��
async_timeoutru�readr`rIrKrir�SERVER_CLOSED_CONNECTION_ERROR�write�socket�asyncior%�NONBLOCKING_EXCEPTIONS�#NONBLOCKING_EXCEPTION_ERROR_NUMBERSrkrQ�errno�args)
rEr�rur��bufZmarker�dataZdata_length�ex�allowedr5r5r6�_read_from_socket�s6>
zSocketBuffer._read_from_socketrtc�st|j�p|j|dd�IdHS)NF�rur�)rOr�r�rvr5r5r6rws�zSocketBuffer.can_read)r�rHc�s�|d}||jkr(|�||j�IdH|jdur:td��|j�|j�|j�|�}|jt|�7_|j|jkrz|�	�|dd�S)Nr*r����)
r�r�r\r#r�r�r�rir��purge)rEr�r�r5r5r6r�s

zSocketBuffer.read�rHc�s�|j}|durtd��|�|j�|��}|�t�sX|��IdH|�|j�|��}q*|jt|�7_|j|j	kr~|�
�|dd�S)Nr�r�)r\r#r�r��readline�endswith�SYM_CRLFr�rir�r�)rEr�r�r5r5r6r�0s

zSocketBuffer.readlinecCs8|jdurtd��|j�d�|j��d|_d|_dS)Nr�r)r\r#r��truncater�r�rcr5r5r6r�Fs

zSocketBuffer.purgecCs:z|��|j��Wnty(Yn0d|_d|_dSrD)r�r\�closer=r[rcr5r5r6r�OszSocketBuffer.close)r0r1r2rVr��StreamReaderrMr	rNrF�propertyr�r�rr/rOr�rwrKr�r�r�r�r5r5r5r6r��s*	�
��*	r�cspeZdZdZejdZed��fdd�Zdd�dd	�Zd
d�Z	e
d�d
d�Zdee
eedfd�dd�Z�ZS)�PythonParserrY)�encoderr_cst��|�d|_dSrD)�superrFr�ra�rQr5r6rFcszPythonParser.__init__rorpcCs:|j|_|jdurtd��t|j|j|j�|_|j|_dS)zCalled when the stream connectsNr�)�_readerr[r#r�r]r�r\r�rrr5r5r6rsgs
�zPythonParser.on_connectcCs4|jdurd|_|jdur*|j��d|_d|_dS)z"Called when the stream disconnectsN)r[r\r�r�rcr5r5r6rbrs


zPythonParser.on_disconnect�ruc�s|jot|j�|�IdH�SrD)r\rOrwrvr5r5r6rw{szPythonParser.can_readFNrxc�sB�jr�jstt���j��IdH}|s0tt��|dd�|dd�}}|dvr`td|����|dkr�|jddd�}��|�}t|t�r�|�|S|dkr�n�|d	kr�t	|�}nn|d
kr�t	|�}|dkr�dS�j�
|�IdH}n>|dk�rt	|�}|dk�r�dS��fd
d�t|�D�IdH}t|t��r>�du�r>�j�|�}|S)Nrg)�-�+�:r,r+zProtocol Error: r��utf-8�replace)r;r�r�r,r�r+c�sg|]}����IdH�qSrD)rz)�.0�_�ryrEr5r6�
<listcomp>�sz.PythonParser.read_response.<locals>.<listcomp>F)
r\r�rr�r�rrSrlrIrMr��rangerK)rEry�rawZbytere�errorr�r5r�r6rz~sB




�zPythonParser.read_response)F)r0r1r2rVrXrWrMrFrsrbrNrwrOrr&r$rz�
__classcell__r5r5r�r6r�^s
	��r�cs�eZdZUdZejdZeed<ed��fdd�Z	dd�d	d
�Z
dd�Zed
�dd�Z
edfeedefed�dd�Zdeeeeefd�dd�Z�ZS)�
HiredisParserz*Parser class for connections using Hiredis)�_next_responser��_socket_timeoutr�r_cs*tstd��t�j|d�d|_d|_dS)NzHiredis is not available.r_)r(r#r�rFr�r�rar�r5r6rF�s
zHiredisParser.__init__rorpcCsX|j|_t|jd�}|jjr4|jj|d<|jj|d<tj	fi|��|_d|_
|j|_dS)N)r8r9r:r;F)
r�r[rrlr�rCr:rB�hiredis�Readerr�r�r�)rErq�kwargsr5r5r6rs�s�zHiredisParser.on_connectcCsd|_d|_d|_dS)NF)r[r�r�rcr5r5r6rb�szHiredisParser.on_disconnectr�c�sL|jr|jstt��|jdur*|j��|_|jdurH|j|dd�IdHSdS)NFr�T)r[r�rr�r��gets�read_from_socketrvr5r5r6rw�s

zHiredisParser.can_readTNr�c
�sR|tur|jn|}z�|dur2|j�|j�IdH}nRt�|�4IdH�*|j�|j�IdH}Wd�IdHq�1IdHsz0Y|r�t|t�s�t	t
�d�|j�|�WdSt
jy��Yn�tjt
jfy�|r�td�d�YdSt�yL}zJt�|jd�}|�s(|j|k�r(WYd}~dSt	d|j����WYd}~n
d}~00dS)NTr�Fr�r�)r�r�r[r�r]r�rurIrKrr�r�Zfeedr��CancelledErrorr�r%r�r�rkrQr�r�)rErur��bufferr�r�r5r5r6r��s*>

zHiredisParser.read_from_socketFrxc�s�|jr|js|��tt�d�|jdur8|j}d|_|S|j��}|durd|��IdH|j��}qBt|t�rt|�n$t|t	�r�|r�t|dt�r�|d�|S)NFr)
r[r�rbrr�r�r�r�rI�list)rEryrer5r5r6rz�s*



���zHiredisParser.read_response)F)r0r1r2rVrXrWrOr>rMrFrsrbrNrwr�rr/r�r&rrzr�r5r5r�r6r��s$

��#��r��
DefaultParserc@seZdZdd�dd�ZdS)�ConnectCallbackProtocolrorpcCsdSrDr5rrr5r5r6�__call__'sz ConnectCallbackProtocol.__call__N�r0r1r2r�r5r5r5r6r�&sr�c@seZdZdd�dd�ZdS)�AsyncConnectCallbackProtocolrorpc�sdSrDr5rrr5r5r6r�,sz%AsyncConnectCallbackProtocol.__call__Nr�r5r5r5r6r�+sr�c@s�eZdZdZdZdddddddddddd	ded
ddddded�eeee	feee	fe
ee
ee
eee
e
e	ee	effe	eeeeeee	ee
ee
ee
ee
eeed�dd
�Zdd�Zdd�Zdd�Zedd��Zdd�Zdd�Zeedd�dd�Zdd�Zdd �Zd!d"�Zdd#�d$d%�Zdd#�d&d'�Z d(d)�Z!d*d+�Z"d,d-�Z#e$edd.�d/d0�Z%dFeeee$efedd2�d3d4�Z&e'e'dd5�d6d7�Z(dGed8�d9d:�Z)dHed;�d<d=�Z*dIed;�d>d?�Z+e,e-ed@�dAdB�Z.e$e$e,e-edC�dDdE�Z/dS)Jroz4Manages TCP communication to and from a Redis server)�pid�host�port�db�username�client_name�passwordr��socket_connect_timeout�socket_keepalive�socket_keepalive_options�socket_type�redis_connect_func�retry_on_timeout�health_check_interval�next_health_checkZlast_active_atr��ssl_contextr��_writer�_parser�_connect_callbacks�_buffer_cutoff�_lock�_socket_read_size�__dict__Z	localhosti�rNFr��strict�)r�r�r�r�r�r�r�r�r�r�r:rBrC�parser_classr`r�r�r��retryr��
encoder_classcCs�t��|_||_t|�|_||_||_||_||_	||_
|pB|pBd|_||_|pRi|_
|	|_|
|_|
r�|sztt�d�|_q�t�|�|_ntt�d�|_||_d|_d|_||||
�|_||_d|_d|_||_|�|�g|_d|_t �!�|_"dS)Nrgrr��p)#�os�getpidr�r�rMr�r�r�r�r�r�r�r�r�r�r�rrr��copy�deepcopyr�r�r�r�r�r�r�r��
set_parserr�r�r��Lockr�)rEr�r�r�r�r�r�r�r�r�r�r:rBrCr�r`r�r�r�r�r�r�r5r5r6rFTs<



zConnection.__init__cCs,d�dd�|��D��}|jj�d|�d�S)N�,css |]\}}|�d|��VqdS)�=Nr5)r��k�vr5r5r6�	<genexpr>�r.z&Connection.__repr__.<locals>.<genexpr>�<�>)�join�repr_piecesrQr0)rEZ	repr_argsr5r5r6�__repr__�szConnection.__repr__cCs6d|jfd|jfd|jfg}|jr2|�d|jf�|S)Nr�r�r�r�)r�r�r�r��append�rE�piecesr5r5r6r��szConnection.repr_piecescCsPz8|jr6t��}|��}|��r,|�|�n
|�|�WntyJYn0dSrD)�is_connectedr��get_event_loop�
disconnectZ
is_runningZcreate_taskZrun_until_completer=)rEZloop�coror5r5r6rd�szConnection.__del__cCs|jo
|jSrD)r�r�rcr5r5r6r��szConnection.is_connectedcCs|j�t�|��dSrD)r�r��weakref�
WeakMethod)rE�callbackr5r5r6�register_connect_callback�sz$Connection.register_connect_callbackcCs
g|_dSrD)r�rcr5r5r6�clear_connect_callbacks�sz"Connection.clear_connect_callbacks)r�rHcCs||jd�|_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
        r_N)r�r�)rEr�r5r5r6r��szConnection.set_parserc
�sR|jr
dSz|��IdHWn�tjy2�Yn~tjtjfyRtd��Yn^ty�}zt|�	|���WYd}~n6d}~0t
y�}zt|�|�WYd}~n
d}~00z@|js�|��IdHn&t�
|j�r�|�|�IdHn|�|�Wn$t�y|��IdH�Yn0|jD]0}|�}||�}|�rt�|��r|IdH�qdS)z5Connects to the Redis server if not already connectedNzTimeout connecting to server)r��_connectr�r�r�rur%�OSErrorr�_error_messager=r�rsZiscoroutinefunctionr#r�r��inspectZisawaitable)rE�e�exc�refrZtaskr5r5r6�connect�s8" ��
zConnection.connectc	�st�|j�4IdH�Dtj|j|j|jr2|j��ndd�IdH\}}Wd�IdHqn1IdHsd0Y||_	||_
|j�d�}|r�|�
tjtjd�z@|jr�|�
tjtjd�|j��D]\}}|�
tj||�q�Wn ttfy�|���Yn0dS)zCreate a TCP socket connectionN)r�r��sslr�rg)r�rur�r�Zopen_connectionr�r�r�rkr�r�Z	transportZget_extra_infoZ
setsockoptr�ZIPPROTO_TCPZTCP_NODELAYr�Z
SOL_SOCKETZSO_KEEPALIVEr��itemsZSOL_TCPr�	TypeErrorr�)rE�reader�writerZsockr�r�r5r5r6r�s&�:zConnection._connectc	Csbt|j�dkr0d|j�d|j�d|jd�d�Sd|jd�d|j�d|j�d|jd�d�	SdS)	NrgzError connecting to �:�. r�.�Error z connecting to )rir�r�r��rE�	exceptionr5r5r6r�s"��zConnection._error_messager�c�s4|j�|�|js|jr�|jr0|j|jp*df}n|jp8df}|jdg|�Rddi�IdHz|��IdH}Wn8ty�|jd|jdd�IdH|��IdH}Yn0t|�dkr�td��|j	r�|�d	d
|j	�IdHt|��IdH�dkr�t
d��|j�r0|�d|j�IdHt|��IdH�dk�r0t
d
��dS)z=Initialize the connection, authenticate and select a database�ZAUTH�check_healthFN�rZOKzInvalid Username or PasswordZCLIENTZSETNAMEzError setting client nameZSELECTzInvalid Database)r�rsr�r��send_commandrzrr)rr�rr�)rEZ	auth_argsZ
auth_responser5r5r6rss*zConnection.on_connectc	�sz�t�|j�4IdH��|j��|js@Wd�IdHWdSz\z8t��|jkrx|j	�
�t|j	d�rx|j	��IdHWnt
y�Yn0Wd|_d|_	nd|_d|_	0Wd�IdHq�1IdHs�0YWn&tjy�td|j���d�Yn0dS)z!Disconnects from the Redis serverN�wait_closedz#Timed out closing connection after )r�rur�r�rbr�r�r�r�r�r��hasattrrrr�r�r%rcr5r5r6r�*s,

�6
��zConnection.disconnectc�s6|jddd�IdHt|��IdH�dkr2td��dS)z Send PING, expect PONG in returnZPINGFrNZPONGz#Bad response from PING health check)rr)rzrrcr5r5r6�
_send_pingAszConnection._send_pingc�s|��IdHdS)z Function to call when PING failsN�r�)rEr�r5r5r6�_ping_failedGszConnection._ping_failedc�sRtjdd�dkrtj}ntj}|jrN|���|jkrN|j�	|j
|j�IdHdS)z3Check the health of the connection with a PING/PONGrr*���N)�sys�version_infor�r��get_running_loopr��timer�r�Zcall_with_retryrr!)rE�funcr5r5r6rKs
zConnection.check_health)�commandrHc�s |j�|�|j��IdHdSrD)r��
writelines�drain)rEr*r5r5r6�_send_packed_commandUszConnection._send_packed_commandT)r*rrHc
�s^|js|��IdHn|r(|��IdHzdt|t�r<|��}t|t�rL|g}|jrnt�	|�
|�|j�IdHn|j�|�|j�
�IdHWn�tjy�|��IdHtd�d�Yn�t�y6}zf|��IdHt|j�dkr�d|jd}}n|jd}|jd}td|�d|�d��|�WYd}~n,d}~0t�yX|��IdH�Yn0dS)NzTimeout writing to socketrgZUNKNOWNrrz while writing to socket. r)r�r
rrIr<rJrKr�r��wait_forr-r�r+r,r%r�rrir�r�
BaseException)rEr*rr
Zerr_no�errmsgr5r5r6�send_packed_commandYs@

�

��zConnection.send_packed_command)r�r�rHc�s&|j|j|�|�dd�d�IdHdS)z+Pack and send a command to the Redis serverrTrN)r1�pack_commandrk)rEr�r�r5r5r6r~s�zConnection.send_commandr�c
�s�|js|��IdHz|j�|�IdHWStyz}z:|��IdHtd|j�d|j�d|j	����WYd}~n
d}~00dS)z8Poll the socket to see if there's data that can be read.N�Error while reading from rz: )
r�r
r�rwrr�rr�r�r�)rErur
r5r5r6rw�s�zConnection.can_read�ryc
�s�z�|j4IdH��|jrnt�|j�4IdH�*|jj|d�IdH}Wd�IdHq�1IdHsb0Yn|jj|d�IdH}Wd�IdHq�1IdHs�0YWn�tjy�|��IdHtd|j	�d|j
����Ynvt�y:}z:|��IdHtd|j	�d|j
�d|j
����WYd}~n,d}~0t�y\|��IdH�Yn0|j�r�tjdd�d	k�r�tj}ntj}|���|j|_t|t��r�|d�|S�
z0Read the response from a previously sent commandNr4zTimeout reading from rr3z : rr*r")r�r�r�rur�rzr�r%r�r�r�rrr�r/r�r%r&r�r'r(r�rIr$�rEryrer
r)r5r5r6rz�s:�8�:�zConnection.read_responsec
�stzt|jr^t�|j�4IdH�*|jj|d�IdH}Wd�IdHqr1IdHsR0Yn|jj|d�IdH}Wn�tjy�|��IdHtd|j�d|j	����Yntt
y�}z:|��IdHtd|j�d|j	�d|j����WYd}~n,d}~0t
�y |��IdH�Yn0|j�r^tjdd�d	k�rFtj}ntj}|���|j|_t|t��rp|d�|Sr5)r�r�rur�rzr�r%r�r�r�rrr�r/r�r%r&r�r'r(r�rIr$r6r5r5r6�read_response_without_lock�s8�8��z%Connection.read_response_without_lock)r�rHc	Gs*g}t|dt�rJ�t|dt�rFt|d�����|dd�}n(d|dvrnt|d���|dd�}t�ttt	|����t
f�}|j}t|j
j|�D]|}t	|�}t	|�|ks�||ks�t|t�r�t�|tt|���t
f�}|�|�|�|�t
}q�t�|tt|���t
|t
f�}q�|�|�|S)z2Pack a series of arguments into the Redis protocolrrgN� )rIrNr<�tuplerJrh�	SYM_EMPTYr��SYM_STARrir�r��mapr�rL�
SYM_DOLLARr�)rEr��outputZbuff�
buffer_cutoff�argZ
arg_lengthr5r5r6r2�sB"
����


��

zConnection.pack_command)�commandsrHc	Cs�g}g}d}|j}|D]~}|j|�D]n}t|�}||ksJ||ksJt|t�rb|�t�|��d}g}||kstt|t�r�|�|�q$|�|�||7}q$q|r�|�t�|��|S)z.Pack multiple commands into the Redis protocolr)r�r2rirIrLr�r:r�)	rErAr>r�Z
buffer_lengthr?�cmd�chunkZchunklenr5r5r6�
pack_commandss.���
zConnection.pack_commands)T)r)F)F)0r0r1r2rVrWr�r@r<rrMr	rNrOrrKrrXr�ConnectCallbackTrFr�r�rdr�r�rrr�r
rrrsr�rr!rrr-r1rrrwrzr7r&rr2rDr5r5r5r6ro3s�!�

�;
%)
��%$#.rocs�eZdZdeeeeeeeeeed��fdd�
Zedd��Zed	d
��Z	edd��Z
ed
d��Zedd��Zedd��Z
�ZS)�
SSLConnectionN�requiredF)�ssl_keyfile�ssl_certfile�
ssl_cert_reqs�ssl_ca_certs�ssl_ca_data�ssl_check_hostnamecs,t�jfi|��t||||||d�|_dS)N��keyfile�certfile�	cert_reqs�ca_certs�ca_data�check_hostname)r�rF�RedisSSLContextr�)rErHrIrJrKrLrMr�r�r5r6rF$s
�zSSLConnection.__init__cCs|jjSrD)r�rOrcr5r5r6rO8szSSLConnection.keyfilecCs|jjSrD)r�rPrcr5r5r6rP<szSSLConnection.certfilecCs|jjSrD)r�rQrcr5r5r6rQ@szSSLConnection.cert_reqscCs|jjSrD)r�rRrcr5r5r6rRDszSSLConnection.ca_certscCs|jjSrD)r�rSrcr5r5r6rSHszSSLConnection.ca_datacCs|jjSrD)r�rTrcr5r5r6rTLszSSLConnection.check_hostname)NNrGNNF)r0r1r2r	r<rOrFr�rOrPrQrRrSrTr�r5r5r�r6rF#s4��




rFc@sNeZdZdZd
eeeeeeeeeeed�dd�Zej	d�dd	�Z
dS)rU)rOrPrQrRrS�contextrTNFrNcCsv||_||_|durtj|_n<t|t�rZtjtjtjd�}||vrPt	d|����|||_||_
||_||_d|_
dS)N)ZnoneZoptionalrGz+Invalid SSL Certificate Requirements Flag: )rOrPrZ	CERT_NONErQrIr<Z
CERT_OPTIONALZ
CERT_REQUIREDr#rRrSrTrV)rErOrPrQrRrSrTZ	CERT_REQSr5r5r6rF\s$	

��
zRedisSSLContext.__init__r�cCsf|js`t��}|j|_|j|_|jr<|jr<|j|j|jd�|j	sH|j
rZ|j|j	|j
d�||_|jS)N)rPrO)ZcafileZcadata)rVrZcreate_default_contextrTrQZverify_moderPrOZload_cert_chainrRrSZload_verify_locations)rErVr5r5r6rkyszRedisSSLContext.get)NNNNNF)r0r1r2rWr	r<rOrFrZ
SSLContextrkr5r5r5r6rUQs ��rUc@s�eZdZddddddddddedddddd	�eeeefeeeeeeeeeee	e	e
eeeeeed
�dd�Z
eeeeeeffd
�dd�Zdd�Zdd�ZdS)�UnixDomainSocketConnectionrrNr�r�Fr�g)�pathr�r�r�r�r�r:rBrCr�r�r`r�r�r�r�)rXr�r�r�r�r�r:rBrCr�r�r`r�r�r�cCs�t��|_||_||_||_||_||_||_|p8|p8d|_	|
|_
|
rl|dur^tt�d�|_
qzt�|�|_
ntt�d�|_
|
|_d|_||_t|||	�|_d|_d|_d|_||_|�|�g|_d|_t��|_dS)z�
        Initialize a new UnixDomainSocketConnection.
        To specify a retry policy, first set `retry_on_timeout` to `True`
        then set `retry` to a valid `Retry` object
        Nrgrr�r�)r�r�r�rXr�r�r�r�r�r�r�rrr�r�r�r�r�r�r@r�Z_sockr�r�r�r�r�r�r�r�r�)rErXr�r�r�r�r�r:rBrCr�r�r`r�r�r�r�r5r5r6rF�s4

z#UnixDomainSocketConnection.__init__r�cCs.d|jfd|jfg}|jr*|�d|jf�|S)NrXr�r�)rXr�r�r�r�r5r5r6r��sz&UnixDomainSocketConnection.repr_piecesc	�svt�|j�4IdH�.tj|jd�IdH\}}Wd�IdHqX1IdHsN0Y||_||_|��IdHdS)N)rX)	r�rur�r�Zopen_unix_connectionrXr�r�rs)rErrr5r5r6r�s
Bz#UnixDomainSocketConnection._connectcCsRt|j�dkr(d|j�d|jd�d�Sd|jd�d|j�d|jd�d�SdS)Nrgz!Error connecting to unix socket: rrrrz connecting to unix socket: )rir�rXrr5r5r6r�s���z)UnixDomainSocketConnection._error_message)r0r1r2r�r<rrMr	rNrOrrXrrFrrr�rrr5r5r5r6rW�sH�
�7"rW)�0�FZFALSE�NZNOr�cCs6|dus|dkrdSt|t�r.|��tvr.dSt|�S)NrF)rIr<�upper�
FALSE_STRINGSrO)rGr5r5r6�to_bool�s
r^)r�r�r�r�r��max_connectionsr�rM.�URL_QUERY_ARGUMENT_PARSERSc@sJeZdZUeed<eed<eeed<eed<eed<eed<eed<dS)	�
ConnectKwargsr�r��connection_classr�r�r�rXN)r0r1r2r<r>rrorMr5r5r5r6ra�s
ra)�urlrHc
Cs�t|�}i}t|j���D]t\}}|rt|�dkrt|d�}t�|�}|r�z||�||<Wq�tt	fy�t	d|�d���Yq�0q|||<q|j
r�t|j
�|d<|jr�t|j�|d<|jdkr�|j
r�t|j
�|d<t|d<n�|jd	v�rx|j�rt|j�|d
<|j�rt|j�|d<|j
�rbd|v�rbztt|j
��d
d��|d<Wntt	f�y`Yn0|jdk�r�t|d<nd}t	d|�d���|S)NrzInvalid value for `z` in connection URL.r�r�ZunixrXrb)Zredis�redissr�r�r��/rrdzredis://, rediss://, unix://z5Redis URL must specify one of the following schemes (�))rr�queryrrirr`rkr�
ValueErrorr�r��schemerXrW�hostnamer�rMr��AttributeErrorrF)rc�parsedr��nameZ
value_listrG�parserZ
valid_schemesr5r5r6�	parse_url�sJ





�ro�_CP�ConnectionPool)�boundc@s�eZdZdZeeeeed�dd��Ze	dfee	e
ed�dd�Zd	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Ze	d�dd�Ze	d�dd�Zded�dd�ZdS)rqa�
    Create a connection pool. ``If max_connections`` is set, then this
    object raises :py:class:`~redis.ConnectionError` when the pool's
    limit is reached.

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

    Any additional keyword arguments are passed to the constructor of
    ``connection_class``.
    )�clsrcrHcKs t|�}|�|�|fi|��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.
        )ro�update)rsrcr�Zurl_optionsr5r5r6�from_url?s(
zConnectionPool.from_urlN�rbr_cKsp|pd}t|t�r|dkr"td��||_||_||_t��|_t	��|_
||||��|j�dt
�|_dS)Nlrz,"max_connections" must be a positive integerr�)rIrMrhrb�connection_kwargsr_�	threadingr��
_fork_lockr�r��resetrkr@r�)rErbr_rwr5r5r6rFks


zConnectionPool.__init__cCs"|jj�d|jfi|j���d�S)Nr�r�)rQr0rbrwrcr5r5r6r��s
��zConnectionPool.__repr__cCs,t��|_d|_g|_t�|_t��|_	dSr�)
r�r�r��_created_connections�_available_connections�set�_in_use_connectionsr�r�r�rcr5r5r6rz�s

zConnectionPool.resetcCsZ|jt��krV|jjdd�}|s$t�z$|jt��kr<|��W|j��n|j��0dS)N�r�)r�r�r�ry�acquirerrz�release)rEZacquiredr5r5r6�	_checkpid�s#
zConnectionPool._checkpidc	�s|��|j4IdH�Lz|j��}Wnty@|��}Yn0|j�|�Wd�IdHqx1IdHsn0Yzv|��IdHz|�	�IdHr�t
d�d�WnFt
y�|��IdH|��IdH|�	�IdHr�t
d�d�Yn0Wn&t�y|�
|�IdH�Yn0|S)zGet a connection from the poolN�Connection has data�Connection not ready)r�r�r|�pop�
IndexError�make_connectionr~�addr
rwrr�r/r��rEZcommand_name�keys�optionsrqr5r5r6�get_connection�s*6zConnectionPool.get_connectioncCs.|j}|j|�dd�|�dd�|�dd�d�S)z,Return an encoder based on encoding settingsr:r�rBr�rCFrA)rwr�rk)rEr�r5r5r6�get_encoder�s


�zConnectionPool.get_encodercCs4|j|jkrtd��|jd7_|jfi|j��S)zCreate a new connectionzToo many connectionsrg)r{r_rrbrwrcr5r5r6r��szConnectionPool.make_connectionrpc	�s�|��|j4IdH��z|j�|�Wnty:Yn0|�|�rT|j�|�n2|jd8_|�	�IdHWd�IdHdSWd�IdHq�1IdHs�0YdS)z(Releases the connection back to the poolNrg)
r�r�r~�remove�KeyError�owns_connectionr|r�r{r�rrr5r5r6r�s
zConnectionPool.releasecCs|j|jkSrD)r�rrr5r5r6r�szConnectionPool.owns_connectionT��inuse_connectionsc	�s�|��|j4IdH�l|r,t|j|j�}n|j}tjdd�|D�ddi�IdH}tdd�|D�d�}|rn|�Wd�IdHq�1IdHs�0YdS)z�
        Disconnects connections in the pool

        If ``inuse_connections`` is True, disconnect connections that are
        current in use, potentially by other tasks. Otherwise only disconnect
        connections that are idle in the pool.
        Ncss|]}|��VqdSrDr �r�rqr5r5r6r�)r.z,ConnectionPool.disconnect.<locals>.<genexpr>�return_exceptionsTcss|]}t|t�r|VqdSrD�rIr/�r��rr5r5r6r�,r.)r�r�rr|r~r��gather�next)rEr�Zconnections�resprr5r5r6r�s���zConnectionPool.disconnect)T)r0r1r2rV�classmethodrrpr<ruror	rMrFr�rzr�r�r�r�r�r�rOr�r5r5r5r6rq1s$
-��/!	cs|eZdZdZddeejfeeee	ee	ej
d��fdd�
Zdd�Zd	d
�Z
dd�Zed
�dd�Zded�dd�Z�ZS)�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�)r_rurb�queue_classcs,||_||_|t�jf||d�|��dS)Nrv)r�rur�rF)rEr_rurbr�rwr�r5r6rFSs	��zBlockingConnectionPool.__init__cCsN|�|j�|_z|j�d�Wqtjy6Yq:Yq0qg|_t��|_	dSrD)
r�r_�pool�
put_nowaitr��	QueueFull�_connectionsr�r�r�rcr5r5r6rzeszBlockingConnectionPool.resetcCs"|jfi|j��}|j�|�|S)zMake a fresh connection.)rbrwr�r�rrr5r5r6r�}sz&BlockingConnectionPool.make_connectionc	�s:|��d}zTt�|j�4IdH�&|j��IdH}Wd�IdHq^1IdHsT0YWn"tjtjfy�td��Yn0|dur�|�	�}zz|�
�IdHz|��IdHr�td�d�WnJt�y
|��IdH|�
�IdH|��IdH�rtd�d�Yn0Wn&t
�y4|�|�IdH�Yn0|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.
        NzNo connection available.r�r�)r�r�rur�rkr�Z
QueueEmptyr%rr�r
rwr�r/r�r�r5r5r6r��s.
>z%BlockingConnectionPool.get_connectionrpc�sZ|��|�|�s0|��IdH|j�d�dSz|j�|�WntjyTYn0dS)z)Releases the connection back to the pool.N)r�r�r�r�r�r�r�rrr5r5r6r��s
zBlockingConnectionPool.releaseTr�c	�s�|��|j4IdH�Ttjdd�|jD�ddi�IdH}tdd�|D�d�}|rV|�Wd�IdHq�1IdHsv0YdS)z(Disconnects all connections in the pool.Ncss|]}|��VqdSrDr r�r5r5r6r��r.z4BlockingConnectionPool.disconnect.<locals>.<genexpr>r�Tcss|]}t|t�r|VqdSrDr�r�r5r5r6r��r.)r�r�r�r�r�r�)rEr�r�rr5r5r6r��s��z!BlockingConnectionPool.disconnect)T)r0r1r2rVror�Z	LifoQueuerMr	rZQueuerFrzr�r�r�rOr�r�r5r5r�r6r�1s #��5r�)ur�r��enumr�r	r�r�r�rr%rxr�	itertoolsr�typesr�typingrrrrrr	r
rrr
r�urllib.parserrrrr�Zredis.asyncio.retryrZ
redis.backoffrZredis.compatrrZredis.exceptionsrrrrrrrrrr r!r"r#r$r%Zredis.typingr&r'Zredis.utilsr(r)r��BlockingIOErrorZEWOULDBLOCKZSSLWantReadErrorZSSLWantWriteErrorZSSLErrorr�r9r�r�r;r=r�ZSYM_LFr:r��Enumr/r4r�r{r}r~r|r7r@r<r=rrXr�r�r�r>r�r�r�rErorFrUrWr]rOr^rMrNr`r3rarorprqr�r5r5r5r6�<module>s�
4
D��)$B
Tms.5Q��
4