
    RC                        d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
 ddl	mZ dd	l	mZ ddlZej                   G d
 de             Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)zContains Flag class - information about single command-line flag.

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)abc)_argument_parser)_exceptions)_helpersc                       e Zd ZdZ	 	 	 ddZed        Zej                  d        Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zy)Flaga	  Information about a command-line flag.

  'Flag' objects define the following fields:
    .name - the name for this flag;
    .default - the default value for this flag;
    .default_unparsed - the unparsed default value for this flag.
    .default_as_str - default value as repr'd string, e.g., "'true'" (or None);
    .value - the most recent parsed value of this flag; set by parse();
    .help - a help string or None if no help is available;
    .short_name - the single letter alias for this flag (or None);
    .boolean - if 'true', this flag does not accept arguments;
    .present - true if this flag was parsed from command line flags;
    .parser - an ArgumentParser object;
    .serializer - an ArgumentSerializer object;
    .allow_override - the flag may be redefined without raising an error, and
                      newly defined flag overrides the old one.
    .allow_override_cpp - use the flag from C++ if available; the flag
                          definition is replaced by the C++ flag after init;
    .allow_hide_cpp - use the Python flag despite having a C++ flag with
                      the same name (ignore the C++ flag);
    .using_default_value - the flag value has not been set by user;
    .allow_overwrite - the flag may be parsed more than once without raising
                       an error, the last set value will be used;
    .allow_using_method_names - whether this flag can be defined even if it has
                                a name that conflicts with a FlagValues method.

  The only public method of a 'Flag' object is parse(), but it is
  typically only called by a 'FlagValues' object.  The parse() method is
  a thin wrapper around the 'ArgumentParser' parse() method.  The parsed
  value is saved in .value, and the .present attribute is updated.  If
  this flag was already present, an Error is raised.

  parse() is also called during __init__ to parse the default value and
  initialize the .value attribute.  This enables other python modules to
  safely use flags even if the __main__ module neglects to parse the
  command line arguments.  The .present attribute is cleared after
  __init__ parsing.  If the default value is set to None, then the
  __init__ parsing step is skipped and the .value attribute is
  initialized to None.

  Note: The default value is also presented to the user in the help
  string, so it is important that it be a legal value for this flag.
  Nc                 Z   || _         |sd}|| _        || _        || _        d| _        || _        || _        || _        |	| _        |
| _	        || _
        || _        d| _        d | _        g | _        | j                  r!| j                  rt        j                   d      | j#                  |       y )N(no help available)r   TzsCan't have both allow_hide_cpp (means use Python flag) and allow_override_cpp (means use C++ flag after InitGoogle))namehelp
short_namebooleanpresentparser
serializerallow_overrideallow_override_cppallow_hide_cppallow_overwriteallow_using_method_namesusing_default_value_value
validatorsr   Error_set_default)selfr   r   r   defaulthelp_stringr   r   r   r   r   r   r   s                +platform/bq/third_party/absl/flags/_flag.py__init__zFlag.__init__Q   s     DI)kDI DODLDLDK DO(D0D(D*D$<D!#DDKDOt66EF F 	g    c                     | j                   S Nr   r   s    r"   valuez
Flag.valuep   s    ;;r$   c                     || _         y r&   r'   r   r)   s     r"   r)   z
Flag.valuet   s	    DKr$   c                 *    t        t        |             S r&   )hashidr(   s    r"   __hash__zFlag.__hash__x   s    4>r$   c                 
    | |u S r&    r   others     r"   __eq__zFlag.__eq__{   s    5=r$   c                 \    t        |t              rt        |       t        |      k  S t        S r&   )
isinstancer   r.   NotImplementedr2   s     r"   __lt__zFlag.__lt__~   s%    %X5	!!r$   c                     t        d      )Nzcan't pickle Flag objects)	TypeErrorr(   s    r"   __getstate__zFlag.__getstate__   s    
/
00r$   c                 D    t        dt        |       j                  z        )Nz>%s does not support shallow copies. Use copy.deepcopy instead.)r:   type__name__r(   s    r"   __copy__zFlag.__copy__   s)    
 137:3F3FG H Hr$   c                     t         j                  t        |             }t        j                  | j
                  |      |_        |S r&   )object__new__r=   copydeepcopy__dict__)r   memoresults      r"   __deepcopy__zFlag.__deepcopy__   s/    ^^DJ'FmmDMM48FOMr$   c                     |y| j                   r$t        | j                   j                  |            S | j                  r|rt        d      S t        d      S t        t	        j
                  |            S )z$Returns parsed flag value as string.Ntruefalse)r   repr	serializer   r	   str_or_unicoder+   s     r"   _get_parsed_value_as_stringz Flag._get_parsed_value_as_string   s_    }$//++E233||	F|G}''.//r$   c                     | j                   r>| j                  s2t        j                  d| j                  d|d| j
                        | j                  |      | _        | xj                   dz  c_         y)z}Parses string and sets flag value.

    Args:
      argument: str or the correct flag value type, argument to be parsed.
    flag --=z: already defined as    N)r   r   r   IllegalFlagValueErrorr   r)   _parse)r   arguments     r"   parsez
