
    1i?                     &   U d dl Z 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mZ d dlmZmZmZmZmZmZ ej,                  j.                  dk\  r ej,                  j0                  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-m.Z. d	dlm/Z/ ddl0m1Z1 ddl2m3Z3m4Z4 dZ5dZ6dZ7dZ8eedZ9de$iZ: e jv                  e<      Z= G d de      Z> G d de>      Z? G d de>      Z@ G d d      ZAdZBdZCdZDd ZEd!ZFd"ZGeDeEeFeGfZHeDeeAj                  feEeeAj                  feFeeAj                  feGeeAj                  feCeeAj                  fiZLeMeNeOePe   e
f   f   eQd#<    G d$ d%e      ZR G d& d'e      ZS G d( d)e@      ZTy)*    N)ABC)IncompleteReadErrorStreamReaderTimeoutError)	AwaitableCallableListOptionalProtocolUnion)MaintenanceNotificationNodeFailedOverNotificationNodeFailingOverNotificationNodeMigratedNotificationNodeMigratingNotificationNodeMovingNotification      )timeout   )AskErrorAuthenticationError$AuthenticationWrongNumberOfArgsErrorBusyLoadingErrorClusterCrossSlotErrorClusterDownErrorConnectionErrorExecAbortErrorExternalAuthProviderError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 setzproblem with LDAP servicec                   t    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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       ]/mnt/e/genesis-system/.venvs/voice-bridge/lib/python3.12/site-packages/redis/_parsers/base.pyparse_errorzBaseParser.parse_errork   s}     ^^C(+
...J! 3 56H!33J?O/40"1"5"5h"N"8,,X&&    c                     t               NNotImplementedErrorselfs    rL   on_disconnectzBaseParser.on_disconnectw       !##rN   c                     t               rP   rQ   rT   
connections     rL   
on_connectzBaseParser.on_connectz   rV   rN   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_ERROREXTERNAL_AUTH_PROVIDER_ERRORr%   r   r   r$   r&   r#   r   r)   r"   r   r   r    rC   classmethodrM   rU   rZ    rN   rL   r0   r0   G   s     ,_ 3!"F!"F{+[ +,k
  
  +!
$  (##!!%#!'*%A!F 	' 	'$$rN   r0   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 rP   )socket_read_sizeencoder_sock_bufferrT   ri   s     rL   __init__z_RESPBase.__init__   s     0
rN   c                 D    	 | j                          y # t        $ r Y y w xY wrP   )rU   	ExceptionrS   s    rL   __del__z_RESPBase.__del__   s%    	  		s    	c                     |j                   | _         t        | j                   | j                  |j                        | _        |j
                  | _        y)zCalled when the socket connectsN)rk   r.   ri   socket_timeoutrl   rj   rX   s     rL   rZ   z_RESPBase.on_connect   sA    %%
#JJ--z/H/H
 "))rN   c                 z    d| _         | j                  !| j                  j                          d| _        d| _        y)z"Called when the socket disconnectsN)rk   rl   closerj   rS   s    rL   rU   z_RESPBase.on_disconnect   s1    
<<#LL DLrN   c                 T    | j                   xr | j                   j                  |      S rP   )rl   can_read)rT   r   s     rL   rw   z_RESPBase.can_read   s     ||> 5 5g >>rN   N)	r[   r\   r]   __doc__rn   rq   rZ   rU   rw   re   rN   rL   rg   rg   ~   s    0*?rN   rg   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_sizeri   c                      d | _         || _        y rP   r{   rm   s     rL   rn   zAsyncBaseParser.__init__   s    /3*rN   returnc                    K   t               wrP   rQ   rS   s    rL   can_read_destructivez$AsyncBaseParser.can_read_destructive   s     !##   disable_decodingNc                    K   t               wrP   rQ   )rT   r   s     rL   read_responsezAsyncBaseParser.read_response   s      "##r   )F)r[   r\   r]   rx   	__slots__intrn   boolr   r   r*   r(   r	   r   re   rN   rL   rz   rz      sO    ?'I+ +$D $ (-$ $$	z=$Z0@@	A$rN   rz   c                   @    e Zd ZdZed        Zed        Zed        Zy)MaintenanceNotificationsParserzEProtocol defining maintenance push notification parsing functionalityc                 (    | d   }| d   } |||      S )Nr+   r   re   )rI   notification_typeidttls       rL   parse_maintenance_start_msgz:MaintenanceNotificationsParser.parse_maintenance_start_msg   s#     a[qk S))rN   c                     | d   } ||      S )Nr+   re   )rI   r   r   s      rL   parse_maintenance_completed_msgz>MaintenanceNotificationsParser.parse_maintenance_completed_msg   s     a[ $$rN   c                     | d   }| d   }| d   d\  }}nH| d   }t        |t              r|j                         }|j                  d      \  }}|t	        |      nd }t        ||||      S )Nr+   r   r   )NN:)rE   bytesdecoderB   r   r   )rI   r   r   hostportvalues         rL   parse_moving_msgz/MaintenanceNotificationsParser.parse_moving_msg   sz     a[qkA;#JD$QKE%'S)JD$ $ 03t9dD%b$c::rN   N)r[   r\   r]   rx   staticmethodr   r   r   re   rN   rL   r   r      s?    O* * % %
 ; ;rN   r   
