a
    Sic8|                     @   s>  d 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mZ ddlm	Z	 zdd	l
mZmZmZ W n ey   Y n0 zddlZW n ey   Y n0 ejeeje  d
d ZejdddfddZejddfddZdd ZejdfddZejfddZejfddZdd ZejdfddZejddfddZddejdfdd Z ddejdfd!d"Z!ejddfd#d$Z"ejdddfd%d&Z#ejdfd'd(Z$dejdfd)d*Z%ejddfd+d,Z&ejdfd-d.Z'ddejdfd/d0Z(ddejdfd1d2Z)ejd3dfd4d5Z*ejdddfd6d7Z+ejdfd8d9Z,dS ):zThis modules contains flags DEFINE functions.

Do NOT import this module directly. Import the flags package and use the
aliases defined at the package level instead.
    N)_argument_parser)_exceptions)_flag)_flagvalues)_helpers)_validators)TextListAnyc                    s4    j dus jdur0 fdd}tj|||d dS )zEnforces lower and upper bounds for numeric flags.

  Args:
    parser: NumericParser (either FloatParser or IntegerParser), provides lower
      and upper bounds, and help text to display.
    name: str, name of the flag
    flag_values: FlagValues.
  Nc                    s.   | d ur*  | r*d|  jf }t|dS )Nz%s is not %sT)is_outside_boundssyntactic_helpr   ValidationError)valuemessageparser O/var/www/html/django/DPS/env/lib/python3.9/site-packages/absl/flags/_defines.pychecker8   s    
z5_register_bounds_validator_if_needed.<locals>.checkerflag_values)lower_boundupper_boundr   register_validator)r   namer   r   r   r   r   $_register_bounds_validator_if_needed-   s    	r   Fc           	      K   s$   t tj| ||||fi ||||S )a	  Registers a generic Flag object.

  NOTE: in the docstrings of all DEFINE* functions, "registers" is short
  for "creates a new flag and registers it".

  Auxiliary function: clients should use the specialized ``DEFINE_<type>``
  function instead.

  Args:
    parser: :class:`ArgumentParser`, used to parse the flag arguments.
    name: str, the flag name.
    default: The default value of the flag.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    serializer: :class:`ArgumentSerializer`, the flag serializer instance.
    module_name: str, the name of the Python module declaring this flag. If not
      provided, it will be computed using the stack trace of this call.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: dict, the extra keyword args that are passed to ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  )DEFINE_flagr   Flag)	r   r   defaulthelpr   
serializermodule_namerequiredargsr   r   r   DEFINEA   s    #r$   c                 C   s   |r| j durtd| j |}| || j< |r<tj|}nt \}}|||  |	t
||  |rvt| j| | j dup|}tj|| |dS )a  Registers a :class:`Flag` object with a :class:`FlagValues` object.

  By default, the global :const:`FLAGS` ``FlagValue`` object is used.

  Typical users will use one of the more specialized DEFINE_xxx
  functions, such as :func:`DEFINE_string` or :func:`DEFINE_integer`.  But
  developers who need to create :class:`Flag` objects themselves should use
  this function to register their flags.

  Args:
    flag: :class:`Flag`, a flag that is key to the module.
    flag_values: :class:`FlagValues`, the ``FlagValues`` instance with which the
      flag will be registered. This should almost never need to be overridden.
    module_name: str, the name of the Python module declaring this flag. If not
      provided, it will be computed using the stack trace of this call.
    required: bool, is this a required flag. This must be used as a keyword
      argument.

  Returns:
    a handle to defined flag.
  Nz1Required flag --%s cannot have a non-None default)ensure_non_none_value)r   
