
    Vi7                     d   S SK r S SKrS SKrS SKrS SKrS SKrS SKJrJr  S SK	J
r
Jr  S SKJr  S SKr \  \" S5      r\R*                  " S5      r\S\S0rS	 rS
 rS rS rS rS rS r S r!S r"S r#S r$SS jr%S r&S r'S r(S r)\)\(l*        S r+SS jr,S r-\-\,l.        g! \ a    \r\r Nxf = f)    N)	pluralize
strip_ansi)splitunique)make_sentinelERRORz^[A-z][-_A-z0-9]*\Zintegerdecimalc                 D   U (       a  [        U [        [        45      (       d  [        SU -  5      eU R	                  S5      (       d  U R	                  S5      (       a  [        SU -  5      e[
        R                  U 5      nU(       d  [        SU -  5      e[        U 5      nU$ )aO  Validate and canonicalize a Command's name, generally on
construction or at subcommand addition. Like
``flag_to_identifier()``, only letters, numbers, '-', and/or
'_'. Must begin with a letter, and no trailing underscores or
dashes.

Python keywords are allowed, as subcommands are never used as
attributes or variables in injection.

z<expected non-zero length string for subcommand name, not: %r-_zHexpected subcommand name without trailing dashes or underscores, not: %rzuvalid subcommand name must begin with a letter, and consist only of letters, digits, underscores, and dashes, not: %r)
isinstancestrunicode
ValueErrorendswithVALID_FLAG_REmatchnormalize_flag_name)name
name_matchsubcmd_names      ]/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/face/utils.pyprocess_command_namer      s     z$g77WZ^^__}}ST]]3// 46:; < 	< $$T*J ,.23 4 	4 &d+K    c                     U R                  S5      n[        U 5      [        U5      -
  S:  a  UR                  5       nUR                  SS5      nU$ )Nr      r   )lstriplenlowerreplace)flagrets     r   r   r   <   sE    
++c
CD	CH!iik
++c3
CJr   c                    U nU (       a  [        U [        [        45      (       d  [        SU -  5      eU R	                  S5      (       d  U R	                  S5      (       a  [        SU-  5      eU SS S:X  a  U SS n [
        R                  U 5      nU(       d  [        SU-  5      e[        U 5      n[        R                  " U5      (       a  [        S	U-  5      eU$ )
aH  Validate and canonicalize a flag name to a valid Python identifier
(variable name).

Valid input strings include only letters, numbers, '-', and/or
'_'. Only single/double leading dash allowed (-/--). No trailing
dashes or underscores. Must not be a Python keyword.

Input case doesn't matter, output case will always be lower.
z1expected non-zero length string for flag, not: %rr   r   z=expected flag without trailing dashes or underscores, not: %rN   --zvalid flag names must begin with a letter, optionally prefixed by two dashes, and consist only of letters, digits, underscores, and dashes, not: %rz0valid flag names must not be Python keywords: %r)
r   r   r   r   r   r   r   r   keyword	iskeyword)r"   	orig_flag
flag_match	flag_names       r   flag_to_identifierr,   E   s     Iz$g77LtSTT}}ST]]3// 46?@ A 	A BQx4ABx$$T*J EGPQ R 	R $D)I##K$% & 	& r   c                     U R                  S5      (       a  [        SU -  5      eU R                  5       R                  SS5      nSU-   $ )zH
Turn an identifier back into its flag format (e.g., "Flag" -> --flag).
r   z&expected identifier, not flag name: %rr   r&   )
startswithr   r    r!   )
identifierr#   s     r   identifier_to_flagr0   i   sK     S!!AJNOO




$
$S#
.C#:r   c                 z   U R                   R                  b  U R                   R                  $ [        U R                  5      /nU R                  (       a  UR                  SU R                  -   5        SR                  U5      nU R                   R                  (       a  USU R                   R                  -   -  nU$ )zCThe default flag label formatter, used in help and error formattingr   z /  )displaylabelr0   r   charappendjoin
value_name)r"   partsr#   s      r   format_flag_labelr:   s   s    ||%||!!!		*+EyyS499_%
**U
C||sT\\,,,,Jr   c                     U R                   R                  (       a  U R                   R                  $ U R                  (       d  g[        U R                   R                  U R
                  U R                  5      $ )HThe default positional argument label formatter, used in help formatting )r3   r4   accepts_argsget_cardinalized_args_labelr   	min_count	max_count)
posargspecs    r   format_posargs_labelrC      sW    !!'''""&z'9'9'>'>
@T@TV`VjVjkkr   c                     X:X  a  SR                  U /U-  5      $ US:X  a  U S-   [        U SUb	  US-
  S9-   $ SS9-   $ US:X  a  SOSnUS:X  a  X0-  $ U[        U 5      S-   -  $ )	z
Examples for parameter values: (min_count, max_count): output for name=arg:

  1, 1: arg
  0, 1: [arg]
  0, None: [args ...]
  1, 3: args ...
r2   r   r   N)r@   rA   z[%s]z%sz ...)r7   r?   r   )r   r@   rA   tmpls       r   r?   r?      s     xx*++A~cz7BCS\Sh)a-t t 	tnrt t 	t !^6DA~{9T?V+,,r   c                 B   U R                   R                  b  U R                   R                  $ U R                  [        R                  L a  gU R                  b6  [        U R                  5      [        R                  U R                  5      :X  a  gSU R                  < S3$ )r<   z
(required)r=   z(defaults to ))r3   post_docmissingfacer   reprobject__repr__)r"   s    r   format_flag_post_docrN      st    ||(||$$$||tzz!||tDLL1V__T\\5RR  S "&//r   c                    [        U 5      (       d  [        SU -  5      e S[        U    4$ ! [         a     Of = f SU R                  4$ ! [
         a     Of = f SU R                  4$ ! [
         a     Of = fS[        U 5      4$ )zHKind of a hacky way to improve message readability around argument typesz(expected parse_as to be callable, not %raswith)callable	TypeErrorFRIENDLY_TYPE_NAMESKeyError__name__AttributeError	func_namerK   )parse_ass    r   get_type_descrZ      s    HBXMNN(222 X&&&& x))))  4>!!s/   
+ 
88A
 

AAA) )
A65A6c                 @   / n/ nU R                  5        HO  nUR                  5       nU(       a  UR                  U5        M-  UR                  SR                  U5      5        / nMQ     U(       a   UR                  SR                  U5      5        SR                  U5      $ )zfTurn wrapped text into flowing paragraphs, ready for rewrapping by
the console, browser, or textwrap.
r2   z

)
splitlinesstripr6   r7   )text	all_grafscur_graflines       r   unwrap_textrb      s     IH!zz|OOD!SXXh/0H " (+,;;y!!r   c                 t   0 nU  H  nU/[        5       / pTnU(       a  UR                  5       nUR                  U5        U R                  U/ 5      nX';   a  [	        SU< SU< 35      eUR                  U Vs/ s H  oU;  d  M
  UPM     sn5        UR                  U5        U(       a  M  XAU'   M     U$ s  snf )zg
expects and returns a dict of {item: set([deps])}

item can be a string or any other hashable object.
zdependency cycle: z0 recursively depends on itself. full dep chain: )setpopr6   getr   extendupdate)	dep_mapr#   keyto_procrdeps	cur_chaincur	cur_rdepscs	            r   get_rdep_maprq      s     C%(E35"	++-CS!C,I EH)"U V V NNyEy!W4DAyEFLL# g C   J	 Fs   7	B5
B5
c                 ~   U c  [         R                  OU n Uc  [        R                  OUnUc  UR	                  SS5      OUn[        U[        [        45      (       a  UR                  S5      n[        R                  R                  U 5      nU H*  n[        R                  R                  X5      U:X  d  M(  Us  $    U $ )a  Get the shortest form of a path to an executable,
based on the state of the process environment.

Args:
  executable (str): Name or path of an executable
  path (list): List of directories on the "PATH", or ':'-separated
    path list, similar to the $PATH env var. Defaults to ``environ['PATH']``.
  environ (dict): Mapping of environment variables, will be used
    to retrieve *path* if it is None. Ignored if *path* is
    set. Defaults to ``os.environ``.

Used by face's default help renderer for a more readable usage string.
PATHr=   :)sys
executableosenvironrf   r   r   r   r   pathbasenamerelpath)rv   ry   rx   executable_basenameps        r   get_minimal_executabler~      s     $.#5:J#ObjjG&*l7;;vr"D$g''zz#''**:677??:)-@@&&  r   c                 D     U R                  5       $ ! [         a     gf = f)z!Returns True if *stream* is a ttyF)isatty	Exceptionstreams    r   r   r     s%    }} s    
c                 "    [        U 5      (       + $ )zNReturns True when ANSI color codes should be stripped from output to *stream*.)r   r   s    r   should_strip_ansir     s    f~r   c                    U =(       d    Sn [        U [        [        45      (       d  [        U 5      n UR                  SS5      nUR                  SU(       d  [        R
                  O[        R                  5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nS	n[        U[        5      (       a  Xv-  nUc  [        U5      (       + nUc0  UR                  S
S5      (       a  [        U [        5      (       a  SOSnU(       a  X-  n U(       a  [        R                  " XS9n U (       a#  U(       d  [        U 5      n UR                  U 5        UR                  5         g)a  A better-behaved :func:`print()` function for command-line applications.

Writes text or bytes to a file or stream and flushes. Seamlessly
handles stripping ANSI color codes when the output file is not a
TTY.

  >>> echo('test')
  test

Args:

  msg (str): A text or byte string to echo.
  err (bool): Set the default output file to ``sys.stderr``
  file (file): Stream or other file-like object to output
    to. Defaults to ``sys.stdout``, or ``sys.stderr`` if *err* is
    True.
  nl (bool): If ``True``, sets *end* to ``'\n'``, the newline character.
  end (str): Explicitly set the line-ending character. Setting this overrides *nl*.
  color (bool): Set to ``True``/``False`` to always/never echo ANSI color
    codes. Defaults to inspecting whether *file* is a TTY.

r=   errFfileendNcolorindentr2   nlT
   
)prefix)r   r   bytesre   ru   stdoutstderrintr   textwrapr   r   writeflush)msgkwis_err_filer   enable_colorr   spaces           r   echor     s   . )CcGU+,,clVVE5!FFF6V3::DE
&&
C66'4(LVVHb!FE&#,U33
{66$%c733%C

ooc1
S/CC	KKM
r   c                  "    SUS'   [        U 0 UD6$ )zx
A convenience function which works exactly like :func:`echo`, but
always defaults the output *file* to ``sys.stderr``.
Tr   )r   )ar   s     r   echo_errr   T  s    
 BuI>b>r   c                 R    [        U [        5      (       d  U R                  S5      $ U $ )Nutf8)r   r   decode)inps    r   	_get_textr   a  s#    c7##zz&!!Jr   c                   ^^ U=(       d    UnU(       a  U(       d  SU R                  5       < 3nUU4S jnU" U 5      n[        U5      nU(       a.  U" U5      n[        U5      nXx:w  a  [        R                  " S5      eU$ )a+  A better-behaved :func:`input()` function for command-line applications.

Ask a user for input, confirming if necessary, returns a text
string. Handles Ctrl-C and EOF more gracefully than Python's built-ins.

Args:

   label (str): The prompt to display to the user.
   confirm (bool): Pass ``True`` to ask the user to retype the input to confirm it.
     Defaults to False, unless *confirm_label* is passed.
   confirm_label (str): Override the confirmation prompt. Defaults
     to "Retype *label*" if *confirm* is ``True``.
   hide_input (bool): If ``True``, disables echoing the user's
     input as they type. Useful for passwords and other secret
     entry. See :func:`prompt_secret` for a more convenient
     interface. Defaults to ``False``.
   err (bool): If ``True``, prompts are printed on
     ``sys.stderr``. Defaults to ``False``.

:func:`prompt` is primarily intended for simple plaintext
entry. See :func:`prompt_secret` for handling passwords and other
secret user input.

Raises :exc:`UsageError` if *confirm* is enabled and inputs do not match.

zRetype c                    > T(       a  [         R                   O[        n [        U STS9  U" S5      nU$ ! [        [        4 a    T(       a
  [        S TS9  e f = f)NF)r   r   r=   )r   )getpass	raw_inputr   KeyboardInterruptEOFError)r4   funcr#   r   
hide_inputs      r   prompt_funcprompt.<locals>.prompt_func  s[    ",w)	 5c*r(C 
 "8, 	 Ts#	s	   5 #AzSorry, inputs did not match.)r    r   rJ   
UsageError)	r4   confirmconfirm_labelr   r   
do_confirmr   r#   ret2s	      ``    r   promptr   g  sl    6 )MJ-',{{}6" e
C
C.C=);//"@AAJr   c                 H    SUS'   UR                  SS5        [        U 40 UD6$ )a   A convenience function around :func:`prompt`, which is
preconfigured for secret user input, like passwords.

All arguments are the same, except *hide_input* is always
``True``, and *err* defaults to ``True``, for consistency with
:func:`getpass.getpass`.

Tr   r   )
setdefaultr   )r4   r   s     r   prompt_secretr     s,     B|MM%%2r   )NNN)NNFF)/rw   reru   r   r'   r   boltons.strutilsr   r   boltons.iterutilsr   r   boltons.typeutilsr   rJ   r   	NameErrorr   inputr   r   compiler   r   floatrT   r   r   r,   r0   r:   rC   r?   rN   rZ   rb   rq   r~   r   r   r   r   r   r   r   r   secret r   r   <module>r      s    	 	 
    2 + + 
 	g 

12Ii) <!H
l-,	0","$<<
5p 8v A  GIs   B" "
B/.B/