
    RiW&                         d dl Z d dlmZmZmZmZmZmZmZ 	 ddl	m
Z
 n# e$ r	 d dlm
Z
 Y nw xY wddlmZ dedefd	Zdedefd
ZdedefdZdedeeeef                  fdZ G d d          ZdS )    N)AnyDictListIterableOptionalTupleUnion   )Lexicon   )Argumentnamereturnc                 z    |                      d                              d                              dd          S )N_-)lstriprstripreplacer   s    M/srv/django_bis/venv311/lib/python3.11/site-packages/invoke/parser/context.pytranslate_underscoresr      s2    ;;s""3''//S999    c                 Z    t          |           } t          |           dk    rd| z   S d| z   S )Nr   r   z--)r   lenr   s    r   to_flagr      s2     &&D
4yyA~~Tz$;r   argc                     | j         }d |D             fd|D             }t          t          rn|          d                   S )Nc                 ^    h | ]*}t          |                    d                     dk    (|+S )r   r   )r   strip.0xs     r   	<setcomp>z!sort_candidate.<locals>.<setcomp>   s4    999A#aggcll"3"3q"8"8a"8"8"8r   c                     h | ]}|v|	S  r&   )r"   r#   shortss     r   r$   z!sort_candidate.<locals>.<setcomp>   s    1111&Qr   r   )namesstrsorted)r   r(   longsr'   s      @r   sort_candidater,      sZ    IE99999F1111111Ev1ffE2215666r   c                    g }t          |           }|                    t          |          dk    rdnd           |                    |                                           d}|D ]A}||                                r|                                n|                                z  }B|                    |           |S )zZ
    Obtain useful key list-of-ints for sorting CLI flags.

    .. versionadded:: 1.0
    r   r    )r,   appendr   lowerisupperupper)r   retr#   inversedchars        r   flag_keyr6      s     "$CsA JJCFFaKKqqQ''' JJqwwyy H E EDLLNNDDJJLLL

DJJxJr   c            	       V   e Zd ZdZ	 	 	 ddee         dee         dee         ddfdZdefd	Z	de
d
e
ddfdZedee         fd            Zedeee
f         fd            Zdedee         fdZdedeeef         fdZdeeeee         f                  fdZdeedf         fdZdS )ParserContextz
    Parsing context with knowledge of flags & their format.

    Generally associated with the core program or a task.

    When run through a parser, will also hold runtime values filled in by the
    parser.

    .. versionadded:: 1.0
    Nr&   r   aliasesargsr   c                     t                      | _        g | _        t                      | _        i | _        || _        || _        |D ]}|                     |           dS )a  
        Create a new ``ParserContext`` named ``name``, with ``aliases``.

        ``name`` is optional, and should be a string if given. It's used to
        tell ParserContext objects apart, and for use in a Parser when
        determining what chunk of input might belong to a given ParserContext.

        ``aliases`` is also optional and should be an iterable containing
        strings. Parsing will honor any aliases when trying to "find" a given
        context in its input.

        May give one or more ``args``, which is a quick alternative to calling
        ``for arg in args: self.add_arg(arg)`` after initialization.
        N)r   r:   positional_argsflagsinverse_flagsr   r9   add_arg)selfr   r9   r:   r   s        r   __init__zParserContext.__init__G   sf    ( II	/1YY
-/	 	 	CLL	 	r   c                 (   d}| j         r-d                    d                    | j                             }| j        rd                    | j        |          nd}| j        rd                    | j                  nd}d                    ||          S )Nr.   z ({}), z {!r}{}z: {!r}z<parser/Context{}{}>)r9   formatjoinr   r:   )r@   r9   r   r:   s       r   __repr__zParserContext.__repr__d   s    < 	>nnTYYt|%<%<==G9=J	  G444/3y@	***b%,,T4888r   kwargsc                 L   t          |          dk    r$t          |d         t                    r	|d         }nt          |i |}|j        D ]/}|| j        v r$d}t          |                    |                    0|j        d         }|| j        |<   |j        r| j        	                    |           || j
        t          |          <   |j        D ]T}| j                            ||           | j
                            t          |          t          |                     U|j        r!| j                            |j        |           |j        t           k    rD|j        du r=t          d                    |                    }t          |          | j        |<   dS dS dS )a  
        Adds given ``Argument`` (or constructor args for one) to this context.

        The Argument in question is added to the following dict attributes:

        * ``args``: "normal" access, i.e. the given names are directly exposed
          as keys.
        * ``flags``: "flaglike" access, i.e. the given names are translated
          into CLI flags, e.g. ``"foo"`` is accessible via ``flags['--foo']``.
        * ``inverse_flags``: similar to ``flags`` but containing only the
          "inverse" versions of boolean flags which default to True. This
          allows the parser to track e.g. ``--no-myflag`` and turn it into a
          False value for the ``myflag`` Argument.

        .. versionadded:: 1.0
        r   r   z;Tried to add an argument named {!r} but one already exists!)toTzno-{}N)r   