ValueErrorr   sysmodulesgetr   "get_calling_module_object_and_nameZregister_flag_by_moduleZregister_flag_by_module_ididr   mark_flag_as_requiredr   
FlagHolder)flagr   r!   r"   fvmoduler%   r   r   r   r   i   s"    
r   c                 C   s   | j | j| dS )a  Changes the default value of the provided flag object.

  The flag's current value is also updated if the flag is currently using
  the default value, i.e. not specified in the command line, and not set
  by FLAGS.name = value.

  Args:
    flag_holder: FlagHolder, the flag to modify.
    value: The new default value.

  Raises:
    IllegalFlagValueError: Raised when value is not valid.
  N)r   set_defaultr   )Zflag_holderr   r   r   r   r1      s    r1   c                 C   s.   |p|}t  }| D ]}||||  qdS )aT  Declares a flag as key for the calling module.

  Internal function.  User code should call declare_key_flag or
  adopt_module_key_flags instead.

  Args:
    flag_names: [str], a list of names of already-registered Flag objects.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flags listed in flag_names have registered (the value of the flag_values
      argument from the ``DEFINE_*`` calls that defined those flags). This
      should almost never need to be overridden.
    key_flag_values: :class:`FlagValues`, the FlagValues instance that (among
      possibly many other things) keeps track of the key flags for each module.
      Default ``None`` means "same as flag_values".  This should almost never
      need to be overridden.

  Raises:
    UnrecognizedFlagError: Raised when the flag is not defined.
  N)r   get_calling_moduleZregister_key_flag_for_module)Z
flag_namesr   key_flag_valuesr0   	flag_namer   r   r   _internal_declare_key_flags   s    r5   c                 C   sf   t | |\} }| tjv r0t| gtj|d dS zt| g|d W n ty`   td|  Y n0 dS )a  Declares one flag as key to the current module.

  Key flags are flags that are deemed really important for a module.
  They are important when listing help messages; e.g., if the
  --helpshort command-line flag is used, then only the key flags of the
  main module are listed (instead of all flags, as in the case of
  --helpfull).

  Sample usage::

      flags.declare_key_flag('flag_1')

  Args:
    flag_name: str | :class:`FlagHolder`, the name or holder of an already
      declared flag. (Redeclaring flags as key, including flags implicitly key
      because they were declared in this module, is a no-op.)
      Positional-only parameter.
    flag_values: :class:`FlagValues`, the FlagValues instance in which the
      flag will be declared as a key flag. This should almost never need to be
      overridden.

  Raises:
    ValueError: Raised if flag_name not defined as a Python flag.
  r   r3   Nr   zNFlag --%s is undefined. To set a flag as a key flag first define it in Python.)r   Zresolve_flag_refr   SPECIAL_FLAGSr5   KeyErrorr&   )r4   r   r   r   r   declare_key_flag   s    
r9   c                 C   sd   t | tjstd| f tdd || jD |d | tj	kr`tdd tj
D tj
|d dS )a  Declares that all flags key to a module are key to the current module.

  Args:
    module: module, the module object from which all key flags will be declared
      as key flags to the current module.
    flag_values: :class:`FlagValues`, the FlagValues instance in which the
      flags will be declared as key flags. This should almost never need to be
      overridden.

  Raises:
    Error: Raised when given an argument that is a module name (a string),
        instead of a module object.
  z!Expected a module object, not %r.c                 S   s   g | ]
}|j qS r   )r   ).0fr   r   r   
<listcomp>      z*adopt_module_key_flags.<locals>.<listcomp>r   c                 S   s   g | ]}t j| jqS r   )r   r7   r   )r:   r   r   r   r   r<     r=   r6   N)
isinstancetypes
ModuleTyper   Errorr5   Zget_key_flags_for_module__name__r   FLAGS_MODULEr7   )r0   r   r   r   r   adopt_module_key_flags   s    
rD   c                  C   s.   t dj} t| \}}tjt| dS )a  Declares that the current module will not define any more key flags.

  Normally, the module that calls the DEFINE_xxx functions claims the
  flag to be its key flag.  This is undesirable for modules that
  define additional DEFINE_yyy functions with its own flag parsers and
  serializers, since that module will accidentally claim flags defined
  by DEFINE_yyy as its key flags.  After calling this function, the
  module disclaims flag definitions thereafter, so the key flags will
  be correctly attributed to the caller of DEFINE_yyy.

  After calling this function, the module will not be able to define
  any more flags.  This function will affect all FlagValues objects.
     N)r'   	_getframe	f_globalsr   get_module_object_and_namedisclaim_module_idsaddr+   )Zglobals_for_callerr0   _r   r   r   disclaim_key_flags  s    rL   c                 K   s.   t  }t  }t|| ||||fd|i|S )z/Registers a flag whose value can be any string.r"   )r   ArgumentParserArgumentSerializerr$   r   r   r   r   r"   r#   r   r    r   r   r   DEFINE_string#  s    rP   c                 K   s    t tj| ||fi ||||S )a  Registers a boolean flag.

  Such a boolean flag does not take an argument.  If a user wants to
  specify a false value explicitly, the long option beginning with 'no'
  must be used: i.e. --noflag

  This flag will have a value of None, True or False.  None is possible
  if default=None and the user does not specify the flag on the command
  line.

  Args:
    name: str, the flag name.
    default: bool|str|None, the default value of the flag.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    module_name: str, the name of the Python module declaring this flag. If not
      provided, it will be computed using the stack trace of this call.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: dict, the extra keyword args that are passed to ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  )r   r   BooleanFlag)r   r   r   r   r!   r"   r#   r   r   r   DEFINE_boolean8  s    !rR   c                 K   sD   t ||}t  }	t|| ||||	fd|i|}
