
    x                        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mZ ddlmZ 	 ddlmZmZmZ 	 ddlZej(                  j+                   eej.                  e                d Zej4                  dddfdZej4                  ddfdZej4                  dfdZej4                  fdZej4                  fdZd Z ej4                  dfdZ!ej4                  ddfdZ"ddej4                  dfdZ#ddej4                  dfdZ$ej4                  ddfdZ%ej4                  dddfdZ&ej4                  dfdZ'dej4                  dfdZ(ej4                  ddfdZ)ej4                  dfdZ*ddej4                  dfdZ+ddej4                  dfd Z,ej4                  d!dfd"Z-ej4                  dddfd#Z.ej4                  dfd$Z/y# e$ r Y w xY w# e$ r Y w xY w)%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.
    )absolute_import)division)print_functionN)_argument_parser)_exceptions)_flag)_flagvalues)_helpers)_validators)TextListAnyc                 r      j                    j                   fd}t        j                  |||       yy)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                 x    | 7j                  |       r&| dj                  }t        j                  |      y)Nz is not T)is_outside_boundssyntactic_helpr   ValidationError)valuemessageparsers     .platform/bq/third_party/absl/flags/_defines.pycheckerz5_register_bounds_validator_if_needed.<locals>.checker<   s:    		v77>$)6+@+@A))'22    flag_values)lower_boundupper_boundr   register_validator)r   namer   r   s   `   r   $_register_bounds_validator_if_neededr    1   s;     #v'9'9'E ""4kJ (Fr   Fc           	      N    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: 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: FlagValues, the FlagValues instance with which the flag will be
      registered. This should almost never need to be overridden.
    serializer: 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argss	            r   DEFINEr*   E   s2    F 
jjT7DADA;8
 r   c                    |r$| j                   t        d| j                  z        |}| || j                  <   |r t        j                  j                  |      }nt        j                         \  }}|j                  ||        |j                  t        |      |        |r t        j                  | j                  |       | j                   duxs |}t        j                  || |      S )aH  Registers a 'Flag' object with a 'FlagValues' object.

  By default, the global FLAGS 'FlagValue' object is used.

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

  Args:
    flag: Flag, a flag that is key to the module.
    flag_values: 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_nameregister_flag_by_moduleregister_flag_by_module_ididr   mark_flag_as_requiredr	   
FlagHolder)flagr   r'   r(   fvmoduler,   s          r   r"   r"   m   s    4 $,,*
HYY     ""TYY-[[__[)F"EEGFK%%k48((FT:%%dii4<<t3@			$&;
= =r   c                 t    |xs |}t        j                         }| D ]  }||   }|j                  ||        y)aQ  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 strings that are names of already-registered
      Flag objects.
    flag_values: 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: 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_moduleregister_key_flag_for_module)
flag_namesr   key_flag_valuesr9   	flag_namer7   s         r   _internal_declare_key_flagsr@      s@    . $2{/&&(&iy!D00> r   c                     | t         j                  v rt        | gt         j                  |       y	 t        | g|       y# t        $ r t	        d| z        w xY w)a1  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, the name of an already declared flag. (Redeclaring flags as
      key, including flags implicitly key because they were declared in this
      module, is a no-op.)
    flag_values: 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   r>   Nr   zNFlag --%s is undefined. To set a flag as a key flag first define it in Python.)r
   SPECIAL_FLAGSr@   KeyErrorr-   )r?   r   s     r   declare_key_flagrE      sk    . ((((
  ,4,B,B0;= ?E	 ?
 24=> ? ??s   A Ac                    t        | t        j                        st        j                  d| d      t        |j                  | j                        D cg c]  }|j                   c}|       | t        j                  k(  rTt        t        j                  D cg c]  }t        j                  |   j                  ! c}t        j                  |       yyc c}w c c}w )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: 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   rB   N)
isinstancetypes
ModuleTyper   Errorr@   get_key_flags_for_module__name__r   r
   FLAGS_MODULErC   )r9   r   fr   s       r   adopt_module_key_flagsrP      s     
FE,,	-


6K
LL";;FOOLML!qvvLM x$$$ 8@7M7MN7Mt			%	*	*7MN**#% % N 	Os   C$Cc                      t        j                  d      j                  } t        j                  |       \  }}t        j
                  j                  t        |             y)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addr4   )globals_for_callerr9   _s      r   disclaim_key_flagsrZ     sF     }}Q'11112DE)&!
""2f:.r   c                 x    t        j                         }t        j                         }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&   s           r   DEFINE_stringr_     sS     **,&224*	


 
 	
 r   c                 J    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: 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)   s          r   DEFINE_booleanrb   )  s0    B 
gt4t4k;
 r   c                     t        j                  ||      }t        j                         }	t        || ||||	fd|i|}
