:d^dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl Z e jdk\rddlmZnddlmZej"ej$ej&ej(ej*gZe jdk\rej/ej0dZndZeeZiZd/d Zd/d ZGd d ej<ej>ej@Z!Gd de"Z#Gdde$Z%Gdde#Z&Gdde#Z'Gdde#Z( ejRdZ*ejRdejVZ,ejZddd0dZ.d0dZ/dZ0d Z1Gd!d"e#Z2Gd#d$e#Z3Gd%d&e#Z4d'Z5d(Z6d)Z7d*Z8Gd+d,ejrZ9d-Z:d.Z;ejxjtejx_=e:ejx_:ej|Z>ej<Zej~Z?ejZ@ejZAejZBejZCejZDej@Z ej>ZejZEejZFejZGejZHejZIejZJeZKeZLeZMeZNeZOeZPe9ZQe9ZRejxjtejx_Sejxjtejx_Te9je9_Ve9je9_Xe ZYeZZe!Z[y)1z A drop-in replacement for `argparse` that allows options to also be set via config files and/or environment variables. :see: `configargparse.ArgumentParser`, `configargparse.add_argument` N) OrderedDict)r)StringIO)r c6t|tjSN) isinstanceargparseBooleanOptionalActionactions 0/usr/lib/python3/dist-packages/configargparse.pyrs 68CaCa0bcy)NFr s rrr!src |d}|tvrtd|dt||jdtj|jddt di|t|<y) zCreates a global ArgumentParser instance with the given name, passing any args other than "name" to the ArgumentParser constructor. This instance can then be retrieved using get_argument_parser(..) Ndefaultz=kwargs besides 'name' can only be passed in the first time. 'z!' ArgumentParser already exists: formatter_classconflict_handlerresolver)_parsers ValueError setdefaultr ArgumentDefaultsHelpFormatterArgumentParsernamekwargss rinit_argument_parserr )sl  | x (4."# # ')O)OP ()4#-f-HTNrc `|d}t|dkDs|tvr t|fi|t|S)a Returns the global ArgumentParser instance with the given name. The 1st time this function is called, a new ArgumentParser instance will be created for the given name, and any args other than "name" will be passed on to the ArgumentParser constructor. rr)lenrr rs rget_argument_parserr#<s7  | 6{Q$h.T,V, D>rceZdZdZy) ArgumentDefaultsRawHelpFormatterzCHelpFormatter that adds default values AND doesn't do line-wrappingN__name__ __module__ __qualname____doc__rrrr%r%Ks Nrr%c"eZdZdZdZdZdZy)ConfigFileParserzRThis abstract class can be extended to add support for new config file formatsctd)z3Returns a string describing the config file syntax.z*get_syntax_description(..) not implementedNotImplementedErrorselfs rget_syntax_descriptionz'ConfigFileParser.get_syntax_descriptionWs!"NOOrctd)aUParses the keys and values from a config file. NOTE: For keys that were specified to configargparse as action="store_true" or "store_false", the config file value must be one of: "yes", "no", "on", "off", "true", "false". Otherwise an error will be raised. Args: stream (IO): A config file input stream (such as an open file object). Returns: OrderedDict: Items where the keys are strings and the values are either strings or lists (eg. to support config file formats like YAML which allow lists). zparse(..) not implementedr.)r1streams rparsezConfigFileParser.parse[s""=>>rctd)aDoes the inverse of config parsing by taking parsed values and converting them back to a string representing config file contents. Args: items: an OrderedDict of items to be converted to the config file format. Keys should be strings, and values should be either strings or lists. Returns: Contents of config file as a string zserialize(..) not implementedr.)r1itemss r serializezConfigFileParser.serializels""ABBrNr'r(r)r*r2r5r8rrrr,r,SsP?" Crr,ceZdZdZy)ConfigFileParserExceptionz'Raised when config file parsing failed.Nr&rrrr;r;{s1rr;c"eZdZdZdZdZdZy)DefaultConfigFileParsera Based on a simplified subset of INI and YAML formats. Here is the supported syntax .. code:: # this is a comment ; this is also a comment (.ini style) --- # lines that start with --- are ignored (yaml style) ------------------- [section] # .ini-style section names are treated as comments # how to specify a key-value pair (all of these are equivalent): name value # key is case sensitive: "Name" isn't "name" name = value # (.ini style) (white space is ignored, so name = value same as name=value) name: value # (yaml style) --name value # (argparse style) # how to set a flag arg (eg. arg which has action="store_true") --name name name = True # "True" and "true" are the same # how to specify a list arg (eg. arg which has action="append") fruit = [apple, orange, lemon] indexes = [1, 12, 35 , 40] c d}|S)NzrConfig file syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at https://goo.gl/R74nmi).rr1msgs rr2z.DefaultConfigFileParser.get_syntax_descriptionsE rc t}t|D]#\}}|j}|r|ddvs|jdr2t j d|}|r|j d}|j d}|j d}|j d} | ||d k7rd }n|d }|jd r'|jd r tj|}| r!| jddj} |||<tdj|t|dd||S#t$r?} |ddjdD cgc]} | jncc} w}} Yd} ~ d} ~ wwxYw)Nr)#;[z---zn^(?P[^:=;#\s]+)\s*(?:(?P[:=\s])\s*([\'"]?)(?P.+?)?\3)?\s*(?:\s[;#]\s*(?P.*?)\s*)?$keyequalvaluecomment truerD],zUnexpected line {} in {}: {}rr4)r enumeratestrip startswithrematchgroupendswithjsonloads Exceptionsplitr;formatgetattr) r1r4r7ilinerTrErFrGrHeelems rr5zDefaultConfigFileParser.parses  ( >GAt::>9 >< %R:?"+:K:KC:P Q$ Q Q QRs$D?? FFE65FFct}|jD][\}}t|tr%ddj t t |zdz}|jdj||]|jS)NrD, rLz{} = {} ) rr7r listjoinmapstrwriter[getvalue)r1r7rrErGs rr8z!DefaultConfigFileParser.serializesq J++- 4JC%&DIIc#uo66s: GGK&&sE2 3  4 zz|rNr9rrrr=r=s: "Hrr=c"eZdZdZdZdZdZy)ConfigparserConfigFileParserz,parses INI files using pythons configparser.c d}|S)NaUses configparser module to parse an INI file which allows multi-line values. Allowed syntax is that for a ConfigParser with the following options: allow_no_value = False, inline_comment_prefixes = ("#",) strict = True empty_lines_in_values = False See https://docs.python.org/3/library/configparser.html for details. Note: INI file sections names are still treated as comments. rr?s rr2z3ConfigparserConfigFileParser.get_syntax_descriptions   rcddl}ddlm}|jdddddd} |j |j t}|jD]v}||jD]^\}} | jd d jd d } d | vr.d | vr*| jd d} d| vr || ||<T| ||<Z| ||<`x|S#t $r}td|zd}~wwxYw)Nr) literal_eval)=:F)rBrCT) delimitersallow_no_valuecomment_prefixesinline_comment_prefixesstrictempty_lines_in_valuesCouldn't parse config file: %s rI rDrL{) configparserastrn ConfigParser read_stringreadrYr;rsectionsr7replacerZ) r1r4r{rnconfigr_resultsectionkvmultiLine2SingleLineprelist_strings rr5z"ConfigparserConfigFileParser.parses!$**  &$-"' +  R   v{{} - ( 5Gg,,. 5!'(yyc':'B'B4'L$..3:N3N%9%?%?%DQ%GN.0$01E$Fq $8q 4F1I 5 5 % R+,Lq,PQ Q RsC C3 C..C3cddl}ddl}|jdddd}d|i}|j||j }|j ||j d|jS)NrF)rBT)rrrtrurvDEFAULT)r{ior} read_dictrrgseekr)r1r7r{rrr4s rr8z&ConfigparserConfigFileParser.serializesq** $*"' +  E" V A{{}rNr9rrrrkrks6"!Frrkc*eZdZdZdZdZdZddZy)YAMLConfigFileParserzdParses YAML config files. Depends on the PyYAML module. https://pypi.python.org/pypi/PyYAML c d}|S)NzThe config file uses YAML syntax and must represent a YAML 'mapping' (for details, see http://learn.getgrav.org/advanced/yaml).rr?s rr2z+YAMLConfigFileParser.get_syntax_descriptionsS rc ddl} ddlm}ddlm}|||fS#t$r tdwxYw#t$rddlm}ddlm}Y4wxYw)zjlazy-import PyYAML so that configargparse doesn't have to depend on it unless this parser is used.rNzJCould not import yaml. It can be installed by running 'pip install PyYAML') CSafeLoader)CDumper) SafeLoader)Dumper)yaml ImportErrorr;rrrr)r1rrrs r _load_yamlzYAMLConfigFileParser._load_yaml$sc G   $ 6 . Z'' G+-FG G G $ ' # $s 0-AAc|j\}}} |j||}t |t s0tdt |dddt|jdt}|jD],\}} t | tr| ||<| t| ||<.|S#t$r}td|zd}~wwxYw)N)Loaderrwz_The config file doesn't appear to contain 'key: value' pairs (aka. a YAML mapping). yaml.load('rr4z') returned type 'z' instead of 'dict'.) rloadrYr;r dictr\typer'rr7rcrf) r1r4rr_ parsed_objr_rrErGs rr5zYAMLConfigFileParser.parse6s"oo/j! R6*=J*d++1D4D4M4M-OP P $**, )JC%&#s !%js  ) % R+,Lq,PQ Q RsB44 C=C  Cch|j\}}}t|}|j|||S)N)default_flow_styler)rrdump)r1r7rrrrs rr8zYAMLConfigFileParser.serializePs7//+aU yy3EfyUUrNF)r'r(r)r*r2rr5r8rrrrrs ($4Vrrz1(^\"(?:\\.|[^\"\\])*\"$)|(^\'(?:\\.|[^\'\\])*\'$)z(^\"\"\"(\s+)?(([^\"]|\"([^\"]|\"[^\"]))*(\"\"?)?)?(\s+)?(?:\\.|[^\"\\])?\"\"\"$)|(^\'\'\'(\s+)?(([^\']|\'([^\']|\'[^\']))*(\'\'?)?)?(\s+)?(?:\\.|[^\'\\])?\'\'\'$))flagsT)maxsizetypedcttj|xs"|xrttj|S)zu Detect whether a string is a quoted representation. :param triple: Also match tripple quoted strings. )bool_QUOTED_STR_REGEXrT_TRIPLE_QUOTED_STR_REGEX)texttriples r is_quotedr}s= !''- . @  >D177=>@rct||r+ tj|}t|tsJ |S|S#t $r}t d|d||d}~wwxYw)a Unquote a maybe quoted string representation. If the string is not detected as being a quoted representation, it returns the same string as passed. It supports all kinds of python quotes: ``"""``, ``'''``, ``"`` and ``'``. :param triple: Also unquote tripple quoted strings. @raises ValueError: If the string is detected as beeing quoted but literal_eval() fails to evaluate it as string. This would be a bug in the regex. rz+Error trying to unquote the quoted string: : N)rr|rnr rfrYr)rrsr_s r unquote_strrssf% _  &Aa% %% K _J4&PRSTRUVW]^ ^ _s'; AAAcg}tj|gdD]3}|D],}|jt|j d.5t |S)u Parse a TOML section name to a sequence of strings. The following names are all valid: .. python:: "a.b.c" # this is best practice -> returns ("a", "b", "c") " d.e.f " # same as [d.e.f] -> returns ("d", "e", "f") " g . h . i " # same as [g.h.i] -> returns ("g", "h", "i") ' j . "ʞ" . "l" ' # same as [j."ʞ"."l"], double or simple quotes here are supported. -> returns ("j", "ʞ", "l") .) delimiterFr)csvreaderappendrrQtuple) section_namerrowas rparse_toml_section_namers]Gzz<.C8A AA NN;qwwy? @ AA >rct|tr t|n|}|j|d}|sy|dd}|r t ||St|t sy|S)z Given some TOML data (as loaded with `toml.load()`), returns the requested section of the data. Returns ``None`` if the section is not found. rNrM)r rfrgetget_toml_sectionr)datarritemdatas rrrs` 4>gs3K&w/QXHxx $H |H(33(D)rc4eZdZdZfdZdZdZdZxZS)TomlConfigParsera( Create a TOML parser bounded to the list of provided sections. Example:: # this is a comment [tool.my-software] # TOML section table. # how to specify a key-value pair format-string = "restructuredtext" # strings must be quoted # how to set an arg which has action="store_true" warnings-as-errors = true # how to set an arg which has action="count" or type=int verbosity = 1 # how to specify a list arg (eg. arg which has action="append") repeatable-option = ["https://docs.python.org/3/objects.inv", "https://twistedmatrix.com/documents/current/api/objects.inv"] # how to specify a multiline text: multi-line-text = ''' Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tortor odio, dignissim non ornare non, laoreet quis nunc. Maecenas quis dapibus leo, a pellentesque leo. ''' Note that the config file fragment above is also valid for the `IniConfigParser` class and would be parsed the same manner. Thought, any valid TOML config file will not be necessarly parsable with `IniConfigParser` (INI files must be rigorously indented whereas TOML files). See the `TOML specification <>`_ for details. c0t|||_y)zO :param sections: The section names bounded to the new parser. N)super__init__r)r1r __class__s rrzTomlConfigParser.__init__s   rc|Srrr0s r__call__zTomlConfigParser.__call__ rcFddl} |j|}t }|j D]R}t ||}|s|jD],\}} t| tr| ||<| t| ||<.|S|S#t$r}td|zd}~wwxYw)z3Parses the keys and values from a TOML config file.rNzCouldn't parse TOML file: %s) tomlrrYr;rrrr7r rcrf) r1r4rrr_rrrrErGs rr5zTomlConfigParser.parses  PYYv&F }} G#FG4D#'**,1JC!%.&+s &)%js 1   + P+,JQ,NO O PsB B  BB cy)NzConfig file syntax is Tom's Obvious, Minimal Language. See https://github.com/toml-lang/toml/blob/v0.5.0/README.md for details.rr0s rr2z'TomlConfigParser.get_syntax_descriptions[r r'r(r)r*rrr5r2 __classcell__rs@rrrs8!:\rrc4eZdZdZfdZdZdZdZxZS)IniConfigParsera Create a INI parser bounded to the list of provided sections. Optionaly convert multiline strings to list. Example (if split_ml_text_to_list=False):: # this is a comment ; also a comment [my-software] # how to specify a key-value pair format-string: restructuredtext # white space are ignored, so name = value same as name=value # this is why you can quote strings quoted-string = ' hello mom... ' # how to set an arg which has action="store_true" warnings-as-errors = true # how to set an arg which has action="count" or type=int verbosity = 1 # how to specify a list arg (eg. arg which has action="append") repeatable-option = ["https://docs.python.org/3/objects.inv", "https://twistedmatrix.com/documents/current/api/objects.inv"] # how to specify a multiline text: multi-line-text = Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tortor odio, dignissim non ornare non, laoreet quis nunc. Maecenas quis dapibus leo, a pellentesque leo. Example (if split_ml_text_to_list=True):: # the same rules are applicable with the following changes: [my-software] # how to specify a list arg (eg. arg which has action="append") repeatable-option = # Just enter one value per line (the list literal format can also be used) https://docs.python.org/3/objects.inv https://twistedmatrix.com/documents/current/api/objects.inv # how to specify a multiline text (you have to quote it): multi-line-text = ''' Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tortor odio, dignissim non ornare non, laoreet quis nunc. Maecenas quis dapibus leo, a pellentesque leo. ''' c>t|||_||_y)z :param sections: The section names bounded to the new parser. :split_ml_text_to_list: Wether to convert multiline strings to list N)rrrsplit_ml_text_to_list)r1rrrs rrzIniConfigParser.__init__2s   %:"rc|Srrr0s rrzIniConfigParser.__call__;rrc ddl}|j} |j|jt }|j|jgzD]}||jvr||jD]\}}|j} | s| jdr+| jdr tj| ||<Ut#| r t%| ||<p|j&rCd|j)dvr0 | j+dD cgc]} | st%| c} ||<|||<|S#t$r}t d|zd}~wwxYw#t$r }t dt!|zdz|d}~wwxYw#t$r}t t!||d}~wwxYwcc} w#t$r}t t!||d}~wwxYw) z3Parses the keys and values from an INI config file.rNzCouldn't parse INI file: %srDrLzError evaluating list: z;. Put quotes around your text if it's meant to be a string.rx)r{r}r~rrYr;rr DEFAULTSECTr7rQrRrVr|rnrrfrrrrstriprZ) r1r4r{rr_rrrrstrip_vr]s rr5zIniConfigParser.parse>s **, O   v{{} - (L,D,D+EE &Gdmm+g,,. &!'')%%c*w/?/?/Dc$'$4$4W$=q !)K(3G(E+#FG%F=- F=:G E(E##E(+ F4FF F: F55F:=G G% G  G%c,d}|jr|dz }|S)NzUses configparser module to parse an INI file which allows multi-line values. See https://docs.python.org/3/library/configparser.html for details. This parser includes support for quoting strings literal as well as python list syntax evaluation. z{Alternatively lists can be constructed with a plain multiline string, each non-empty line will be converted to a list item.)rr?s rr2z&IniConfigParser.get_syntax_descriptionls+v  % % H IC rrrs@rrrs)V;,\rrc4eZdZdZfdZdZdZdZxZS)CompositeConfigParserz Createa a config parser composed by others `ConfigFileParser`s. The composite parser will successively try to parse the file with each parser, until it succeeds, else raise execption with all encountered errors. c`t||Dcgc] }| c}|_ycc}wr)rrparsers)r1config_parser_typesprs rrzCompositeConfigParser.__init__}s% %899 9s+c|Srrr0s rrzCompositeConfigParser.__call__rrcg}|jD]} |j|cSt ddj d|D#t$r,}|jd|j |Yd}~ld}~wwxYw)NrzError parsing config: rbc3DK|]}tt|ywr)reprrf).0r_s r z.CompositeConfigParser.parse..s2PA4A<2Ps )rr5rYrrr;rd)r1r4errorsrr_s rr5zCompositeConfigParser.parses !A !wwv& ! ((2P2P)P(QRT T ! A a   !sA  B"A;;Bc d}d}t|jD]?\}}|d|dzd||jjd|j dz }A|S)Nc|jjdjddjddjdd}|r|jSdS)NrparserrJrfilez??)lowerrQrupper) classnamerQs rguess_format_namezGCompositeConfigParser.get_syntax_description..guess_format_namesVOO%++C088GHb)''&"*= $)5;;= 3t 3rz2Uses multiple config parser settings (in order): rDrMz] rz )rPrrr'r2)r1rr@r]rs rr2z,CompositeConfigParser.get_syntax_descriptionss 4 D"4<<0 sIAv Qqse2/0@0@0I0IJK2fNkNkNmMnnqr rC s rrrs@rrrus: T rr command_lineenvironment_variables config_filedefaultsceZdZdZdZdddej fdZdddej dfdZdZ ddZ d Z d Z d Z d Zd ZdZej$fdZdZy)rzDrop-in replacement for `argparse.ArgumentParser` that adds support for environment variables and ``.ini`` or ``.yaml-style`` config files. c|jdd}|jdd}|jdd}|jdg}|jdd}|jd t}|jd g} |jd d} |jd d } |jdg} |jdd} |jdt|_||_||_||_tjj|g|i||t|_ n ||_ ||_ ||_ | r|j| d| | dd| r|j| dd| ddyy)aR Supports args of the `argparse.ArgumentParser` constructor as \*\*kwargs, as well as the following additional args. Arguments: add_config_file_help: Whether to add a description of config file syntax to the help message. add_env_var_help: Whether to add something to the help message for args that can be set through environment variables. auto_env_var_prefix: If set to a string instead of None, all config- file-settable options will become also settable via environment variables whose names are this prefix followed by the config file key, all in upper case. (eg. setting this to ``foo_`` will allow an arg like ``--my-arg`` to also be set via the FOO_MY_ARG environment variable) default_config_files: When specified, this list of config files will be parsed in order, with the values from each config file taking precedence over previous ones. This allows an application to look for config files in multiple standard locations such as the install directory, home directory, and current directory. Also, shell \* syntax can be used to specify all conf files in a directory. For example:: ["/etc/conf/app_config.ini", "/etc/conf/conf-enabled/*.ini", "~/.my_app_config.ini", "./app_config.txt"] ignore_unknown_config_file_keys: If true, settings that are found in a config file but don't correspond to any defined configargparse args will be ignored. If false, they will be processed and appended to the commandline like other args, and can be retrieved using parse_known_args() instead of parse_args() config_file_open_func: function used to open a config file for reading or writing. Needs to return a file-like object. config_file_parser_class: configargparse.ConfigFileParser subclass which determines the config file format. configargparse comes with DefaultConfigFileParser and YAMLConfigFileParser. args_for_setting_config_path: A list of one or more command line args to be used for specifying the config file path (eg. ["-c", "--config-file"]). Default: [] config_arg_is_required: When args_for_setting_config_path is set, set this to True to always require users to provide a config path. config_arg_help_message: the help message to use for the args listed in args_for_setting_config_path. args_for_writing_out_config_file: A list of one or more command line args to use for specifying a config file output path. If provided, these args cause configargparse to write out a config file with settings based on the other provided commandline args, environment variants and defaults, and then to exit. (eg. ["-w", "--write-out-config-file"]). Default: [] write_out_config_file_arg_help_message: The help message to use for the args in args_for_writing_out_config_file. add_config_file_helpTadd_env_var_helpauto_env_var_prefixNdefault_config_filesignore_unknown_config_file_keysFconfig_file_parser_classargs_for_setting_config_pathconfig_arg_is_requiredconfig_arg_help_messagezconfig file path args_for_writing_out_config_file&write_out_config_file_arg_help_messagezftakes the current command line args and writes them out to a config file at the given path, then exitsconfig_file_open_funcr)destrequiredhelpis_config_file_arg"write_out_config_file_to_this_pathCONFIG_OUTPUT_PATH)rmetavarris_write_out_config_file_arg)popr=open_config_file_open_func_add_config_file_help_add_env_var_help_auto_env_var_prefixr rr_config_file_parser_default_config_files _ignore_unknown_config_file_keys add_argument)r1argsrrrrrrrrrrrrs rrzArgumentParser.__init__st &zz*@$G!::&8$?$jj)>E%zz*@"E*0** -u+6'#)::.H.E$G '-zz *B(0$!',De!L"(**-F-?#A+1:: .,4(17 47%2&. '-jj1H$&O#%9"!1$7!((??? $ +'>'@D $'?'AD $%9"0O- ' D  ;-/6M#' ) , D  ?9,;-1  3 ,rNc|j||||d\}}|r#|jddj|z|S)aSupports all the same args as the `argparse.ArgumentParser.parse_args()`, as well as the following additional args. Arguments: args: a list of args as in argparse, or a string (eg. "-x -y bla") config_file_contents: String. Used for testing. env_vars: Dictionary. Used for testing. Returns: argparse.Namespace: namespace F)r namespaceconfig_file_contentsenv_varsignore_help_argszunrecognized arguments: %srI)parse_known_argserrorrd)r1rrrrargvs r parse_argszArgumentParser.parse_argssP**!5" +$ d  JJ3chhtnD E rFc  |tjdd}n,t|tr|j }n t |}|j D]}|j |_|r|Dcgc] }|dvs| }}t|_ |r"dt |f}d|i|jt<|j|j D]}|j|} | s|jr$|jr1|jr>|j rKt|t"j$rft|t"j&r| dj)|j*} |j| zj-ddj/|_g} d} |j Dcgc]K}|js=|jr1|j|vr#t1||j|j*s|M} }| D]}|j}||}|j2st|t"j4r:d } |j7d r'|j9d r t;j<|}| |jA|||z } | r|| z}n| |z}| rEt| Dcgc]}|j|||jff!c}|jtB<tEd|j D}|xr d|vxsd|v}|j Dcic]}|j|D]}||}}}g}|tG|}d|_$|g}n|s|jK|}tM|D]Z} |jNjQ|}tW|dr|jY g}d} j[D]\}}||vr'||}t1||j|j*}n7d}|j\xs't1||j_|g|j*}|rk||jA|||z }t`d|jH}||jvrt|j|<||f|j||<|r |j2st|t"j4sd } | r||z}V||z}]t}|j D]}|j xs|j2tbtdfv}t1||j|j*s1|r/|jf#|jfthk(st|tjr}|jr|jd }n |jl}|t|jff||<|r||jtn<t"jpjs|||\}}|j Dcgc]&}tu|ddrtu||jld(} }| Dcgc]}|| } }|jw|| d ||fScc}wcc}w#t>$r9|dd j d Dcgc]}|j)ncc}w}}YwxYwcc}wcc}}w#tR$r%}|jUt|Yd}~7d}~wwxYw#tW|dr|jYwwxYwcc}wcc}w)aSupports all the same args as the `argparse.ArgumentParser.parse_args()`, as well as the following additional args. Arguments: args: a list of args as in argparse, or a string (eg. "-x -y bla") config_file_contents (str). Used for testing. env_vars (dict). Used for testing. ignore_help_args (bool): This flag determines behavior when user specifies ``--help`` or ``-h``. If False, it will have the default behavior - printing help and exiting. If True, it won't do either. Returns: tuple[argparse.Namespace, list[str]]: tuple namescpace, unknown_args NrM)-h--helprJr-rFTrDrLrNrOc3VK|]!}t|tjs|#ywr)r r _HelpActionrrs rrz2ArgumentParser.parse_known_args..s& M 1h6J6J(KA Ms))r!r"z method argclose|)rrr ) exit_after)<sysrr rfrZrc_actionsoption_stringsis_positional_argr_source_to_settings_COMMAND_LINE_SOURCE_KEYrget_possible_config_keysenv_varrr r _VersionActionr%rQ prefix_charsrralready_on_command_linenargs _AppendActionrRrVrWrXrY convert_item_to_command_line_arg_ENV_VAR_SOURCE_KEYanyrr_open_config_filesreversedrr5r;rhasattrr'r7r4get_command_line_key_for_unknown_config_file_setting_CONFIG_FILE_SOURCE_KEYOPTIONAL ZERO_OR_MORErSUPPRESS#ACTION_TYPES_THAT_DONT_NEED_A_VALUEr_DEFAULTS_SOURCE_KEYrrr\write_config_file)!r1rrrrrrarga_v_pairconfig_file_keysstripped_config_file_key env_var_argsr5actions_with_env_var_valuesr rErGr`supports_help_argskip_config_file_parsing config_keyknown_config_keysconfig_streamsr4 config_itemsr_ config_argsdiscard_this_key source_keydefault_settingscares_about_default_value unknown_argsoutput_file_pathss! rrzArgumentParser.parse_known_args(s* <88AB  $ $ 0]] U#'#@#@#C #QYY!:M:M++q/M/Mq("9"9:q("6"67/?/B/H/H))0+,!%!:!:!9":;B73;LUUWI U 26--'\Q&&199h9N/a6F6FHYHYZ()'\#'\2 $F..CSME||z&(2H2HI##C(U^^C-@R $ 5 1 DAAU$ $L $ ,&D$&D f33T5F5F(H$"F'+'L'L(// !VVWZ[\ --/% (4#H#HU$,,K+BFKK!PJ!)A)AA?J}00>|LM$5 5 001A3G5;%%m455 5 )DII6G,HH I !    * !C!J!J$a")** *55s9CCC5C<C C C9C44C9<D cf|j|j}|jddz|z}|S)aMCompute a commandline arg key to be used for a config file setting that doesn't correspond to any defined configargparse arg (and so doesn't have a user-specified commandline arg key). Args: key: The config file key that was being set. Returns: str: command line key r)rQr3)r1rEkey_without_prefix_charscommand_line_keys rr=zCArgumentParser.get_command_line_key_for_unknown_config_file_setting s;$'99T->->#? ,,Q/14LLrct}|jD]\}}|tk(r|d\}}|jD]}|j |} | s|j r$t ||j|jsFt||jd} | `t| trt| j} | || d<|tk(rS|jD]>\} \}} |j |} | st||jd} | 7| || d<@|j!t"r"|jD] \} \}} | || <K|t$k(sV|jD]>\} \}} |j |} | st||jd} | 7| || d<@|S)aConverts the given settings back to a dictionary that can be passed to ConfigFormatParser.serialize(..). Args: source_to_settings: the dictionary described in parse_known_args() parsed_namespace: namespace object created within parse_known_args() Returns: OrderedDict: where keys are strings and values are either strings or lists rJNr)rr7r/r+r0r-r4r,r3r\rr rrfrr8rRr>rC) r1source_to_settingsr`config_file_itemssourcesettingsrexisting_command_line_argsr rGrGrEs rr]z/ArgumentParser.get_items_for_config_file_outputs(M 2 8 8 : K FH1108 --"mm KF'+'D'DV'L$'0H0H/0J060E0E040A0AC!((8&++t L ,)%6(+E (8(8(:EJ-.>q.AB K..,4NN,<K(C&%'+'D'DV'L$' '(8&++t L ,EJ-.>q.AB K ""#:;,4NN,<3(C&%-2%c*3//,4NN,<K(C&%'+'D'DV'L$' '(8&++t L ,EJ-.>q.AB K5 K@! rc g}||j|}nt|s|jd}|It|tr8t|t sJd|j dvr>t|s|j|S|j|jd|S|j dvr.t|s |S|j|jd|St|tjr]|D]7}t|jDcgc]}|j|c}s6d}9||jdgt|zz }|S|jd|d |d |St|tra|duxr|jduxrst|tj xst|tj"xr;|jd vxs+t|jtxr|jdkD}|t|tj"rm|D]f} |rCt| tr3|j| D]} |jt | H|jd t | h|S|r4|j|D]} |jt | |S|j|d |d|St|t r|jd ||St%dj't)||cc}w)aConverts a config file or env var key + value to a list of commandline args to append to the commandline. Args: action: The argparse Action object for this setting, or None if this config file setting doesn't correspond to any defined configargparse arg. key: string (config file key or env var name) value: parsed value of type string or list Returns: list[str]: args NrNzCconfig parser should convert anything that is not a list to string.)rKyeson1r)falsenooff0rMzUnexpected value for z: 'zB'. Expecting 'true', 'false', 'yes', 'no', 'on', 'off', '1' or '0')+*roz can't be set to a list 'zS' unless its action type is changed to 'append' or nargs is set to '*', '+', or > 1z&Unexpected value type {} for value: {})r=is_boolean_optional_actionr,r rBrfrrr _CountActionr9rRintrrcr5 _StoreActionr6rr[r) r1r rErGrrgrEraccepts_list_and_has_nargs list_elemsub_elems rr7z/ArgumentParser.convert_item_to_command_line_argKs? >II#N .f5#)#8#8#<   *V5X"YeS) p+p p){{} ::1&9KK!13^ YKK 5 5a 89X W"==1&9P KKK 5 5a 89J IFH$9$9:"Cv7L7LM!CNN1-MN !"..q12SZ??@ = NQSXZ[< 9t $)/t);* TX@X*fh&;&;<j 6S[SiSi@j* *bz&,,/L/aQWQ]Q]`aQa ' ~FH4J4J!K!&TI1jD6Q $45(17H KKH 67 0@#i.%QS T( , -/!&2IKKY12  RUW\^_ s # KK$4e< >  ELLU U$% %?NsL; cg}t|ddr|S|jD]+tfd|jDs"|ddgz }-|S)aThis method decides which actions can be set in a config file and what their keys will be. It returns a list of 0 or more config keys that can be used to set the given action's value in a config file. Returns: list[str]: keys r Nc3FK|]}jd|zyw)reN)rR)rcrEs rrz:ArgumentParser.get_possible_config_keys..sB13>>!A#&Bs!re)r\r,r9r3)r1r keysrEs @rr0z'ArgumentParser.get_possible_config_keyssb 694 @K(( 'CB0A0ABBQR#& ' rcg}ttjttjj|j D])}|D]"}|j |j|$+|jDcgc]}t|dds|}}|s|S|D]}tj|jd}|j|d} tj| ||_|j#|} | sh| \} } t| |j$d} | stjj | } |j| }|gz }|Scc}w#t&$r{}t)|j*dk(r|j*\}}n t-|}|D]"} |j/#t&$rY wxYw|j!d| d |Yd}~d}~wwxYw) aTries to parse config file path(s) from within command_line_args. Returns a list of opened config files, including files specified on the commandline as well as any default_config_files specified in the constructor that are present on disk. Args: command_line_args: List of all args Returns: list[IO]: open config files rF)r3add_helpcyrr)r1messages r error_methodz7ArgumentParser._open_config_files..error_methodsr)rNrezUnable to open config file: z . Error: )reglobospath expanduserrrrr+r\r rr3 _add_actiontypes MethodTyperrrrYr"rrfr')r1command_line_args config_filesfilesfruser_config_file_arg_actionsr arg_parserr parsed_argrruser_config_filer4r_errnor@rs rr:z!ArgumentParser._open_config_filess  C(:(:DrCrr.r7rZrrgr[r rfrcrdrh)r1source_key_to_display_value_maprirkrlrEr rGs r format_valueszArgumentParser.format_valuess %&; !; #%: - + ' J $ 8 8 > > @ < FH\\#&F4VAY?%qr BSSF GGFO(0(8 <$_feGGN11#c'5AB!%-5 01#E40388E? :; < <zz|rcB|j|jy)zBPrints the format_values() string (to sys.stdout or another file).N)rgr)r1rs r print_valueszArgumentParser.print_valuess 4%%'(rc Dd}d}d}|jr;|j}d|jdz}|jDcgc]O}|jD]>}|j |r+|j dk(s|js|js||f@Q}}}|jDcgc]}t|ddr|} }|r|s| rd|_d}|d|zz }d jd | D} | rd | z} |s| r7|d d jt|ttd| gzzz }|d |jjzz }|jr|jDcgc]}t|ddr|j |f} }| D]^\} }|j"t$k(rd| z} |j"sd|_| |j"vsA|xj"| z c_d}d|_`|s|r*dg}|rdg|z}|rdg|z}|ddj|zz }t'|j)j*d}t-j.||}t0j2j5||dk7rdj7|zSdzScc}}wcc}wcc}w)NrJFrerrrTz:Args that start with '%s' can also be set in a config filez or c3RK|]}|jr|jd!yw)rN)r,r&s rrz-ArgumentParser.format_help...s-0FA4D4D120@0@0C0Fs%'zspecified via z (%s).rIr1z [env var: %s]rzconfig file valueszenvironment variablesz- In general, command-line values override %s.z which override z {} )rrr3r+r,r0rrr r\rdrfilterrr2rr1rrAmax_get_formatter_widthtextwrapfillr r format_helpr[)r1r@added_config_file_helpadded_env_var_helprccrrEconfig_settable_argsconfig_path_actionsconfig_arg_stringenv_var_actionsr1env_var_help_string value_sources text_widths rrzArgumentParser.format_helps!&"  % %#'#=#= 4$$Q''B6:mm$2  $2$($A$A!$D6!Q%9%9//&)!H$2H$2 $2  #J!(,@%!H$%#J #J$)=)<-2*)-&(+-..$*KK0F00F%F!$(8;L(L%'+<8fkk%8L2M27tFWEX8Y2Z3['\\\CsT55LLNNN  ! !7;}}?!")!Y"=!" 1~?O?- 3 66X%&87&B#vvAF&aff4FF11F)-&-2D* 3 !7'LM%!5 6 F !!8 9M I B"'' 68 8C,,.55r: mmC,''33D9),%< =8:< =c$2#J(?sAJ&J)"Jr)r'r(r)r*rrenvironrrrYrDr=r]r7r0r:rr*stdoutrrrrrrrsh3T!%$*.2::4!%ZZ" s'j($: -!^KZ(IV<#&**)9=rrc,|jdd}|jddxs|jdd}|jdd}|j|i|}|j |_||_||_||_|jr |r td|j r%t|tjs td|j r:d}t|tjst|d z|rt|d z|S) aH This method supports the same args as ArgumentParser.add_argument(..) as well as the additional args below. Arguments: env_var: If set, the value of this environment variable will override any config file or default values for this arg (but can itself be overridden on the commandline). Also, if auto_env_var_prefix is set in the constructor, this env var name will be used instead of the automatic name. is_config_file_arg: If True, this arg is treated as a config file path This provides an alternative way to specify config files in place of the ArgumentParser(fromfile_prefix_chars=..) mechanism. Default: False is_write_out_config_file_arg: If True, this arg will be treated as a config file path, and, when it is specified, will cause configargparse to write all current commandline args to this file as config options and then exit. Default: False Returns: argparse.Action: the new argparse action r1Nris_config_filer z*env_var can't be set for a positional arg.z9arg with is_config_file_arg=True must have action='store'z+arg with is_write_out_config_file_arg=True zmust have action='store'z'can't also have is_config_file_arg=True) r original_add_argument_methodr,r-r1rr rr r r{)r1rrr1rr r error_prefixs rrrUs.2jjD)Gd$ '-zz$( $*::&$. /T . . ? ?F#)#8#88FFN 2F*FF' GEFF   FH.s'4 "s)rZrr9)existing_args_listpotential_command_line_argsr3 arg_string option_string explicit_argrs @rr4r4s}I() *Q-<7C:rCrrr4_ActionsContainerrAction ArgumentErrorArgumentTypeErrorFileType HelpFormatterMetavarTypeHelpFormatter Namespace ONE_OR_MOREr?PARSER REMAINDERrAr@initArgumentParsergetArgumentParser getArgParser getParserget_arg_parser get_parser ArgParserParseradd_argaddrr5r parse_known RawFormatterDefaultsFormatterDefaultsRawFormatterrrrrs   #v!(0'@'@  5 5  ; ;'=#v'..x/M/MN!b!5&+,O&P# .&   ** !! (( %Cv%CP2 2O.OdF#3FR>V+>VB2BJJ ;<&2::'{CECLCL M S-@.@&&"F\'F\Pm&m^#,#L*-'!q =X,,q =h6r,;C:T:T:a:a7*6'  ( F F&& ..   && #<<    &BB44""          $$ *'"  %  %-%?%?%L%L"!)!;!;!H!H%00+<<* 17r