a
    ijoN                     @   s&  d Z ddlm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mZ ddlmZ ddlmZ ddlmZ ddlmZ ed	Zed
ejdZejG dd de	e ZG dd dee ZG dd dee ZG dd dee ZG dd de	e eee  Z G dd de e Z!dS )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.
    )abcN)	AnyDictGenericIterableListOptionalTypeTypeVarUnion)minidom)_argument_parser)_exceptions)_helpers_T_ET)boundc                   @   s  e Zd ZU dZee ed< ee ed< eee ef ed< e	j
e ed< d=e	j
e ee	je  eeee ef ee ee eeeeeedd	d
dZeee dddZejee dddZdd Zdd Zdd Zdd Zdd Zdd Zeeef dddd Zee ee d!d"d#Zeeef dd$d%d&Zeeef ee d$d'd(Zddd)d*Zedd+d,Zee ed!d-d.Z eee ef dd!d/d0Z!eeef ee d!d1d2Z"edd3d4Z#d>e$j%eee$j&d5d6d7Z'ee ed!d8d9Z(e$j%e)e$j& d:d;d<Z*dS )?Flaga	  Information about a command-line flag.

  Attributes:
    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 :meth:`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 :class:`~absl.flags.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.
    validators: list of the flag validators.

  The only public method of a ``Flag`` object is :meth:`parse`, but it is
  typically only called by a :class:`~absl.flags.FlagValues` object.  The
  :meth:`parse` method is a thin wrapper around the
  :meth:`ArgumentParser.parse()<absl.flags.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.

  :meth:`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.
  defaultdefault_as_strdefault_unparsedparserNFT)r   
serializernamer   help_string
short_namebooleanallow_overrideallow_override_cppallow_hide_cppallow_overwriteallow_using_method_namesreturnc                 C   s   || _ |sd}|| _|| _|| _d| _|| _|| _|| _|	| _|
| _	|| _
|| _d| _d | _g | _| j	rx| jrxtd| | d S )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))r   helpr   r   presentr   r   r   r   r   r    r!   using_default_value_valueZ
validatorsr   Error_set_default)selfr   r   r   r   r   r   r   r   r   r   r    r!    r+   N/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/absl/flags/_flag.py__init__\   s,    zFlag.__init__)r"   c                 C   s   | j S Nr'   r*   r+   r+   r,   value   s    z
Flag.value)r1   c                 C   s
   || _ d S r.   r/   r*   r1   r+   r+   r,   r1      s    c                 C   s   t t| S r.   )hashidr0   r+   r+   r,   __hash__   s    zFlag.__hash__c                 C   s   | |u S r.   r+   r*   otherr+   r+   r,   __eq__   s    zFlag.__eq__c                 C   s   t |trt| t|k S tS r.   )
isinstancer   r4   NotImplementedr6   r+   r+   r,   __lt__   s    
zFlag.__lt__c                 C   s   t dd S )NzRA Flag instance would always be True. Did you mean to test the `.value` attribute?	TypeErrorr0   r+   r+   r,   __bool__   s    zFlag.__bool__c                 C   s   t dd S )Nzcan't pickle Flag objectsr<   r0   r+   r+   r,   __getstate__   s    zFlag.__getstate__c                 C   s   t dt| j d S )Nz>%s does not support shallow copies. Use copy.deepcopy instead.)r=   type__name__r0   r+   r+   r,   __copy__   s    zFlag.__copy__zFlag[_T])memor"   c                 C   s"   t t| }t| j||_|S r.   )object__new__r@   copydeepcopy__dict__)r*   rC   resultr+   r+   r,   __deepcopy__   s    zFlag.__deepcopy__r1   r"   c                 C   sH   |du rdS | j r"t| j |S | jr<|r4tdS tdS tt|S )z$Returns parsed flag value as string.Ntruefalse)r   repr	serializer   strr2   r+   r+   r,   _get_parsed_value_as_string   s    z Flag._get_parsed_value_as_string)argumentr"   c                 C   sB   | j r$| js$td| j|| jf | || _|  j d7  _ dS )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 %s   N)r%   r    r   IllegalFlagValueErrorr   r1   _parse)r*   rR   r+   r+   r,   parse   s    
z
Flag.parsec              
   C   sT   z| j |W S  tttfyN } z"td| j||f W Y d}~n
d}~0 0 dS )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.
    zflag --%s=%s: %sN)r   rV   r=   
