
    AHjgR                        U d dl Z d dlmZmZ d dl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mZmZ d dlmZ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l0m1Z1m2Z2 dZ3dZ4dZ5dZ6eedZ7de#iZ8 e jr                  e:      Z; G d de      Z< G d de<      Z= G d de<      Z> G d d      Z?dZ@dZAdZBdZCdZDd ZEd!ZFd"ZGeBeCeDeEeFfZHeBee?j                  feCee?j                  feDee?j                  feEee?j                  feAee?j                  feFee?j                  feGee?j                  fiZNeOePeQeRe   e	f   f   eSd#<    G d$ d%e      ZT G d& d'e      ZU G d( d)e>      ZVy)*    N)ABCabstractmethod)IncompleteReadErrorStreamReader)	AwaitableCallableListOptionalProtocolUnion)MaintenanceNotificationNodeFailedOverNotificationNodeFailingOverNotificationNodeMigratedNotificationNodeMigratingNotificationNodeMovingNotificationOSSNodeMigratedNotificationOSSNodeMigratingNotification)deprecated_functionsafe_str   )AskErrorAuthenticationError$AuthenticationWrongNumberOfArgsErrorBusyLoadingErrorClusterCrossSlotErrorClusterDownErrorConnectionErrorExecAbortErrorExternalAuthProviderErrorMasterDownErrorModuleError
MovedErrorNoPermissionErrorNoScriptErrorOutOfMemoryErrorReadOnlyError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                       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ed        Ze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 rP|t        |      dz   d }| j                  |   }t        |t              r|j                  |t              } |||      S t        |      S )zParse an error response r   r+   N)status_code)splitEXCEPTION_CLASSESlen
isinstancedictgetr(   )clsresponse
error_codeexception_classs       K/root/tools/cai/cai_env/lib/python3.12/site-packages/redis/_parsers/base.pyparse_errorzBaseParser.parse_errorg   s     ^^C(+
...J! 3 56H!33J?O/40"1"5"5h"N"8DDX&&    c                      y N selfs    rM   on_disconnectzBaseParser.on_disconnects       rO   c                      y rQ   rR   rT   
connections     rM   
on_connectzBaseParser.on_connectw   rV   rO   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!   rD   classmethodrN   r   rU   rZ   rR   rO   rM   r0   r0   C   s     ,_ 3!"F!"F{+[ +,k
  
  +!
$  (##!!%#!'*%A!F 	' 	'    rO   r0   c                   :    e Zd ZdZd Zd Zd Zd Zd
dede	fdZ
y	)	_RESPBasez&Base class for sync-based resp parsingc                 <    || _         d | _        d | _        d | _        y rQ   )socket_read_sizeencoder_sock_bufferrT   rh   s     rM   __init__z_RESPBase.__init__   s     0
rO   c                 D    	 | j                          y # t        $ r Y y w xY wrQ   )rU   	ExceptionrS   s    rM   __del__z_RESPBase.__del__   s%    	  		s    	c                     |j                   | _         t        | j                   | j                  |j                        | _        |j
                  | _        y)zCalled when the socket connectsN)rj   r.   rh   socket_timeoutrk   ri   rX   s     rM   rZ   z_RESPBase.on_connect   sA    %%
#JJ--z/H/H
 "))rO   c                 z    d| _         | j                  !| j                  j                          d| _        d| _        y)z"Called when the socket disconnectsN)rj   rk   closeri   rS   s    rM   rU   z_RESPBase.on_disconnect   s1    
<<#LL DLrO   timeoutreturnc                 R    | j                   y| j                   j                  |      S )NF)rk   can_read)rT   ru   s     rM   rx   z_RESPBase.can_read   s&     <<||$$W--rO   N)r   )r[   r\   r]   __doc__rm   rp   rZ   rU   floatboolrx   rR   rO   rM   rf   rf   |   s,    0*. .d .rO   rf   c            
           e Zd ZdZdZdefdZ eddd      ed	e	fd
              Z
e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_sizerh   c                      d | _         || _        y rQ   r~   rl   s     rM   rm   zAsyncBaseParser.__init__   s    /3*rO   8.0.0Use can_read() insteadcan_read_destructiveversionreasonnamerv   c                    K   y wrQ   rR   rS   s    rM   r   z$AsyncBaseParser.can_read_destructive   s     
 	   c                    K   y wrQ   rR   rS   s    rM   rx   zAsyncBaseParser.can_read   s      	r   disable_decodingNc                    K   t               wrQ   NotImplementedError)rT   r   s     rM   read_responsezAsyncBaseParser.read_response   s      "##   )F)r[   r\   r]   ry   	__slots__intrm   r   r   r{   r   rx   r   r*   r(   r	   r   rR   rO   rM   r}   r}      s    ?'I+ +  8?U D      (-$ $$	z=$Z0@@	A$rO   r}   c                   `    e Zd ZdZed        Zed        Zed        Zed        Zed        Z	y)MaintenanceNotificationsParserzEProtocol defining maintenance push notification parsing functionalityc                 @    | d   }t        | d         }t        ||      S Nr+   r   )r   r   )rJ   idslotss      rM   parse_oss_maintenance_start_msgz>MaintenanceNotificationsParser.parse_oss_maintenance_start_msg   s(     a[!%+B66rO   c                     | d   }| d   }i }|D ]F  \  }}}t        |      }t        |      }t        |      }	||vrg ||<   ||   j                  ||	i       H t        ||      S r   )r   appendr   )