invalidateMOVING	MIGRATINGMIGRATEDFAILING_OVERFAILED_OVER-MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPINGc                   |    e Zd ZU dZeed<   dZee   ed<   dZee   ed<   dZ	ee   ed<   d Z
d Zd	 Zd
 Zd Zd Zy)PushNotificationsParserz6Protocol defining RESP3-specific parsing functionalitypubsub_push_handler_funcNinvalidation_push_handler_funcnode_moving_push_handler_funcmaintenance_push_handler_funcc                     t               )zHandle pubsub push responsesrQ   rT   rI   s     rL   handle_pubsub_push_responsez3PushNotificationsParser.handle_pubsub_push_response  s    !##rN   c                 f   |d   }t        |t              r|j                         }|t        gt        t
        vr| j                  |      S 	 |t        k(  r| j                  r| j                  |      S |t
        k(  r1| j                  r%t        |   d   } ||      }| j                  |      S |t        v r@| j                  r4t        |   d   }t        |   d   } |||      }|| j                  |      S y # t        $ r0}t        j                  dj                  |||             Y d }~y d }~ww xY w)Nr   r+   "Error handling {} message ({}): {}rE   r   r   _INVALIDATION_MESSAGE_MAINTENANCE_MESSAGES_MOVING_MESSAGEr   r   r   r   r   rp   loggererrorformatrT   rI   kwargsmsg_typeparser_functionnotificationr   es           rL   handle_push_responsez,PushNotificationsParser.handle_push_response  se   A;h&(H!
"
 
 

 00::	1177::8DD?*t/Q/Q"O##  /x899,GG00T5W5W"O## %R%%!  /x9JK+==lKK   	LL4;;HhPQR  	s%   %C7 49C7 .AC7 7	D0 &D++D0c                     || _         y rP   r   rT   r   s     rL   set_pubsub_push_handlerz/PushNotificationsParser.set_pubsub_push_handler5  s
    (@%rN   c                     || _         y rP   r   rT   r   s     rL   set_invalidation_push_handlerz5PushNotificationsParser.set_invalidation_push_handler8  s
    .L+rN   c                     || _         y rP   r   rT   r   s     rL   set_node_moving_push_handlerz4PushNotificationsParser.set_node_moving_push_handler;  
    -J*rN   c                     || _         y rP   r   rT   r   s     rL   set_maintenance_push_handlerz4PushNotificationsParser.set_maintenance_push_handler>  r   rN   )r[   r\   r]   rx   r   __annotations__r   r
   r   r   r   r   r   r   r   r   re   rN   rL   r   r      s^    @&&9="HX$6=8<!8H#5<8<!8H#5<$+ZAMKKrN   r   c                       e Zd ZU dZeed<   dZee   ed<   dZeede	d   f      ed<   dZ