ValueErrorOverflowErrorr   rT   r   )r*   rR   er+   r+   r,   rU      s    zFlag._parsec                 C   s   | j | _d| _d| _d S )NTr   )r   r1   r&   r%   r0   r+   r+   r,   unparse   s    zFlag.unparsec                 C   s   |  | jS )zSerializes the flag.)
_serializer1   r0   r+   r+   r,   rO      s    zFlag.serializec                 C   s\   |du rdS | j r,|r d| j S d| j S n,| jsBtd| j d| j| j|f S dS )zInternal serialize function.N z--%sz--no%s"Serializer not present for flag %sz--%s=%s)r   r   r   r   r(   rO   r2   r+   r+   r,   r[      s    
zFlag._serializec                 C   sB   || _ |du rd| _n| || _| | j| _| jr>| j| _dS )z@Changes the default value (and current value too) for this Flag.N)r   r   _parse_from_defaultrQ   r   r&   r1   r2   r+   r+   r,   r)      s    zFlag._set_defaultc                 C   s
   |  |S r.   )rU   r2   r+   r+   r,   r^      s    zFlag._parse_from_defaultc                 C   s
   | 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_typer0   r+   r+   r,   r`      s    zFlag.flag_type)docmodule_nameis_keyr"   c                 C   s(  | d}|r"|t|dd |t|d| |t|d| j | jrh|t|d| j | jr|t|d| j | jrt| j	t
s| j	dur| j| j	}qd	}n| j	}|t|d
| | | j}|t|d| |t|d|   | |D ]}|| q|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   ZmeaningNr\   r   currentr@   )ZcreateElementZappendChildr   create_xml_dom_elementr   r   r$   r   r9   r   rP   rO   _serialize_value_for_xmlr1   r`   _extra_xml_dom_elements)r*   ra   rb   rc   elementZdefault_serializedvalue_serializedrY   r+   r+   r,   _create_xml_dom_element  sB    


