
    :Ohy                        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\  r e j                  j                  dk\  rd 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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e      Z. G d de.      Z/ G d de.      Z0 G d de0      Z1y)    N)ABC)IncompleteReadErrorStreamReaderTimeoutError)ListOptionalUnion      )timeout   )AskErrorAuthenticationError$AuthenticationWrongNumberOfArgsErrorBusyLoadingErrorClusterCrossSlotErrorClusterDownErrorConnectionErrorExecAbortErrorMasterDownErrorModuleError
MovedErrorNoPermissionErrorNoScriptErrorOutOfMemoryErrorReadOnlyError
RedisErrorResponseErrorTryAgainError)
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                   p    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eeeeeedZed        Zd Zd Zy	)

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NOPERMASKTRYAGAINMOVEDCLUSTERDOWN	CROSSSLOT
MASTERDOWNc                     |j                  d      d   }|| j                  v rN|t        |      dz   d }| j                  |   }t        |t              r|j                  |t              } ||      S t        |      S )zParse an error response r   r!   N)splitEXCEPTION_CLASSESlen
isinstancedictgetr   )clsresponse
error_codeexception_classs       X/var/www/html/lionshead-backend/venv/lib/python3.12/site-packages/redis/_parsers/base.pyparse_errorzBaseParser.parse_errorY   s}     ^^C(+
...J! 3 56H!33J?O/40"1"5"5h"N"8,,X&&    c                     t               NNotImplementedErrorselfs    rB   on_disconnectzBaseParser.on_disconnecte       !##rD   c                     t               rF   rG   rJ   
connections     rB   
on_connectzBaseParser.on_connecth   rL   rD   N)__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   r   r   r   r   r   r9   classmethodrC   rK   rP    rD   rB   r&   r&   6   s     ,_ 3!"F!"F{+[ +,k
  
"  (##!!%#!'*%? D 	' 	'$$rD   r&   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)	_RESPBasez&Base class for sync-based resp parsingc                 <    || _         d | _        d | _        d | _        y rF   )socket_read_sizeencoder_sock_bufferrJ   r^   s     rB   __init__z_RESPBase.__init__o   s     0
rD   c                 D    	 | j                          y # t        $ r Y y w xY wrF   )rK   	ExceptionrI   s    rB   __del__z_RESPBase.__del__u   s%    	  		s    	c                     |j                   | _         t        | j                   | j                  |j                        | _        |j
                  | _        y)zCalled when the socket connectsN)r`   r$   r^   socket_timeoutra   r_   rN   s     rB   rP   z_RESPBase.on_connect{   sA    %%
#JJ--z/H/H
 "))rD   c                 z    d| _         | j                  !| j                  j                          d| _        d| _        y)z"Called when the socket disconnectsN)r`   ra   closer_   rI   s    rB   rK   z_RESPBase.on_disconnect   s1    
<<#LL DLrD   c                 T    | j                   xr | j                   j                  |      S rF   )ra   can_read)rJ   r   s     rB   rl   z_RESPBase.can_read   s     ||> 5 5g >>rD   N)	rQ   rR   rS   __doc__rc   rf   rP   rK   rl   rZ   rD   rB   r\   r\   l   s    0*?rD   r\   c            
       T    e Zd ZdZdZdefdZdefdZ	 d
dede	e
edee
   f   fd	Zy)AsyncBaseParserz5Base parsing class for the python-backed async parser_stream
_read_sizer^   c                      d | _         || _        y rF   rp   rb   s     rB   rc   zAsyncBaseParser.__init__   s    /3*rD   returnc                    K   t               wrF   rG   rI   s    rB   can_read_destructivez$AsyncBaseParser.can_read_destructive   s     !##   disable_decodingNc                    K   t               wrF   rG   )rJ   rx   s     rB   read_responsezAsyncBaseParser.read_response   s      "##rw   )F)rQ   rR   rS   rm   	__slots__intrc   boolrv   r	   r    r   r   rz   rZ   rD   rB   ro   ro      sO    ?'I+ +$D $ (-$ $$	z=$Z0@@	A$rD   ro   c                        e Zd ZdZej
                  dz   Zdef fdZd Zd Z	d Z
