
    0Vhe7                        U d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZmZmZmZ ddlmZ eej$                     ed<   	 ddlZeej$                     ed<   	 ddlZdZdZd	Z ej4                  d
      Z eej:                  e         hZee    ed<   dZ!eed<   dZ"eej$                     ed<    G d de      Z#de	e$ef   de#fdZ%de#fdZ&de$fdZ'dejP                  de$dedejR                  fdZ*de fdZ+de$dee$   dee$   fdZ,d Z-	 	 	 d)de$dee    d e$d!ee$   de$f
d"Z.	 d*d#e	e$ef   d$eee$      de
e$   fd%Z/d&e$de$fd'Z0de$de$fd(Z1y# e$ r dZY w xY w# e$ r dZY 	w xY w)+z:Internal helper functions for Abseil Python flags library.    N)AnyDictIterableList
NamedTupleOptionalSequenceSet)minidomfcntltermiosP   (   g      ?u    [ -----￾￿]disclaim_module_idsSPECIAL_FLAGSFLAGS_MODULEc                   @    e Zd ZU dZeej                     ed<   eed<   y)_ModuleObjectAndNamezkModule object and name.

  Fields:
  - module: object, module object.
  - module_name: str, module name.
  modulemodule_nameN)	__name__
__module____qualname____doc__r   types
ModuleType__annotations__str     C/home/dcms/DCMS/lib/python3.12/site-packages/absl/flags/_helpers.pyr   r   S   s      5##
$$r    r   globals_dictreturnc                     | j                  dd      }t        j                  j                  |d      }t        ||dk(  rt        j                  d         S |      S )aN  Returns the module that defines a global environment, and its name.

  Args:
    globals_dict: A dictionary that should correspond to an environment
      providing the values of the globals.

  Returns:
    _ModuleObjectAndName - pair of module object & module name.
    Returns (None, None) if the module could not be identified.
  r   N__main__r   )getsysmodulesr   argv)r"   namer   s      r!   get_module_object_and_namer+   ^   s\     
		*d	+$;;??4&&	f.2j.@sxx{
M MFJ
M Mr    c                      t        dt        j                               D ]Q  } t        j                  |       j                  }t        |      \  }}t        |      t        vsB|Et        ||      c S  t        d      )a)  Returns the module that's calling into this module.

  We generally use this function to get the name of the module calling a
  DEFINE_foo... function.

  Returns:
    The module object that called into this one.

  Raises:
    AssertionError: Raised when no calling module could be identified.
     zNo module was found)
ranger'   getrecursionlimit	_getframe	f_globalsr+   idr   r   AssertionError)depthglobals_for_framer   r   s       r!   "get_calling_module_object_and_namer6   r   sw     Q--/0 7e e,6645FGFK	&z,,1H!&+667 	,--r    c                  *    t               j                  S )z?Returns the name of the module that's calling into this module.)r6   r   r   r    r!   get_calling_moduler8      s    	+	-	9	99r    docr*   valuec                     t        |      }t        |t              r|j                         }t        j                  d|      }| j                  |      }|j                  | j                  |             |S )a  Returns an XML DOM element with name and text value.

  Args:
    doc: minidom.Document, the DOM document it should create nodes from.
    name: str, the tag of XML element.
    value: object, whose string representation will be used
        as the value of the XML element. Illegal or highly discouraged xml 1.0
        characters are stripped.

  Returns:
    An instance of minidom.Element.
   )	r   