zFlag._create_xml_dom_elementc                 C   s   |S )z:Returns the serialized value, for use in an XML help text.r+   r2   r+   r+   r,   rj   <  s    zFlag._serialize_value_for_xmlra   r"   c                 C   s   | 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   Z_custom_xml_dom_elements)r*   ra   r+   r+   r,   rk   @  s    zFlag._extra_xml_dom_elements)NFFFFTF)F)+rA   
__module____qualname____doc__r   r   __annotations__rP   r   r   ArgumentParserArgumentSerializerboolr-   propertyr1   setterr5   r8   r;   r>   r?   rB   r   intr   rJ   rQ   rV   rU   rZ   rO   r[   r)   r^   r`   r   DocumentElementrn   rj   r   rk   r+   r+   r+   r,   r   $   sp   
0	       *
 6r   c                       sD   e Zd ZdZdeeee ef ee ee dd fddZ  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``.
  N)r   r   r$   r   r"   c                    s,   t  }t j|d ||||dfi | d S )NT)r   ZBooleanParsersuperr-   )r*   r   r   r$   r   argsp	__class__r+   r,   r-   _  s    zBooleanFlag.__init__)N)
rA   rp   rq   rr   rP   r   r   rv   r-   __classcell__r+   r+   r   r,   r|   R  s    r|   c                       sf   e Zd ZU dZejed< deee ee e	e ee e
d fddZejeej dd	d
Z  ZS )EnumFlagzFBasic enum flag; its value can be any string from list of enum_values.r   NT)r   r   r$   enum_valuesr   case_sensitivec           
         sT   t ||}t  }	t j||	||||fi | || _dd|j| jf | _d S )N<%s>: %s|)	r   
EnumParserru   r}   r-   r   joinr   r$   )
r*   r   r   r$   r   r   r   r~   r   gr   r+   r,   r-   p  s
    
zEnumFlag.__init__ro   c                 C   s*   g }| j jD ]}|t|d| q|S N
enum_value)r   r   appendr   ri   r*   ra   elementsr   r+   r+   r,   rk     s    z EnumFlag._extra_xml_dom_elements)NT)rA   rp   rq   rr   r   r   rs   rP   r   r   rv   r-   r   rz   r   r{   rk   r   r+   r+   r   r,   r   k  s   

  r   c                       sn   e Zd ZU dZejed< deee	e
 ef e	e ee
 e	e ed fddZejeej dd	d
Z  ZS )EnumClassFlagz5Basic enum flag; its value is an enum class's member.r   NF)r   r   r$   
enum_classr   r   c           
         s\   t j||d}t j| d}	t j||	||||fi | || _dd|j| jf | _d S )Nr   )	lowercaser   r   )	r   EnumClassParserZEnumClassSerializerr}   r-   r   r   member_namesr$   )
r*   r   r   r$   r   r   r   r~   r   r   r   r+   r,   r-     s    
zEnumClassFlag.__init__ro   c                 C   s0   g }| j jj D ]}|t|d| q|S r   r   r   __members__keysr   r   ri   r   r+   r+   r,   rk     s    z%EnumClassFlag._extra_xml_dom_elements)NF)rA   rp   rq   rr   r   r   rs   rP   r   r   r   r	   rv   r-   r   rz   r   r{   rk   r   r+   r+   r   r,   r     s   

  r   c                       s   e Zd ZdZ fddZeeeee f dddZ	eeeee f e
e d fdd	Zee
e  ed
 fddZdd Zeje
ej dddZ  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                    s$   t  j|i | |  jd7  _d S )Nz4;
    repeat this option to specify a list of values)r}   r-   r$   )r*   r~   kwargsr   r+   r,   r-     s    zMultiFlag.__init__)	argumentsc                 C   sH   |  |}| jr,| jdusJ | j| n|| _|  jt|7  _dS )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%   r1   extendlen)r*   r   
new_valuesr+   r+   r,   rV     s    
zMultiFlag.parse)r   r"   c                    sB   t |tr|g}nt |tjr(t|}n|g} fdd|D S )Nc                    s   g | ]}t t|qS r+   )r}   r   rU   ).0itemr   r*   r+   r,   
<listcomp>      z$MultiFlag._parse.<locals>.<listcomp>)r9   rP   r   r   list)r*   r   Zarguments_listr   r0   r,   rU     s    

zMultiFlag._parserK   c                    s@    j std j |du r"dS  fdd|D }d|S )See base class.r]   Nr\   c                    s   g | ]}t t|qS r+   )r}   r   r[   )r   Z
value_itemr   r+   r,   r     s   z(MultiFlag._serialize.<locals>.<listcomp>
)r   r   r(   r   r   )r*   r1   Zserialized_itemsr   r0   r,   r[     s    zMultiFlag._serializec                 C   s   d| j   S )r   zmulti r_   r0   r+   r+   r,   r`     s    zMultiFlag.flag_typero   c                 C   s6   g }t | jdr2| jjD ]}|t|d| q|S )Nr   r   )hasattrr   r   r   r   ri   r   r+   r+   r,   rk     s    z!MultiFlag._extra_xml_dom_elements)rA   rp   rq   rr   r-   r   rP   r   r   rV   r   rU   r   r[   r`   r   rz   r{   rk   r   r+   r+   r   r,   r     s   &r   c                       sz   e Zd ZU dZeje ed< dee	de
e ee
e ef eee ed fddZejeej dd	d
Zdd Z  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.
  r   FN)r   r   r   r   r   c           	         sd   t j||d}t jd| d}t j|||||fi | || _|| _dd|j|pXdf | _	d S )Nr   ,)Zlist_sepr   z<<%s>: %s;
    repeat this option to specify a list of valuesr   r#   )
r   r   ZEnumClassListSerializerr}   r-   r   r   r   r   r$   )	r*   r   r   r   r   r   r~   r   r   r   r+   r,   r-     s    	zMultiEnumClassFlag.__init__ro   c                 C   s0   g }| j jj D ]}|t|d| q|S r   r   r   r+   r+   r,   rk   #  s    z*MultiEnumClassFlag._extra_xml_dom_elementsc                 C   s4   |dur,| j std| j | j |}nd}|S )r   Nr]   r\   )r   r   r(   r   rO   )r*   r1   rm   r+   r+   r,   rj   ,  s    z+MultiEnumClassFlag._serialize_value_for_xml)F)rA   rp   rq   rr   r   r   r   rs   rP   r   r   r	   rv   r-   r   rz   r   r{   rk   rj   r   r+   r+   r   r,   r     s   
 	r   )"rr   collectionsr   rF   enum	functoolstypingr   r   r   r   r   r   r	   r
   r   Zxml.domr   Z
absl.flagsr   r   r   r   Enumr   total_orderingr   rv   r|   rP   r   r   r   r   r+   r+   r+   r,   <module>   s(   ,  / "T