t|| |d |
S )a  Registers a flag whose value must be a float.

  If ``lower_bound`` or ``upper_bound`` are set, then this flag must be
  within the given range.

  Args:
    name: str, the flag name.
    default: float|str|None, the default value of the flag.
    help: str, the help message.
    lower_bound: float, min value of the flag.
    upper_bound: float, max value of the flag.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: dict, the extra keyword args that are passed to :func:`DEFINE`.

  Returns:
    a handle to defined flag.
  r"   r   )r   FloatParserrN   r$   r   r   r   r   r   r   r   r"   r#   r   r    resultr   r   r   DEFINE_float^  s     	rV   c                 K   sD   t ||}t  }	t|| ||||	fd|i|}
t|| |d |
S )a  Registers a flag whose value must be an integer.

  If ``lower_bound``, or ``upper_bound`` are set, then this flag must be
  within the given range.

  Args:
    name: str, the flag name.
    default: int|str|None, the default value of the flag.
    help: str, the help message.
    lower_bound: int, min value of the flag.
    upper_bound: int, max value of the flag.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: dict, the extra keyword args that are passed to :func:`DEFINE`.

  Returns:
    a handle to defined flag.
  r"   r   )r   IntegerParserrN   r$   r   rT   r   r   r   DEFINE_integer  s     	rX   c                 K   s"   t tj| |||fi ||||S )a  Registers a flag whose value can be any string from enum_values.

  Instead of a string enum, prefer `DEFINE_enum_class`, which allows
  defining enums from an `enum.Enum` class.

  Args:
    name: str, the flag name.
    default: str|None, the default value of the flag.
    enum_values: [str], a non-empty list of strings with the possible values for
      the flag.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    module_name: str, the name of the Python module declaring this flag. If not
      provided, it will be computed using the stack trace of this call.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: dict, the extra keyword args that are passed to ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  )r   r   EnumFlag)r   r   enum_valuesr   r   r!   r"   r#   r   r   r   DEFINE_enum  s    r[   c           	      K   s&   t tj| |||fd|i||||S )a  Registers a flag whose value can be the name of enum members.

  Args:
    name: str, the flag name.
    default: Enum|str|None, the default value of the flag.
    enum_class: class, the Enum class with all the possible values for the flag.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    module_name: str, the name of the Python module declaring this flag. If not
      provided, it will be computed using the stack trace of this call.
    case_sensitive: bool, whether to map strings to members of the enum_class
      without considering case.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: dict, the extra keyword args that are passed to ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  case_sensitive)r   r   EnumClassFlag	r   r   
