Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python35/lib/python3.5/site-packages/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python35/lib/python3.5/site-packages/__pycache__/gflags.cpython-35.pyc



0�]>��@s|dZddlZddlZddlZddlZddlZddlZddlZyddlZWne	k
r�dZYnXyddl
Z
Wne	k
r�dZ
YnXddlZdejkZ
dd�Zdd�Zdd	�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZiadZdd�Zdd�Zdddd d!d"�Zd#d$�Zd%d&�Z d'd(�Z!Gd)d*�d*�Z"e"�Z#d+d,�Z$d-d.�Z%d/d0�Z&Gd1d2�d2�Z'Gd3d4�d4e(�Z)Gd5d6�d6e*d7e)�Z+Gd8d9�d9�Z,Gd:d;�d;e,�Z-d<e#d=d>�Z.e#d?d@�Z/dAdB�Z0e#ddCdD�Z1e#dEdF�Z2e#ddGdH�Z3e#dIdJ�Z4e#dKdL�Z5e#dMdN�Z6GdOdP�dPe+�Z7GdQdR�dRe'�Z8e#dSdT�Z9e9Z:GdUdV�dVe8�Z;GdWdX�dXe8�Z<GdYdZ�dZe8�Z=Gd[d\�d\e+�Z>Gd]d^�d^e>�Z?dde#d_d`�Z@Gdadb�dbe>�ZAdde#dcdd�ZBGdedf�dfe+�ZCGdgdh�dhe'�ZDe#didj�ZEGdkdl�dle+�ZFGdmdn�dneF�ZGGdodp�dpeF�ZHe#dqdr�ZIe#dsdt�ZJGdudv�dve'�ZKe#dwdx�ZLe#dydz�ZMdde#d{d|�ZNdde#d}d~�ZOe2e;��e2e=��e2e<��e"�ZPe6ddd�eP�e6d�dd�eP�dS)�a�5This module is used to define and parse command line flags.

This module defines a *distributed* flag-definition policy: rather than
an application having to define all flags in or near main(), each python
module defines flags that are useful to it.  When one python module
imports another, it gains access to the other's flags.  (This is
implemented by having all modules share a common, global registry object
containing all the flag information.)

Flags are defined through the use of one of the DEFINE_xxx functions.
The specific function used determines how the flag is parsed, checked,
and optionally type-converted, when it's seen on the command line.


IMPLEMENTATION: DEFINE_* creates a 'Flag' object and registers it with a
'FlagValues' object (typically the global FlagValues FLAGS, defined
here).  The 'FlagValues' object can scan the command line arguments and
pass flag arguments to the corresponding 'Flag' objects for
value-checking and type conversion.  The converted flag values are
available as attributes of the 'FlagValues' object.

Code can access the flag through a FlagValues object, for instance
gflags.FLAGS.myflag.  Typically, the __main__ module passes the command
line arguments to gflags.FLAGS for parsing.

At bottom, this module calls getopt(), so getopt functionality is
supported, including short- and long-style flags, and the use of -- to
terminate flags.

Methods defined by the flag module will throw 'FlagsError' exceptions.
The exception argument will be a human-readable string.


FLAG TYPES: This is a list of the DEFINE_*'s that you can do.  All flags
take a name, default value, help-string, and optional 'short' name
(one-letter name).  Some flags have other arguments, which are described
with the flag.

DEFINE_string: takes any input, and interprets it as a string.

DEFINE_bool or
DEFINE_boolean: typically does not take an argument: say --myflag to
                set FLAGS.myflag to true, or --nomyflag to set
                FLAGS.myflag to false.  Alternately, you can say
                   --myflag=true  or --myflag=t or --myflag=1  or
                   --myflag=false or --myflag=f or --myflag=0

DEFINE_float: takes an input and interprets it as a floating point
              number.  Takes optional args lower_bound and upper_bound;
              if the number specified on the command line is out of
              range, it will raise a FlagError.

DEFINE_integer: takes an input and interprets it as an integer.  Takes
                optional args lower_bound and upper_bound as for floats.

DEFINE_enum: takes a list of strings which represents legal values.  If
             the command-line value is not in this list, raise a flag
             error.  Otherwise, assign to FLAGS.flag as a string.

DEFINE_list: Takes a comma-separated list of strings on the commandline.
             Stores them in a python list object.

DEFINE_spaceseplist: Takes a space-separated list of strings on the
                     commandline.  Stores them in a python list object.
                     Example: --myspacesepflag "foo bar baz"

DEFINE_multistring: The same as DEFINE_string, except the flag can be
                    specified more than once on the commandline.  The
                    result is a python list object (list of strings),
                    even if the flag is only on the command line once.

DEFINE_multi_int: The same as DEFINE_integer, except the flag can be
                  specified more than once on the commandline.  The
                  result is a python list object (list of ints), even if
                  the flag is only on the command line once.


SPECIAL FLAGS: There are a few flags that have special meaning:
   --help          prints a list of all the flags in a human-readable fashion
   --helpshort     prints a list of all key flags (see below).
   --helpxml       prints a list of all flags, in XML format.  DO NOT parse
                   the output of --help and --helpshort.  Instead, parse
                   the output of --helpxml.  For more info, see
                   "OUTPUT FOR --helpxml" below.
   --flagfile=foo  read flags from file foo.
   --undefok=f1,f2 ignore unrecognized option errors for f1,f2.
                   For boolean flags, you should use --undefok=boolflag, and
                   --boolflag and --noboolflag will be accepted.  Do not use
                   --undefok=noboolflag.
   --              as in getopt(), terminates flag-processing


FLAGS VALIDATORS: If your program:
  - requires flag X to be specified
  - needs flag Y to match a regular expression
  - or requires any more general constraint to be satisfied
then validators are for you!

Each validator represents a constraint over one flag, which is enforced
starting from the initial parsing of the flags and until the program
terminates.

Also, lower_bound and upper_bound for numerical flags are enforced using flag
validators.

Howto:
If you want to enforce a constraint over one flag, use

gflags.RegisterValidator(flag_name,
                        checker,
                        message='Flag validation failed',
                        flag_values=FLAGS)

After flag values are initially parsed, and after any change to the specified
flag, method checker(flag_value) will be executed. If constraint is not
satisfied, an IllegalFlagValue exception will be raised. See
RegisterValidator's docstring for a detailed explanation on how to construct
your own checker.


EXAMPLE USAGE:

FLAGS = gflags.FLAGS

gflags.DEFINE_integer('my_version', 0, 'Version number.')
gflags.DEFINE_string('filename', None, 'Input file name', short_name='f')

gflags.RegisterValidator('my_version',
                        lambda value: value % 2 == 0,
                        message='--my_version must be divisible by 2')
gflags.MarkFlagAsRequired('filename')


NOTE ON --flagfile:

Flags may be loaded from text files in addition to being specified on
the commandline.

Any flags you don't feel like typing, throw them in a file, one flag per
line, for instance:
   --myflag=myvalue
   --nomyboolean_flag
You then specify your file with the special flag '--flagfile=somefile'.
You CAN recursively nest flagfile= tokens OR use multiple files on the
command line.  Lines beginning with a single hash '#' or a double slash
'//' are comments in your flagfile.

Any flagfile=<file> will be interpreted as having a relative path from
the current working directory rather than from the place the file was
included from:
   myPythonScript.py --flagfile=config/somefile.cfg

If somefile.cfg includes further --flagfile= directives, these will be
referenced relative to the original CWD, not from the directory the
including flagfile was found in!

The caveat applies to people who are including a series of nested files
in a different dir than they are executing out of.  Relative path names
are always from CWD, not from the directory of the parent include
flagfile. We do now support '~' expanded directory names.

Absolute path names ALWAYS work!


EXAMPLE USAGE:


  FLAGS = gflags.FLAGS

  # Flag names are globally defined!  So in general, we need to be
  # careful to pick names that are unlikely to be used by other libraries.
  # If there is a conflict, we'll get an error at import time.
  gflags.DEFINE_string('name', 'Mr. President', 'your name')
  gflags.DEFINE_integer('age', None, 'your age in years', lower_bound=0)
  gflags.DEFINE_boolean('debug', False, 'produces debugging output')
  gflags.DEFINE_enum('gender', 'male', ['male', 'female'], 'your gender')

  def main(argv):
    try:
      argv = FLAGS(argv)  # parse flags
    except gflags.FlagsError, e:
      print '%s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], FLAGS)
      sys.exit(1)
    if FLAGS.debug: print 'non-flag arguments:', argv
    print 'Happy Birthday', FLAGS.name
    if FLAGS.age is not None:
      print 'You are a %d year old %s' % (FLAGS.age, FLAGS.gender)

  if __name__ == '__main__':
    main(sys.argv)


KEY FLAGS:

As we already explained, each module gains access to all flags defined
by all the other modules it transitively imports.  In the case of
non-trivial scripts, this means a lot of flags ...  For documentation
purposes, it is good to identify the flags that are key (i.e., really
important) to a module.  Clearly, the concept of "key flag" is a
subjective one.  When trying to determine whether a flag is key to a
module or not, assume that you are trying to explain your module to a
potential user: which flags would you really like to mention first?

