
     hw                     <    d dl mZmZ d dlmZ  G d d          ZdS )    )
RedisErrorResponseErrorstr_if_bytesc                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	CommandsParsera  
    Parses Redis commands to get command keys.
    COMMAND output is used to determine key locations.
    Commands that do not have a predefined key location are flagged with
    'movablekeys', and these commands' keys are determined by the command
    'COMMAND GETKEYS'.
    c                 >    i | _         |                     |           d S N)commands
initialize)selfredis_connections     Q/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/redis/commands/parser.py__init__zCommandsParser.__init__   s"    ()))))    c                    |                     d          }g }|D ]0}t          d |D                       r|                    |           1|D ],}|                    |          ||                                <   -|| _        d S )NCOMMANDc              3   >   K   | ]}|                                 V  d S r
   )isupper).0xs     r   	<genexpr>z,CommandsParser.initialize.<locals>.<genexpr>   s*      ,,1199;;,,,,,,r   )execute_commandanyappendpoplowerr   )r   rr   uppercase_commandscmds        r   r   zCommandsParser.initialize   s    $$Y// 	/ 	/C,,,,,,, /"))#...% 	6 	6C$,LL$5$5HSYY[[!! r   c                 B   i }t          |d                   }||d<   t          |d                   |d<   d |d         D             |d<   |d         |d	<   |d
         |d<   |d         |d<   t          |          dk    r!|d         |d<   |d         |d<   |d         |d<   |S )Nr   name   arityc                 ,    g | ]}t          |          S  r   )r   flags     r   
<listcomp>z3CommandsParser.parse_subcommand.<locals>.<listcomp>!   s     GGGD\$//GGGr      flags   first_key_pos   last_key_pos   
step_count   tips   key_specifications	   subcommands)r   intlen)r   commandoptionscmd_dictcmd_names        r   parse_subcommandzCommandsParser.parse_subcommand   s    
++#
OOGGGAJGGG$+AJ!#*1: !(w<<!&qzHV-4QZH)*&-ajH]#r   c                    t                    dk     rdS d                                         }|| j        vr|                                }|d         }|| j        v r|t	          dd                   z   nB|                     |           || j        vr$t          |                                 d          | j                            |          }d|d         v r | j	        |gR  }nd|d         v s|d	         dk    r | j
         }n|d
         dk    r||d         dk    rp|d         dk    rdd}d|v rZ| dd                                          }|d         D ]2}	t          |	d                   |k    r|                     |	          }d}3|sdS |d         }
|
dk     rt                    t          |
          z
  }
t	          t          |d         |
dz   |d
                             }fd|D             }|S )ap  
        Get the keys from the passed command.

        NOTE: Due to a bug in redis<7.0, this function does not work properly
        for EVAL or EVALSHA when the `numkeys` arg is 0.
         - issue: https://github.com/redis/redis/issues/9493
         - fix: https://github.com/redis/redis/pull/9733

        So, don't use this function with EVAL or EVALSHA.
        r)   Nr   r#   z( command doesn't exist in Redis commandsmovablekeysr*   pubsubr"   r0   r,   r.   Fr6   |Tc                      g | ]
}|         S r&   r&   )r   posargss     r   r(   z+CommandsParser.get_keys.<locals>.<listcomp>k   s    222#DI222r   )r8   r   r   splitlistr   r   upperget_get_moveable_keys_get_pubsub_keysr   r=   absrange)r   
redis_connrD   r<   cmd_name_splitr9   keys	is_subcmdsubcmd_namesubcmdr.   keys_poss     `         r   get_keyszCommandsParser.get_keys.   sb    t99q==47==??4=(( &^^--N%a(H4=((%T!""X6 
+++4=00$#>>++UUU   -##H--GG,,,*4*:====DD)))WV_-H-H(4($/DD %**O,11N+q00!	 G++%-"A"AQ"A"AK")-"8 - -'q	22kAA&*&;&;F&C&CG(,I !  4">2La"4yy3|+<+<<go.q0@',BWXX H 3222222Dr   c                    g }|d         }||                                 z   }|t          |dd                   z   }	  |j        dg|R  }n6# t          $ r)}|                                }d|v sd|v rY d}~dS |d}~ww xY w|S )aA  
        NOTE: Due to a bug in redis<7.0, this function does not work properly
        for EVAL or EVALSHA when the `numkeys` arg is 0.
         - issue: https://github.com/redis/redis/issues/9493
         - fix: https://github.com/redis/redis/pull/9733

        So, don't use this function with EVAL or EVALSHA.
        r   r#   NzCOMMAND GETKEYSzInvalid argumentsz The command has no key arguments)rE   rF   r   r   __str__)r   rM   rD   piecesr<   rO   emessages           r   rI   z!CommandsParser._get_moveable_keyso   s     7 (..***$tABBx..(
	-:-.?I&IIIDD 	 	 	iikkG#w..5@@ttttt	 s   A 
A?A:8A::A?c                 4   t          |          dk     rdS d |D             }|d                                         }d}|dk    r)|d                                         }|dv r
|dd         }n+|dv rt          |dd                   }n|d	k    r	|d         g}|S )
z
        Get the keys from pubsub command.
        Although PubSub commands have predetermined key locations, they are not
        supported in the 'COMMAND's output, so the key positions are hardcoded
        in this method
        r)   Nc                 ,    g | ]}t          |          S r&   r   )r   args     r   r(   z3CommandsParser._get_pubsub_keys.<locals>.<listcomp>   s     222cS!!222r   r   PUBSUBr#   )CHANNELSNUMSUB)	SUBSCRIBE
PSUBSCRIBEUNSUBSCRIBEPUNSUBSCRIBEPUBLISH)r8   rG   rF   )r   rD   r9   rO   pubsub_types        r   rJ   zCommandsParser._get_pubsub_keys   s     t99q==422T222q'--//h q'--//K444ABBxRRR QRR>>DD	!! G9Dr   N)
__name__
__module____qualname____doc__r   r   r=   rT   rI   rJ   r&   r   r   r   r      sy         * * *! ! !  $? ? ?B  8    r   r   N)redis.exceptionsr   r   redis.utilsr   r   r&   r   r   <module>rl      sk    6 6 6 6 6 6 6 6 $ $ $ $ $ $a a a a a a a a a ar   