
    h?                     
   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        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-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 j;        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eAjI        feEeeAjJ        feFeeAjI        feGeeAjJ        feCeeAjK        fiZLeMeNeOePe         e
f         f         eQd#<    G d$ d%e          ZR G d& d'e          ZS G d( d)e@          ZTdS )*    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                   |    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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NOPERMASKTRYAGAINMOVEDCLUSTERDOWN	CROSSSLOT
MASTERDOWNc                 ,   |                     d          d         }|| j        v rb|t          |          dz   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_classs       S/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/redis/_parsers/base.pyparse_errorzBaseParser.parse_errork   s     ^^C((+
...J! 3 5 56H!3J?O/400 O"1"5"5h"N"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                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )	_RESPBasez&Base class for sync-based resp parsingc                 >    || _         d | _        d | _        d | _        d S rP   )socket_read_sizeencoder_sock_bufferrT   ri   s     rL   __init__z_RESPBase.__init__   s#     0
rN   c                 R    	 |                                   d S # t          $ r Y d S w xY wrP   )rU   	ExceptionrS   s    rL   __del__z_RESPBase.__del__   sA    	      	 	 	DD	s    
&&c                     |j         | _         t          | j         | j        |j                  | _        |j        | _        dS )zCalled when the socket connectsN)rk   r.   ri   socket_timeoutrl   rj   rX   s     rL   rZ   z_RESPBase.on_connect   s<    %
#J-z/H
 
 ")rN   c                 p    d| _         | j         | j                                         d| _        d| _        dS )z"Called when the socket disconnectsN)rk   rl   closerj   rS   s    rL   rU   z_RESPBase.on_disconnect   s7    
<#L   DLrN   c                 D    | j         o| 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   ~   se        00    * * *  ? ? ? ? ?rN   rg   c            
       b    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d	S )AsyncBaseParserz5Base parsing class for the python-backed async parser_stream
_read_sizeri   c                 "    d | _         || _        d S rP   r{   rm   s     rL   rn   zAsyncBaseParser.__init__   s    /3*rN   returnc                 "   K   t                      rP   rQ   rS   s    rL   can_read_destructivez$AsyncBaseParser.can_read_destructive   s      !###rN   Fdisable_decodingNc                 "   K   t                      rP   rQ   )rT   r   s     rL   read_responsezAsyncBaseParser.read_response   s       "###rN   )F)r[   r\   r]   rx   	__slots__intrn   boolr   r   r*   r(   r	   r   re   rN   rL   rz   rz      s        ??'I+ + + + +$D $ $ $ $ (-$ $ $$	z=$Z0@@	A$ $ $ $ $ $rN   rz   c                   T    e Zd ZdZed             Zed             Zed             ZdS )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\  }}n\| d         }t          |t                    r|                                }|                    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   s     a[qkA;#JD$$QKE%'' 'S))JD$ $ 03t999dD%b$c:::rN   N)r[   r\   r]   rx   staticmethodr   r   r   re   rN   rL   r   r      si        O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dS )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                    |d         }t          |t                    r|                                }|t          gt          t
          R vr|                     |          S 	 |t          k    r| j        r|                     |          S |t
          k    r:| j        r3t          |         d         } ||          }|                     |          S |t          v rP| j
        rIt          |         d         }t          |         d         } |||          }|| 
                    |          S nF# t          $ r9}t                              d                    |||                     Y d }~nd }~ww xY wd S )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  s   A;h&& 	)((H!
"
 
 
 
 

 00:::	1117 2 ::8DDD?**t/Q*"O##  /x8899,GGG000T5W0"O## %R%%!  /x9JKK+==lKKK 	 	 	LL4;;HhPQRR       	
 ts&   !&D' AD' AD' '