We'll describe shortly how to declare which flags are key to a module.
For the moment, assume we know the set of key flags for each module.
Then, if you use the app.py module, you can use the --helpshort flag to
print only the help for the flags that are key to the main module, in a
human-readable format.

NOTE: If you need to parse the flag help, do NOT use the output of
--help / --helpshort.  That output is meant for human consumption, and
may be changed in the future.  Instead, use --helpxml; flags that are
key for the main module are marked there with a <key>yes</key> element.

The set of key flags for a module M is composed of:

1. Flags defined by module M by calling a DEFINE_* function.

2. Flags that module M explictly declares as key by using the function

     DECLARE_key_flag(<flag_name>)

3. Key flags of other modules that M specifies by using the function

     ADOPT_module_key_flags(<other_module>)

   This is a "bulk" declaration of key flags: each flag that is key for
   <other_module> becomes key for the current module too.

Notice that if you do not use the functions described at points 2 and 3
above, then --helpshort prints information only about the flags defined
by the main module of our script.  In many cases, this behavior is good
enough.  But if you move part of the main module code (together with the
related flags) into a different module, then it is nice to use
DECLARE_key_flag / ADOPT_module_key_flags and make sure --helpshort
lists all relevant flags (otherwise, your code refactoring may confuse
your users).

Note: each of DECLARE_key_flag / ADOPT_module_key_flags has its own
pluses and minuses: DECLARE_key_flag is more targeted and may lead a
more focused --helpshort documentation.  ADOPT_module_key_flags is good
for cases when an entire module is considered key to the current script.
Also, it does not require updates to client scripts when a new flag is
added to the module.


EXAMPLE USAGE 2 (WITH KEY FLAGS):

Consider an application that contains the following three files (two
auxiliary modules and a main module)

File libfoo.py:

  import gflags

  gflags.DEFINE_integer('num_replicas', 3, 'Number of replicas to start')
  gflags.DEFINE_boolean('rpc2', True, 'Turn on the usage of RPC2.')

  ... some code ...

File libbar.py:

  import gflags

  gflags.DEFINE_string('bar_gfs_path', '/gfs/path',
                      'Path to the GFS files for libbar.')
  gflags.DEFINE_string('email_for_bar_errors', 'bar-team@google.com',
                      'Email address for bug reports about module libbar.')
  gflags.DEFINE_boolean('bar_risky_hack', False,
                       'Turn on an experimental and buggy optimization.')

  ... some code ...

File myscript.py:

  import gflags
  import libfoo
  import libbar

  gflags.DEFINE_integer('num_iterations', 0, 'Number of iterations.')

  # Declare that all flags that are key for libfoo are
  # key for this module too.
  gflags.ADOPT_module_key_flags(libfoo)

  # Declare that the flag --bar_gfs_path (defined in libbar) is key
  # for this module.
  gflags.DECLARE_key_flag('bar_gfs_path')

  ... some code ...

When myscript is invoked with the flag --helpshort, the resulted help
message lists information about all the key flags for myscript:
--num_iterations, --num_replicas, --rpc2, and --bar_gfs_path.

Of course, myscript uses all the flags declared by it (in this case,
just --num_replicas) or by any of the modules it transitively imports
(e.g., the modules libfoo, libbar).  E.g., it can access the value of
FLAGS.bar_risky_hack, even if --bar_risky_hack is not declared as a key
flag for myscript.


OUTPUT FOR --helpxml:

The --helpxml flag generates output with the following structure:

<?xml version="1.0"?>
<AllFlags>
  <program>PROGRAM_BASENAME</program>
  <usage>MAIN_MODULE_DOCSTRING</usage>
  (<flag>
    [<key>yes</key>]
    <file>DECLARING_MODULE</file>
    <name>FLAG_NAME</name>
    <meaning>FLAG_HELP_MESSAGE</meaning>
    <default>DEFAULT_FLAG_VALUE</default>
    <current>CURRENT_FLAG_VALUE</current>
    <type>FLAG_TYPE</type>
    [OPTIONAL_ELEMENTS]
  </flag>)*
</AllFlags>

Notes:

1. The output is intentionally similar to the output generated by the
C++ command-line flag library.  The few differences are due to the
Python flags that do not have a C++ equivalent (at least not yet),
e.g., DEFINE_list.

2. New XML elements may be added in the future.

3. DEFAULT_FLAG_VALUE is in serialized form, i.e., the string you can
pass for this flag on the command-line.  E.g., for a flag defined
using DEFINE_list, this field may be foo,bar, not ['foo', 'bar'].

4. CURRENT_FLAG_VALUE is produced using str().  This means that the
string 'false' will be represented in the same way as the boolean
False.  Using repr() would have removed this ambiguity and simplified
parsing, but would have broken the compatibility with the C++
command-line flags.

5. OPTIONAL_ELEMENTS describe elements relevant for certain kinds of
flags: lower_bound, upper_bound (for flags that specify bounds),
enum_value (for enum flags), list_separator (for flags that consist of
a list of values, separated by a special token).

6. We do not provide any example here: please use --helpxml instead.

This module requires at least python 2.2.1 to run.
�Nzpychecker.pythoncCs�xrtdtj��D][}tj|�jt�k	rtj|�j}t|�\}}|dk	r||fSqWtd��dS)z�Returns the module that's calling into this module.

  We generally use this function to get the name of the module calling a
  DEFINE_foo... function.
  �NzNo module was found)�range�sys�getrecursionlimit�	_getframe�	f_globals�globals�_GetModuleObjectAndName�AssertionError)�depthZglobals_for_frame�module�module_name�r�7/opt/alt/python35/lib/python3.5/site-packages/gflags.py�_GetCallingModuleObjectAndName�srcCst�dS)z?Returns the name of the module that's calling into this module.r)rrrrr�_GetCallingModule�srcCs
tt��S)z6Returns: (module object, module name) for this module.)r	rrrrr�_GetThisModuleObjectAndName�src@seZdZdZdS)�
FlagsErrorz$The base class for all flags errors.N)�__name__�
__module__�__qualname__�__doc__rrrrr�src@seZdZdZdS)�
DuplicateFlagz*Raised if there is a flag naming conflict.N)rrrrrrrrr�src@seZdZdZdS)�CantOpenFlagFileErrorzHRaised if flagfile fails to open: doesn't exist, wrong permissions, etc.N)rrrrrrrrr�src@seZdZdZdS)�&DuplicateFlagCannotPropagateNoneToSwigaBSpecial case of DuplicateFlag -- SWIG flag value can't be set to None.

  This can be raised when a duplicate flag is created. Even if allow_override is
  True, we still abort if the new value is None, because it's currently
  impossible to pass None default value back to SWIG. See FlagValues.SetDefault
  for details.
  N)rrrrrrrrr�src@s%eZdZdZddd�ZdS)�DuplicateFlagErrora=A DuplicateFlag whose message cites the conflicting definitions.

  A DuplicateFlagError conveys more information than a DuplicateFlag,
  namely the modules where the conflicting definitions occur. This
  class was created to avoid breaking external modules which depend on
  the existing DuplicateFlags interface.
  NcCsu||_|j|dd�}|dkr6t�}n|j|dd�}d|j||f}tj||�dS)aCreate a DuplicateFlagError.

    Args:
      flagname: Name of the flag being redefined.
      flag_values: FlagValues object containing the first definition of
          flagname.
      other_flag_values: If this argument is not None, it should be the
          FlagValues object where the second definition of flagname occurs.
          If it is None, we assume that we're being called when attempting
          to create the flag a second time, and we use the module calling
          this one as the source of the second definition.
    �defaultz	<unknown>Nz=The flag '%s' is defined twice. First from %s, Second from %s)�flagname�FindModuleDefiningFlagrr�__init__)�selfr�flag_values�other_flag_valuesZfirst_moduleZ
second_module�msgrrrr�s
	zDuplicateFlagError.__init__)rrrrrrrrrr�src@seZdZdZdS)�IllegalFlagValuez*The flag command line argument is illegal.N)rrrrrrrrr$�sr$c@seZdZdZdS)�UnrecognizedFlagz!Raised if a flag is unrecognized.N)rrrrrrrrr%�sr%c@seZdZddd�ZdS)�UnrecognizedFlagError�cCs*||_||_tj|d|�dS)NzUnknown command line flag '%s')r�	flagvaluer%r)r rr(rrrrs		zUnrecognizedFlagError.__init__N)rrrrrrrrr&sr&�Pc