enum_classr   r   r!   r\   r"   r#   r   r   r   DEFINE_enum_class  s    r`   c                 K   s0   t  }t d}t|| ||||fd|i|S )ax  Registers a flag whose value is a comma-separated list of strings.

  The flag value is parsed with a CSV parser.

  Args:
    name: str, the flag name.
    default: list|str|None, the default value of the flag.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  ,r"   )r   
ListParserCsvListSerializerr$   rO   r   r   r   DEFINE_list  s    
rd   c           	      K   s4   t j|d}t d}t|| ||||fd|i|S )aa  Registers a flag whose value is a whitespace-separated list of strings.

  Any whitespace can be used as a separator.

  Args:
    name: str, the flag name.
    default: list|str|None, the default value of the flag.
    help: str, the help message.
    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.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  )comma_compat r"   )r   WhitespaceSeparatedListParserListSerializerr$   )	r   r   r   re   r   r"   r#   r   r    r   r   r   DEFINE_spaceseplist(  s     
ri   c           	      K   s$   t tj| ||||fi ||||S )aV  Registers a generic MultiFlag that parses its args with a given parser.

  Auxiliary function.  Normal users should NOT use it directly.

  Developers who need to create their own 'Parser' classes for options
  which can appear multiple times can call this module function to
  register their flags.

  Args:
    parser: ArgumentParser, used to parse the flag arguments.
    serializer: ArgumentSerializer, the flag serializer instance.
    name: str, the flag name.
    default: Union[Iterable[T], Text, None], the default value of the flag. If
      the value is text, it will be parsed as if it was provided from the
      command line. If the value is a non-string iterable, it will be iterated
      over to create a shallow copy of the values. If it is None, it is left
      as-is.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    module_name: A string, the name of the Python module declaring this flag. If
      not provided, it will be computed using the stack trace of this call.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  )r   r   	MultiFlag)	r   r    r   r   r   r   r!   r"   r#   r   r   r   DEFINE_multiS  s    (rk   c                 K   s.   t  }t  }t||| |||fd|i|S )aO  Registers a flag whose value can be a list of any strings.

  Use the flag on the command line multiple times to place multiple
  string values into the list.  The 'default' may be a single string
  (which will be converted into a single-element list) or a list of
  strings.


  Args:
    name: str, the flag name.
    default: Union[Iterable[Text], Text, None], the default value of the flag;
      see :func:`DEFINE_multi`.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  r"   )r   rM   rN   rk   rO   r   r   r   DEFINE_multi_string  s    rl   c           
      K   s2   t ||}t  }	t||	| |||fd|i|S )a  Registers a flag whose value can be a list of arbitrary integers.

  Use the flag on the command line multiple times to place multiple
  integer values into the list.  The 'default' may be a single integer
  (which will be converted into a single-element list) or a list of
  integers.

  Args:
    name: str, the flag name.
    default: Union[Iterable[int], Text, None], the default value of the flag;
      see `DEFINE_multi`.
    help: str, the help message.
    lower_bound: int, min values of the flag.
    upper_bound: int, max values of the flag.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  r"   )r   rW   rN   rk   
r   r   r   r   r   r   r"   r#   r   r    r   r   r   DEFINE_multi_integer  s    !rn   c           
      K   s2   t ||}t  }	t||	| |||fd|i|S )a  Registers a flag whose value can be a list of arbitrary floats.

  Use the flag on the command line multiple times to place multiple
  float values into the list.  The 'default' may be a single float
  (which will be converted into a single-element list) or a list of
  floats.

  Args:
    name: str, the flag name.
    default: Union[Iterable[float], Text, None], the default value of the flag;
      see `DEFINE_multi`.
    help: str, the help message.
    lower_bound: float, min values of the flag.
    upper_bound: float, max values of the flag.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  r"   )r   rS   rN   rk   rm   r   r   r   DEFINE_multi_float  s    !ro   Tc           
   	   K   s@   t ||}t  }	t||	| |dd||f |fd|i|S )a  Registers a flag whose value can be a list strings from enum_values.

  Use the flag on the command line multiple times to place multiple
  enum values into the list.  The 'default' may be a single string
  (which will be converted into a single-element list) or a list of
  strings.

  Args:
    name: str, the flag name.
    default: Union[Iterable[Text], Text, None], the default value of the flag;
      see `DEFINE_multi`.
    enum_values: [str], a non-empty list of strings with the possible values for
      the flag.
    help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    case_sensitive: Whether or not the enum is to be case-sensitive.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  z<%s>: %s|r"   )r   