E*1/E%%E*c                     || _         d S rP   r   rT   r   s     rL   set_pubsub_push_handlerz/PushNotificationsParser.set_pubsub_push_handler5  s    (@%%%rN   c                     || _         d S rP   r   rT   r   s     rL   set_invalidation_push_handlerz5PushNotificationsParser.set_invalidation_push_handler8  s    .L+++rN   c                     || _         d S rP   r   rT   r   s     rL   set_node_moving_push_handlerz4PushNotificationsParser.set_node_moving_push_handler;      -J***rN   c                     || _         d S 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 A AM M MK K KK K K 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dS )AsyncPushNotificationsParserz<Protocol defining async RESP3-specific parsing functionalityr   Nr   .r   r   c                 "   K   t                      )z+Handle pubsub push responses asynchronouslyrQ   r   s     rL   r   z8AsyncPushNotificationsParser.handle_pubsub_push_responseJ  s      !###rN   c                 d  K   |d         }t          |t                    r|                                }|t          gt          t
          R vr|                     |           d{V S 	 |t          k    r"| j        r|                     |           d{V S t          |t                    r|                                }|t
          k    r@| j        r9t          |         d         } ||          }|                     |           d{V S |t          v rV| j
        rOt          |         d         }t          |         d         } |||          }|| 
                    |           d{V S nF# t          $ r9}t                              d                    |||                     Y d}~nd}~ww xY wdS )z$Handle push responses asynchronouslyr   Nr+   r   r   r   s           rL   r   z1AsyncPushNotificationsParser.handle_push_responseN  s8      A;h&& 	)((H!
"
 
 
 
 

 66x@@@@@@@@@	1117 2 "@@JJJJJJJJJ(E** -#??,,?**t/Q*"O##  /x88!??MMMMMMMMM000T5W0"O## %R%%!  /x9JKK+!%!C!CL!Q!QQQQQQQQ 	 	 	LL4;;HhPQRR       	
 ts&   ),E* A3E* 
AE* *
F-4/F((F-c                     || _         dS )z$Set the pubsub push handler functionNr   r   s     rL   r   z4AsyncPushNotificationsParser.set_pubsub_push_handler  s    (@%%%rN   c                     || _         dS )z*Set the invalidation push handler functionNr   r   s     rL   r   z:AsyncPushNotificationsParser.set_invalidation_push_handler  s    .L+++rN   c                     || _         d S rP   r   r   s     rL   r   z9AsyncPushNotificationsParser.set_node_moving_push_handler  r   rN   c                     || _         d S 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  s         FF&&&&9="HX$6===NR!8HS)D/5I,J#KRRRNR!8HS)D/5I,J#KRRR$ $ $/ / /bA A AM M MK K KK K K K KrN   r   c                   v     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| _        d S )NrN   r   )superrn   rj   rl   r   r   )rT   ri   	__class__s     rL   rn   z_AsyncRESPBase.__init__  s<    )****.			rN   c                 F    d| _         | j                                         d S )NrN   )rl   r   clearrS   s    rL   _clearz_AsyncRESPBase._clear  s#    rN   c                     |j         | _        | j        t          d          |j        | _        |                                  d| _        dS )zCalled when the stream connectsNBuffer is closed.T)_readerr|   r'   rj   r   
_connectedrX   s     rL   rZ   z_AsyncRESPBase.on_connect  sE    !)<0111!)rN   c                     d| _         dS )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dS 	 t          d          4 d {V  | j                                        cd d d           d {V  S # 1 d {V swxY w Y   d S # t          $ r Y dS w xY w)Nr   Tr   F)r   r'   rl   async_timeoutr|   at_eofr   rS   s    rL   r   z#_AsyncRESPBase.can_read_destructive  s2      	20111< 	4	$Q'' - - - - - - - -|**,,- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 	 	 	55	s4   A7 A$A7 $
A..A7 1A.2A7 7
BBlengthc                   K   |dz   }| j         |z   }t          | j                  |k    r| j        | j         |dz
           }n| j        | j         d         }	 | j                            |t          |          z
             d{V }n'# t
          $ r}t          t                    |d}~ww xY w||z   dd         }| j        	                    |           | xj         |z  c_         |S )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i$t|##\$)cAg"56FF<	,DQ!\55dSYY6FGGGGGGGG& Q Q Q%&DEE5PQTk3B3'FL%%%		T		s   0B 
B,B''B,c                   K   | j                             d| j                  }|dk    r| j         | j        |         }n| j         | j        d         }| j                                         d{V }|                    d          st          t                    ||z   dd         }| j        	                    |           | xj        t          |          dz   z  c_        |S )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      
 !!'4955A::\$)e"34FF<	,D..00000000D==)) F%&DEEETk3B3'FL%%%		S[[1_$		rN   )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 C C C C C C C C G G G G G G G G G G G G G G G G                Q3#3#9R#?#?0000000666666                                         *              @ @ @ @ @ @ @ @P N #T     ':0C    !:   
	8	$	$4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$n ?  ?  ?  ?  ?
  ?  ?  ?F$ $ $ $ $j $ $ $$; ; ; ; ; ; ; ;B %    & $  	  !&B  &F #&B "&F &7# .tt+,h6	770   4CK CK CK CK CKh CK CK CKLIK IK IK IK IK8 IK IK IKXL L L L L_ L L L L LrN   