Cs�tjj�s(tdks(tdkr,tSy[tjtjtjd�}tj	d|�d}|dkrp|St
tjdt��SWn"t
ttjfk
r�tSYnXdS)zFReturns: an integer, the width of help lines that is used in TextWrap.NZ1234Zhhr�(�COLUMNS)r�stdout�isatty�termios�fcntl�_help_widthZioctlZ
TIOCGWINSZ�struct�unpack�int�os�getenv�	TypeError�IOError�error)�data�columnsrrr�GetHelpWidths(r;cCs|j�}x%|r3|dr3|dd	�}qW|r|dra|ddj�rag}n|jd�g}tjjdd�|D��}t|�t|j��}|r�x<tt|��D](}||r�|||d�||<q�Wdj	||�SdS)
a�Removes a common space prefix from the lines of a multiline text.

  If the first line does not start with a space, it is left as it is and
  only in the remaining lines a common space prefix is being searched
  for. That means the first line will stay untouched. This is especially
  useful to turn doc strings into help texts. This is because some
  people prefer to have the doc comment start already after the
  apostrophe and then align the following lines while others have the
  apostrophes on a separate line.

  The function also drops trailing empty lines and ignores empty lines
  following the initial content line while calculating the initial
  common whitespace.

  Args:
    text: text to work on

  Returns:
    the resulting text
  rNrcSsg|]}|r|�qSrr)�.0�linerrr�
<listcomp>Ds	z(CutCommonSpacePrefix.<locals>.<listcomp>�
r'���r@)
�
splitlines�isspace�popr4�path�commonprefix�len�lstripr�join)�textZ
text_linesZtext_first_lineZ
common_prefixZspace_prefix_len�indexrrr�CutCommonSpacePrefix$s	
rKr'z    cCs|dkrt�}|dkr'd}t|�|krEtd��|dkr`d}|}n$|}t|�|kr�td��|s�|dkr�|jdd�}n
|j�}tjdtj�}g}x*|j�D]}	t|�}
x�|j	|	j
��D]�\}}}
|r�|r0||ksC|rc||krc|d
dkrc|dd�}|r�||t|�7}n|t|�|
}
t|�t|
�|kr+t|�t|
�|kr+|j|j
��||
}d}
t|�d|kr!|j|j
��|}n
|d7}xWt|�t|
�|kr�||
7}|j|d|��||d�}
|}q.W|
r	||
d7}q	W|r�||ks�|r�||kr�|j|j
��nt|�|
kr�|jd�|}q�Wd	j|�S)a�Wraps a given text to a maximum line length and returns it.

  We turn lines that only contain whitespace into empty lines.  We keep
  new lines and tabs (e.g., we do not treat tabs as spaces).

  Args:
    text:             text to wrap
    length:           maximum length of a line, includes indentation
                      if this is None then use GetHelpWidth()
    indent:           indent for all but first line
    firstline_indent: indent for first line; if None, fall back to indent
    tabs:             replacement for tabs

  Returns:
    wrapped text

  Raises:
    FlagsError: if indent not shorter than length
    FlagsError: if firstline_indent not shorter than length
  Nr'z"Indent must be shorter than lengthz-First line indent must be shorter than length� �	z([ ]*)(	*)([^ 	]+)rr?r@r@)
r;rFr�replace�strip�re�compile�	MULTILINErA�findall�rstrip�appendrH)rI�length�indent�firstline_indent�tabsr=Ztabs_are_whitespaceZ
line_regex�resultZ	text_lineZold_result_lenZspacesZcurrent_tabs�wordrrr�TextWrapOs`		
%#8
	


%

r\cCs^|j�}tjdtj�}|jd|�}t|�}tjdd|tj�}|S)z0Takes a __doc__ string and reformats it as help.z^[ 	]+$r'z(?<=\S)
(?=\S)rL)rOrPrQ�M�subrK)�docZwhitespace_only_linerrr�	DocToHelp�sr`cCsex^ttjj��D]G\}}t|dd�|kr|dkrStjd}||fSqWdS)a^Returns the module that defines a global environment, and its name.

  Args:
    globals_dict: A dictionary that should correspond to an environment
      providing the values of the globals.

  Returns:
    A pair consisting of (1) module object and (2) module name (a
    string).  Returns (None, None) if the module could not be
    identified.
  �__dict__N�__main__r)NN)�listr�modules�items�getattr�argv)Zglobals_dict�namerrrrr	�s"
r	cCsdtjd�}x|jdk	r-|j}qW|j}t|�d}|dkr`tjd}|S)zAReturns: string, name of the module from which execution started.rNr)rr�f_backrr	rg)Z
deepest_frameZglobals_for_main_moduleZmain_module_namerrr�_GetMainModule�s	
	
rjc@s�eZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zddd�Zddd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�ZeZd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdGdH�Z&dFdIdJ�Z'dFdKdL�Z(dFdMdN�Z)dOdP�Z*dQdR�Z+dSdTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1dd`da�Z2dbdc�Z3ddde�Z4ddfdg�Z5dhdi�Z6dS)j�
FlagValuesa1Registry of 'Flag' objects.

  A 'FlagValues' can then scan command line arguments, passing flag
  arguments through to the 'Flag' objects that it owns.  It also
  provides easy access to the flag values.  Typically only one
  'FlagValues' object is needed by an application: gflags.FLAGS

  This class is heavily overloaded:

  'Flag' objects are registered via __setitem__:
       FLAGS['longname'] = x   # register a new flag

  The .value attribute of the registered 'Flag' objects can be accessed
  as attributes of this 'FlagValues' object, through __getattr__.  Both
  the long and short name of the original 'Flag' objects can be used to
  access its value:
       FLAGS.longname          # parsed flag value
       FLAGS.x                 # parsed flag value (short name)

  Command line arguments are scanned and passed to the registered 'Flag'
  objects through the __call__ method.  Unparsed arguments, including
  argv[0] (e.g. the program name) are returned.
       argv = FLAGS(sys.argv)  # scan command line arguments

  The original registered Flag objects can be retrieved through the use
  of the dictionary-like operator, __getitem__:
       x = FLAGS['longname']   # access the registered Flag object

  The str() operator of a 'FlagValues' object provides help for all of
  the registered 'Flag' objects.
  cCsEi|jd<i|jd<i|jd<i|jd<|jd�dS)N�__flags�__flags_by_module�__flags_by_module_id�__key_flags_by_moduleF)ra�UseGnuGetOpt)r rrrr+s




zFlagValues.__init__TcCs||jd<dS)z�Use GNU-style scanning. Allows mixing of flag and non-flag arguments.

    See http://docs.python.org/library/getopt.html#getopt.gnu_getopt

    Args:
      use_gnu_getopt: wether or not to use GNU style scanning.
    �__use_gnu_getoptN)ra)r Zuse_gnu_getoptrrrrp?szFlagValues.UseGnuGetOptcCs|jdS)Nrq)ra)r rrr�IsGnuGetOptIszFlagValues.IsGnuGetOptcCs|jdS)Nrl)ra)r rrr�FlagDictLszFlagValues.FlagDictcCs|jdS)z�Returns the dictionary of module_name -> list of defined flags.

    Returns:
      A dictionary.  Its keys are module names (strings).  Its values
      are lists of Flag objects.
    rm)ra)r rrr�FlagsByModuleDictOszFlagValues.FlagsByModuleDictcCs|jdS)z�Returns the dictionary of module_id -> list of defined flags.

    Returns:
      A dictionary.  Its keys are module IDs (ints).  Its values
      are lists of Flag objects.
    rn)ra)r rrr�FlagsByModuleIdDictXszFlagValues.FlagsByModuleIdDictcCs|jdS)z�Returns the dictionary of module_name -> list of key flags.

    Returns:
      A dictionary.  Its keys are module names (strings).  Its values
      are lists of Flag objects.
    ro)ra)r rrr�KeyFlagsByModuleDictaszFlagValues.KeyFlagsByModuleDictcCs)|j�}|j|g�j|�dS)a&Records the module that defines a specific flag.

    We keep track of which flag is defined by which module so that we
    can later sort the flags by module.

    Args:
      module_name: A string, the name of a Python module.
      flag: A Flag object, a flag that is key to the module.
    N)rt�
setdefaultrU)r r
�flag�flags_by_modulerrr�_RegisterFlagByModulejs
z FlagValues._RegisterFlagByModulecCs)|j�}|j|g�j|�dS)z�Records the module that defines a specific flag.

    Args:
      module_id: An int, the ID of the Python module.
      flag: A Flag object, a flag that is key to the module.
    N)rurwrU)r �	module_idrxZflags_by_module_idrrr�_RegisterFlagByModuleIdwsz"FlagValues._RegisterFlagByModuleIdcCs;|j�}|j|g�}||kr7|j|�dS)z�Specifies that a flag is a key flag for a module.

    Args:
      module_name: A string, the name of a Python module.
      flag: A Flag object, a flag that is key to the module.
    N)rvrwrU)r r
rxZkey_flags_by_module�	key_flagsrrr�_RegisterKeyFlagForModule�sz$FlagValues._RegisterKeyFlagForModulecCs4t|t�s|j}t|j�j|g��S)a*Returns the list of flags defined by a module.

    Args:
      module: A module object or a module name (a string).

    Returns:
      A new list of Flag objects.  Caller may update this list as he
      wishes: none of those changes will affect the internals of this
      FlagValue object.
    )�
