
    b9                        S r SSKJr  SSKJr  SSKJr  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r SSKrSSKrSSKJr  SrSrS	r\R(                  " S
5      r\" \" \	R0                  \   5      /5      rSrSr " S S\R:                  " SS5      5      rS rS r S r!S r"S r#S r$S r%S r&SS jr'SS jr(S r)S r*S r+g! \ a    Sr Nf = f! \ a    Sr Nf = f)z:Internal helper functions for Abseil Python flags library.    )absolute_import)division)print_functionN)rangeP   (   g      ?u    [ -----￾￿]c                       \ rS rSrSrSrg)_ModuleObjectAndNamer   zcModule object and name.

Fields:
- module: object, module object.
- module_name: str, module name.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       .platform/bq/third_party/absl/flags/_helpers.pyr
   r
   P   s    r   r
   zmodule module_namec                     U R                  SS5      n[        R                  R                  US5      n[        UUS:X  a  [        R                  S   5      $ U5      $ )a@  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)globals_dictnamemodules      r   get_module_object_and_namer   Z   s\     
		*d	+$;;??4&&	f.2j.@sxx{
M MFJ
M Mr   c                     [        S[        R                  " 5       5       HU  n [        R                  " U 5      R                  n[        U5      u  p#[        U5      [        ;  d  ME  Uc  MJ  [        X#5      s  $    [        S5      e)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)
r   r   getrecursionlimit	_getframe	f_globalsr   iddisclaim_module_idsr
   AssertionError)depthglobals_for_framer   module_names       r   "get_calling_module_object_and_namer)   l   sn     Q--/0e e,6645FGF	&z,,1H!&66 1 	,--r   c                  *    [        5       R                  $ )z?Returns the name of the module that's calling into this module.)r)   r(   r   r   r   get_calling_moduler+      s    	+	-	9	99r   c                 P     [        U 5      $ ! [         a    [        U 5      s $ f = f)an  Converts a value to a python string.

Behavior of this function is intentionally different in Python2/3.

In Python2, the given value is attempted to convert to a str (byte string).
If it contains non-ASCII characters, it is converted to a unicode instead.

In Python3, the given value is always converted to a str (unicode string).

This behavior reflects the (bad) practice in Python2 to try to represent
a string as str as long as it contains ASCII characters only.

Args:
  value: An object to be converted to a string.

Returns:
  A string representation of the given value. See the description above
  for its type.
)strUnicodeEncodeErrorunicode)values    r   str_or_unicoder1      s*    (u:	 5>s   
 %%c                 l   [        U5      n[        R                  (       a'  [        U[        5      (       d  UR                  SS5      n[        U[        5      (       a  UR                  5       n[        R                  SU5      nU R                  U5      nUR                  U R                  U5      5        U$ )az  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.
zutf-8ignore )r1   sixPY2
isinstancer/   decodeboollower_ILLEGAL_XML_CHARS_REGEXsubcreateElementappendChildcreateTextNode)docr   r0   ses        r   create_xml_dom_elementrC      s     U!WWZ7++	(#At		A""3*!	!--""1%&	
(r   c                     [         R                  R                  5       (       a  [        b  [        c  [
        $  [        R                  " [         R                  [        R                  S5      n [        R                  " SU 5      S   nU[        :  a  U$ [        [        R                  " S[
        5      5      $ ! [        [        [        R                   4 a	    [
        s $ f = f)zAReturns the integer width of help lines that is used in TextWrap.1234hhr   COLUMNS)r   stdoutisattytermiosfcntl_DEFAULT_HELP_WIDTHioctl
TIOCGWINSZstructunpack_MIN_HELP_WIDTHintosgetenv	TypeErrorIOErrorerror)datacolumnss     r   get_help_widthrZ      s    					5=;;szz7#5#5v>DmmD$'*G /!nryy$7899
Wfll	+ s   AB7 #B7 7%CCc                    [        U 5      S::  d  U(       d  / $ U Vs/ s H  o"R                  S5      S   PM     nnU Vs/ s H  n[        XS[        U 5       5      U4PM     nnUR                  5         US   u  pgU[        [        U 5      -  :  a  / $ / nU H  u  pX:X  a  UR                  U
5        M    U$    U$ s  snf s  snf )z4Returns helpful similar matches for an invalid flag.   =r   )lensplit_damerau_levenshteinsort _SUGGESTION_ERROR_RATE_THRESHOLDappend)attemptlongopt_listvoption_namesoption	distancesleast_errors_suggestionserrorsr   s              r   get_flag_suggestionsrn      s     	\QlI+78<a''#,q/<,8
 *+)6 %WQs7|.DEvN)  + ..aL/,5GDDI+lf	  
 
) 9+s   B< #Cc                 (   ^^ 0 mUU4S jmT" X5      $ )z6Returns Damerau-Levenshtein edit distance from a to b.c           
        > X4T;   a  TX4   $ U (       d  [        U5      nOU(       d  [        U 5      nO[        T" U SS U5      S-   T" XSS 5      S-   T" U SS USS 5      U S   US   :g  -   5      n[        U 5      S:  a@  [        U5      S:  a1  U S   US   :X  a%  U S   US   :X  a  T" U SS USS 5      S-   nX#:  a  UnUTX4'   U$ )z5Recursively defined string distance with memoization.r   Nr   r\   )r^   min)xydtdistancememos       r   rv   &_damerau_levenshtein.<locals>.distance   s    	v~!$Z
a&a
a&a

1QR5!
q
 
1e
q
 
1QR5!AB%
 AaDAaDL
13a 
Q1Q111!A$!A$,QqrUAabE"Q&5!DJHr   r   )abrv   rw   s     @@r   r`   r`      s    	$* 
!r   c                    Uc
  [        5       nUc  SnUc  Un[        U5      U:  a  [        S5      e[        U5      U:  a  [        S5      eU R                  S5      n / n[        R
                  " XUS9n[        R
                  " XUS9nS U R                  5        5        H>  nU(       a!  UR                  UR                  U5      5        OUR                  S5        UnM@     SR                  U5      $ )a2  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.
r4   zLength of indent exceeds lengthz*Length of first line indent exceeds length   )widthinitial_indentsubsequent_indentc              3   @   #    U  H  oR                  5       v   M     g 7fN)strip).0ps     r   	<genexpr>text_wrap.<locals>.<genexpr>6  s     9'8!GGII'8s   
)rZ   r^   
ValueError
expandtabstextwrapTextWrapper
splitlinesextendwraprc   join)textlengthindentfirstline_indentresultwrappersubsequent_wrapper	paragraphs           r   	text_wrapr     s    ( ^F^F[F
6
77	f$
A
BB		$&   vO'++VE :t'89immGLL+,mmB G : 
6	r   c              #     #    [         R                  " U 5       H  u  p#Uc	  SU-  v   M  [        U[        5      (       a  U(       a	  SU-  v   M6  SU-  v   M?  [        U[        [        S5      45      (       a  SU< SU< 3v   Mm   U(       a%  X!;   a   U H  nSU< S[        U5      < 3v   M     M  SU< SSR                  S U 5       5      < 3v   M     g! [         a    SU< SU< 3v    M  f = f7f)	a  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%sr4   z--r]   ,c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r-   )r   items     r   r   $flag_dict_to_args.<locals>.<genexpr>i  s     *G3t99s   )	r5   	iteritemsr7   r9   bytestyper-   r   rU   )flag_mapmulti_flagskeyr0   r   s        r   flag_dict_to_argsr   A  s     , MM(+jc}SL	E4	 	 	sln	EE49-	.	.e$$'3-d"CI..  !#((*G*G"GH
H% ,&  '&&'s6   BC7*C1C73"CC7C40C73C44C7c                 b   U (       d  gSnU R                  5       R                  5       nUnUSS  H=  nUR                  5       nU(       d  M  [        U[	        U5      [	        U5      -
  5      nM?     US   R                  5       /nX1:  a-  USS  H$  nUR                  XCS R                  5       5        M&     U(       a-  US   (       d#  UR                  5         U(       a  US   (       d  M#  U(       a.  US   (       d$  UR                  S5        U(       a  US   (       d  M$  SR                  U5      $ )zRemoves 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.
r4   i    r   Nr   r   )
r   r   lstriprq   r^   r   rc   rstrippopr   )	docstring
max_indentlinesr   linestrippedtrimmeds          r   trim_docstringr   o  s    
 * 


 
+
+
-% &ABid{{}Hx63t9s8}45f 
 1X^^'ab	nnT']))+,  	KKM 	
KKN 	

 
7	r   c                     U R                  5       n [        R                  " S[        R                  5      nUR	                  SU 5      n [        U 5      n [        R                  " SSU [        R                  S9n U $ )z0Takes a __doc__ string and reformats it as help.z^[ 	]+$r4   z(?<=\S)\n(?=\S) )flags)r   recompileMr<   r   )r@   whitespace_only_lines     r   doc_to_helpr     sd     			# J5  S)# 	s# 	!32448#	*r   c                 h    [         [        L a  [        U [        5      $ [        U [         [        45      $ r   )r-   r   r7   
basestring)maybe_strings    r   is_bytes_or_stringr     s'    E\lJ//lS%L11r   )Nr4   Nr   ),r   
__future__r   r   r   collectionsrS   r   rO   r   r   rK   ImportErrorrJ   r5   	six.movesr   rL   rQ   rb   r   r;   setr#   r   r   r$   SPECIAL_FLAGSFLAGS_MODULE
namedtupler
   r   r)   r+   r1   rC   rZ   rn   r`   r   r   r   r   r   r   r   r   <module>r      s!   A &  %  	 	  
      $(  
 ::NP  2ckk(3456   13GHM$.,:
48$:86r+'\'T42m  
%
  's"   C C CCCC