t	        || |       |
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: 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 DEFINE.

  Returns:
    a handle to defined flag.
  r(   r   )r   FloatParserr]   r*   r    r   r$   r%   r   r   r   r(   r)   r   r&   results              r   DEFINE_floatrg   O  sg    : ''[A&224*

  	& 'vtM	-r   c                     t        j                  ||      }t        j                         }	t        || ||||	fd|i|}
t	        || |       |
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: 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 DEFINE.

  Returns:
    a handle to defined flag.
  r(   r   )r   IntegerParserr]   r*   r    re   s              r   DEFINE_integerrj   {  sg    : ))+{C&224*

  	& 'vtM	-r   c                 L    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: 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)   s           r   DEFINE_enumrn     s/    > 
nnT7D+>>8
 r   c                 P    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: 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'   rp   r(   r)   s	            r   DEFINE_enum_classrt     sH    < 




	
 (  X
7 7r   c                 z    t        j                         }t        j                  d      }t        || ||||fd|i|S )ak  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: 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*   r^   s           r   DEFINE_listry     sU    2 &&(&11#6*	


 
 	
 r   c                 ~    t        j                  |      }t        j                  d      }t        || ||||fd|i|S )aT  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: 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%   r{   r   r(   r)   r   r&   s	            r   DEFINE_spaceseplistr     sZ    : 99!&..s3*	


 
 	
 r   c           	      N    t        t        j                  | ||||fi ||||      S )aI  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: 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)   s	            r   DEFINE_multir   D  s2    P 
oofj$FF;
* *r   c                 x    t        j                         }t        j                         }t        ||| |||fd|i|S )a<  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 `DEFINE_multi`.
    help: str, the help message.
    flag_values: 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   r\   r]   r   r^   s           r   DEFINE_multi_stringr   q  sS    < **,&224*	


 
 	
 r   c                 |    t        j                  ||      }t        j                         }	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: 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   ri   r]   r   
r   r$   r%   r   r   r   r(   r)   r   r&   s
             r   DEFINE_multi_integerr     sX    B ))+{C&224*	


 
 	
 r   c                 |    t        j                  ||      }t        j                         }	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: 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   rd   r]   r   r   s
             r   DEFINE_multi_floatr     sX    B ''[A&224*	


 
 	
 r   Tc                 |    t        j                  ||      }t        j                         }	t        ||	| |||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: 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.
  r(   )r   
EnumParserr]   r   )
r   r$   rm   r%   r   rp   r(   r)   r   r&   s
             r   DEFINE_multi_enumr     sX    D &&{NC&224*	


 
 	
 r   c           	      R    t        t        j                  | ||||      ||fd|i|S )a2  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: 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.
  )rp   r(   )r"   r   MultiEnumClassFlagrr   s	            r   DEFINE_multi_enum_classr   '  sF    L 

z.J	

 
 	
 r   c           
         ||vrt        j                  |      ||    G fddt        j                        }dj                  z  }t         |j                  j                  | j                  |j                        ||      S )a?  Defines an alias flag for an existing one.

  Args:
    name: str, the flag name.
    original_name: str, the original flag name.
    flag_values: 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                   ^    e Zd ZdZ fdZd Ze fd       Zej                   fd       Zy) DEFINE_alias.<locals>._FlagAliaszCOverrides Flag class so alias value is copy of original flag value.c                 R    j                  |       | xj                  dz  c_        y )NrR   )parsepresent)selfargumentr7   s     r   r   z&DEFINE_alias.<locals>._FlagAlias.parses  s    
jj
llalr   c                     |S N )r   r   s     r   _parse_from_defaultz4DEFINE_alias.<locals>._FlagAlias._parse_from_defaultw  s	     lr   c                     j                   S r   r   )r   r7   s    r   r   z&DEFINE_alias.<locals>._FlagAlias.value  s    ZZr   c                     |_         y r   r   )r   r   r7   s     r   r   z&DEFINE_alias.<locals>._FlagAlias.value  s
    djr   N)	rM   
__module____qualname____doc__r   r   propertyr   setter)r7   s   r   
_FlagAliasr   p  s<    M   \\ r   r   zAlias for --%s.)boolean)
r   UnrecognizedFlagErrorr   r#   r   r"   r   r&   r$   r   )r   original_namer   r'   r   help_msgr7   s         @r   DEFINE_aliasr   V  s    , +%

+
+M
::	]	#$5:: . *(	
++
//

,,
,,  "-k
; ;r   )0r   
__future__r   r   r   r.   rI   
absl.flagsr   r   r   r	   r
   r   typingr   r   r   ImportErrorenumrV   rW   r4   r/   rM   r    FLAGSr*   r"   r@   rE   rP   rZ   r_   rb   rg   rj   rn   rt   ry   r   r   r   r   r   r   r   r   r   r   r   <module>r      sZ   '  % 
  ' "  "  "$$
 	      CKK$9!: ;K2 !!%T !!	+=^ -8,=,=04?@ -8,=,= $?N 0;/@/@ %>/. !!2 !!#T !!)` !!)b !!!R !!%7X !!#T !!(b !!**b !!(^ !!+d !!+f !!,h !!,d !!	:;c  
  s$   
G G$ G! G!$G-,G-