isinstance�strrrcrt�get)r rrrr�_GetFlagsDefinedByModule�s	z#FlagValues._GetFlagsDefinedByModulecCsgt|t�s|j}|j|�}x9|j�j|g�D]}||kr@|j|�q@W|S)a&Returns the list of key flags for a module.

    Args:
      module: A module object or a module name (a string)

    Returns:
      A new list of Flag objects.  Caller may update this list as he
      wishes: none of those changes will affect the internals of this
      FlagValue object.
    )rr�rr�rvr�rU)r rr}rxrrr�_GetKeyFlagsForModule�s	z FlagValues._GetKeyFlagsForModuleNcCsZxS|j�j�D]?\}}x0|D](}|j|ksJ|j|kr&|Sq&WqW|S)a�Return the name of the module defining this flag, or default.

    Args:
      flagname: Name of the flag to lookup.
      default: Value to return if flagname is not defined. Defaults
          to None.

    Returns:
      The name of the module which registered the flag with this name.
      If no such module exists (i.e. no flag with this name exists),
      we return default.
    )rtrerh�
short_name)r rrr�flagsrxrrrr�s


z!FlagValues.FindModuleDefiningFlagcCsZxS|j�j�D]?\}}x0|D](}|j|ksJ|j|kr&|Sq&WqW|S)aReturn the ID of the module defining this flag, or default.

    Args:
      flagname: Name of the flag to lookup.
      default: Value to return if flagname is not defined. Defaults
          to None.

    Returns:
      The ID of the module which registered the flag with this name.
      If no such module exists (i.e. no flag with this name exists),
      we return default.
    )rurerhr�)r rrr{r�rxrrr�FindModuleIdDefiningFlag�s


z#FlagValues.FindModuleIdDefiningFlagcCsnxg|j�j�D]S\}}||jkry|||<Wqtk
ret||d|��YqXqWdS)zqAppends flags registered in another FlagValues instance.

    Args:
      flag_values: registry to copy from
    r"N)rsrerhr)r r!�	flag_namerxrrr�AppendFlagValues�s
zFlagValues.AppendFlagValuescCs(x!|j�D]}|j|�q
WdS)z�Remove flags that were previously appended from another FlagValues.

    Args:
      flag_values: registry containing flags to remove.
    N)rs�__delattr__)r r!r�rrr�RemoveFlagValues�szFlagValues.RemoveFlagValuescCsT|j�}t|t�s't|��t|td��sHtd��t|�dkrftd��||kr�|jr�||jr�tr�t	�\}}|j
|�|kr�t|�|j|�kr�dSt
||��|j}|dk	r<||kr2|jr2||jr2tr2t
||��|||<|||<|t|<dS)zRegisters a new flag variable.r'zFlag name must be a stringrzFlag name cannot be emptyN)rsr�Flagr$�typerrF�allow_override�_RUNNING_PYCHECKERrr�idr�rr��_exported_flags)r rhrx�flrr
r�rrr�__setitem__�s,	

zFlagValues.__setitem__cCs|j�|S)z.Retrieves the Flag object for the flag --name.)rs)r rhrrr�__getitem__szFlagValues.__getitem__cCs/|j�}||kr$t|��||jS)z3Retrieves the 'value' attribute of the flag --name.)rs�AttributeError�value)r rhr�rrr�__getattr__szFlagValues.__getattr__cCs1|j�}|||_|j||j�|S)z.Sets the 'value' attribute of the flag --name.)rsr��_AssertValidators�
validators)r rhr�r�rrr�__setattr__$s
zFlagValues.__setattr__cCsXt�}x;|j�j�D]'}x|jD]}|j|�q,WqW|j|�dS)N)�setrs�valuesr��addr�)r Zall_validatorsrx�	validatorrrr�_AssertAllValidators+s
	zFlagValues._AssertAllValidatorscCs�x�t|ddd��D]m}y|j|�Wqtjk
r�}z0|j|�}td|t|�f��WYdd}~XqXqWdS)akAssert if all validators in the list are satisfied.

    Asserts validators in the order they were created.
    Args:
      validators: Iterable(gflags_validators.Validator), validators to be
        verified
    Raises:
      AttributeError: if validators work with a non-existing flag.
      IllegalFlagValue: if validation fails for at least one validator
    �keycSs|jS)N)Zinsertion_index)r�rrr�<lambda>>sz.FlagValues._AssertValidators.<locals>.<lambda>z%s: %sN)�sortedZVerify�gflags_validators�ErrorZPrintFlagsWithValuesr$r�)r r�r��e�messagerrrr�2szFlagValues._AssertValidatorscCsf|j�}|j}|j|d�|kr1dS|j}|dk	rb|j|d�|krbdSdS)aChecks whether a Flag object is registered under some name.

    Note: this is non trivial: in addition to its normal name, a flag
    may have a short name too.  In self.FlagDict(), both the normal and
    the short name are mapped to the same flag object.  E.g., calling
    only "del FLAGS.short_name" is not unregistering the corresponding
    Flag object (it is still registered under the longer name).

    Args:
      flag_obj: A Flag object.

    Returns:
      A boolean: True iff flag_obj is registered under some name.
    NTF)rsrhr�r�)r �flag_objZ	flag_dictrhr�rrr�_FlagIsRegisteredEs		zFlagValues._FlagIsRegisteredcCs�|j�}||kr$t|��||}||=|j|�s�|j|j�|�|j|j�|�|j|j�|�dS)a�Deletes a previously-defined flag from a flag object.

    This method makes sure we can delete a flag by using

      del flag_values_object.<flag_name>

    E.g.,

      gflags.DEFINE_integer('foo', 1, 'Integer flag.')
      del gflags.FLAGS.foo

    Args:
      flag_name: A string, the name of the flag to be deleted.

    Raises:
      AttributeError: When there is no registered flag named flag_name.
    N)rsr�r��'_FlagValues__RemoveFlagFromDictByModulertrurv)r r�r�r�rrrr�bs
zFlagValues.__delattr__cCsAx:|j�D],\}}x||kr8|j|�qWq
WdS)z�Removes a flag object from a module -> list of flags dictionary.

    Args:
      flags_by_module_dict: A dictionary that maps module names to lists of
        flags.
      flag_obj: A flag object.
    N)re�remove)r Zflags_by_module_dictr�Z