Flag.parse   sZ     ||D00--ii4::/0 0 X&DJLLALr$   c           	          	 | j                   j                  |      S # t        t        f$ r-}t	        j
                  d| j                  d|d|      d}~ww xY w)zInternal parse function.

    It returns the parsed value, and does not modify class states.

    Args:
      argument: str or the correct flag value type, argument to be parsed.

    Returns:
      The parsed value.
    rQ   rR   z: N)r   rW   r:   
ValueErrorr   rT   r   )r   rV   es      r"   rU   zFlag._parse   sR    9[[x((z" 9-- $		8Q
79 99s    A(AAc                 B    | j                   | _        d| _        d| _        y )NTr   )r    r)   r   r   r(   s    r"   unparsezFlag.unparse   s    DJ#DDLr$   c                 8    | j                  | j                        S )zSerializes the flag.)
_serializer)   r(   s    r"   rM   zFlag.serialize   s    ??4::&&r$   c                    |y| j                   r |rd| j                  z  S d| j                  z  S | j                  s"t        j                  d| j                  z        d| j                  d| j                  j                  |      S )zInternal serialize function. z--%sz--no%s"Serializer not present for flag %sz--rR   )r   r   r   r   r   rM   r+   s     r"   r^   zFlag._serialize   s}    }||			!!$))##__0499<> 	>  ))T__%>%>u%EFFr$   c                     || _         |d| _        n| j                  |      | _        | j                  | j                        | _        | j
                  r| j                  | _        yy)z@Changes the default value (and current value too) for this Flag.N)default_unparsedr    _parse_from_defaultrO   default_as_strr   r)   r+   s     r"   r   zFlag._set_default   sX    !D}dl--e4dl::4<<HD<<dj  r$   c                 $    | j                  |      S r&   )rU   r+   s     r"   rd   zFlag._parse_from_default   s    ;;ur$   c                 6    | j                   j                         S )a   Returns a str that describes the type of the flag.

    NOTE: we use strings, and not the types.*Type constants because
    our flags can have more exotic types, e.g., 'comma separated list
    of strings', 'whitespace separated list of strings', etc.
    r   	flag_typer(   s    r"   ri   zFlag.flag_type   s     ;;  ""r$   c                 f   |j                  d      }|r&|j                  t        j                  |dd             |j                  t        j                  |d|             |j                  t        j                  |d| j                               | j
                  r0|j                  t        j                  |d| j
                               | j                  r0|j                  t        j                  |d| j                               | j                  rOt        | j                  t              s5| j                  &| j                  j                  | j                        }nd}n| j                  }|j                  t        j                  |d	|             | j                  | j                        }|j                  t        j                  |d
