
    1yi                         d dl mZmZmZmZmZmZ ddlmZ	 ddl
mZmZ ddlmZmZ dedefdZdedefd	Zdedefd
Z	 	 	 ddeedf   deedf   dededee   deee   ee   f   fdZy)    )TupleListDictAnySequenceOptional   )_msgs)IntFloat)SimpleErrornull_terminatesreturnc                 j    d}|t        |       k  r"| |   dv r|dz  }|t        |       k  r| |   dv r|S )Nr   z.+*~r	   )len)r   ress     a/var/www/html/content_weaver/venv/lib/python3.12/site-packages/fakeredis/_command_args_parsing.py_count_paramsr      sC    
C
A,1S6V+q A,1S6V+J    c                 :    | t        |       d  j                         S )N)r   encode)r   s    r   _encode_argr      s    ]1 ''))r   c                 N    | d   dk(  ry t        |       }|dk(  ry|dk(  ry d g|z  S )Nr   ~Fr	   )r   )r   inds     r   _default_valuer      s:    ts{

C
ax	v|r   Nactual_args.expectederror_on_unexpectedleft_from_first_unexpected	exceptionc           
         t              D ci c]  \  }}t        |      |t        |      f c}}dt        dt        dt
        t        df   dt
        t        t        f   ffd}D cg c]  }t        |       }	}g }
d}|t        |       k  rd}D ]4  }t        | |         |k(  s|   \  }} ||||       \  |	|<   }||z  }d	} n |sW|r8|t        t        j                        t        |j                  | |               |r|	| |d
 fS |
j                  | |          |dz  }|t        |       k  r|	|
fS c c}}w c c}w )a  Parse argument values.

    Extract from actual arguments which arguments exist and their value if relevant.

    :param actual_args: The actual arguments to parse
    :param expected: Arguments to look for, see below explanation.
    :param error_on_unexpected: Should an error be raised when actual_args contain an unexpected argument?
    :param left_from_first_unexpected: Once reaching an unexpected argument in actual_args, Should parsing stop?
    :param exception: What exception msg to raise
    :returns:
        - List of values for expected arguments.
        - List of remaining args.

    An expected argument can have parameters:
    - A numerical (Int) parameter is identified with '+'
    - A float (Float) parameter is identified with '.'
    - A non-numerical parameter is identified with a '*'
    - An argument with potentially ~ or = between the
      argument name and the value is identified with a '~'
    - A numberical argument with potentially ~ or = between the
      argument name and the value marked with a '~+'

    E.g.
    '++limit' will translate as an argument with 2 int parameters.

    >>> extract_args((b'nx', b'ex', b'324', b'xx',), ('nx', 'xx', '+ex', 'keepttl'))
    [True, True, 324, False], None

    >>> extract_args(
        (b'maxlen', b'10',b'nx', b'ex', b'324', b'xx',),
        ('~+maxlen', 'nx', 'xx', '+ex', 'keepttl'))
    10, [True, True, 324, False], None
    keyr   _actual_args.r   c                    |    \  }}|   }|d   dk(  r|dz   t        |      k\  rt        t        j                        ||dz      dk7  r||dz      dk7  r||dz      d}}n4|dz   t        |      k\  rt        t        j                        ||dz      d}}|d   dk(  rt	        j
                  |      }||fS |dk(  ry||z   t        |      k\  rt        t        j                        g }t        |      D ]Y  }	|||	z   dz      }
||	   dk(  rt	        j
                  |
      }
n||	   d	k(  rt        j
                  |
      }
|j                  |
       [ t        |      dk(  r|d   |fS ||fS )
zParse an argument from actual args.
        :param key: Argument name to parse
        :param ind: index of argument in actual_args
        :param _actual_args: actual args
        r   r   r	      ~   =   +)Tr   .)	r   r   msgsSYNTAX_ERROR_MSGr   decoderanger   append)r$   r   r%   posexpected_followingargument_namearg_parsedtemp_resicurr_arg	args_infor   s              r   _parse_paramsz#extract_args.<locals>._parse_paramsI   s    #,C.  s"Qw#l++!$"7"788C!G$,cAg1F$1N+C!G4aWqC--!$"7"788+C!G4aWQ3&jjo<"##s<'88d3344)* 	&A(q15HQ3&::h/q!S( <<1OOH%	& x=AA; 222///r   r   FTNr	   )	enumerater   r   bytesintr   r   r   r   r   r   r,   r-   formatr0   )r   r   r    r!   r"   r7   kr:   r$   results	left_argsfoundarg_position_parsedr9   s    `             @r   extract_argsrF      s   P dmmucv.wY_Z[]^{1~=QRCS?T/T.wI)05 )0s )0%s
:K )0PUVY[^V^P_ )0V :BB#.-BGBI	A
c+
 	Ck!n-4"+C.a0=c1k0R-%vV	 " !(   5 56 %Y%5%5k!n%EF
 *AB//[^,	Q) c+
* IK /xZ Cs   !E/E)TTN)typingr   r   r   r   r   r    r
   r,   	_commandsr   r   _helpersr   r   strr=   r   r<   r   r   boolrF    r   r   <module>rN      s    = =  ! 1S S *3 *5 *	c 	c 	 !%'+#mucz"mCHom m !%	m
 }m 49hsm#$mr   