isinstanceboollower_ILLEGAL_XML_CHARS_REGEXsubcreateElementappendChildcreateTextNode)r9   r*   r:   ses        r!   create_xml_dom_elementrG      s`     
%j!t		A""2q)!	!--""1%&	
(r    c                     t         j                  j                         rt        t        t
        S 	 t	        j                  t         j                  t        j                  d      } t        j                  d|       d   }|t        k\  r|S t        t        j                  dt
                    S # t        t        t        j                   f$ r	 t
        cY S w xY w)zAReturns the integer width of help lines that is used in TextWrap.s   1234hhr-   COLUMNS)r'   stdoutisattyr   r   _DEFAULT_HELP_WIDTHioctl
TIOCGWINSZstructunpack_MIN_HELP_WIDTHintosgetenv	TypeErrorOSErrorerror)datacolumnss     r!   get_help_widthr[      s    				5=;;szz7#5#5w?DmmD$'*G /!nryy$7899
Wfll	+ s   AB, 	"B, ,$CCattemptlongopt_listc                 v   t        |       dk  s|sg S |D cg c]  }|j                  d      d    }}|D cg c]  }t        | |dt        |              |f }}|j                          |d   \  }}|t        t        |       z  k\  rg S g }|D ]  \  }	}
|	|k(  r|j                  |
        |S  |S c c}w c c}w )z4Returns helpful similar matches for an invalid flag.   =r   )lensplit_damerau_levenshteinsort _SUGGESTION_ERROR_RATE_THRESHOLDappend)r\   r]   voption_namesoption	distancesleast_errors_suggestionserrorsr*   s              r!   get_flag_suggestionsro      s    
 	\QlI+78a!''#,q/8,8
 *+ %WfQs7|.DEvN +) + ..aL/,5GDDI+ lfd	
 
) 9+s
   B1!B6c                 (    i fd | |      S )z6Returns Damerau-Levenshtein edit distance from a to b.c           
      ~   | |fv r| |f   S | st        |      }n|st        |       }nt         | dd |      dz    | |dd       dz    | dd |dd       | d   |d   k7  z         }t        |       dk\  r=t        |      dk\  r/| d   |d   k(  r$| d   |d   k(  r | dd |dd       dz   }||kD  r|}|| |f<   |S )z5Recursively defined string distance with memoization.r-   Nr   r_   )ra   min)xydtdistancememos       r!   rw   z&_damerau_levenshtein.<locals>.distance   s    	1v~!Q$Z
a&a
a&a

1QR5!
q
 
1ae
q
 
1QR5!AB%
 AaDAaDL
13a 
Q1Q111!A$!A$,QqrUAabE"Q&q5!DAJHr    r   )abrw   rx   s     @@r!   rc   rc      s    	$* 
!Qr    textlengthindentfirstline_indentc                    |
t               }|d}||}t        |      |k\  rt        d      t        |      |k\  rt        d      | j                  d      } g }t	        j
                  |||      }t	        j
                  |||      }d | j                         D        D ]8  }|r!|j                  |j                  |             n|j                  d       |}: dj                  |      S )aL  Wraps a given text to a maximum line length and returns it.

  It turns lines that only contain whitespace into empty lines, keeps new lines,
  and expands tabs using 4 spaces.

  Args:
    text: str, text to wrap.
    length: int, maximum length of a line, includes indentation.
        If this is None then use get_help_width()
    indent: str, indent for all but first line.
    firstline_indent: str, indent for first line; if None, fall back to indent.

  Returns:
    str, the wrapped text.

  Raises:
    ValueError: Raised if indent or firstline_indent not shorter than length.
  r<   zLength of indent exceeds lengthz*Length of first line indent exceeds length   )widthinitial_indentsubsequent_indentc              3   <   K   | ]  }|j                           y wN)strip).0ps     r!   	<genexpr>ztext_wrap.<locals>.<genexpr>(  s     9!AGGI9s   
)r[   ra   
ValueError
expandtabstextwrapTextWrapper
splitlinesextendwraprf   join)r{   r|   r}   r~   resultwrappersubsequent_wrapper	paragraphs           r!   	text_wrapr      s    2 ^F^F[F
6
77	f$
A
BB		$&   #3vO'++6VE :t'89 !immGLL+,mmB G! 
6	r    flag_mapmulti_flagsc              #     K   | j                         D ]  \  }}|d|z   t        |t              r|rd|z   *d|z   2t        |t        t        f      rd|d| S	 |r||v r|D ]  }d|dt	        |        n d|ddj                  d |D                y# t        $ r d|d| Y w xY ww)a3  Convert a dict of values into process call parameters.

  This method is used to convert a dictionary into a sequence of parameters
  for a binary that parses arguments using this module.

  Args:
    flag_map: dict, a mapping where the keys are flag names (strings).
        values are treated according to their type:

        * If value is ``None``, then only the name is emitted.
        * If value is ``True``, then only the name is emitted.
        * If value is ``False``, then only the name prepended with 'no' is
          emitted.
        * If value is a string then ``--name=value`` is emitted.
        * If value is a collection, this will emit
          ``--name=value1,value2,value3``, unless the flag name is in
          ``multi_flags``, in which case this will emit
          ``--name=value1 --name=value2 --name=value3``.
        * Everything else is converted to string an passed as such.

    multi_flags: set, names (strings) of flags that should be treated as
        multi-flags.
  Yields:
    sequence of string suitable for a subprocess execution.
  Nz--%sz--no%sz--r`   ,c              3   2   K   | ]  }t        |        y wr   )r   )r   items     r!   r   z$flag_dict_to_args.<locals>.<genexpr>a  s     *G3t9*Gs   )itemsr=   r>   bytesr   r   rV   )r   r   keyr:   r   s        r!   flag_dict_to_argsr   3  s     8 NN$ 'jc5}SL	E4	 	sln	EE3<	(e$$'3+- /d"CI../ !#((*G*G"GH