|             |j                  t        j                  |d| j                                      | j                  |      D ]  }|j                  |        |S )a6  Returns an XML element that contains this flag's information.

    This is information that is relevant to all flags (e.g., name,
    meaning, etc.).  If you defined a flag that has some other pieces of
    info, then please override _ExtraXMLInfo.

    Please do NOT override this method.

    Args:
      doc: minidom.Document, the DOM document it should create nodes from.
      module_name: str,, the name of the module that defines this flag.
      is_key: boolean, True iff this flag is key for main module.

    Returns:
      A minidom.Element instance.
    flagkeyyesfiler   r   meaningr`   r    currentr=   )createElementappendChildr	   create_xml_dom_elementr   r   r   r   r6   r    strrM   _serialize_value_for_xmlr)   ri   _extra_xml_dom_elements)r   docmodule_nameis_keyelementdefault_serializedvalue_serializedrZ   s           r"   _create_xml_dom_elementzFlag._create_xml_dom_element   s   " 'G(99#ueLM77V[" # 77VTYYOP(99
|T__. /yy(99
y$))% &
 z$,,<		!!__66t||D<<77Y*, -44TZZ@77Y(* +77VT^^%' ( ))#.! /Nr$   c                     |S )z:Returns the serialized value, for use in an XML help text.r1   r+   s     r"   ru   zFlag._serialize_value_for_xml  s    Lr$   c                 8    | j                   j                  |      S )a   Returns extra info about this flag in XML.

    "Extra" means "not already included by _create_xml_dom_element above."

    Args:
      doc: minidom.Document, the DOM document it should create nodes from.

    Returns:
      A list of minidom.Element.
    )r   _custom_xml_dom_elements)r   rw   s     r"   rv   zFlag._extra_xml_dom_elements#  s     ;;//44r$   )NFFFFTFF)r>   
__module____qualname____doc__r#   propertyr)   setterr/   r4   r8   r;   r?   rH   rO   rW   rU   r\   rM   r^   r   rd   ri   r}   ru   rv   r1   r$   r"   r   r   #   s    *Z ?D8=>C>   	<< 
1H
09"
'G	 #2h5r$   r   c                   $     e Zd ZdZd fd	Z xZS )BooleanFlaga  Basic boolean flag.

  Boolean flags do not take any arguments, and their value is either
  True (1) or False (0).  The false value is specified on the command
  line by prepending the word 'no' to either the long or the short flag
  name.

  For example, if a Boolean flag was created whose long name was
  'update' and whose short name was 'x', then this flag could be
  explicitly unset through either --noupdate or --nox.
  c           	      b    t        j                         }t        t        |   |d ||||dfi | y )NrS   )r   BooleanParsersuperr   r#   )r   r   r    r   r   argsp	__class__s          r"   r#   zBooleanFlag.__init__@  s7    &&(A	+t%	4wj!=7;=r$   r&   )r>   r   r   r   r#   __classcell__r   s   @r"   r   r   3  s    
= =r$   r   c                   ,     e Zd ZdZ	 d fd	Zd Z xZS )EnumFlagzFBasic enum flag; its value can be any string from list of enum_values.c                     t        j                  ||      }t        j                         }	t        t        |   ||	||||fi | ddj                  |      d| j                  | _        y )N<|>: )r   
EnumParserArgumentSerializerr   r   r#   joinr   )r   r   r    r   enum_valuesr   case_sensitiver   r   gr   s             r"   r#   zEnumFlag.__init__I  s`    ##K@A++-A	(D"	1dGT:7157!hh{3TYY?DIr$   c                     g }| j                   j                  D ](  }|j                  t        j                  |d|             * |S N
enum_value)r   r   appendr	   rs   r   rw   elementsr   s       r"   rv   z EnumFlag._extra_xml_dom_elementsQ  sB    Hkk--
ooh55
|Z) * . Or$   )NTr>   r   r   r   r#   rv   r   r   s   @r"   r   r   F  s    N 04@r$   r   c                   .     e Zd ZdZ	 	 d fd	Zd Z xZS )EnumClassFlagz5Basic enum flag; its value is an enum class's member.c                     t        j                  ||      }t        j                  |       }	t        t        |   ||	||||fi | ddj                  |j                        d| j                  | _        y )Nr   )	lowercaser   r   r   )	r   EnumClassParserEnumClassSerializerr   r   r#   r   member_namesr   )r   r   r    r   
enum_classr   r   r   r   r   r   s             r"   r#   zEnumClassFlag.__init__\  sn     	((>	3A,,>7IJA	-'	1dGT:7157!hhq~~6		BDIr$   c                     g }| j                   j                  j                  j                         D ](  }|j	                  t        j                  |d|             * |S r   r   r   __members__keysr   r	   rs   r   s       r"   rv   z%EnumClassFlag._extra_xml_dom_elementsl  R    Hkk,,88==?
ooh55
|Z) * @ Or$   )NFr   r   s   @r"   r   r   Y  s    = C r$   r   c                   H     e Zd ZdZ fdZd Z fdZ fdZd Zd Z	 xZ
S )	MultiFlagae  A flag that can appear multiple time on the command-line.

  The value of such a flag is a list that contains the individual values
  from all the appearances of that flag on the command-line.

  See the __doc__ for Flag for most behavior of this class.  Only
  differences in behavior are described here:

    * The default value may be either a single value or an iterable of values.
      A single value is transformed into a single-item list of that value.

    * The value of the flag is always a list, even if the option was
      only supplied once, and even if the default value is a single
      value
  c                 V    t        t        | 
  |i | | xj                  dz  c_        y )N4;
    repeat this option to specify a list of values)r   r   r#   r   )r   r   kwargsr   s      r"   r#   zMultiFlag.__init__  s&    	)T#T4V4IIHHIr$   c                     | j                  |      }| j                  r| j                  j                  |       n|| _        | xj                  t	        |      z  c_        y)a  Parses one or more arguments with the installed parser.

    Args:
      arguments: a single argument or a list of arguments (typically a
        list of default values); a single argument is converted
        internally into a list containing one item.
    N)rU   r   r)   extendlen)r   	arguments
