
    S                        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	J
r
  SSKrS r " S S	\5      r " S
 S\R                  " \\5      5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      rg)(zContains base classes used to parse and convert arguments.

Do NOT import this module directly. Import the flags package and use the
aliases defined at the package level instead.
    )absolute_import)division)print_functionN)_helpersc                 n    [        U [        R                  5      =(       a    [        U [        5      (       + $ )z7Returns True if instance is an integer, and not a bool.)
isinstancesixinteger_typesbool)instances    6platform/bq/third_party/absl/flags/_argument_parser.py_is_integer_typer   "   s)    
Xs00
1 )4(
(*    c                   "    \ rS rSrSr0 rS rSrg)_ArgumentParserCache(   z?Metaclass used to cache and share argument parsers among flags.c                 6   U(       a  [         R                  " U /UQ70 UD6$ U R                  nU 4[        U5      -   n X4   $ ! [         a*    UR                  U[         R                  " U /UQ76 5      s $ [         a    [         R                  " U /UQ76 s $ f = f)a#  Returns an instance of the argument parser cls.

This method overrides behavior of the __new__ methods in
all subclasses of ArgumentParser (inclusive). If an instance
for cls with the same set of arguments exists, this instance is
returned, otherwise a new instance is created.

If any keyword arguments are defined, or the values in args
are not hashable, this method always returns a new instance of
cls.

Args:
  *args: Positional initializer arguments.
  **kwargs: Initializer keyword arguments.

Returns:
  An instance of cls, shared or new.
)type__call__
_instancestupleKeyError
setdefault	TypeError)clsargskwargs	instanceskeys        r   r   _ArgumentParserCache.__call__-   s    & ]]30000..iFU4[ c)~ D##Cs)BT)BCC ) }}S(4(()s   A 1B5 BB N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__r!   r   r   r   r   (   s    G* )r   r   c                   .    \ rS rSrSrSrS rS rS rSr	g)	ArgumentParserb   a  Base class used to parse and convert arguments.

The parse() method checks to make sure that the string argument is a
legal value and convert it to a native type.  If the value cannot be
converted, it should throw a 'ValueError' exception with a human
readable explanation of why the value is illegal.

Subclasses should also define a syntactic_help string which may be
presented to the user to describe the form of the legal values.

Argument parser classes must be stateless, since instances are cached
and shared between flags. Initializer arguments are allowed, but all
member variables must be derived from initializer arguments only.
 c                     [        U[        R                  5      (       d#  [        SR	                  [        U5      5      5      eU$ )aQ  Parses the string argument and returns the native value.

By default it returns its argument unmodified.

Args:
  argument: string argument passed in the commandline.

Raises:
  ValueError: Raised when it fails to parse the argument.
  TypeError: Raised when the argument has the wrong type.

Returns:
  The parsed value in native type.
z'flag value must be a string, found "{}")r   r	   string_typesr   formatr   selfarguments     r   parseArgumentParser.parset   s>     h 0 011?FF
x.  Or   c                     g)z3Returns a string representing the type of the flag.stringr!   r0   s    r   	flag_typeArgumentParser.flag_type   s    r   c                     A/ $ )zReturns a list of minidom.Element to add additional flag information.

Args:
  doc: minidom.Document, the DOM document it should create nodes from.
r!   )r0   docs     r   _custom_xml_dom_elements'ArgumentParser._custom_xml_dom_elements   s     	Ir   r!   N)
r"   r#   r$   r%   r&   syntactic_helpr2   r7   r;   r'   r!   r   r   r)   r)   b   s     .(r   r)   c                       \ rS rSrSrS rSrg)ArgumentSerializer   zABase class for generating string representations of a flag value.c                 .    [         R                  " U5      $ )z)Returns a serialized string of the value.)r   str_or_unicoder0   values     r   	serializeArgumentSerializer.serialize   s    ""5))r   r!   N)r"   r#   r$   r%   r&   rE   r'   r!   r   r   r?   r?      s
    I*r   r?   c                   0    \ rS rSrSrS rS rS rS rSr	g)	NumericParser   zYParser of numeric values.

