
    h&                        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
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      Z0 G d de0      Z1 G d de0      Z2ddgZ3 G d de      Z4 G d de      Z5 G d d e2      Z6y)!    N)ABC)IncompleteReadErrorStreamReaderTimeoutError)CallableListOptionalProtocol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       u/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/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    rD   on_disconnectzBaseParser.on_disconnecte       !##rF   c                     t               rH   rI   rL   
connections     rD   
on_connectzBaseParser.on_connecth   rN   rF   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   r;   classmethodrE   rM   rR    rF   rD   r(   r(   6   s     ,_ 3!"F!"F{+[ +,k
  
"  (##!!%#!'*%? D 	' 	'$$rF   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 rH   )socket_read_sizeencoder_sock_bufferrL   r`   s     rD   __init__z_RESPBase.__init__o   s     0
rF   c                 D    	 | j                          y # t        $ r Y y w xY wrH   )rM   	ExceptionrK   s    rD   __del__z_RESPBase.__del__u   s%    	  		s    	c                     |j                   | _         t        | j                   | j                  |j                        | _        |j
                  | _        y)zCalled when the socket connectsN)rb   r&   r`   socket_timeoutrc   ra   rP   s     rD   rR   z_RESPBase.on_connect{   sA    %%
#JJ--z/H/H
 "))rF   c                 z    d| _         | j                  !| j                  j                          d| _        d| _        y)z"Called when the socket disconnectsN)rb   rc   closera   rK   s    rD   rM   z_RESPBase.on_disconnect   s1    
<<#LL DLrF   c                 T    | j                   xr | j                   j                  |      S rH   )rc   can_read)rL   r   s     rD   rn   z_RESPBase.can_read   s     ||> 5 5g >>rF   N)	rS   rT   rU   __doc__re   rh   rR   rM   rn   r\   rF   rD   r^   r^   l   s    0*?rF   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 rH   rr   rd   s     rD   re   zAsyncBaseParser.__init__   s    /3*rF   returnc                    K   t               wrH   rI   rK   s    rD   can_read_destructivez$AsyncBaseParser.can_read_destructive   s     !##   disable_decodingNc                    K   t               wrH   rI   )rL   rz   s     rD   read_responsezAsyncBaseParser.read_response   s      "##ry   )F)rS   rT   rU   ro   	__slots__intre   boolrx   r   r"   r    r   r|   r\   rF   rD   rq   rq      sO    ?'I+ +$D $ (-$ $$	z=$Z0@@	A$rF   rq   s
   invalidate
invalidatec                   H    e Zd ZU dZeed<   dZee   ed<   d Zd Z	d Z
d Zy)	PushNotificationsParserz6Protocol defining RESP3-specific parsing functionalitypubsub_push_handler_funcNinvalidation_push_handler_funcc                     t               )zHandle pubsub push responsesrI   rL   rA   s     rD   handle_pubsub_push_responsez3PushNotificationsParser.handle_pubsub_push_response   s    !##rF   c                 v    |d   t         vr| j                  |      S | j                  r| j                  |      S y )Nr   _INVALIDATION_MESSAGEr   r   rL   rA   kwargss      rD   handle_push_responsez,PushNotificationsParser.handle_push_response   s?    A;3300::..66x@@ /rF   c                     || _         y rH   r   rL   r   s     rD   set_pubsub_push_handlerz/PushNotificationsParser.set_pubsub_push_handler   s
    (@%rF   c                     || _         y rH   r   rL   r   s     rD   set_invalidation_push_handlerz5PushNotificationsParser.set_invalidation_push_handler   s
    .L+rF   rS   rT   rU   ro   r   __annotations__r   r	   r   r   r   r   r\   rF   rD   r   r      s2    @&&9="HX$6=$AAMrF   r   c                   H    e Zd ZU dZeed<   dZee   ed<   d Zd Z	d Z
d Zy)	AsyncPushNotificationsParserz<Protocol defining async RESP3-specific parsing functionalityr   Nr   c                    K   t               w)z+Handle pubsub push responses asynchronouslyrI   r   s     rD   r   z8AsyncPushNotificationsParser.handle_pubsub_push_response   s     !##ry   c                    K   |d   t         vr| j                  |       d{   S | j                  r| j                  |       d{   S y7 *7 w)z$Handle push responses asynchronouslyr   Nr   r   s      rD   r   z1AsyncPushNotificationsParser.handle_push_response   sS     A;3366x@@@..<<XFFF / AFs!    AA$AAAAc                     || _         y)z$Set the pubsub push handler functionNr   r   s     rD   r   z4AsyncPushNotificationsParser.set_pubsub_push_handler   s
    (@%rF   c                     || _         y)z*Set the invalidation push handler functionNr   r   s     rD   r   z:AsyncPushNotificationsParser.set_invalidation_push_handler   s
    .L+rF   r   r\   rF   rD   r   r      s2    F&&9="HX$6=$GAMrF   r   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)ra   rc   _pos_chunksr`   c                 \    t         |   |       d | _        d| _        g | _        d| _        y )NrF   r   )superre   ra   rc   r   r   )rL   r`   	__class__s     rD   re   z_AsyncRESPBase.__init__   s-    )**.	rF   c                 F    d| _         | j                  j                          y )NrF   )rc   r   clearrK   s    rD   _clearz_AsyncRESPBase._clear   s    rF   c                     |j                   | _        | j                  t        d      |j                  | _        | j	                          d| _        y)zCalled when the stream connectsNBuffer is closed.T)_readerrs   r   ra   r   
_connectedrP   s     rD   rR   z_AsyncRESPBase.on_connect   sB    !))<<011!))rF   c                     d| _         y)z"Called when the stream disconnectsFN)r   rK   s    rD   rM   z_AsyncRESPBase.on_disconnect   s	    rF   rv   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   rc   async_timeoutrs   at_eofr   rK   s    rD   rx   z#_AsyncRESPBase.can_read_destructive   s     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<   rc   rs   readexactlyr   r   r%   r   append)rL   r   wantendresulttaildataerrors           rD   _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   )rc   findr   rs   readlineendswithr   r%   r   r   r<   )rL   foundr   r   r   s        rD   	_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+)rS   rT   rU   ro   rq   r}   r~   re   r   rR   rM   r   rx   bytesr   r   __classcell__)r   s   @rD   r   r      s]    +)),UUI  	D 	# % ( rF   r   )7sysabcr   asyncior   r   r   typingr   r   r	   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&   rV   rX   rY   rW   rZ   r(   r^   rq   r   r   r   r   r\   rF   rD   <module>r      s    
  C C < <Q3#3#3#9#9R#?06    (    @P N #T     ':0C 3$ 3$l ?
  ?F$j $$ '5 Mh M.M8 M4L_ LrF   