new_valuess      r"   rW   zMultiFlag.parse  sD     Y'J||
jj
#djLLC
O#Lr$   c                     t        |t        j                        r%t        |t        j                        st        |      }t        |t
              s|g}|D cg c]  }t        t        | #  |       c}S c c}w r&   )	r6   r   Iterablesixstring_typeslistr   r   rU   )r   r   itemr   s      r"   rU   zMultiFlag._parse  sa    9cll+y#"2"23y/ii& +i<EFIDE)T)$/IFFFs   A5c                     | j                   s"t        j                  d| j                  z        |y|D cg c]  }t        t
        |   |       }}dj                  |      S c c}w )See base class.ra   r`   
)r   r   r   r   r   r   r^   r   )r   r)   
value_itemserialized_itemsr   s       r"   r^   zMultiFlag._serialize  st    ??
.
:< <} INHM*i)*5   99%&&	s   A$c                 <    d| j                   j                         z   S )r   zmulti rh   r(   s    r"   ri   zMultiFlag.flag_type  s    dkk++---r$   c                     g }t        | j                  d      rA| j                  j                  D ](  }|j                  t	        j
                  |d|             * |S )Nr   r   )hasattrr   r   r   r	   rs   r   s       r"   rv   z!MultiFlag._extra_xml_dom_elements  sP    Ht{{M*//*77z+ 	, 0 Or$   )r>   r   r   r   r#   rW   rU   r^   ri   rv   r   r   s   @r"   r   r   t  s(     I$G'.r$   r   c                   2     e Zd ZdZ	 d fd	Zd Zd Z xZS )MultiEnumClassFlagzA multi_enum_class flag.

  See the __doc__ for MultiFlag for most behaviors of this class.  In addition,
  this class knows how to handle enum.Enum instances as values for this flag
  type.
  c                     t        j                  ||      }t        j                  d|       }t        t        |   |||||fi | ddj                  |j                        d|xs dd| _        y )	Nr   ,)list_sepr   r   r   r   r   r   )	r   r   EnumClassListSerializerr   r   r#   r   r   r   )
r   r   r    r!   r   r   r   r   r   r   s
            r"   r#   zMultiEnumClassFlag.__init__  s     	((>	3A00N 2	4A	
d,	1dG[2,02 
!..	!;#G2G#G	I 	Ir$   c                     g }| j                   j                  j                  j                         D ](  }|j	                  t        j                  |d|             * |S r   r   r   s       r"   rv   z*MultiEnumClassFlag._extra_xml_dom_elements  r   r$   c                 H    || j                   j                  |      }|S d}|S )r   r`   )r   rM   )r   r)   r|   s      r"   ru   z+MultiEnumClassFlag._serialize_value_for_xml  s3    2259  r$   r   )r>   r   r   r   r#   rv   ru   r   r   s   @r"   r   r     s     $J"r$   r   )r   
__future__r   r   r   rC   	functoolsabsl._collections_abcr   
absl.flagsr   r   r	   r   total_orderingrA   r   r   r   r   r   r   r1   r$   r"   <module>r      s    '  %   % ' "  
 L56 L5 L5^=$ =&t &D 6I IX& &r$   