unused_moduleZflags_in_modulerrrZ__RemoveFlagFromDictByModule�sz'FlagValues.__RemoveFlagFromDictByModulecCsM|j�}||kr$t|��||j|�|j||j�dS)z3Changes the default value of the named flag object.N)rsr��
SetDefaultr�r�)r rhr�r�rrrr��s
zFlagValues.SetDefaultcCs||j�kS)z3Returns True if name is a value (flag) in the dict.)rs)r rhrrr�__contains__�szFlagValues.__contains__cCst|j��S)N)�iterrs)r rrr�__iter__�szFlagValues.__iter__cCs�t|�}d}g}|j�}|dd�|j|dd�dd�}t|�}d}xt|j��D]�\}}|js�qv|dkr�|j|�}d|}	||}
||	}x�tdt|��D]�}||}
|
jd�dkrq�|
j	d	|
�r<d	|j	|
�r<d
|||<q�|
j	d	|�r�d	|	j	|
�r�d|||<q�WqvWx`t|j��D]L\}}|j
|d�t|�dkr�||7}|js�|d7}q�W|j
d
�g}g}|dd�}xQyK|jdr5tj
|||�\}}ntj|||�\}}PWqtjk
rS}z�|js�|j|kr�t|��x�tt|��D]�}||d	|jks�||d|jks�||j	d	|jd�r�|j
|j||f�|d|�||dd�}Pq�Wt|��WYdd}~XqXqWx�|D]�\}}
|dkr�|
jd�}|j|�|jdd�|D��q_|j	d	�r�|dd�}d}n|dd�}d}||kr_||}|jr|rd}
|j|
�q_Wx/|D]'\}}||kr1t||��q1W|r�|jdr�|dd�|}q�|dd�|t|�d�}n|dd�}|j�|S)a�Parses flags from argv; stores parsed flags into this FlagValues object.

    All unparsed arguments are returned.  Flags are parsed using the GNU
    Program Argument Syntax Conventions, using getopt:

    http://www.gnu.org/software/libc/manual/html_mono/libc.html#Getopt

    Args:
       argv: argument list. Can be of any type that may be converted to a list.

    Returns:
       The list of arguments not parsed as options, including argv[0]

    Raises:
       FlagsError: on any parsing error
    r'Nr�	force_gnuF�no�=rz--z	--%s=truez
--%s=false�:zundefok=rq�-z	--undefok�,css|]}d|VqdS)r�Nr)r<rhrrr�	<genexpr>sz&FlagValues.__call__.<locals>.<genexpr>�)rcrs�ReadFlagsFromFilesre�boolean�ShortestUniquePrefixesrrF�find�
startswithrUra�getopt�
gnu_getopt�GetoptError�optr�split�extend�Parser&r�)r rg�	shortopts�longoptsr�Z
original_argv�shortest_matchesrhrxZno_name�prefixZ	no_prefixZarg_idx�argZ
undefok_flagsZunrecognized_opts�argsZoptlistZ
unparsed_argsr�Z	arg_index�
flag_names�short_optionr�r�Zret_valrrr�__call__�s�-	



&&
	

"#
		

(
zFlagValues.__call__cCs1x*t|j�j��D]}|j�qWdS)z=Resets the values to the point before FLAGS(argv) was called.N)rcrsr��Unparse)r �frrr�Reset6szFlagValues.ResetcCst|j��S)zEReturns: a list of the names and short names of all registered flags.)rcrs)r rrr�RegisteredFlags;szFlagValues.RegisteredFlagscCs>i}x1|j�D]#}|j�|}|j||<qW|S)z:Returns: a dictionary that maps flag names to flag values.)r�rsr�)r r!r�rxrrr�FlagValuesDict?s
zFlagValues.FlagValuesDictcCs
|j�S)z,Generates a help string for all known flags.)�GetHelp)r rrr�__str__IszFlagValues.__str__r'cCs�g}|j�}|r�t|�}t�}||krS|j|�|g|}x|D]}|j||�qZW|jdttj�j	��|�n;|j
t|j�j	��ttj�j	��||�dj|�S)z,Generates a help string for all known flags.�gflagsr?)rtr�rjr��!_FlagValues__RenderOurModuleFlags�_FlagValues__RenderModuleFlagsrc�_SPECIAL_FLAGSrsr��_FlagValues__RenderFlagListrH)r r��helplistryrdZmain_modulerrrrr�Ms"	


	
+
zFlagValues.GetHelpcCsJt|t�s|j}|jd||f�|j|||d�dS)z+Generates a help string for a given module.z
%s%s:z  N)rr�rrUr�)r rr��output_linesr�rrrZ__RenderModuleFlagsks	zFlagValues.__RenderModuleFlagscCs/|j|�}|r+|j||||�dS)z+Generates a help string for a given module.N)r�r�)r rr�r�r�rrrZ__RenderOurModuleFlagsrsz!FlagValues.__RenderOurModuleFlagscCs/|j|�}|r+|j||||�dS)a=Generates a help string for the key flags of a given module.

    Args:
      module: A module object or a module name (a string).
      output_lines: A list of strings.  The generated help message
        lines will be appended to this list.
      prefix: A string that is prepended to each generated help line.
    N)r�r�)r rr�r�r}rrrZ__RenderOurModuleKeyFlagsxs	z$FlagValues.__RenderOurModuleKeyFlagscCs#g}|j||�dj|�S)z�Describe the key flags of a module.

    Args:
      module: A module object or a module name (a string).

    Returns:
      string describing the key flags of a module.
    r?)�$_FlagValues__RenderOurModuleKeyFlagsrH)r rr�rrr�
ModuleHelp�s	zFlagValues.ModuleHelpcCs|jt��S)zpDescribe the key flags of the main module.

    Returns:
      string describing the key flags of a module.
    )r�rj)r rrr�MainModuleHelp�szFlagValues.MainModuleHelpz  c
Cs�|j�}tj�}dd�|D�}|j�i}xm|D]e\}}|j|d�|kr�|j|d�|kr�qB||kr�qBd||<d}	|jr�|	d|j7}	|jr�|	d|jd7}	n|	d|jd7}	|	d	7}	|jr|	|j7}	t|	d
|d	d|�}	|j	r`|	d7}	|	td
|j	d
|d	�7}	|j
jr�|	d7}	|	td|j
jd
|d	�7}	|j|	�qBWdS)NcSsg|]}|j|f�qSr)rh)r<rxrrrr>�s	z/FlagValues.__RenderFlagList.<locals>.<listcomp>rr'z-%s,z--[no]%sr�z--%sz  rWrXr?z
(default: %s)z(%s))
rsr��sortr�r�r�rh�helpr\�default_as_str�parser�syntactic_helprU)
r Zflaglistr�r�r�Z
special_flZflagsetrhrxZflaghelprrrZ__RenderFlagList�s>
0
		
	
		

zFlagValues.__RenderFlagListcCs'|j|�}|dk	r|S|SdS)z�Returns the value of a flag (if not None) or a default value.

    Args:
      name: A string, the name of a flag.
      default: Default value to use if the flag value is None.
    N)r�)r rhrr�rrrr��szFlagValues.getcCsOg}xGt|j��D]3\}}|j|�|jr|jd|�qW|j�i}d}x�tt|��D]�}||}|t|�dkr�d}	n||d}	t|	�}
x�tt|��D]Z}|	dks||
ks|||	|kr�|dt||�d�||<|}Pq�W|||<|d}qyW|S)zEReturns: dictionary; maps flag names to their shortest unique prefix.zno%srrN)rcrerUr�r�rrF�max)r r�Zsorted_flagsrhrxr�Zprev_idxZflag_idx�curr�nextZnext_lenZcurr_idxrrrr��s0
	

	!
z!FlagValues.ShortestUniquePrefixescCsct|td��r_|jd�r(dS|dkr8dS|jd�rKdS|dkr[dSdSdS)z@Checks whether flag_string contain a --flagfile=<foo> directive.r'z--flagfile=rz
--flagfilez
-flagfile=z	-flagfiler)rr�r�)r Zflag_stringrrrZ__IsFlagFileDirective�sz FlagValues.__IsFlagFileDirectivecCs~|jd�r5tjj|td�d�j��S|jd�rjtjj|td�d�j��Std|��dS)z�Returns filename from a flagfile_str of form -[-]flagfile=filename.

    The cases of --flagfile foo and -flagfile foo shouldn't be hitting
    this function, as they are dealt with in the level above this
    function.
    z--flagfile=Nz
-flagfile=zHit illegal --flagfile type: %s)r�r4rD�
expanduserrFrOr)r Zflagfile_strrrr�ExtractFilenames
&&zFlagValues.ExtractFilenamec
Cs8g}g}yt|d�}Wn5tk
rV}ztd|��WYdd}~XnX|j�}|j�|j|�x�|D]�}|j�r�q�|jd�s0|jd�r�q�|j|�r|j	|�}||kr|j
||�}	|j|	�q0tj
jd|f�q�|j|j��q�W|S)aXReturns the useful (!=comments, etc) lines from a file with flags.

    Args:
      filename: A string, the name of the flag file.
      parsed_file_list: A list of the names of the files we have
        already read.  MUTATED BY THIS FUNCTION.

    Returns:
      List of strings. See the note below.

    NOTE(springer): This function checks for a nested --flagfile=<foo>
    tag and handles the lower file recursively. It returns a list of
    all the lines that _could_ contain command flags. This is
    EVERYTHING except whitespace lines and comments (lines starting
    with '#' or '//').
    �rz#ERROR:: Unable to open flagfile: %sN�#z//z.Warning: Hit circular flagfile dependency: %s
)�openr7r�	readlines�closerUrBr�� _FlagValues__IsFlagFileDirectiver��_FlagValues__GetFlagFileLinesr�r�stderr�writerO)
r �filename�parsed_file_listZ	line_listZflag_line_listZfile_objZe_msgr=Zsub_filenameZincluded_flagsrrrZ__GetFlagFileLiness0#


		zFlagValues.__GetFlagFileLinescCsg}|}g}x�|r|d}|dd�}|j|�r�|dks\|dkr�|sntd��tjj|d�}|dd�}n|j|�}|j|j||��q|j|�|dkr�P|j	d�s|r|j
d	rPqW|r|j|�|S)
a^Processes command line args, but also allow args to be read from file.

    Args:
      argv: A list of strings, usually sys.argv[1:], which may contain one or
        more flagfile directives of the form --flagfile="./filename".
        Note that the name of the program (sys.argv[0]) should be omitted.
      force_gnu: If False, --flagfile parsing obeys normal flag semantics.
        If True, --flagfile parsing instead follows gnu_getopt semantics.
        *** WARNING *** force_gnu=False may become the future default!

    Returns:

      A new list which has the original list combined with what we read
      from any flagfile(s).

    References: Global gflags.FLAG class instance.

    This function should be called before the normal FLAGS(argv) call.
    This function scans the input list for a flag that looks like:
    --flagfile=<somefile>. Then it opens <somefile>, reads all valid key
    and value pairs and inserts them into the input list between the
    first item of the list and any subsequent items in the list.

    Note that your application's flags are still defined the usual way
    using gflags DEFINE_flag() type functions.

    Notes (assuming we're getting a commandline of some sort as our input):
    --> Flags from the command line argv _should_ always take precedence!
    --> A further "--flagfile=<otherfile.cfg>" CAN be nested in a flagfile.
        It will be processed after the parent flag file is done.
    --> For duplicate flags, first one we hit should "win".
    --> In a flagfile, a line beginning with # or // is a comment.
    --> Entirely blank lines _should_ be ignored.
    rrNz
--flagfilez	-flagfilez--flagfile with no argumentz--r�rq)r�r$r4rDr�r�r�r�rUr�ra)r rgr�r�Zrest_of_argsZnew_argvZcurrent_argZ
flag_filenamerrrr�Ds0#	


