
    MhW&                         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
 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y# e$ r	 d dlm
Z
 Y Fw xY w)    N)AnyDictListIterableOptionalTupleUnion   )Lexicon   )Argumentnamereturnc                 b    | j                  d      j                  d      j                  dd      S )N_-)lstriprstripreplacer   s    m/var/www/pru.catia.catastroantioquia-mas.com/valormasv2/lib/python3.12/site-packages/invoke/parser/context.pytranslate_underscoresr      s)    ;;s""3'//S99    c                 H    t        |       } t        |       dk(  rd| z   S d| z   S )Nr   r   z--)r   lenr   s    r   to_flagr      s+     &D
4yA~Tz$;r   argc                     | j                   }|D ch c]"  }t        |j                  d            dk(  s!|$ }}|D ch c]	  }||vs| }}t        t	        |r|n|      d         S c c}w c c}w )Nr   r   r   )namesr   stripstrsorted)r   r   xshortslongss        r   sort_candidater&      sl    IIE9A#aggcl"3q"8a9F911&Q1E1vfE21566 :1s   "A)A)	A.A.c                 :   g }t        |       }|j                  t        |      dk(  rdnd       |j                  |j                                d}|D ]5  }||j	                         r|j                         n|j                         z  }7 |j                  |       |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_keyr0      s     "$CsA JJCFaKqQ' JJqwwy H EDLLNDJJL

DEJJxJr   c            	          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y)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   aliasesargsr   c                     t               | _        g | _        t               | _        i | _        || _        || _        |D ]  }| j                  |        y)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   r4   positional_argsflagsinverse_flagsr   r3   add_arg)selfr   r3   r4   r   s        r   __init__zParserContext.__init__G   sO    ( I	/1Y
-/	 	CLL	r   c                 <   d}| j                   r*dj                  dj                  | j                               }| j                  rdj                  | j                  |      nd}| j                  rdj                  | j                        nd}dj                  ||      S )Nr(   z ({}), z {!r}{}z: {!r}z<parser/Context{}{}>)r3   formatjoinr   r4   )r:   r3   r   r4   s       r   __repr__zParserContext.__repr__d   st    <<nnTYYt||%<=G9=	  G4/3yy		*b%,,T488r   kwargsc                 b   t        |      dk(  rt        |d   t              r|d   }nt        |i |}|j                  D ],  }|| j                  v sd}t        |j                  |             |j                  d   }|| j                  |<   |j                  r| j                  j                  |       || j                  t        |      <   |j                  D ]N  }| j                  j                  ||       | j                  j                  t        |      t        |             P |j                  r'| j                  j                  |j                  |       |j                  t         k(  rB|j"                  du r3t        dj                  |            }t        |      | j$                  |<   yyy)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   r4   
ValueErrorr>   
positionalr6   r)   r7   r   	nicknamesalias	attr_namekindbooldefaultr8   )r:   r4   rA   r   r   msgmaininverse_names           r   r9   zParserContext.add_argl   sd   $ t9>ja(;q'CD+F+CII 	3Dtyy S D!122	3
 yy|		$>>  '',$'

74=!MM 	>DIIOODTO*JJWT]wt}=	> ==IIOOCMMdO388tt 3 #7>>$#78L/6t}D|, !4r   c                 Z    | j                   D cg c]  }|j                  | c}S c c}w N)r6   value)r:   r#   s     r   missing_positional_argsz%ParserContext.missing_positional_args   s$    //Ca177?CCCs   ((c                 z    i }| j                   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
        )r4   valuesrR   r   )r:   r-   r   s      r   	as_kwargszParserContext.as_kwargs   s;     99##% 	&CIICM	&
r   flagc                 d    t        t        |g| j                  j                  |      z               S rQ   )listsetr7   
aliases_of)r:   rW   s     r   	names_forzParserContext.names_for   s(    C!6!6t!<<=>>r   c                    || j                   vr5d}t        |j                  || j                   j                                     | j                   |   }t        dt
        dij                  |j                        }g }| j                  |      D ]  }|r}t        |j                  d            dk(  r1|j                  rdj                  |      n|}dj                  |      }nadj                  |      }|j                  rDdj                  |      }n2|| j                  j                         v rd	j                  |d
d       }d}|j                  ||z           dj                  t!        |t                    }	|j"                  xs 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(   r=   key)r7   rE   r>   keysr!   intgetrJ   r\   r   r    optionalr8   rU   r)   r?   r"   help)r:   rW   errr   rR   
full_namesr   value_valuestrnamestrhelpstrs              r   help_forzParserContext.help_for   sT    tzz!TCSZZdjjoo.?@AAjjhU+//9
NN4( 	/D tzz#'1,7:||fmmE2F$||F3H$||E2H||#)==#: 4--4466&--d12h7DdXo.'	/( ))F:378((.br   c           	           t        t         fdt         j                  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                 L    j                  t        | j                              S rQ   )rm   r   r   )r#   r:   s    r   <lambda>z+ParserContext.help_tuples.<locals>.<lambda>   s    $--8 r   r`   )rY   mapr"   r7   rU   r0   )r:   s   `r   help_tupleszParserContext.help_tuples   s4    6 8tzz((*9
 	
r   .c                 t   t        | j                  j                         t              }|D cg c]&  }| j	                  t        |j                              ( }}|j                  t        | j                  j                                      t        t        j                  j                  |            S c c}w )z
        Similar to `help_tuples` but returns flag names only, no helpstrs.

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

        .. versionadded:: 1.0
        r`   )r"   r7   rU   r0   r\   r   r   r)   rY   r8   rb   tuple	itertoolschainfrom_iterable)r:   r7   r#   r   s       r   
flag_nameszParserContext.flag_names   s     tzz((*9:?@Q0@@T$,,11345Y__2259:: As   +B5)N ry   )__name__
__module____qualname____doc__r   r!   r   r   r;   r@   r   r9   propertyr   rS   r   rV   r\   r   rm   rr   rx   ry   r   r   r2   r2   ;   s   	 #!##%	sm # x 	
 
:9# 9/=S /=C /=D /=b Dh D D 4S>  ?c ?d3i ?% S % U38_ % N 
T%Xc](:";<  
D;E#s(O ;r   r2   )ru   typingr   r   r   r   r   r   r	   vendor.lexiconr   ImportErrorlexiconargumentr   r!   r   r   r&   rc   r0   r2   ry   r   r   <module>r      s     D D D ( : : :# # 7 7S 7( tE#s(O4 8O; O;k    s   A A%$A%