Parsed value may be bounded to a given upper and lower bound.
c                     U R                   SL=(       a    XR                   :  =(       d#    U R                  SL=(       a    XR                  :  $ )z7Returns whether the value is outside the bounds or not.N)lower_boundupper_bound)r0   vals     r   is_outside_boundsNumericParser.is_outside_bounds   sF    T)Dc4D4D.D FT)Dc4D4D.DGr   c                     U R                  U5      nU R                  U5      (       a  [        U< SU R                  < 35      eU$ )See base class.z is not )convertrN   
ValueErrorr=   )r0   r1   rM   s      r   r2   NumericParser.parse   s<    
,,x
 Cc""d.A.ABCCJr   c                    / nU R                   b1  UR                  [        R                  " USU R                   5      5        U R                  b1  UR                  [        R                  " USU R                  5      5        U$ )NrK   rL   )rK   appendr   create_xml_dom_elementrL   )r0   r:   elementss      r   r;   &NumericParser._custom_xml_dom_elements   sp    H#ooh55
}d..0 1#ooh55
}d..0 1Or   c                     [         e)a  Returns the correct numeric value of argument.

Subclass must implement this method, and raise TypeError if argument is not
string or has the right numeric type.

Args:
  argument: string argument passed in the commandline, or the numeric type.

Raises:
  TypeError: Raised when argument is not a string or the right numeric type.
  ValueError: Raised when failed to convert argument to the numeric value.
)NotImplementedErrorr/   s     r   rR   NumericParser.convert   s
     r   r!   N)
