a
    Sic6P                     @   s>  d Z ddlZddlZddlZddlZddlmZ dd ZG dd deZ	G dd	 d	e	d
Z
G dd deZG dd de
ZG dd deZG dd deZG dd de
ZG dd de
ZG dd de
ZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"e
ZG d#d$ d$eZG d%d& d&eZdS )'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.
    N)_helpersc                 C   s   t | tot | t S )z7Returns True if instance is an integer, and not a bool.)
isinstanceintbool)instance r   W/var/www/html/django/DPS/env/lib/python3.9/site-packages/absl/flags/_argument_parser.py_is_integer_type   s    

r	   c                   @   s   e Zd ZdZi Zdd ZdS )_ArgumentParserCachez?Metaclass used to cache and share argument parsers among flags.c              	   O   s   |rt j| g|R i |S | j}| ft| }z
|| W S  tyf   ||t j| g|R   Y S  ty   t j| g|R   Y S 0 dS )aW  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.
    N)type__call__
_instancestupleKeyError
setdefault	TypeError)clsargskwargs	instanceskeyr   r   r   r   (   s    
z_ArgumentParserCache.__call__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r
   #   s   r
   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
ArgumentParsera  Base class used to parse and convert arguments.

  The :meth:`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                 C   s    t |tstdt||S )au  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   strr   formatr   selfargumentr   r   r   parseo   s
    
zArgumentParser.parsec                 C   s   dS )z3Returns a string representing the type of the flag.stringr   r    r   r   r   	flag_type   s    zArgumentParser.flag_typec                 C   s   ~g S )zReturns a list of minidom.Element to add additional flag information.

    Args:
      doc: minidom.Document, the DOM document it should create nodes from.
    r   )r    docr   r   r   _custom_xml_dom_elements   s    z'ArgumentParser._custom_xml_dom_elementsN)r   r   r   r   syntactic_helpr"   r%   r'   r   r   r   r   r   ]   s
   r   )	metaclassc                   @   s   e Zd ZdZdd ZdS )ArgumentSerializerzABase class for generating string representations of a flag value.c                 C   s   t |S )z)Returns a serialized string of the value.r   r    valuer   r   r   	serialize   s    zArgumentSerializer.serializeN)r   r   r   r   r.   r   r   r   r   r*      s   r*   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )NumericParserz]Parser of numeric values.

  Parsed value may be bounded to a given upper and lower bound.
  c                 C   s(   | j dur|| j k p&| jduo&|| jkS )z7Returns whether the value is outside the bounds or not.N)lower_boundupper_bound)r    valr   r   r   is_outside_bounds   s    zNumericParser.is_outside_boundsc                 C   s*   |  |}| |r&td|| jf |S )See base class.z%s is not %s)convertr3   
ValueErrorr(   )r    r!   r2   r   r   r   r"      s    

zNumericParser.parsec                 C   sH   g }| j d ur$|t|d| j  | jd urD|t|d| j |S )Nr0   r1   )r0   appendr   create_xml_dom_elementr1   r    r&   elementsr   r   r   r'      s    

z&NumericParser._custom_xml_dom_elementsc                 C   s   t dS )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.
    N)NotImplementedErrorr   r   r   r   r5      s    zNumericParser.convertN)r   r   r   r   r3   r"   r'   r5   r   r   r   r   r/      s
   
r/   c                       sH   e Zd ZdZdZdZdeefZd fdd	Zdd	 Z	d
d Z
  ZS )FloatParserzdParser of floating point values.

  Parsed value may be bounded to a given upper and lower bound.
  anumber Nc                    s   t t|   || _|| _| j}|d ur@|d ur@d|||f }nV|dkrTd| j }nB|dkrhd| j }n.|d urd| j|f }n|d urd| j|f }|| _d S )N%s in the range [%s, %s]r   a non-negative %sa non-positive %s%s <= %s%s >= %s)superr<   __init__r0   r1   r(   number_namer    r0   r1   sh	__class__r   r   rF      s    zFloatParser.__init__c                 C   s:   t |st|tst|tr$t|S tdt|dS )z$Returns the float value of argument.z7Expect argument to be a string, int, or float, found {}N)r	   r   floatr   r   r   r   r   r   r   r   r5      s    zFloatParser.convertc                 C   s   dS )r4   rL   r   r$   r   r   r   r%      s    zFloatParser.flag_type)NNr   r   r   r   Znumber_articlerG   joinr(   rF   r5   r%   __classcell__r   r   rJ   r   r<      s   
r<   c                       sH   e Zd ZdZdZdZdeefZd fdd	Zdd	 Z	d
d Z
  ZS )IntegerParserz_Parser of an integer value.

  Parsed value may be bounded to a given upper and lower bound.
  anintegerr?   Nc                    s   t t|   || _|| _| j}|d ur@|d ur@d|||f }n~|dkrTd| j }nj|dkrhd| j }nV|dkr|d| j }nB|dkrd| j }n.|d urd	| j|f }n|d urd
| j|f }|| _d S )Nr@      za positive %sza negative %sr   rA   rB   rC   rD   )rE   rP   rF   r0   r1   r(   rG   rH   rJ   r   r   rF      s&    zIntegerParser.__init__c                 C   st   t |r|S t|tr^d}t|dkrT|d dkrT|d dkrDd}n|d dkrTd	}t||S td
t|dS )z"Returns the int value of argument.
      r   0rS   o   x   z/Expect argument to be a string or int, found {}N)r	   r   r   lenr   r   r   r   )r    r!   baser   r   r   r5     s    

zIntegerParser.convertc                 C   s   dS )r4   r   r   r$   r   r   r   r%     s    zIntegerParser.flag_type)NNrM   r   r   rJ   r   rP      s   rP   c                   @   s    e Zd ZdZdd Zdd ZdS )BooleanParserzParser of boolean values.c                 C   sl   t |tr6| dv rdS | dv r*dS td|n(t |tr^t|}||krT|S td|td|dS )r4   )truet1T)falsefrW   Fz$Non-boolean argument to boolean flagN)r   r   lowerr6   r   r   r   )r    r!   Z
bool_valuer   r   r   r"   $  s    


zBooleanParser.parsec                 C   s   dS )r4   r   r   r$   r   r   r   r%   8  s    zBooleanParser.flag_typeN)r   r   r   r   r"   r%   r   r   r   r   r^   !  s   r^   c                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )

EnumParserz@Parser of a string enum value (a string value from a given set).Tc                    s0   |st d|tt|   || _|| _dS )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)r6   r   rE   re   rF   enum_valuescase_sensitive)r    rf   rg   rJ   r   r   rF   @  s    
zEnumParser.__init__c                    sv   | j r, | jvr&tdd| j qr S nF  dd | jD vrZtdd| j n fdd| jD d S dS )a  Determines 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>|c                 S   s   g | ]}|  qS r   upper.0r-   r   r   r   
<listcomp>d      z$EnumParser.parse.<locals>.<listcomp>c                    s    g | ]}|     kr|qS r   ri   rk   r!   r   r   rm   h  s   r   N)rg   rf   r6   rN   rj   r   r   ro   r   r"   Q  s    


zEnumParser.parsec                 C   s   dS )r4   zstring enumr   r$   r   r   r   r%   k  s    zEnumParser.flag_type)Tr   r   r   r   rF   r"   r%   rO   r   r   rJ   r   re   =  s   re   c                       s>   e Zd ZdZd fdd	Zedd Zdd Zd	d
 Z  Z	S )EnumClassParserzParser of an Enum class member.Tc                    s   ddl }t||js"td||js6td||sttdd |jD }dd |	 D }|rttd	|t
t|   || _|| _|rt|j| _ntd
d |jD | _dS )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                 s   s   | ]}|  V  qd S Nrd   rl   namer   r   r   	<genexpr>  s   z+EnumClassParser.__init__.<locals>.<genexpr>c                 S   s   h | ]\}}|d kr|qS )rS   r   )rl   membercountr   r   r   	<setcomp>  s   z+EnumClassParser.__init__.<locals>.<setcomp>z7Duplicate enum values for {} using case_sensitive=Falsec                 s   s   | ]}|  V  qd S rr   rs   rt   r   r   r   rv     s   )enum
issubclassEnumr   r   __members__r6   collectionsCounteritemsrE   rq   rF   
enum_class_case_sensitiver   _member_names)r    r   rg   rz   membersZduplicate_keysrJ   r   r   rF   s  s8    
zEnumClassParser.__init__c                 C   s   | j S )z<The accepted enum names, in lowercase if not case sensitive.)r   r$   r   r   r   member_names  s    zEnumClassParser.member_namesc                    st   t || jr|S t |ts,td|| jt| j| jd| | jrR| j  S t	 fdd| jj
 D S dS )a6  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 {})rg   c                 3   s&   | ]\}}|     kr|V  qd S rr   rs   )rl   ru   r-   r   r   r   rv     s   
z(EnumClassParser.parse.<locals>.<genexpr>N)r   r   r   r6   r   re   r   r   r"   nextr}   r   r   r   r   r   r"     s     

zEnumClassParser.parsec                 C   s   dS )r4   z
enum classr   r$   r   r   r   r%     s    zEnumClassParser.flag_type)T)
r   r   r   r   rF   propertyr   r"   r%   rO   r   r   rJ   r   rq   p  s   )
rq   c                   @   s   e Zd Zdd Zdd ZdS )ListSerializerc                 C   s
   || _ d S rr   list_sepr    r   r   r   r   rF     s    zListSerializer.__init__c                 C   s   | j dd |D S )r4   c                 S   s   g | ]}t |qS r   r+   rl   rZ   r   r   r   rm     rn   z,ListSerializer.serialize.<locals>.<listcomp>)r   rN   r,   r   r   r   r.     s    zListSerializer.serializeNr   r   r   rF   r.   r   r   r   r   r     s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )EnumClassListSerializerzA serializer for :class:`MultiEnumClass` flags.

  This serializer simply joins the output of `EnumClassSerializer` using a
  provided separator.
  c                    s$   t t| | tf i || _dS )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.
    N)rE   r   rF   EnumClassSerializer_element_serializer)r    r   r   rJ   r   r   rF     s    z EnumClassListSerializer.__init__c                    s4   t |tr$ j fdd|D S  j|S dS )r4   c                 3   s   | ]} j |V  qd S rr   )r   r.   r   r$   r   r   rv     s   z4EnumClassListSerializer.serialize.<locals>.<genexpr>N)r   listr   rN   r   r.   r,   r   r$   r   r.     s
    
z!EnumClassListSerializer.serialize)r   r   r   r   rF   r.   rO   r   r   rJ   r   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )CsvListSerializerc                 C   s
   || _ d S rr   r   r   r   r   r   rF     s    zCsvListSerializer.__init__c                 C   s@   t  }tj|| jd}|dd |D  |  }t|S )z-Serializes a list as a CSV string or unicode.)	delimiterc                 S   s   g | ]}t |qS r   r+   r   r   r   r   rm     rn   z/CsvListSerializer.serialize.<locals>.<listcomp>)	ioStringIOcsvwriterr   writerowgetvaluestripr   )r    r-   outputr   Zserialized_valuer   r   r   r.     s
    zCsvListSerializer.serializeNr   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   zHClass for generating string representations of an enum class flag value.c                 C   s
   || _ dS )zInitializes EnumClassSerializer.

    Args:
      lowercase: If True, enum member names are lowercased during serialization.
    N)
_lowercase)r    Z	lowercaser   r   r   rF     s    zEnumClassSerializer.__init__c                 C   s   t |j}| jr| S |S )z4Returns a serialized string of the Enum class value.)r   ru   r   rd   )r    r-   	as_stringr   r   r   r.     s    
zEnumClassSerializer.serializeN)r   r   r   r   rF   r.   r   r   r   r   r     s   r   c                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )
BaseListParsera   Base class for a parser of lists of strings.

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

      super().__init__(token, name)

  where token is a character used to tokenize, and name is a description
  of the separator.
  Nc                    s2   |sJ t t|   || _|| _d| j | _d S )Nza %s separated list)rE   r   rF   _token_namer(   )r    tokenru   rJ   r   r   rF     s
    zBaseListParser.__init__c                 C   s0   t |tr|S |sg S dd || jD S dS )r4   c                 S   s   g | ]}|  qS r   r   rl   sr   r   r   rm   "  rn   z(BaseListParser.parse.<locals>.<listcomp>N)r   r   splitr   r   r   r   r   r"     s
    
zBaseListParser.parsec                 C   s
   d| j  S )r4   z%s separated list of strings)r   r$   r   r   r   r%   $  s    zBaseListParser.flag_type)NNrp   r   r   rJ   r   r   	  s   
	r   c                       s4   e Zd ZdZ fddZdd Z fddZ  ZS )
ListParserz-Parser for a comma-separated list of strings.c                    s   t t| dd d S )N,comma)rE   r   rF   r$   rJ   r   r   rF   ,  s    zListParser.__init__c              
   C   s|   t |tr|S |sg S z$dd ttj|gddd D W S  tjyv } z"td||  |f W Y d}~n
d}~0 0 dS )z3Parses argument as comma-separated list of strings.c                 S   s   g | ]}|  qS r   r   r   r   r   r   rm   7  rn   z$ListParser.parse.<locals>.<listcomp>T)strictr   z(Unable to parse the value %r as a %s: %sN)r   r   r   readerErrorr6   r%   )r    r!   er   r   r   r"   /  s    
$zListParser.parsec                    s,   t t| |}|t|dtd |S )Nlist_separatorr   )rE   r   r'   r7   r   r8   reprr9   rJ   r   r   r'   A  s
    
z#ListParser._custom_xml_dom_elementsr   r   r   r   rF   r"   r'   rO   r   r   rJ   r   r   )  s   r   c                       s6   e Zd ZdZd	 fdd	Zdd Z fddZ  ZS )
WhitespaceSeparatedListParserz2Parser for a whitespace-separated list of strings.Fc                    s*   || _ | j rdnd}tt| d| dS )a
  Initializer.

    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_compatrE   r   rF   )r    Zcomma_compatru   rJ   r   r   rF   K  s    z&WhitespaceSeparatedListParser.__init__c                 C   s4   t |tr|S |sg S | jr(|dd}| S dS )a  Parses 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   r?   N)r   r   r   replacer   r   r   r   r   r"   W  s    
z#WhitespaceSeparatedListParser.parsec              	      sX   t t| |}ttj}| jr*|d |  |D ]}|t	
|dt| q6|S )Nr   r   )rE   r   r'   r   r#   r   r   r7   sortr   r8   r   )r    r&   r:   
separatorsZsep_charrJ   r   r   r'   k  s    



z6WhitespaceSeparatedListParser._custom_xml_dom_elements)Fr   r   r   rJ   r   r   H  s   r   )r   r~   r   r   r#   
absl.flagsr   r	   r   r
   r   objectr*   r/   r<   rP   r^   re   rq   r   r   r   r   r   r   r   r   r   r   r   <module>   s,   :4,)33R
 