zFlagValues.ReadFlagsFromFilescCsPd}xCt|j�j��D])}|jdk	r||j�d7}qW|S)a2Returns a string with the flags assignments from this FlagValues object.

    This function ignores flags whose value is None.  Each flag
    assignment is separated by a newline.

    NOTE: MUST mirror the behavior of the C++ CommandlineFlagsIntoString
    from http://code.google.com/p/google-gflags
    r'Nr?)rcrsr�r��	Serialize)r �srxrrr�FlagsIntoString�s
	zFlagValues.FlagsIntoStringcCs0t|d�}|j|j��|j�dS)z�Appends all flags assignments from this FlagInfo object to a file.

    Output will be in the format of a flagfile.

    NOTE: MUST mirror the behavior of the C++ AppendFlagsIntoFile
    from http://code.google.com/p/google-gflags
    �aN)r�r�r�r�)r r��out_filerrr�AppendFlagsIntoFile�szFlagValues.AppendFlagsIntoFilec	Csq|ptj}|jd�|jd�d}t|dtjjtjd�|�tjdj	}|sdtjd}n|j
dtjd�}t|d	||�|jt��}|j
�}t|j��}|j�xn|D]f}d
d�||D�}|j�x<|D]4\}	}
|
|k}|
j||d|d
|�qWq�W|jd�|j�dS)a�Outputs flag documentation in XML format.

    NOTE: We use element names that are consistent with those used by
    the C++ command-line flag library, from
    http://code.google.com/p/google-gflags
    We also use a few new elements (e.g., <key>), but we do not
    interfere / overlap with existing XML elements used by the C++
    library.  Please maintain this consistency.

    Args:
      outfile: File object we write to.  Default None means sys.stdout.
    z<?xml version="1.0"?>
z<AllFlags>
z  �programrrbz
USAGE: %s [flags]
z%s�usagecSsg|]}|j|f�qSr)rh)r<r�rrrr>�s	z3FlagValues.WriteHelpInXMLFormat.<locals>.<listcomp>�is_keyrWz</AllFlags>
N)rr,r��_WriteSimpleXMLElementr4rD�basenamergrdrrNr�rjrtrc�keysr��WriteInfoInXMLFormat�flush)r �outfilerWZ	usage_docr}ryZall_module_namesr
Z	flag_listZunused_flag_namerxr�rrr�WriteHelpInXMLFormat�s0






zFlagValues.WriteHelpInXMLFormatcCs;x4|j�D]&}|j�|}|jj|�q
WdS)z�Register new flags validator to be checked.

    Args:
      validator: gflags_validators.Validator
    Raises:
      AttributeError: if validators work with a non-existing flag.
    N)Z
GetFlagsNamesrsr�rU)r r�r�rxrrr�AddValidator�szFlagValues.AddValidator)7rrrrrrprrrsrtrurvrzr|r~r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�Zhas_keyr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrk
sh
			

	"�


%$6E.rkcCs1yt|�SWntk
r,t|�SYnXdS)zCConverts value to a python string or, if necessary, unicode-string.N)r��UnicodeEncodeError)r�rrr�
_StrOrUnicode�s
rcCs:tj|�}tjdd|�}|jdd�}|S)z>Escapes <, >, and & from s, and removes XML 1.0-illegal chars.z[\x00-\x08\x0b\x0c\x0e-\x1f]r'�ascii�xmlcharrefreplace)�cgi�escaperPr^�encode)r�rrr�_MakeXMLSafe�sr	cCsTt|�}t|t�r'|j�}t|�}|jd||||f�dS)a9Writes a simple XML element.

  Args:
    outfile: File object we write the XML element to.
    name: A string, the name of XML element.
    value: A Python object, whose string representation will be used
      as the value of the XML element.
    indent: A string, prepended to each line of generated output.
  z%s<%s>%s</%s>
N)rr�bool�lowerr	r�)r�rhr�rWZ	value_strZsafe_value_strrrrr��s

r�c@s�eZdZdZddddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dddd�Zdd�ZdS)r�awInformation about a command-line flag.

  'Flag' objects define the following fields:
    .name  - the name for this flag
    .default - the default value for this flag
    .default_as_str - default value as repr'd string, e.g., "'true'" (or None)
    .value  - the most recent parsed value of this flag; set by Parse()
    .help  - a help string or None if no help is available
    .short_name  - the single letter alias for this flag (or None)
    .boolean  - if 'true', this flag does not accept arguments
    .present  - true if this flag was parsed from command line flags.
    .parser  - an ArgumentParser object
    .serializer - an ArgumentSerializer object
    .allow_override - the flag may be redefined without raising an error

  The only public method of a 'Flag' object is Parse(), but it is
  typically only called by a 'FlagValues' object.  The Parse() method is
  a thin wrapper around the 'ArgumentParser' Parse() method.  The parsed
  value is saved in .value, and the .present attribute is updated.  If
  this flag was already present, a FlagsError is raised.

  Parse() is also called during __init__ to parse the default value and
  initialize the .value attribute.  This enables other python modules to
  safely use flags even if the __main__ module neglects to parse the
  command line arguments.  The .present attribute is cleared after
  __init__ parsing.  If the default value is set to None, then the
  __init__ parsing step is skipped and the .value attribute is
  initialized to None.

  Note: The default value is also presented to the user in the help
  string, so it is important that it be a legal value for this flag.
  Nrc		Csw||_|sd}||_||_||_d|_||_||_||_d|_g|_	|j
|�dS)Nz(no help available)r)rhr�r�r��presentr��
serializerr�r�r�r�)	r r�r
rhr�help_stringr�r�r�rrrr/s										z
Flag.__init__cCstt|��S)N)�hashr�)r rrr�__hash__Bsz
Flag.__hash__cCs
||kS)Nr)r �otherrrr�__eq__EszFlag.__eq__cCs)t|t�r%t|�t|�kStS)N)rr�r��NotImplemented)r rrrr�__lt__HszFlag.__lt__cCsb|dkrdS|jr/t|jj|��S|jrR|rHtd�Std�Stt|��S)N�true�false)r
�reprr�r�r)r r�rrrZ__GetParsedValueAsStringMs		

