B s `RC@sdZddlmZddlmZddlmZddlZddlZddlmZddl m Z ddl m Z dd l m Z ddl Z ejGd d d eZGd d d eZGdddeZGdddeZGdddeZGdddeZdS)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@seZdZdZd.ddZeddZejd dZd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd/d(d)Zd*d+Zd,d-ZdS)0Flaga 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. NFTc Cs||_|sd}||_||_||_d|_||_||_||_| |_| |_ | |_ | |_ d|_ d|_ g|_|j rx|jrxtd||dS)Nz(no help available)rTzsCan't have both allow_hide_cpp (means use Python flag) and allow_override_cpp (means use C++ flag after InitGoogle))namehelp short_namebooleanpresentparser serializerallow_overrideallow_override_cppallow_hide_cppallow_overwriteallow_using_method_namesusing_default_value_valueZ validatorsrError _set_default) selfrrr default help_stringr r rrrrrr4/tmp/pip-unpacked-wheel-00lyeop_/absl/flags/_flag.py__init__Qs* z Flag.__init__cCs|jS)N)r)rrrrvaluepsz Flag.valuecCs ||_dS)N)r)rr rrrr tscCs tt|S)N)hashid)rrrr__hash__xsz Flag.__hash__cCs||kS)Nr)rotherrrr__eq__{sz Flag.__eq__cCst|trt|t|kStS)N) isinstancer r"NotImplemented)rr$rrr__lt__~s z Flag.__lt__cCs tddS)Nzcan't pickle Flag objects) TypeError)rrrr __getstate__szFlag.__getstate__cCstdt|jdS)Nz>%s does not support shallow copies. Use copy.deepcopy instead.)r)type__name__)rrrr__copy__sz Flag.__copy__cCs"tt|}t|j||_|S)N)object__new__r+copydeepcopy__dict__)rmemoresultrrr __deepcopy__szFlag.__deepcopy__cCsJ|dkr dS|jr"t|j|S|jr<|r4tdStdStt|S)z$Returns parsed flag value as string.Ntruefalse)rrepr serializer rZstr_or_unicode)rr rrr_get_parsed_value_as_stringsz Flag._get_parsed_value_as_stringcCsB|jr$|js$td|j||jf|||_|jd7_dS)z}Parses string and sets flag value. Args: argument: str or the correct flag value type, argument to be parsed. z#flag --%s=%s: already defined as %sN)rrrIllegalFlagValueErrorr r _parse)rargumentrrrparses   z Flag.parsec CsNy |j|Sttfk rH}ztd|j||fWdd}~XYnXdS)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. zflag --%s=%s: %sN)rr?r) ValueErrorrr<r )rr>errrr=s  z Flag._parsecCs|j|_d|_d|_dS)NTr)rr rr)rrrrunparsesz Flag.unparsecCs ||jS)zSerializes the flag.) _serializer )rrrrr9szFlag.serializecCs\|dkr dS|jr,|r d|jSd|jSn,|jsBtd|jd|j|j|fSdS)zInternal serialize function.Nz--%sz--no%sz"Serializer not present for flag %sz--%s=%s)r r rrrr9)rr rrrrCs   zFlag._serializecCsB||_|dkrd|_n |||_||j|_|jr>|j|_dS)z@Changes the default value (and current value too) for this Flag.N)Zdefault_unparsedr_parse_from_defaultr:Zdefault_as_strrr )rr rrrrs zFlag._set_defaultcCs ||S)N)r=)rr rrrrEszFlag._parse_from_defaultcCs |jS)aReturns 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_type)rrrrrFszFlag.flag_typecCs,|d}|r"|t|dd|t|d||t|d|j|jrh|t|d|j|jr|t|d|j|jrt|j t s|j dk r|j |j }qd }n|j }|t|d || |j }|t|d ||t|d |x||D]}||qW|S) a6Returns 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. flagkeyyesfiler r ZmeaningNrDrcurrentr+) createElement appendChildrcreate_xml_dom_elementr r r rr&rstrr9_serialize_value_for_xmlr rF_extra_xml_dom_elements)rdoc module_nameZis_keyelementZdefault_serializedvalue_serializedrArrr_create_xml_dom_elements6      zFlag._create_xml_dom_elementcCs|S)z:Returns the serialized value, for use in an XML help text.r)rr rrrrPszFlag._serialize_value_for_xmlcCs |j|S)aReturns 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. )rZ_custom_xml_dom_elements)rrRrrrrQ#s zFlag._extra_xml_dom_elements)NFFFFTF)F)r, __module__ __qualname____doc__rpropertyr setterr#r%r(r*r-r5r:r?r=rBr9rCrrErFrVrPrQrrrrr #s0,      4r cs"eZdZdZdfdd ZZS) BooleanFlagaBasic 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. Nc s,t}tt|j|d||||df|dS)Nr;)rZ BooleanParsersuperr\r)rr rr r argsp) __class__rrr@s zBooleanFlag.__init__)N)r,rWrXrYr __classcell__rr)r`rr\3s r\cs*eZdZdZdfdd ZddZZS) EnumFlagzFBasic enum flag; its value can be any string from list of enum_values.NTc  sLt||}t} tt|j|| ||||f|dd||jf|_dS)Nz<%s>: %s|)rZ EnumParserZArgumentSerializerr]rbrjoinr ) rr rr enum_valuesr case_sensitiver^r_g)r`rrrIs   zEnumFlag.__init__cCs.g}x$|jjD]}|t|d|qW|S)N enum_value)rreappendrrN)rrRelementsrhrrrrQQs z EnumFlag._extra_xml_dom_elements)NT)r,rWrXrYrrQrarr)r`rrbFsrbcs*eZdZdZdfdd ZddZZS) EnumClassFlagz5Basic enum flag; its value is an enum class's member.NFc  sVtj||d}tj| d} tt|j|| ||||f|dd|j|jf|_dS)N)rf) lowercasez<%s>: %src) rEnumClassParserZEnumClassSerializerr]rkrrd member_namesr ) rr rr enum_classr rfr^r_rg)r`rrr\s   zEnumClassFlag.__init__cCs4g}x*|jjjD]}|t|d|qW|S)Nrh)rro __members__keysrirrN)rrRrjrhrrrrQls z%EnumClassFlag._extra_xml_dom_elements)NF)r,rWrXrYrrQrarr)r`rrkYs rkcsPeZdZdZfddZddZfddZfdd Zd d Zd d Z Z S) MultiFlagaeA 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 cs$tt|j|||jd7_dS)Nz4; repeat this option to specify a list of values)r]rrrr )rr^kwargs)r`rrrszMultiFlag.__init__cCs:||}|jr|j|n||_|jt|7_dS)aParses 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)r=rr extendlen)r argumentsZ new_valuesrrrr?s  zMultiFlag.parsecsDt|tjr t|tjs t|}t|ts0|g}fdd|DS)Ncsg|]}tt|qSr)r]rrr=).0item)r`rrr sz$MultiFlag._parse..)r&rIterablesix string_typeslist)rrv)r`)rrr=s    zMultiFlag._parsecs@jstdj|dkr"dSfdd|D}d|S)zSee base class.z"Serializer not present for flag %sNrDcsg|]}tt|qSr)r]rrrC)rwZ value_item)r`rrrrysz(MultiFlag._serialize.. )rrrr rd)rr Zserialized_items)r`)rrrCs zMultiFlag._serializecCsd|jS)zSee base class.zmulti )rrF)rrrrrFszMultiFlag.flag_typecCs:g}t|jdr6x$|jjD]}|t|d|qW|S)Nrerh)hasattrrrerirrN)rrRrjrhrrrrQs  z!MultiFlag._extra_xml_dom_elements) r,rWrXrYrr?r=rCrFrQrarr)r`rrrts  rrcs2eZdZdZd fdd ZddZddZZS) 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. Fc  sXtj||d}tjd| d}tt|j|||||f|dd|j|pLdf|_dS)N)rf,)Zlist_seprlz<<%s>: %s; repeat this option to specify a list of valuesrcz(no help available)) rrmZEnumClassListSerializerr]rrrdrnr ) rr rrrorfr^r_rg)r`rrrs   zMultiEnumClassFlag.__init__cCs4g}x*|jjjD]}|t|d|qW|S)Nrh)rrorprqrirrN)rrRrjrhrrrrQs z*MultiEnumClassFlag._extra_xml_dom_elementscCs|dk r|j|}nd}|S)zSee base class.NrD)rr9)rr rUrrrrPsz+MultiEnumClassFlag._serialize_value_for_xml)F)r,rWrXrYrrQrPrarr)r`rrs r)rY __future__rrrr0 functoolsZabsl._collections_abcrZ absl.flagsrrrr{total_orderingr.r r\rbrkrrrrrrrs&       L