
    ph,+                         S SK JrJrJrJrJrJr  S SKJrJ	r	  S SK
Jr  \(       a  S SKJr   " S S5      r " S S\5      r " S	 S
\5      rg)    )TYPE_CHECKINGAnyDictOptionalTupleUnion)
RedisErrorResponseError)str_if_bytes)ClusterNodec                        \ rS rSrS rS rSrg)AbstractCommandsParser
   c                     [        U5      S:  a  gU Vs/ s H  n[        U5      PM     nnUS   R                  5       nSnUS:X  a   US   R                  5       nUS;   a  USS nU$ US;   a  [        USS 5      nU$ US;   a  US   /nU$ s  snf )	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
   Nr   PUBSUB   )CHANNELSNUMSUBSHARDCHANNELSSHARDNUMSUB)	SUBSCRIBE
PSUBSCRIBEUNSUBSCRIBEPUNSUBSCRIBE)PUBLISHSPUBLISH)lenr   upperlist)selfargsargcommandkeyspubsub_types         Q/home/james-whalen/.local/lib/python3.13/site-packages/redis/_parsers/commands.py_get_pubsub_keys'AbstractCommandsParser._get_pubsub_keys   s     t9q=-12TcS!T2q'--/h q'--/KTTABx  RR QR>D
 	 // G9D# 3s   Bc                    0 n[        US   5      nXCS'   [        US   5      US'   US    Vs/ s H  n[        U5      PM     snUS'   US   US'   US	   US