zFlag.__GetParsedValueAsStringcCspy|jj|�|_WnAtk
r\}z!td|j||f��WYdd}~XnX|jd7_dS)Nzflag --%s=%s: %sr)r�r�r��
ValueErrorr$rhr)r �argumentr�rrrr�Ys
/z
Flag.ParsecCs8|jdkrd|_n|j|j�d|_dS)Nr)rr�r�r)r rrrr�`szFlag.UnparsecCs~|jdkrdS|jr>|jr0d|jSd|jSn<|jsZtd|j��d|j|jj|j�fSdS)Nr'z--%sz--no%sz"Serializer not present for flag %sz--%s=%s)r�r�rhr
rr�)r rrrr�gs			zFlag.SerializecCsP|dkr$|jr$t|j��||_|j�|j|j�|_dS)z@Changes the default value (and current value too) for this Flag.N)r�rrhrr��_Flag__GetParsedValueAsStringr�r�)r r�rrrr�ts

	
zFlag.SetDefaultcCs
|jj�S)z7Returns: a string that describes the type of this Flag.)r��Type)r rrrr�sz	Flag.TypeFr'cCs?|j|d�|d}|r4t|dd|�t|d||�t|d|j|�|jr|t|d|j|�|jr�t|d|j|�|jr�t|jt�r�|jj	|j�}n	|j}t|d	||�t|d
|j
|�t|d|j�|�|j||�|j|d�d
S)a-Writes common info about this flag, in XML format.

    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 _WriteCustomInfoInXMLFormat.

    Please do NOT override this method.

    Args:
      outfile: File object we write to.
      module_name: A string, the name of the module that defines this flag.
      is_key: A boolean, True iff this flag is key for main module.
      indent: A string that is prepended to each generated line.
    z<flag>
z  r��yes�filerhr�Zmeaningr�currentr�z</flag>
N)
r�r�rhr�r�r
rrr�r�r�r�_WriteCustomInfoInXMLFormat)r r�r
r�rWZinner_indentZdefault_serializedrrrr��s&
			zFlag.WriteInfoInXMLFormatcCs|jj||�dS)z�Writes extra info about this flag, in XML format.

    "Extra" means "not already printed by WriteInfoInXMLFormat above."

    Args:
      outfile: File object we write to.
      indent: A string that is prepended to each generated line.
    N)r��WriteCustomInfoInXMLFormat)r r�rWrrrr�sz Flag._WriteCustomInfoInXMLFormat)rrrrrrrrrr�r�r�r�rr�rrrrrr�
s 
)r�c@s(eZdZdZiZdd�ZdS)�_ArgumentParserCachez?Metaclass used to cache and share argument parsers among flags.cOs�|rtj|||�S|j}|ft|�}y||SWnOtk
rq|j|tj||��SYn"tk
r�tj||�SYnXdS)aTReturns 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 mcs 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)r�r��
_instances�tuple�KeyErrorrwr6)Zmcsr��kwargsZ	instancesr�rrrr��s	
 
z_ArgumentParserCache.__call__N)rrrrr"r�rrrrr!�sr!c@s@eZdZdZdZdd�Zdd�Zdd�Zd	S)
�ArgumentParsera�Base class used to parse and convert arguments.

  The 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.
  r'cCs|S)z?Default implementation: always returns its argument unmodified.r)r rrrrr�szArgumentParser.ParsecCsdS)N�stringr)r rrrrszArgumentParser.TypecCsdS)Nr)r r�rWrrrr sz)ArgumentParser.WriteCustomInfoInXMLFormatN)rrrrr�r�rr rrrrr&�s
r&�	metaclassc@s"eZdZdZdd�ZdS)�ArgumentSerializerzABase class for generating string representations of a flag value.cCs
t|�S)N)r)r r�rrrr�szArgumentSerializer.SerializeN)rrrrr�rrrrr)sr)c@s(eZdZdd�Zdd�ZdS)�ListSerializercCs
||_dS)N)�list_sep)r r+rrrrszListSerializer.__init__cCs|jjdd�|D��S)NcSsg|]}t|��qSr)r)r<�xrrrr>s	z,ListSerializer.Serialize.<locals>.<listcomp>)r+rH)r r�rrrr�szListSerializer.SerializeN)rrrrr�rrrrr*sr*zFlag validation failedcCs |jtj|||��dS)a�Adds a constraint, which will be enforced during program execution.

  The constraint is validated when flags are initially parsed, and after each
  change of the corresponding flag's value.
  Args:
    flag_name: string, name of the flag to be checked.
    checker: method to validate the flag.
      input  - value of the corresponding flag (string, boolean, etc.
        This value will be passed to checker by the library). See file's
        docstring for examples.
      output - Boolean.
        Must return True if validator constraint is satisfied.
        If constraint is not satisfied, it should either return False or
          raise gflags_validators.Error(desired_error_message).
    message: error text to be shown to the user if checker returns False.
      If checker raises gflags_validators.Error, message from the raised
        Error will be shown.
    flag_values: FlagValues
  Raises:
    AttributeError: if flag_name is not registered as a valid flag name.
  N)rr�ZSimpleValidator)r�Zcheckerr�r!rrr�RegisterValidatorsr-cCs't|dd�dd|d|�dS)a"Ensure that flag is not None during program execution.

  Registers a flag validator, which will follow usual validator
  rules.
  Args:
    flag_name: string, name of the flag
    flag_values: FlagValues
  Raises:
    AttributeError: if flag_name is not registered as a valid flag name.
  cSs
|dk	S)Nr)r�rrrr�Isz$MarkFlagAsRequired.<locals>.<lambda>r�zFlag --%s must be specified.r!N)r-)r�r!rrr�MarkFlagAsRequired=s
r.csG�jdk	s�jdk	rC�fdd�}t||d|�dS)z�Enforce 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: string, name of the flag
    flag_values: FlagValues
  NcsA|dk	r=�j|�r=d|�jf}tj|��dS)Nz%s is not %sT)�IsOutsideBoundsr�r�r�)r�r�)r�rr�CheckerYsz1_RegisterBoundsValidatorIfNeeded.<locals>.Checkerr!)�lower_bound�upper_boundr-)r�rhr!r0r)r�r� _RegisterBoundsValidatorIfNeededNs
	r3cKs&tt||||||�|�dS)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 that is used to parse the flag arguments.
    name: A string, the flag name.
    default: The default value of the flag.
    help: A help string.
    flag_values: FlagValues object the flag will be registered with.
    serializer: ArgumentSerializer that serializes the flag value.
    args: Dictionary with extra keyword args that are passes to the
      Flag __init__.
  N)�DEFINE_flagr�)r�rhrr�r!r
r�rrr�DEFINEgsr5cCs[|}|||j<t|t�rWt�\}}|j||�|jt|�|�dS)a\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.
  N)rhrrkrrzr|r�)rxr!Zfvrr
rrrr4s
r4cCsb|p	|}t�}xF|D]>}||kr:t|��|j�|}|j||�qWdS)a<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: A list of strings that are names of already-registered
      Flag objects.
    flag_values: A FlagValues object that the flags listed in
      flag_names have registered with (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: A FlagValues object 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: when we refer to a flag that was not
      defined yet.
  N)rr&rsr~)r�r!�key_flag_valuesrr�rxrrr�_InternalDeclareKeyFlags�s	
r7cCs@|tkr)t|gdtd|�dSt|gd|�dS)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
  --help).

  Sample usage:

    gflags.DECLARED_key_flag('flag_1')

  Args:
    flag_name: A string, 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: A FlagValues object.  This should almost never
      need to be overridden.
  r!r6N)r�r7)r�r!rrr�DECLARE_key_flag�sr8cCs�t|t�rtd|��tdd�|j|j�D�d|�|t�dkr�tdd�ttj	�j
��D�dtd|�dS)	a@Declares that all flags key to a module are key to the current module.

  Args:
    module: A module object.
    flag_values: A FlagValues object.  This should almost never need
      to be overridden.

  Raises:
    FlagsError: When given an argument that is a module name (a
    string), instead of a module object.
  z2Received module name %s; expected a module object.cSsg|]}|j�qSr)rh)r<r�rrrr>�s	z*ADOPT_module_key_flags.<locals>.<listcomp>r!rcSsg|]}|j�qSr)rh)r<r�rrrr>�s	r6N)rr�rr7r�rrrcr�rsr�)rr!rrr�ADOPT_module_key_flags�s
%r9cKs2t�}t�}t|||||||�dS)z/Registers a flag whose value can be any string.N)r&r)r5)rhrr�r!r�r�r
rrr�
DEFINE_string	s		r:c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�
BooleanParserzParser of boolean values.cCsmt|�tkr>|j�dkr(dS|j�dkr>dSt|�}||krZ|Std	|��d
S)
z?Converts the argument to a boolean; raise ValueError on errors.r�t�1Trr��0Fz$Non-boolean argument to boolean flagN)rr<r=)rr�r>)r�r�rr
r)r rZ
bool_argumentrrr�Convert	szBooleanParser.ConvertcCs|j|�}|S)N)r?)r r�valrrrr�!	szBooleanParser.ParsecCsdS)Nr
r)r rrrr%	szBooleanParser.TypeN)rrrrr?r�rrrrrr;	sr;c@s%eZdZdZddd�ZdS)�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.
  Nc
KsDt�}tj||d||||d|�|js@d|_dS)Nrza boolean value)r;r�rr�)r rhrr�r�r��prrrr6	s	%	zBooleanFlag.__init__)rrrrrrrrrrA)	srAcKs tt||||�|�dS)aaRegisters 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.
  N)r4rA)rhrr�r!r�rrr�DEFINE_boolean<	srCc@s.eZdZdZdd�Zdd�ZdS)�HelpFlaga
  HelpFlag is a special boolean flag that prints usage information and
  raises a SystemExit exception if it is ever found in the command
  line arguments.  Note this is called with allow_override=1, so other
  apps can define their own --help flag, replacing this one, if they want.
  c	Cs&tj|ddddddd�dS)Nr�rzshow this helpr��?r�r)rAr)r rrrrU	szHelpFlag.__init__cCsh|rdtjdj}tt�}t|p9dtjd�|rWtd�t|�tjd�dS)Nrbz
USAGE: %s [flags]
rzflags:r)rrdrr��FLAGS�printrg�exit)r r�r_r�rrrr�X	s

zHelpFlag.ParseN)rrrrrr�rrrrrDN	srDc@s.eZdZdZdd�Zdd�ZdS)�HelpXMLFlagz8Similar to HelpFlag, but generates output in XML format.cCs tj|ddddd�dS)NZhelpxmlFz%like --help, but generates XML outputr�r)rAr)r rrrrc	szHelpXMLFlag.__init__cCs'|r#tjtj�tjd�dS)Nr)rFrrr,rH)r r�rrrr�g	szHelpXMLFlag.ParseN)rrrrrr�rrrrrIa	srIc@s.eZdZdZdd�Zdd�ZdS)�
HelpshortFlagaB
  HelpshortFlag is a special boolean flag that prints usage
  information for the "main" module, and rasies a SystemExit exception
  if it is ever found in the command line arguments.  Note this is
  called with allow_override=1, so other apps can define their own
  --helpshort flag, replacing this one, if they want.
  cCs tj|ddddd�dS)NZ	helpshortrzshow usage only for this moduler�r)rAr)r rrrrs	szHelpshortFlag.__init__cCsh|rdtjdj}tj�}t|p9dtjd�|rWtd�t|�tjd�dS)Nrbz
USAGE: %s [flags]
rzflags:r)rrdrrFr�rGrgrH)r r�r_r�rrrr�v	s

zHelpshortFlag.ParseN)rrrrrr�rrrrrJk	srJc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
NumericParserz]Parser of numeric values.

  Parsed value may be bounded to a given upper and lower bound.
  cCs:|jdk	r||jkp9|jdk	o9||jkS)N)r1r2)r r@rrrr/�	szNumericParser.IsOutsideBoundscCs;|j|�}|j|�r7td||jf��|S)Nz%s is not %s)r?r/rr�)r rr@rrrr��	szNumericParser.ParsecCsN|jdk	r%t|d|j|�|jdk	rJt|d|j|�dS)Nr1r2)r1r�r2)r r�rWrrrr �	sz(NumericParser.WriteCustomInfoInXMLFormatcCs|S)z?Default implementation: always returns its argument unmodified.r)r rrrrr?�	szNumericParser.ConvertN)rrrrr/r�r r?rrrrrK�	s
rKcsgeZdZdZdZdZdjeef�Zdd�fdd�Zdd	�Z	d
d�Z
�S)�FloatParserzdParser of floating point values.

  Parsed value may be bounded to a given upper and lower bound.
  r��numberrLNcs�tt|�j�||_||_|j}|dk	r\|dk	r\d|||f}ny|dkrxd|j}n]|dkr�d|j}nA|dk	r�d|j|f}n|dk	r�d|j|f}||_dS)Nz%s in the range [%s, %s]rza non-negative %sza non-positive %sz%s <= %sz%s >= %s)�superrLrr1r2r��number_name)r r1r2�sh)�	__class__rrr�	s			zFloatParser.__init__cCs
t|�S)z:Converts argument to a float; raises ValueError on errors.)�float)r rrrrr?�	szFloatParser.ConvertcCsdS)NrRr)r rrrr�	szFloatParser.Type)rrrr�number_articlerOrHr�rr?rrr)rQrrL�	srLc	KsKt||�}t�}t|||||||�t||d|�dS)z�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.
  r!N)rLr)r5r3)	rhrr�r1r2r!r�r�r
rrr�DEFINE_float�	s	rTcsgeZdZdZdZdZdjeef�Zdd�fdd�Zdd	�Z	d
d�Z
�S)�
IntegerParserz_Parser of an integer value.

  Parsed value may be bounded to a given upper and lower bound.
  Zan�integerrLNcstt|�j�||_||_|j}|dk	r\|dk	r\d|||f}n�|dkrxd|j}n�|d
kr�d|j}ny|dkr�d|j}n]|dkr�d|j}nA|dk	r�d|j|f}n|dk	r
d	|j|f}||_dS)Nz%s in the range [%s, %s]rz
a positive %sz
a negative %srza non-negative %sza non-positive %sz%s <= %sz%s >= %sr@)rNrUrr1r2r�rO)r r1r2rP)rQrrr�	s&			zIntegerParser.__init__cCsqd}t|�tkrcd}t|�dkrV|ddkrV|ddkrVd}t||�St|�SdS)	Nzno-returnvalues�
r�rr>rr,�)r�r�rFr3)r rZ
__pychecker__�baserrrr?�	s2
zIntegerParser.ConvertcCsdS)Nr3r)r rrrr
szIntegerParser.Type)rrrrrSrOrHr�rr?rrr)rQrrU�	s
rUc	KsKt||�}t�}t|||||||�t||d|�dS)z�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.
  r!N)rUr)r5r3)	rhrr�r1r2r!r�r�r
rrr�DEFINE_integer
s	rZcsCeZdZdZd�fdd�Zdd�Zdd�Z�S)	�
EnumParserz�Parser of a string enum value (a string value from a given set).

  If enum_values (see below) is not specified, any string is allowed.
  Ncs tt|�j�||_dS)N)rNr[r�enum_values)r r\)rQrrr
szEnumParser.__init__cCs8|jr4||jkr4tddj|j���|S)Nzvalue should be one of <%s>�|)r\rrH)r rrrrr�"
szEnumParser.ParsecCsdS)Nzstring enumr)r rrrr(
szEnumParser.Type)rrrrrr�rrr)rQrr[
sr[c@s4eZdZdZdddd�Zdd�ZdS)�EnumFlagzFBasic enum flag; its value can be any string from list of enum_values.Nc		Ksx|p	g}t|�}t�}tj||||||||�|jsUd|_ddj|�|jf|_dS)Nzan enum stringz<%s>: %sr])r[r)r�rr�rH)	r rhrr�r\r�r�rB�grrrr/
s	"		zEnumFlag.__init__cCs.x'|jjD]}t|d||�q
WdS)N�
enum_value)r�r\r�)r r�rWr`rrrr8
sz$EnumFlag._WriteCustomInfoInXMLFormat)rrrrrrrrrrr^,
sr^cKs#tt|||||�|�dS)z@Registers a flag whose value can be any string from enum_values.N)r4r^)rhrr\r�r!r�rrr�DEFINE_enum=
sracsFeZdZdZdd�fdd�Zdd�Zdd�Z�S)	�BaseListParseraBase class for a parser of lists of strings.

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

    BaseListParser.__init__(self, token, name)

  where token is a character used to tokenize, and name is a description
  of the separator.
  NcsE|st�tt|�j�||_||_d|j|_dS)Nza %s separated list)r