r"   r#   r$   r%   r&   rN   r2   r;   rR   r'   r!   r   r   rH   rH      s    
G
r   rH   c                   j   ^  \ rS rSrSrSrSrSR                  \\45      rS
U 4S jjr	S r
S rS	rU =r$ )FloatParser   z`Parser of floating point values.

Parsed value may be bounded to a given upper and lower bound.
anumber c                 B  > [         [        U ]  5         Xl        X l        U R
                  nUb  Ub  U< SU< SU< S3nOYUS:X  a  SU R                  -  nOCUS:X  a  SU R                  -  nO-Ub  U R                  < SU< 3nOUb  U R                  < SU< 3nX0l        g )	N in the range [, ]r   a non-negative %sa non-positive %s <=  >= )superr^   __init__rK   rL   r=   number_namer0   rK   rL   sh	__class__s       r   rl   FloatParser.__init__   s    	+t%'""			B;#:*,k;Gb		!1!11b		!1!11b		 ));7b		 ));7br   c                     [        U5      (       d4  [        U[        5      (       d  [        U[        R                  5      (       a  [        U5      $ [        SR                  [        U5      5      5      e)z$Returns the float value of argument.z7Expect argument to be a string, int, or float, found {})r   r   floatr	   r-   r   r.   r   r/   s     r   rR   FloatParser.convert   sX    ""j5&A&A8S--..8_
C
J
J8n r   c                     g)rQ   rs   r!   r6   s    r   r7   FloatParser.flag_type   s    r   rK   r=   rL   NNr"   r#   r$   r%   r&   number_articlerm   joinr=   rl   rR   r7   r'   __classcell__rp   s   @r   r^   r^      s;     .+88^[9:." r   r^   c                   j   ^  \ rS rSrSrSrSrSR                  \\45      rS
U 4S jjr	S r
S rS	rU =r$ )IntegerParser   z[Parser of an integer value.

Parsed value may be bounded to a given upper and lower bound.
anintegerrb   c                   > [         [        U ]  5         Xl        X l        U R
                  nUb  Ub  U< SU< SU< S3nOUS:X  a  SU R                  -  nOoUS:X  a  SU R                  -  nOYUS:X  a  S	U R                  -  nOCUS:X  a  S
U R                  -  nO-Ub  U R                  < SU< 3nOUb  U R                  < SU< 3nX0l        g )Nrd   re   rf      za positive %sza negative %sr   rg   rh   ri   rj   )rk   r   rl   rK   rL   r=   rm   rn   s       r   rl   IntegerParser.__init__   s    	-')""			B;#:*,k;Gb		T---b		T---b		!1!11b		!1!11b		 ));7b		 ));7br   c                 "   [        U5      (       a  U$ [        U[        R                  5      (       a<  Sn[	        U5      S:  a   US   S:X  a  US   S:X  a  SnOUS   S:X  a  S	n[        X5      $ [        S
R                  [        U5      5      5      e)z"Returns the int value of argument.
      r   0r   o   x   z/Expect argument to be a string or int, found {})	r   r   r	   r-   lenintr   r.   r   )r0   r1   bases      r   rR   IntegerParser.convert  s    !!o	Hc..	/	/d	X	x{c1A;#$a[C$  GNN
x.  r   c                     g)rQ   r   r!   r6   s    r   r7   IntegerParser.flag_type!  s    r   rw   rx   ry   r}   s   @r   r   r      s;     .+88^[9:.*  r   r   c                   $    \ rS rSrSrS rS rSrg)BooleanParseri&  zParser of boolean values.c                 >   [        U[        R                  5      (       a6  UR                  5       S;   a  gUR                  5       S;   a  g[	        SU5      e[        U[        R
                  5      (       a  [        U5      nX:X  a  U$ [	        SU5      e[        SU5      e)rQ   )truet1T)falsefr   Fz$Non-boolean argument to boolean flag)r   r	   r-   lowerrS   r
   r   r   )r0   r1   
bool_values      r   r2   BooleanParser.parse)  s    (C,,--		/	/>>22?JJ	Hc//	0	0 >j		?JJ
:H
EEr   c                     g)rQ   r   r!   r6   s    r   r7   BooleanParser.flag_type=  s    r   r!   N)r"   r#   r$   r%   r&   r2   r7   r'   r!   r   r   r   r   &  s    !F(r   r   c                   <   ^  \ rS rSrSrSU 4S jjrS rS rSrU =r	$ )
EnumParseriB  z@Parser of a string enum value (a string value from a given set).c                    > U(       d  [        SR                  U5      5      e[        [        U ]  5         Xl        X l        g)zInitializes EnumParser.

Args:
  enum_values: [str], a non-empty list of string values in the enum.
  case_sensitive: bool, whether or not the enum is to be case-sensitive.

Raises:
  ValueError: When enum_values is empty.
z'enum_values cannot be empty, found "{}"N)rS   r.   rk   r   rl   enum_valuescase_sensitive)r0   r   r   rp   s      r   rl   EnumParser.__init__E  s>     
3
:
:;
GI I	*d$&"(r   c                    U R                   (       a8  XR                  ;  a'  [        SSR                  U R                  5      -  5      eU$ UR	                  5       U R                   Vs/ s H  o"R	                  5       PM     sn;  a'  [        SSR                  U R                  5      -  5      eU R                   Vs/ s H)  nUR	                  5       UR	                  5       :X  d  M'  UPM+     snS   $ s  snf s  snf )zDetermines validity of argument and returns the correct element of enum.

Args:
  argument: str, the supplied flag value.

Returns:
  The first matching element from enum_values.

Raises:
  ValueError: Raised when argument didn't match anything in enum.
zvalue should be one of <%s>|r   )r   r   rS   r{   upper)r0   r1   rD   s      r   r2   EnumParser.parseV  s     	))	)6$"2"234 5 	5 		T=M=M!N=ME++-=M!N	N6$"2"234 5 	5 $(#3#3 6#3%;;=HNN$44 #3 6679 	9	 "O6s   'C1;&C6%C6c                     g)rQ   zstring enumr!   r6   s    r   r7   EnumParser.flag_typep  s    r   )r   r   T
r"   r#   r$   r%   r&   rl   r2   r7   r'   r|   r}   s   @r   r   r   B  s    H)"94 r   r   c                   L   ^  \ rS rSrSrSU 4S jjr\S 5       rS rS r	Sr
U =r$ )	EnumClassParseriu  zParser of an Enum class member.c                   > SSK n[        XR                  5      (       d  [        SR	                  U5      5      eUR
                  (       d  [        SR	                  U5      5      eU(       dt  [        R                  " S UR
                   5       5      nUR                  5        VVs1 s H  u  pVUS:  d  M  UiM     nnnU(       a  [        SR	                  U5      5      e[        [        U ]3  5         Xl        X l        U(       a  [        UR
                  5      U l        g[        S UR
                   5       5      U l        gs  snnf )	aX  Initializes EnumParser.

Args:
  enum_class: class, the Enum class with all possible flag values.
  case_sensitive: bool, whether or not the enum is to be case-sensitive. If
    False, all member names must be unique when case is ignored.

Raises:
  TypeError: When enum_class is not a subclass of Enum.
  ValueError: When enum_class is empty.
r   Nz{} is not a subclass of Enum.z.enum_class cannot be empty, but "{}" is empty.c              3   @   #    U  H  oR                  5       v   M     g 7fNr   .0names     r   	<genexpr>+EnumClassParser.__init__.<locals>.<genexpr>  s      $;#94**,,#9   r   z7Duplicate enum values for {} using case_sensitive=Falsec              3   @   #    U  H  oR                  5       v   M     g 7fr   r   r   s     r   r   r     s      !;#94**,,#9r   )enum
issubclassEnumr   r.   __members__rS   collectionsCounteritemsrk   r   rl   
enum_class_case_sensitiver   _member_names)	r0   r   r   r   membersmembercountduplicate_keysrp   s	           r   rl   EnumClassParser.__init__x  s    j)),,5<<ZHII!!Gz*, ,## $;#-#9#9$; ;g '.mmo&5]V&o   
ELL ! 	! 
/4)+ O) !7!78d  !;#-#9#9!; ;ds   &E6Ec                     U R                   $ )z<The accepted enum names, in lowercase if not case sensitive.)r   r6   s    r   member_namesEnumClassParser.member_names  s     r   c                   ^ [        XR                  5      (       a  U$ [        U[        R                  5      (       d$  [	        SR                  XR                  5      5      e[        U R                  U R                  S9R                  U5      mU R                  (       a  U R                  T   $ [        U4S jU R                  R                  R                  5        5       5      $ )a  Determines validity of argument and returns the correct element of enum.

Args:
  argument: str or Enum class member, the supplied flag value.

Returns:
  The first matching Enum class member in Enum class.

Raises:
  ValueError: Raised when argument didn't match anything in enum.
z4{} is not an enum member or a name of a member in {})r   c              3   t   >#    U  H-  u  pUR                  5       TR                  5       :X  d  M)  Uv   M/     g 7fr   r   )r   r   rD   r   s      r   r   (EnumClassParser.parse.<locals>.<genexpr>  s0      2+NKDZZ\SYY[0 %+Ns   (8	8)r   r   r	   r-   rS   r.   r   r   r   r2   nextr   r   )r0   r1   r   s     @r   r2   EnumClassParser.parse  s     (OO,,o#"2"233
@
G
G)* * 4+?+?AAFx __S!!  24??+F+F+L+L+N 2 2 2r   c                     g)rQ   z
enum classr!   r6   s    r   r7   EnumClassParser.flag_type  s    r   )r   r   r   r   )r"   r#   r$   r%   r&   rl   propertyr   r2   r7   r'   r|   r}   s   @r   r   r   u  s/    '';R  28 r   r   c                        \ rS rSrS rS rSrg)ListSerializeri  c                     Xl         g r   list_sepr0   r   s     r   rl   ListSerializer.__init__      Mr   c                     U R                   R                  U Vs/ s H  n[        R                  " U5      PM     sn5      $ s  snf rQ   )r   r{   r   rB   )r0   rD   r   s      r   rE   ListSerializer.serialize  s4    ==5I5ax66q95IJJIs    Ar   Nr"   r#   r$   r%   rl   rE   r'   r!   r   r   r   r     s    Kr   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )EnumClassListSerializeri  zA serializer for MultiEnumClass flags.

This serializer simply joins the output of `EnumClassSerializer` using a
provided separator.
c                 L   > [         [        U ]  U5        [        S0 UD6U l        g)zInitializes EnumClassListSerializer.

Args:
  list_sep: String to be used as a separator when serializing
  **kwargs: Keyword arguments to the `EnumClassSerializer` used to serialize
    individual values.
Nr!   )rk   r   rl   EnumClassSerializer_element_serializer)r0   r   r   rp   s      r   rl    EnumClassListSerializer.__init__  s%     

!41(;2<V<Dr   c                    ^  [        U[        5      (       a%  T R                  R                  U 4S jU 5       5      $ T R                  R                  U5      $ )rQ   c              3   Z   >#    U  H   nTR                   R                  U5      v   M"     g 7fr   )r   rE   )r   r   r0   s     r   r   4EnumClassListSerializer.serialize.<locals>.<genexpr>  s)       @9>A$
"
"
,
,Q
/
/s   (+)r   listr   r{   r   rE   rC   s   ` r   rE   !EnumClassListSerializer.serialize  sQ    %]]  @9> @ @ @ %%//66r   )r   )	r"   r#   r$   r%   r&   rl   rE   r'   r|   r}   s   @r   r   r     s    	=7 7r   r   c                        \ rS rSrS rS rSrg)CsvListSerializeri  c                     Xl         g r   r   r   s     r   rl   CsvListSerializer.__init__  r   r   c                    [         R                  (       a  [        R                  " 5       n[        R
                  " X R                  S9nUR                  U Vs/ s H  n[        U5      R                  S5      PM     sn5        UR                  5       R                  S5      R                  5       nO|[        R                  " 5       n[        R
                  " X R                  S9nUR                  U Vs/ s H  n[        U5      PM     sn5        UR                  5       R                  5       n[        R                   " U5      $ s  snf s  snf )z-Serializes a list as a CSV string or unicode.)	delimiterzutf-8)r	   PY2ioBytesIOcsvwriterr   writerowunicodeencodegetvaluedecodestripStringIOstrr   rB   )r0   rD   outputr   r   serialized_values         r   rE   CsvListSerializer.serialize  s    