EnumParserrN   rk   join)
r   r   rZ   r   r   r\   r"   r#   r   r    r   r   r   DEFINE_multi_enum  s    "rs   c           	      K   s(   t tj| ||||d||fd|i|S )a?  Registers a flag whose value can be a list of enum members.

  Use the flag on the command line multiple times to place multiple
  enum values into the list.

  Args:
    name: str, the flag name.
    default: Union[Iterable[Enum], Iterable[Text], Enum, Text, None], the
      default value of the flag; see `DEFINE_multi`; only differences are
      documented here. If the value is a single Enum, it is treated as a
      single-item list of that Enum value. If it is an iterable, text values
      within the iterable will be converted to the equivalent Enum objects.
    enum_class: class, the Enum class with all the possible values for the flag.
        help: str, the help message.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    module_name: A string, the name of the Python module declaring this flag. If
      not provided, it will be computed using the stack trace of this call.
    case_sensitive: bool, whether to map strings to members of the enum_class
      without considering case.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: Dictionary with extra keyword args that are passed to the
      ``Flag.__init__``.

  Returns:
    a handle to defined flag.
  )r\   r"   )r   r   MultiEnumClassFlagr^   r   r   r   DEFINE_multi_enum_class6  s    &
ru   c              	      s^   ||vrt |||  G  fdddtj}d j }t| j j|  j| j	d||S )aH  Defines an alias flag for an existing one.

  Args:
    name: str, the flag name.
    original_name: str, the original flag name.
    flag_values: :class:`FlagValues`, the FlagValues instance with which the
      flag will be registered. This should almost never need to be overridden.
    module_name: A string, the name of the module that defines this flag.

  Returns:
    a handle to defined flag.

  Raises:
    flags.FlagError:
      UnrecognizedFlagError: if the referenced flag doesn't exist.
      DuplicateFlagError: if the alias name has been used by some existing flag.
  c                       sF   e Zd ZdZ fddZdd Ze fddZej fddZd	S )
z DEFINE_alias.<locals>._FlagAliaszCOverrides Flag class so alias value is copy of original flag value.c                    s     | |  jd7  _d S )NrE   )parseZpresent)selfargumentr.   r   r   rv     s    
z&DEFINE_alias.<locals>._FlagAlias.parsec                 S   s   |S Nr   rw   r   r   r   r   _parse_from_default  s    z4DEFINE_alias.<locals>._FlagAlias._parse_from_defaultc                    s    j S rz   r   )rw   ry   r   r   r     s    z&DEFINE_alias.<locals>._FlagAlias.valuec                    s
   | _ d S rz   r}   r{   ry   r   r   r     s    N)	rB   
__module____qualname____doc__rv   r|   propertyr   setterr   ry   r   r   
_FlagAlias  s   r   zAlias for --%s.)boolean)
r   UnrecognizedFlagErrorr   r   r   r   r   r    r   r   )r   original_namer   r!   r   Zhelp_msgr   ry   r   DEFINE_aliase  s     

r   )-r   r'   r?   
absl.flagsr   r   r   r   r   r   typingr   r	   r
   ImportErrorenumrI   rJ   r+   r(   rB   r   FLAGSr$   r   r1   r5   r9   rD   rL   rP   rR   rV   rX   r[   r`   rd   ri   rk   rl   rn   ro   rs   ru   r   r   r   r   r   <module>   s   
*
.
* 

*
0
1
)
,
*
1
1
/
2
3
4
2