rNrbr�_token�_namer�)r �tokenrh)rQrrrT
s
		zBaseListParser.__init__cCsDt|t�r|S|dkr#gSdd�|j|j�D�SdS)Nr'cSsg|]}|j��qSr)rO)r<r�rrrr>a
s	z(BaseListParser.Parse.<locals>.<listcomp>)rrcr�rc)r rrrrr�[
s
zBaseListParser.ParsecCsd|jS)Nz%s separated list of strings)rd)r rrrrc
szBaseListParser.Type)rrrrrr�rrr)rQrrbI
s	rbc@s.eZdZdZdd�Zdd�ZdS)�
ListParserz-Parser for a comma-separated list of strings.cCstj|dd�dS)Nr�Zcomma)rbr)r rrrrj
szListParser.__init__cCs0tj|||�t|dtd�|�dS)N�list_separatorr�)rbr r�r)r r�rWrrrr m
sz%ListParser.WriteCustomInfoInXMLFormatN)rrrrrr rrrrrfg
srfc@s.eZdZdZdd�Zdd�ZdS)�WhitespaceSeparatedListParserz2Parser for a whitespace-separated list of strings.cCstj|dd�dS)N�
whitespace)rbr)r rrrru
sz&WhitespaceSeparatedListParser.__init__cCs]tj|||�ttj�}|j�x*tjD]}t|dt|�|�q6WdS)Nrg)rbr rcr'rir�r�r)r r�rWZ
separatorsZws_charrrrr x
s

z8WhitespaceSeparatedListParser.WriteCustomInfoInXMLFormatN)rrrrrr rrrrrhr
srhcKs5t�}td�}t|||||||�dS)zBRegisters a flag whose value is a comma-separated list of strings.r�N)rfr*r5)rhrr�r!r�r�r
rrr�DEFINE_list�
s	rjcKs5t�}td�}t|||||||�dS)zxRegisters a flag whose value is a whitespace-separated list of strings.

  Any whitespace can be used as a separator.
  rLN)rhr*r5)rhrr�r!r�r�r
rrr�DEFINE_spaceseplist�
s	rkc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�	MultiFlagaXA 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 a list of values.
      A single value is interpreted as the [value] singleton list.

    * 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
  cOs&tj|||�|jd7_dS)Nz4;
    repeat this option to specify a list of values)r�rr�)r r�r%rrrr�
szMultiFlag.__init__cCsqt|t�s|g}|jr-|j}ng}x.|D]&}tj||�|j|j�q:W||_dS)aParses one or more arguments with the installed parser.

    Args:
      arguments: a single argument or a list of arguments (typically a
        list of default values); a single argument is converted
        internally into a list containing one item.
    N)rrcrr�r�r�rU)r �	argumentsr��itemrrrr��
s		
zMultiFlag.ParsecCs�|jstd|j��|jdkr/dSd}|j}x4|D],|_|r^|d7}|tj|�7}qEW||_|S)Nz"Serializer not present for flag %sr'rL)r
rrhr�r�r�)r r�Zmulti_valuerrrr��
s		
	zMultiFlag.SerializecCsd|jj�S)Nzmulti )r�r)r rrrr�
szMultiFlag.TypeN)rrrrrr�r�rrrrrrl�
s
rlcKs&tt||||||�|�dS)a.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.
  N)r4rl)r�r
rhrr�r!r�rrr�DEFINE_multi�
s
rocKs2t�}t�}t|||||||�dS)aRegisters 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.
  N)r&r)ro)rhrr�r!r�r�r
rrr�DEFINE_multistring�
s		rpc	Ks8t||�}t�}t|||||||�dS)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.
  N)rUr)ro)	rhrr�r1r2r!r�r�r
rrr�DEFINE_multi_int�
s		rqc	Ks8t||�}t�}t|||||||�dS)aRegisters 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.
  N)rLr)ro)	rhrr�r1r2r!r�r�r
rrr�DEFINE_multi_floats		rrZflagfilezBInsert flag definitions from the given file into the command line.Zundefokz�comma-separated list of flag names that it is okay to specify on the command line even if the program does not define a flag with that name.  IMPORTANT: flags in this list that have arguments MUST use the --flag=value format.)Qrrr�r4rPr'r1rr/�ImportErrorr.r�rdr�rrr�	Exceptionrrrrrr$r%r&r�r0r;rKr\r`r	rjrkrFrr	r�r�r�r!�objectr&r)r*r-r.r3r5r4r7r8r9r:r;rArCZDEFINE_boolrDrIrJrKrLrTrUrZr[r^rarbrfrhrjrkrlrorprqrrr�rrrr�<module>�s�

#+q����	�(! '
!#,H