o
    `f3                     @   s,  d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	m
Z
 e jjdkr1e jjdkr1d dlmZ nd dlmZ dd	lmZmZmZmZmZmZmZmZmZmZmZmZ dd
lmZ ddlmZ ddl m!Z!m"Z" dZ#dZ$dZ%dZ&eedZ'G dd deZ(G dd de(Z)G dd de(Z*G dd de*Z+dS )    N)ABC)IncompleteReadErrorStreamReaderTimeoutError)ListOptionalUnion      )timeout   )AuthenticationError$AuthenticationWrongNumberOfArgsErrorBusyLoadingErrorConnectionErrorExecAbortErrorModuleErrorNoPermissionErrorNoScriptErrorOutOfMemoryErrorReadOnlyError
RedisErrorResponseError)
EncodableT   )Encoder)SERVER_CLOSED_CONNECTION_ERRORSocketBufferz:Error loading the extension. Please check the server logs.z5Error unloading module: no such module with that namez/Error unloading module: operation not possible.z[Error unloading module: the module exports one or more module-side data types, can't unload)zxAUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?z(Client sent AUTH, but no password is setc                   @   sd   e Zd Zdedededeeeeee	ee
eieeeeeeeeed	Zedd Zdd	 Zd
d ZdS )
BaseParserzmax number of clients reachedzinvalid passwordz,wrong number of arguments for 'auth' commandz,wrong number of arguments for 'AUTH' command)	ERROOM	WRONGPASS	EXECABORTLOADINGNOSCRIPTREADONLYNOAUTHNOPERMc                 C   s\   | dd }|| jv r*|t|d d }| j| }t|tr&||t}||S t|S )zParse an error response r   r   N)splitEXCEPTION_CLASSESlen
isinstancedictgetr   )clsresponse
error_codeexception_class r3   L/home/ubuntu/webapp/venv/lib/python3.10/site-packages/redis/_parsers/base.pyparse_errorM   s   


zBaseParser.parse_errorc                 C      t  NNotImplementedErrorselfr3   r3   r4   on_disconnectY      zBaseParser.on_disconnectc                 C   r6   r7   r8   r;   
connectionr3   r3   r4   
on_connect\   r=   zBaseParser.on_connectN)__name__
__module____qualname__r   r   r   MODULE_LOAD_ERRORr   MODULE_EXPORTS_DATA_TYPES_ERRORNO_SUCH_MODULE_ERROR MODULE_UNLOAD_NOT_POSSIBLE_ERRORNO_AUTH_SET_ERRORr   r   r   r   r   r   r*   classmethodr5   r<   r@   r3   r3   r3   r4   r   0   s6    
r   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )	_RESPBasez&Base class for sync-based resp parsingc                 C   s   || _ d | _d | _d | _d S r7   )socket_read_sizeencoder_sock_bufferr;   rK   r3   r3   r4   __init__c   s   
z_RESPBase.__init__c                 C   s$   z|    W d S  ty   Y d S w r7   )r<   	Exceptionr:   r3   r3   r4   __del__i   s
   z_RESPBase.__del__c                 C   s(   |j | _ t| j | j|j| _|j| _dS )zCalled when the socket connectsN)rM   r   rK   socket_timeoutrN   rL   r>   r3   r3   r4   r@   o   s
   z_RESPBase.on_connectc                 C   s*   d| _ | jdur| j  d| _d| _dS )z"Called when the socket disconnectsN)rM   rN   closerL   r:   r3   r3   r4   r<   w   s
   


z_RESPBase.on_disconnectc                 C   s   | j o| j |S r7   )rN   can_read)r;   r   r3   r3   r4   rU      s   z_RESPBase.can_readN)	rA   rB   rC   __doc__rP   rR   r@   r<   rU   r3   r3   r3   r4   rJ   `   s    rJ   c                
   @   sV   e Zd ZdZdZdefddZdefddZ		dd
ede	e
edee
 f fddZdS )AsyncBaseParserz5Base parsing class for the python-backed async parser_stream
_read_sizerK   c                 C   s   d | _ || _d S r7   rX   rO   r3   r3   r4   rP      s   
zAsyncBaseParser.__init__returnc                       t  r7   r8   r:   r3   r3   r4   can_read_destructive   s   z$AsyncBaseParser.can_read_destructiveFdisable_decodingNc                    r\   r7   r8   )r;   r^   r3   r3   r4   read_response   s   zAsyncBaseParser.read_response)F)rA   rB   rC   rV   	__slots__intrP   boolr]   r   r   r   r   r_   r3   r3   r3   r4   rW      s    rW   c                       sv   e Zd ZdZejd Zdef fddZdd Zdd	 Z	d
d Z
defddZdedefddZdefddZ  ZS )_AsyncRESPBasez!Base class for async resp parsing)rL   rN   _pos_chunksrK   c                    s(   t  | d | _d| _g | _d| _d S )N    r   )superrP   rL   rN   re   rd   rO   	__class__r3   r4   rP      s
   
z_AsyncRESPBase.__init__c                 C   s   d| _ | j  d S )Nrf   )rN   re   clearr:   r3   r3   r4   _clear   s   z_AsyncRESPBase._clearc                 C   s4   |j | _| jdu rtd|j| _|   d| _dS )zCalled when the stream connectsNBuffer is closed.T)_readerrY   r   rL   rk   
_connectedr>   r3   r3   r4   r@      s   

z_AsyncRESPBase.on_connectc                 C   s
   d| _ dS )z"Called when the stream disconnectsFN)rn   r:   r3   r3   r4   r<      s   
z_AsyncRESPBase.on_disconnectr[   c              	      s~   | j std| jrdS z'td4 I d H  | j W  d   I d H  W S 1 I d H s-w   Y  W d S  ty>   Y dS w )Nrl   Tr   F)rn   r   rN   async_timeoutrY   at_eofr   r:   r3   r3   r4   r]      s   4z#_AsyncRESPBase.can_read_destructivelengthc              
      s   |d }| j | }t| j|kr| j| j |d  }n7| j| j d }z| j|t| I dH }W n tyD } ztt|d}~ww || dd }| j	| |  j |7  _ |S )z
        Read `length` bytes of data.  These are assumed to be followed
        by a '
' terminator which is subsequently discarded.
        r   N)
rd   r+   rN   rY   readexactlyr   r   r   re   append)r;   rq   wantendresulttaildataerrorr3   r3   r4   _read   s    

z_AsyncRESPBase._readc                    s   | j d| j}|dkr| j | j| }n'| j | jd }| j I dH }|ds/tt|| dd }| j	| |  jt
|d 7  _|S )zq
        read an unknown number of bytes up to the next '
'
        line separator, which is discarded.
        s   
r   Nrr   r   )rN   findrd   rY   readlineendswithr   r   re   rt   r+   )r;   foundrw   rx   ry   r3   r3   r4   	_readline   s   
z_AsyncRESPBase._readline)rA   rB   rC   rV   rW   r`   ra   rP   rk   r@   r<   rb   r]   bytesr{   r   __classcell__r3   r3   rh   r4   rc      s    
	rc   ),sysabcr   asyncior   r   r   typingr   r   r   version_infomajorminorr   ro   
exceptionsr   r   r   r   r   r   r   r   r   r   r   r   r   encodersr   socketr   r   rD   rF   rG   rE   rH   r   rJ   rW   rc   r3   r3   r3   r4   <module>   s.    8

0#