'   US   US'   [        U5      S:  a  US   US'   US   US'   US   US'   U$ s  snf )Nr   namer   arityr   flags   first_key_pos   last_key_pos   
step_count   tips   key_specifications	   subcommands)r   intr   )r!   r$   optionscmd_dictcmd_nameflags         r'   parse_subcommand'AbstractCommandsParser.parse_subcommand(   s    
+#
O<CAJGJD\$/JG$+AJ!#*1: !(w<!&qzHV-4QZH)*&-ajH]# Hs   B	 N)__name__
__module____qualname____firstlineno__r(   r?   __static_attributes__rA       r'   r   r   
   s    :rG   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	CommandsParser8   z
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                 4    0 U l         U R                  U5        g N)commands
initialize)r!   redis_connections     r'   __init__CommandsParser.__init__A   s    ()rG   c                     UR                  5       n/ nU H-  n[        S U 5       5      (       d  M  UR                  U5        M/     U H$  nUR                  U5      X$R	                  5       '   M&     X l        g )Nc              3   @   #    U  H  oR                  5       v   M     g 7frL   )isupper).0xs     r'   	<genexpr>,CommandsParser.initialize.<locals>.<genexpr>I   s     ,199;;s   )r$   anyappendpoplowerrM   )r!   rrM   uppercase_commandscmds        r'   rN   CommandsParser.initializeE   sd    99;C,,,,"))#.  &C$,LL$5HYY[! & rG   c                    [        U5      S:  a  gUS   R                  5       nX0R                  ;  ar  UR                  5       nUS   nX0R                  ;   a  U[	        USS 5      -   nO<U R                  U5        X0R                  ;  a  [        UR                  5        S35      eU R                  R                  U5      nSUS   ;   a  U R                  " U/UQ76 nU$ SUS   ;   d	  US	   S:X  a  U R                  " U6 nU$ US
   S:X  am  US   S:X  ad  US   S:X  a[  SnSU;   aK  U SUS   R                  5        3nUS    H*  n	[        U	S   5      U:X  d  M  U R                  U	5      nSnM,     U(       d  gUS   n
U
S:  a  [        U5      [        U
5      -
  n
[	        [        US   U
S-   US
   5      5      nU Vs/ s H  oU   PM	     nnU$ s  snf a8  
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+   r3   r/   r1   Fr9   |Tr   r\   rM   splitr    rN   r	   r   get_get_moveable_keysr(   r   r?   absrange)r!   
redis_connr"   r=   cmd_name_splitr$   r%   	is_subcmdsubcmd_namesubcmdr1   keys_posposs                r'   get_keysCommandsParser.get_keysR   s    t9q=7==?==( &^^-N%a(H==(%T!"X6 
+==0$#>>+,,TU  --##H-GG,,**:==D8 7 ))WV_-H(($/D4 / %*O,1N+q0!	 G+%-JaQ/@"AK")-"8'q	2kA&*&;&;F&CG(,I #9 !">2La"4y3|+<<go.q0@',BWXH *22#ID2 3s   <Gc                     US   R                  5       [        USS 5      -   n UR                  " S/UQ76 nU$ ! [         a(  nUR	                  5       nSU;   d  SU;   a   SnAgUeSnAff = f)a  
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   NCOMMAND GETKEYSInvalid arguments The command has no key arguments)rg   r    execute_commandr
   __str__)r!   rl   r"   piecesr%   emessages          r'   ri   !CommandsParser._get_moveable_keys   sy     a4QR>1
	--.?I&ID   	iikG#w.5@	s   9 
A+A&$A&&A+rM   N)
rB   rC   rD   rE   __doc__rP   rN   rs   ri   rF   rA   rG   r'   rI   rI   8   s    *!?BrG   rI   c                       \ rS rSrSrSrSS jrSS\S   SS4S	 jjrS
\	S\\
\S4      4S jrS
\	S\\
\S4      4S jrSrg)AsyncCommandsParser   a  
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'.

NOTE: Due to a bug in redis<7.0, this 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 with EVAL or EVALSHA.
)rM   nodereturnNc                     0 U l         g rL   r   )r!   s    r'   rP   AsyncCommandsParser.__init__   s	    ?ArG   r   r   c                    #    U(       a  Xl         U R                   R                  S5      I S h  vN nUR                  5        VVs0 s H  u  p4UR                  5       U_M     snnU l        g  N>s  snnf 7f)NCOMMAND)r   ry   itemsr\   rM   )r!   r   rM   r_   r$   s        r'   rN   AsyncCommandsParser.initialize   sX     I229==BJ..BRSBR,#g-BRS >Ss!   ,A5A-A5A/#A5/A5r"   .c                   #    [        U5      S:  a  gUS   R                  5       nX R                  ;  ay  UR                  5       nUS   nX R                  ;   a  U[	        USS 5      -   nOCU R                  5       I Sh  vN   X R                  ;  a  [        UR                  5        S35      eU R                  R                  U5      nSUS   ;   a  U R                  " U6 I Sh  vN nU$ SUS   ;   d	  US	   S:X  a  U R                  " U6 nU$ US
   S:X  am  US   S:X  ad  US   S:X  a[  SnSU;   aK  U SUS   R                  5        3nUS    H*  n[        US   5      U:X  d  M  U R                  U5      nSnM,     U(       d  gUS   n	U	S:  a  [        U5      [        U	5      -
  n	[	        [        US   U	S-   US
   5      5      n
U
 Vs/ s H  oU   PM	     nnU$  GN] Ns  snf 7frb   rf   )r!   r"   r=   rm   r$   r%   rn   ro   rp   r1   rq   rr   s               r'   rs   AsyncCommandsParser.get_keys   s     t9q=7==?==( &^^-N%a(H==(%T!"X6 oo'''==0$#>>+,,TU  --##H-GG,,00$77D8 7 ))WV_-H(($/D4 / %*O,1N+q0!	 G+%-JaQ/@"AK")-"8'q	2kA&*&;&;F&CG(,I #9 !">2La"4y3|+<<go.q0@',BWXH *22#ID2I ( 84 3s?   A<G%>G?A%G%$G%A<G%%A$G%	G G%G% G%c                    #     U R                   R                  " S/UQ76 I S h  vN nU$  N! [         a(  nUR                  5       nSU;   d  SU;   a   S nAg UeS nAff = f7f)Nrv   rw   rx   )r   ry   r
   rz   )r!   r"   r%   r|   r}   s        r'   ri   &AsyncCommandsParser._get_moveable_keys  sf     
	223DLtLLD  M 	iikG#w.5@	s<   A" - +- A"- 
AAA"AAA")r   NrL   )rB   rC   rD   rE   r   	__slots__rP   r   rN   r   r   strrs   ri   rF   rA   rG   r'   r   r      sp     %IBTXm%< T T?C ?HU38_,E ?Bc huS#X6O rG   r   N)typingr   r   r   r   r   r   redis.exceptionsr	   r
   redis.utilsr   redis.asyncio.clusterr   r   rI   r   rA   rG   r'   <module>r      sA    C C 6 $1+ +\r+ rjl0 lrG   