rJ   r   nodes_to_slots_mapping_datanodes_to_slots_mappingsrc_node	dest_noder   src_node_strdest_node_str	slots_strs
             rM   #parse_oss_maintenance_completed_msgzBMaintenanceNotificationsParser.parse_oss_maintenance_completed_msg   s     a[&.qk# "$*E 	T&Hi#H-L$Y/M I#9979&|4"<077	8RS	T +2/EFFrO   c                 (    | d   }| d   } |||      S r   rR   )rJ   notification_typer   ttls       rM   parse_maintenance_start_msgz:MaintenanceNotificationsParser.parse_maintenance_start_msg   s#     a[qk S))rO   c                     | d   } ||      S )Nr+   rR   )rJ   r   r   s      rM   parse_maintenance_completed_msgz>MaintenanceNotificationsParser.parse_maintenance_completed_msg   s     a[ $$rO   c                     | d   }| d   }| d   d\  }}n1t        | d         }|j                  d      \  }}|t        |      nd }t        ||||      S )Nr+   r      )NN:)r   rC   r   r   )rJ   r   r   hostportvalues         rM   parse_moving_msgz/MaintenanceNotificationsParser.parse_moving_msg   sj     a[qkA;#JD$Xa[)ES)JD$ $ 03t9dD%b$c::rO   N)
r[   r\   r]   ry   staticmethodr   r   r   r   r   rR   rO   rM   r   r      si    O7 7 G G2 * * % % ; ;rO   r   
invalidateMOVING	MIGRATINGMIGRATEDFAILING_OVERFAILED_OVER
SMIGRATING	SMIGRATED-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
ee   ed<   d Z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_func#oss_cluster_maint_push_handler_funcc                     t               )zHandle pubsub push responsesr   rT   rJ   s     rM   handle_pubsub_push_responsez3PushNotificationsParser.handle_pubsub_push_responseB  s    !##rO   c                 x   |d   }t        |t              r|j                         }|t        gt        t
        t        vr| j                  |      S 	 |t        k(  r| j                  r| j                  |      S |t
        k(  r1| j                  r%t        |   d   } ||      }| j                  |      S |t        v rR| j                  rFt        |   d   }|t        k(  r	 ||      }nt        |   d   } |||      }|| j                  |      S |t        k(  rh| j                  s| j                  rPt        |   d   } ||      }|:| j                  r| j                  |       | j                  r| j                  |       y # t        $ r0}t        j!                  dj#                  |||             Y d }~y d }~ww xY w)Nr   r+   "Error handling {} message ({}): {}rF   bytesdecode_INVALIDATION_MESSAGE_MAINTENANCE_MESSAGES_MOVING_MESSAGE_SMIGRATED_MESSAGEr   r   r   r   r   _SMIGRATING_MESSAGEr   ro   loggererrorformatrT   rJ   kwargsmsg_typeparser_functionnotificationr   es           rM   handle_push_responsez,PushNotificationsParser.handle_push_responseF  s   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## 22#28#<L(U ))% $38=N#OL+==lKK--8855"O##  /x8+99::<H??@@N   	LL4;;HhPQR  	s,   %F  :9F  4AF  A1F   	F9	&F44F9c                     || _         y rQ   r   rT   r   s     rM   set_pubsub_push_handlerz/PushNotificationsParser.set_pubsub_push_handler  s
    (@%rO   c                     || _         y rQ   r   rT   r   s     rM   set_invalidation_push_handlerz5PushNotificationsParser.set_invalidation_push_handler  s
    .L+rO   c                     || _         y rQ   r   rT   r   s     rM   set_node_moving_push_handlerz4PushNotificationsParser.set_node_moving_push_handler  
    -J*rO   c                     || _         y rQ   r   rT   r   s     rM   set_maintenance_push_handlerz4PushNotificationsParser.set_maintenance_push_handler  r   rO   c                     || _         y rQ   r   rT   r   s     rM   "set_oss_cluster_maint_push_handlerz:PushNotificationsParser.set_oss_cluster_maint_push_handler  
    3V0rO   )r[   r\   r]   ry   r   __annotations__r   r
   r   r   r   r   r   r   r   r   r   r   rR   rO   rM   r   r   9  st    @&&9="HX$6=8<!8H#5<8<!8H#5<>B'();B$=~AMKKWrO   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eede	d   f      ed<   d	 Zd
 Zd Zd Zd Zd Zd Zy)AsyncPushNotificationsParserz<Protocol defining async RESP3-specific parsing functionalityr   Nr   .r   r   r   c                    K   t               w)z+Handle pubsub push responses asynchronouslyr   r   s     rM   r   z8AsyncPushNotificationsParser.handle_pubsub_push_response  s     !##r   c                   K   |d   }t        |t              r|j                         }|t        gt        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 rZ| j                  rNt        |   d   }|t        k(  r	 ||      }nt        |   d   } |||      }|| j                  |       d{   S |t        k(  r;| j                  r/t        |   d   } ||      }|| j                  |       d{   S y7 =7 7 7 Q7 # 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           rM   r   z1AsyncPushNotificationsParser.handle_push_response  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## 22#28#<L(U ))% $38=N#OL+!%!C!CL!QQQ..<<"O##  /x8+!%!I!I,!WWW a A K N R X 	LL4;;HhPQR  	s   AGFG)F! FF! GAF! )F*F! -G.AF! FF! G?F! FF! GF! F! F! F! !	G*&GGGGc                     || _         y)z$Set the pubsub push handler functionNr   r   s     rM   r   z4AsyncPushNotificationsParser.set_pubsub_push_handler  s
    (@%rO   c                     || _         y)z*Set the invalidation push handler functionNr   r   s     rM   r   z:AsyncPushNotificationsParser.set_invalidation_push_handler  s
    .L+rO   c                     || _         y rQ   r   r   s     rM   r   z9AsyncPushNotificationsParser.set_node_moving_push_handler  r   rO   c                     || _         y rQ   r   r   s     rM   r   z9AsyncPushNotificationsParser.set_maintenance_push_handler  r   rO   c                     || _         y rQ   r   r   s     rM   r   z?AsyncPushNotificationsParser.set_oss_cluster_maint_push_handler  r   rO   )r[   r\   r]   ry   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   rR   rO   rM   r   r     s    F&&9="HX$6=NR!8HS)D/5I,J#KRNR!8HS)D/5I,J#KRTX'(3	$;O2P)QX$=~AMKKWrO   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
 edd	d
      def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)ri   rk   _pos_chunksrh   c                 \    t         |   |       d | _        d| _        g | _        d| _        y )NrO   r   )superrm   ri   rk   r   r   )rT   rh   	__class__s     rM   rm   z_AsyncRESPBase.__init__  s-    )**.	rO   c                 F    d| _         | j                  j                          y )NrO   )rk   r   clearrS   s    rM   _clearz_AsyncRESPBase._clear  s    rO   c                     |j                   | _        | j                  t        t              |j                  | _        | j                          d| _        y)zCalled when the stream connectsNT)_readerr   r   r-   ri   r  