isinstancer   r(   r:   
ValueErrorrD   
positionalr<   r/   r=   r   	nicknamesalias	attr_namekindbooldefaultr>   )r@   r:   rG   r   r   msgmaininverse_names           r   r?   zParserContext.add_argl   s   $ t99>>ja(;;>q'CCD+F++CI 	3 	3Dty  S D!1!1222 ! y|	$> 	- '',,,$'
74==!M 	> 	>DIOODTO***JWT]]wt}}===== 	4IOOCMdO3338tt 3 3 #7>>$#7#788L/6t}}D|,,,  3 3r   c                 $    d | j         D             S )Nc                      g | ]}|j         	|S N)valuer!   s     r   
<listcomp>z9ParserContext.missing_positional_args.<locals>.<listcomp>   s    CCCa17????r   )r<   r@   s    r   missing_positional_argsz%ParserContext.missing_positional_args   s    CC4/CCCCr   c                 `    i }| j                                         D ]}|j        ||j        <   |S )a  
        This context's arguments' values keyed by their ``.name`` attribute.

        Results in a dict suitable for use in Python contexts, where e.g. an
        arg named ``foo-bar`` becomes accessible as ``foo_bar``.

        .. versionadded:: 1.0
        )r:   valuesrY   r   )r@   r3   r   s      r   	as_kwargszParserContext.as_kwargs   s:     9##%% 	& 	&CICMM
r   flagc                 r    t          t          |g| j                            |          z                       S rX   )listsetr=   
aliases_of)r@   r`   s     r   	names_forzParserContext.names_for   s/    C!6!6t!<!<<==>>>r   c                 V   || j         vr<d}t          |                    || j                                                             | j         |         }t          dt
          di                    |j                  }g }|                     |          D ]}|rt          |
                    d                    dk    r4|j        rd                    |          n|}d                    |          }nld                    |          }|j        rd                    |          }n:|| j                                        v rd	                    |d
d                   }d}|                    ||z              d                    t!          |t                              }	|j        pd}
|	|
fS )zs
        Return 2-tuple of ``(flag-spec, help-string)`` for given ``flag``.

        .. versionadded:: 1.0
        z@{!r} is not a valid flag for this context! Valid flags are: {!r}STRINGINTr   r   z[{}]z {}z={}z	--[no-]{}r
   Nr.   rC   key)r=   rK   rD   keysr)   intgetrP   re   r   r    optionalr>   r^   r/   rE   r*   help)r@   r`   errr   rY   
full_namesr   value_valuestrnamestrhelpstrs              r   help_forzParserContext.help_for   s    tz!!TCSZZdjoo.?.?@@AAAjhU+//99
NN4(( 	/ 	/D  tzz#''1,,7:|NfmmE222F$||F33HH$||E22H| ;#)==#:#: 4-446666&--d122h77DdXo....))F:377788(.br   c           	           t          t           fdt           j                                        t
                                        S )a  
        Return sorted iterable of help tuples for all member Arguments.

        Sorts like so:

        * General sort is alphanumerically
        * Short flags win over long flags
        * Arguments with *only* long flags and *no* short flags will come
          first.
        * When an Argument has multiple long or short flags, it will sort using
          the most favorable (lowest alphabetically) candidate.

        This will result in a help list like so::

            --alpha, --zeta # 'alpha' wins
            --beta
            -a, --query # short flag wins
            -b, --argh
            -c

        .. versionadded:: 1.0
        c                 R                         t          | j                            S rX   )rv   r   r   )r#   r@   s    r   <lambda>z+ParserContext.help_tuples.<locals>.<lambda>   s    $--88 r   ri   )rb   mapr*   r=   r^   r6   r[   s   `r   help_tupleszParserContext.help_tuples   sN    6 8888tz((**999 
 
 	
r   .c                 D    t           j                                        t                    } fd|D             }|                    t           j                                                             t          t          j
                            |                    S )z
        Similar to `help_tuples` but returns flag names only, no helpstrs.

        Specifically, all flag names, flattened, in rough order.

        .. versionadded:: 1.0
        ri   c                 ^    g | ])}                     t          |j                            *S r&   )re   r   r   )r"   r#   r@   s     r   rZ   z,ParserContext.flag_names.<locals>.<listcomp>  s-    @@@Q00@@@r   )r*   r=   r^   r6   r/   rb   r>   rk   tuple	itertoolschainfrom_iterable)r@   r=   r(   s   `  r   
flag_nameszParserContext.flag_names   s     tz((**999@@@@%@@@T$,113344555Y_22599:::r   )Nr&   r&   )__name__
__module____qualname____doc__r   r)   r   r   rA   rF   r   r?   propertyr   r\   r   r_   re   r   rv   r{   r   r&   r   r   r8   r8   ;   s       	 	 #!##%	 sm # x 	
 
   :9# 9 9 9 9/=S /=C /=D /= /= /= /=b Dh D D D XD 4S>    X?c ?d3i ? ? ? ?% S % U38_ %  %  %  % N 
T%Xc](:";<  
  
  
  
D;E#s(O ; ; ; ; ; ;r   r8   )r   typingr   r   r   r   r   r   r	   vendor.lexiconr   ImportErrorlexiconargumentr   r)   r   r   r,   rl   r6   r8   r&   r   r   <module>r      sy       D D D D D D D D D D D D D D D D D D (((((((             : : : : : :# #    7 7S 7 7 7 7( tE#s(O4    8O; O; O; O; O; O; O; O; O; O;s    --