eede	d   f      ed<   d Zd	 Zd
 Zd Zd Zd Zy)AsyncPushNotificationsParserz<Protocol defining async RESP3-specific parsing functionalityr   Nr   .r   r   c                    K   t               w)z+Handle pubsub push responses asynchronouslyrQ   r   s     rL   r   z8AsyncPushNotificationsParser.handle_pubsub_push_responseJ  s     !##r   c                   K   |d   }t        |t              r|j                         }|t        gt        t
        vr| j                  |       d{   S 	 |t        k(  r%| j                  r| j                  |       d{   S t        |t              r|j                         }|t
        k(  r9| j                  r-t        |   d   } ||      }| j                  |       d{   S |t        v rH| j                  r<t        |   d   }t        |   d   } |||      }|| j                  |       d{   S y7 7 7 Y7 # t        $ r0}t        j                  dj                  |||             Y d}~yd}~ww xY ww)z$Handle push responses asynchronouslyr   Nr+   r   r   r   s           rL   r   z1AsyncPushNotificationsParser.handle_push_responseN  s     A;h&(H!
"
 
 

 66x@@@	1177!@@JJJ(E*#??,?*t/Q/Q"O##  /x8!??MMM00T5W5W"O## %R%%!  /x9JK+!%!C!CL!QQQ G A K N R 	LL4;;HhPQR  	s   AE=D9E=)E D;E E=AE #D=$E 'E=(AE 3D?4E 7E=;E =E ?E 	E:
&E50E=5E::E=c                     || _         y)z$Set the pubsub push handler functionNr   r   s     rL   r   z4AsyncPushNotificationsParser.set_pubsub_push_handler  s
    (@%rN   c                     || _         y)z*Set the invalidation push handler functionNr   r   s     rL   r   z:AsyncPushNotificationsParser.set_invalidation_push_handler  s
    .L+rN   c                     || _         y rP   r   r   s     rL   r   z9AsyncPushNotificationsParser.set_node_moving_push_handler  r   rN   c                     || _         y rP   r   r   s     rL   r   z9AsyncPushNotificationsParser.set_maintenance_push_handler  r   rN   )r[   r\   r]   rx   r   r   r   r
   r   r   r   r   r   r   r   r   r   re   rN   rL   r   r   B  sz    F&&9="HX$6=NR!8HS)D/5I,J#KRNR!8HS)D/5I,J#KR$/bAMKKrN   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)rj   rl   _pos_chunksri   c                 \    t         |   |       d | _        d| _        g | _        d| _        y )NrN   r   )superrn   rj   rl   r   r   )rT   ri   	__class__s     rL   rn   z_AsyncRESPBase.__init__  s-    )**.	rN   c                 F    d| _         | j                  j                          y )NrN   )rl   r   clearrS   s    rL   _clearz_AsyncRESPBase._clear  s    rN   c                     |j                   | _        | j                  t        d      |j                  | _        | j	                          d| _        y)zCalled when the stream connectsNBuffer is closed.T)_readerr|   r'   rj   r   
_connectedrX   s     rL   rZ   z_AsyncRESPBase.on_connect  sB    !))<<011!))rN   c                     d| _         y)z"Called when the stream disconnectsFN)r   rS   s    rL   rU   z_AsyncRESPBase.on_disconnect  s	    rN   r   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'   rl   async_timeoutr|   at_eofr   rS   s    rL   r   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   rD   rl   r|   readexactlyr   r   r-   r   append)rT   r   wantendresulttaildatar   s           rL   _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   )rl   findr   r|   readlineendswithr   r-   r   r   rD   )rT   foundr   r   r   s        rL   	_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+)r[   r\   r]   rx   rz   r   r   rn   r   rZ   rU   r   r   r   r   r   __classcell__)r   s   @rL   r   r     s]    +)),UUI  	D 	# % ( rN   r   )Uloggingsysabcr   asyncior   r   r   typingr   r   r	   r
   r   r   redis.maint_notificationsr   r   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)   r*   encodersr,   socketr-   r.   r^   r`   ra   r_   rb   rc   	getLoggerr[   r   r0   rg   rz   r   r   r   _MIGRATING_MESSAGE_MIGRATED_MESSAGE_FAILING_OVER_MESSAGE_FAILED_OVER_MESSAGEr   r   r   r   r   rF   strtupletyper   r   r   r   re   rN   rL   <module>r     s    
  C C G G  Q3#3#3#9#9R#?06     *    @P N #T     ':0C   !:   
		8	$4$ 4$n ?
  ?F$j $$; ;B %    & $  	  !&BB  &FF #&BB "&FF &77# .tt+,h6	770 4CKh CKLIK8 IKXL_ LrN   