_connectedrX   s     rM   rZ   z_AsyncRESPBase.on_connect  sB    !))<<!"@AA!))rO   c                     d| _         y)z"Called when the stream disconnectsFN)r  rS   s    rM   rU   z_AsyncRESPBase.on_disconnect  s	    rO   r   r   r   r   rv   c                 >   K   | j                          d {   S 7 wrQ   )rx   rS   s    rM   r   z#_AsyncRESPBase.can_read_destructive  s      ]]_$$$s   c                    K   | j                   st        d      | j                  ryt        | j                  j                        xs | j                  j                         S w)NzBuffer is closed.T)r  OSErrorrk   r{   r   at_eofrS   s    rM   rx   z_AsyncRESPBase.can_read  sN      -..<< DLL(()BT\\-@-@-BBs   A A"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   rE   rk   r   readexactlyr   r   r-   r   r   )rT   r  wantendresulttaildatar   s           rM   _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   )rk   findr   r   readlineendswithr   r-   r   r   rE   )rT   foundr  r  r  s        rM   	_readlinez_AsyncRESPBase._readline8  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]   ry   r}   r   r   rm   r  rZ   rU   r   r{   r   rx   r   r  r  __classcell__)r   s   @rM   r   r     s    +)),UUI   '#
%D %
%
C 
C# % ( rO   r   )Wloggingabcr   r   asyncior   r   typingr   r   r	   r
   r   r   redis.maint_notificationsr   r   r   r   r   r   r   r   redis.utilsr   r   
exceptionsr   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   rf   r}   r   r   r   _MIGRATING_MESSAGE_MIGRATED_MESSAGE_FAILING_OVER_MESSAGE_FAILED_OVER_MESSAGEr   r   r   r   r   r   r   r   r   rG   strtupletyper   r   r   r   rR   rO   rM   <module>r.     s    # 5 G G	 	 	 6    (    @P N #T     ':0C   !:   
		8	$6 6r$.
 $.N$j $8D; D;N %    & $ "      !&BB  &FF #&BB "&FF &77 $&FF #&JJ3 .tt+,h6	770 DYWh YWx[W8 [W|U_ UrO   