wwzz|fzz&MM:foo5A5awqz((15AB*11':@@B {{}fzz&MM:foou-u!s1vu-.*002 ""#344 B .s   $E3Er   Nr   r!   r   r   r   r     s    5r   r   c                   $    \ rS rSrSrS rS rSrg)r   i  zHClass for generating string representations of an enum class flag value.c                     Xl         g)zuInitializes EnumClassSerializer.

Args:
  lowercase: If True, enum member names are lowercased during serialization.
N
_lowercase)r0   	lowercases     r   rl   EnumClassSerializer.__init__  s	      Or   c                     [         R                  " UR                  5      nU R                  (       a  UR	                  5       $ U$ )z4Returns a serialized string of the Enum class value.)r   rB   r   r  r   )r0   rD   	as_strings      r   rE   EnumClassSerializer.serialize  s.    ''

3I $9??>Y>r   r  N)r"   r#   r$   r%   r&   rl   rE   r'   r!   r   r   r   r     s    P ?r   r   c                   <   ^  \ rS rSrSrSU 4S jjrS rS rSrU =r	$ )BaseListParseri  zBase class for a parser of lists of strings.

To extend, inherit from this class; from the subclass __init__, call

    BaseListParser.__init__(self, token, name)

where token is a character used to tokenize, and name is a description
of the separator.
c                 |   > U(       d   e[         [        U ]  5         Xl        X l        SU R                  -  U l        g )Nza %s separated list)rk   r  rl   _token_namer=   )r0   tokenr   rp   s      r   rl   BaseListParser.__init__!  s2    K4	.$(*KJ/$**<Dr   c                     [        U[        5      (       a  U$ U(       d  / $ UR                  U R                  5       Vs/ s H  o"R	                  5       PM     sn$ s  snf r   )r   r   splitr  r   )r0   r1   ss      r   r2   BaseListParser.parse(  sG    (D!!oi!)!<=!<Aggi!<===s   Ac                      SU R                   -  $ )rQ   z%s separated list of strings)r  r6   s    r   r7   BaseListParser.flag_type1  s    )DJJ66r   )r  r  r=   rx   r   r}   s   @r   r  r    s    =>7 7r   r  c                   >   ^  \ rS rSrSrU 4S jrS rU 4S jrSrU =r	$ )
ListParseri6  z-Parser for a comma-separated list of strings.c                 .   > [         [        U ]  SS5        g )N,comma)rk   r  rl   )r0   rp   s    r   rl   ListParser.__init__9  s    	*d$S'2r   c           	      P   [        U[        5      (       a  U$ U(       d  / $  [        [        R                  " U/SS95      S    Vs/ s H  o"R	                  5       PM     sn$ s  snf ! [        R
                   a*  n[        SU< SU R                  5       < SU< 35      eSnAff = f)z3Parses argument as comma-separated list of strings.T)strictr   zUnable to parse the value z as a z: N)r   r   r   readerr   ErrorrS   r7   )r0   r1   r  es       r   r2   ListParser.parse<  s    (D!!oi	<#'

H:d(K#LQ#OP#Oa	#OPPPYY < $dnn&6; < 	<<s)   $A' A"A' "A' 'B%;%B  B%c           	         > [         [        U ]  U5      nUR                  [        R
                  " US[        S5      5      5        U$ )Nlist_separatorr  )rk   r  r;   rV   r   rW   repr)r0   r:   rX   rp   s      r   r;   #ListParser._custom_xml_dom_elementsN  s>    Z?DHOOH33tCy* +Or   r!   
r"   r#   r$   r%   r&   rl   r2   r;   r'   r|   r}   s   @r   r  r  6  s    53<$ r   r  c                   B   ^  \ rS rSrSrSU 4S jjrS rU 4S jrSrU =r	$ )WhitespaceSeparatedListParseriU  z2Parser for a whitespace-separated list of strings.c                 d   > Xl         U R                   (       a  SOSn[        [        U ]  SU5        g)zInitializer.

Args:
  comma_compat: bool, whether to support comma as an additional separator.
      If False then only whitespace is supported.  This is intended only for
      backwards compatibility with flags that used to be comma-separated.
zwhitespace or comma
whitespaceN)_comma_compatrk   r,  rl   )r0   comma_compatr   rp   s      r   rl   &WhitespaceSeparatedListParser.__init__X  s-     &$($6$6 LD	
'7dCr   c                     [        U[        5      (       a  U$ U(       d  / $ U R                  (       a  UR                  SS5      nUR	                  5       $ )zParses argument as whitespace-separated list of strings.

It also parses argument as comma-separated list of strings if requested.

Args:
  argument: string argument passed in the commandline.

Returns:
  [str], the parsed flag value.
r  rb   )r   r   r/  replacer  r/   s     r   r2   #WhitespaceSeparatedListParser.parsed  sF     (D!!oi			##C-^^r   c           
      6  > [         [        U ]  U5      n[        [        R
                  5      nU R                  (       a  UR                  S5        UR                  5         U H3  nUR                  [        R                  " US[        U5      5      5        M5     U$ )Nr  r'  )rk   r,  r;   r   r5   r.  r/  rV   sortr   rW   r(  )r0   r:   rX   
separatorssep_charrp   s        r   r;   6WhitespaceSeparatedListParser._custom_xml_dom_elementsx  s    2D //23 f''(JOOooh55
h1 2  Or   )r/  )Fr*  r}   s   @r   r,  r,  U  s    :
D(
 
r   r,  ) r&   
__future__r   r   r   r   r   r   r5   
absl.flagsr   r	   r   r   r   with_metaclassobjectr)   r?   rH   r^   r   r   r   r   r   r   r   r   r  r  r,  r!   r   r   <module>r>     s	   '  %  
 	   
*%)4 %)t1S''(<fE 1h* *)N )X&- &R0M 0fN 80 0fOn OdK' K7n 765* 52?, ?"7^ 7@ >-N -r   