defd	Zd
edefdZdefdZ xZS )_AsyncRESPBasez!Base class for async resp parsing)r_   ra   _pos_chunksr^   c                 \    t         |   |       d | _        d| _        g | _        d| _        y )NrD   r   )superrc   r_   ra   r   r   )rJ   r^   	__class__s     rB   rc   z_AsyncRESPBase.__init__   s-    )**.	rD   c                 F    d| _         | j                  j                          y )NrD   )ra   r   clearrI   s    rB   _clearz_AsyncRESPBase._clear   s    rD   c                     |j                   | _        | j                  t        d      |j                  | _        | j	                          d| _        y)zCalled when the stream connectsNBuffer is closed.T)_readerrq   r   r_   r   
_connectedrN   s     rB   rP   z_AsyncRESPBase.on_connect   sB    !))<<011!))rD   c                     d| _         y)z"Called when the stream disconnectsFN)r   rI   s    rB   rK   z_AsyncRESPBase.on_disconnect   s	    rD   rt   c                 "  K   | j                   st        d      | j                  ry	 t        d      4 d {    | j                  j                         cd d d       d {    S 7 /7 # 1 d {  7  sw Y   y xY w# t        $ r Y yw xY ww)Nr   Tr   F)r   r   ra   async_timeoutrq   at_eofr   rI   s    rB   rv   z#_AsyncRESPBase.can_read_destructive   sm     011<<	$Q''||**, ('''''' 		sy   %BB  A'B  A+B  !A)"B  &B'B  )B  +A=1A42A=9B  <B=B   	B	BBBlengthc                   K   |dz   }| j                   |z   }t        | j                        |k\  r| j                  | j                   |dz
   }nl| j                  | j                   d }	 | j                  j	                  |t        |      z
         d{   }||z   dd }| j                  j                  |       | xj                   |z  c_         |S 7 ># t
        $ r}t        t              |d}~ww xY ww)z
        Read `length` bytes of data.  These are assumed to be followed
        by a '
' terminator which is subsequently discarded.
        r   N)
r   r:   ra   rq   readexactlyr   r   r#   r   append)rJ   r   wantendresulttaildataerrors           rB   _readz_AsyncRESPBase._read   s     
 zii$t||#\\$))cAg6F<<		,DQ!\\55dSY6FGG Tk3B'FLL%		T	 H& Q%&DE5PQs<   A#C2&*C CC :C2C 	C/C**C//C2c                   K   | j                   j                  d| j                        }|dk\  r| j                   | j                  | }n~| j                   | j                  d }| j                  j	                          d{   }|j                  d      st        t              ||z   dd }| j                  j                  |       | xj                  t        |      dz   z  c_        |S 7 jw)zq
        read an unknown number of bytes up to the next '
'
        line separator, which is discarded.
        s   
r   Nr   r   )ra   findr   rq   readlineendswithr   r#   r   r   r:   )rJ   foundr   r   r   s        rB   	_readlinez_AsyncRESPBase._readline   s     
 !!'4995A:\\$))e4F<<		,D..00D==)%&DEETk3B'FLL%		S[1_$	 1s   A<C+>C)?A+C+)rQ   rR   rS   rm   ro   r{   r|   rc   r   rP   rK   r}   rv   bytesr   r   __classcell__)r   s   @rB   r   r      s]    +)),UUI  	D 	# % ( rD   r   )2sysabcr   asyncior   r   r   typingr   r   r	   version_infomajorminorr   r   
exceptionsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    encodersr"   socketr#   r$   rT   rV   rW   rU   rX   r&   r\   ro   r   rZ   rD   rB   <module>r      s    
  C C ( (Q3#3#3#9#9R#?06    (    @P N #T     ':0C 3$ 3$l ?
  ?F$j $$L_ LrD   