H%'&  '&&'s+   A$C'AB+(C+C>C CC	docstringc                    | syd}| j                         j                         }|}|dd D ]6  }|j                         }|st        |t	        |      t	        |      z
        }8 |d   j                         g}||k  r,|dd D ]$  }|j                  ||d j                                & |r|d   s|j                          |r|d   s|r|d   s|j                  d       |r|d   sdj                  |      S )a  Removes indentation from triple-quoted strings.

  This is the function specified in PEP 257 to handle docstrings:
  https://www.python.org/dev/peps/pep-0257/.

  Args:
    docstring: str, a python docstring.

  Returns:
    str, docstring with indentation removed.
  r<   i    r-   Nr   r   )
r   r   lstriprr   ra   r   rf   rstrippopr   )r   
max_indentlinesr}   linestrippedtrimmeds          r!   trim_docstringr   g  s	    
 * 


 
+
+
-% &ABi 6d{{}H63t9s8}45f6
 1X^^'jab	 -nnT&']))+,- 	KKM 	
KKN 	
 
7	r    c                     | j                         } t        j                  dt        j                        }|j	                  d|       } t        |       } t        j                  dd| t        j                        } | S )z0Takes a __doc__ string and reformats it as help.z^[ 	]+$r<   z(?<=\S)\n(?=\S) )flags)r   recompileMrA   r   )r9   whitespace_only_lines     r!   doc_to_helpr     sd     			# J5  S)# 	s# 	!32448#	*r    )Nr<   Nr   )2r   rT   r   rP   r'   r   r   typingr   r   r   r   r   r   r	   r
   xml.domr   r   r   r   ImportErrorr   rM   rR   re   r   r@   r2   r(   r   r   rS   r   r   r   r   r+   r6   r8   DocumentElementrG   r[   ro   rc   r   r   r   r   r   r    r!   <module>r      sM   A 	 	  
   Q Q Q   ! ! 
%""	# #    $(  
 &2::M  "$CKK$9!: ; SX ; s  ,0hu''( /: MsCx.MM(.,@ .,:C :
			!$-0__6 $ (	#Y>< !&*	;
;SM; ; sm	;
 	;~ AE1'38n1'+3CH+=1'c]1'h'c 'c 'TS S i  
%  's$   	E  E# E E #E.-E.