U e5dw@s0dZdZdddddddd d d d d dddddgZddlZddlZddlZddl Z ddl m Z m Z dZdZdZdZdZdZdZGdddeZdd ZGd!ddeZGd"ddeZGd#d d eZGd$ddeZGd%d d eZd&d'ZGd(ddeZGd)ddeZ Gd*d d eZ!Gd+d,d,e!Z"Gd-d.d.e!Z#Gd/d0d0e#Z$Gd1d2d2e#Z%Gd3d4d4e!Z&Gd5d6d6e!Z'Gd7d8d8e!Z(Gd9d:d:e!Z)Gd;d<dd>e!Z+Gd?d@d@e&Z,GdAddeZ-GdBd d eZ.GdCdDdDeZ/GdEdFdFe/Z0GdGdHdHe0Z1GdIddee/Z2dS)Ja Command-line parsing library This module is an optparse-inspired command-line parsing library that: - handles both optional and positional arguments - produces highly informative usage messages - supports parsers that dispatch to sub-parsers The following is a simple usage example that sums integers from the command-line and writes the result to a file:: parser = argparse.ArgumentParser( description='sum the integers at the command line') parser.add_argument( 'integers', metavar='int', nargs='+', type=int, help='an integer to be summed') parser.add_argument( '--log', default=sys.stdout, type=argparse.FileType('w'), help='the file where the sum should be written') args = parser.parse_args() args.log.write('%s' % sum(args.integers)) args.log.close() The module contains the following public classes: - ArgumentParser -- The main entry point for command-line parsing. As the example above shows, the add_argument() method is used to populate the parser with actions for optional and positional arguments. Then the parse_args() method is invoked to convert the args at the command-line into an object with attributes. - ArgumentError -- The exception raised by ArgumentParser objects when there are errors with the parser's actions. Errors raised while parsing the command-line are caught by ArgumentParser and emitted as command-line messages. - FileType -- A factory for defining types of files to be created. As the example above shows, instances of FileType are typically passed as the type= argument of add_argument() calls. - Action -- The base class for parser actions. Typically actions are selected by passing strings like 'store_true' or 'append_const' to the action= argument of add_argument(). However, for greater customization of ArgumentParser actions, subclasses of Action may be defined and passed as the action= argument. - HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter, ArgumentDefaultsHelpFormatter -- Formatter classes which may be passed as the formatter_class= argument to the ArgumentParser constructor. HelpFormatter is the default, RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser not to change the formatting for help text, and ArgumentDefaultsHelpFormatter adds information about argument defaults to the help. All other classes in this module are considered implementation details. (Also note that HelpFormatter and RawDescriptionHelpFormatter are only considered public as object names -- the API of the formatter objects is still considered an implementation detail.) z1.1ArgumentParser ArgumentErrorArgumentTypeErrorFileType HelpFormatterArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterRawTextHelpFormatterMetavarTypeHelpFormatter NamespaceAction ONE_OR_MOREOPTIONALPARSER REMAINDERSUPPRESS ZERO_OR_MOREN)gettextngettextz ==SUPPRESS==?*+zA......Z_unrecognized_argsc@s(eZdZdZddZddZddZdS) _AttributeHolderaAbstract base class that provides __repr__. The __repr__ method returns a string in the format:: ClassName(attr=name, attr=name, ...) The attributes are determined either by a class-level attribute, '_kwarg_names', or by inspecting the instance __dict__. cCst|j}g}i}|D]}|t|q|D],\}}|rZ|d||fq6|||<q6|rz|dt|d|d|fS)N%s=%rz**%s%s(%s), )type__name__ _get_argsappendrepr _get_kwargs isidentifierjoin)selfZ type_name arg_stringsZ star_argsargnamevaluer* /usr/lib64/python3.8/argparse.py__repr__ts   z_AttributeHolder.__repr__cCst|jSN)sorted__dict__itemsr%r*r*r+r"sz_AttributeHolder._get_kwargscCsgSr-r*r1r*r*r+rsz_AttributeHolder._get_argsN)r __module__ __qualname____doc__r,r"rr*r*r*r+rksrcCs6|dkr gSt|tkr$|ddSddl}||S)Nr)rlistcopy)r0r6r*r*r+ _copy_itemss   r7c@seZdZdZd;ddZddZd d ZGd d d eZd dZ ddZ ddZ ddZ dsz6HelpFormatter._Section.format_help..z%*s%s:  ) rXrWrU _join_partsr0rVrYrrD)r%r$Z item_helpZcurrent_indentrYr*r*r+ format_helps    z"HelpFormatter._Section.format_help)N)rr2r3rQrar*r*r*r+rGs rGcCs|jj||fdSr-)rIr0r )r%r[r\r*r*r+ _add_itemszHelpFormatter._add_itemcCs0||||j|}||jg||_dSr-)rUrGrIrbra)r%rYZsectionr*r*r+ start_sectionszHelpFormatter.start_sectioncCs|jj|_|dSr-)rIrXrVr1r*r*r+ end_sections zHelpFormatter.end_sectioncCs$|tk r |dk r ||j|gdSr-)rrb _format_text)r%textr*r*r+add_textszHelpFormatter.add_textcCs&|tk r"||||f}||j|dSr-)rrb _format_usage)r%usageactionsgroupsprefixr\r*r*r+ add_usages zHelpFormatter.add_usagecCsv|jtk rr|j}||g}||D]}|||q$tdd|D}||j}t|j||_||j |gdS)NcSsg|] }t|qSr*lenrZsr*r*r+r] sz.HelpFormatter.add_argument..) helpr_format_action_invocation_iter_indented_subactionsr rArDrFrb_format_action)r%actionZget_invocationZ invocations subactionZinvocation_lengthZ action_lengthr*r*r+ add_arguments   zHelpFormatter.add_argumentcCs|D]}||qdSr-)rx)r%rjrvr*r*r+ add_argumentsszHelpFormatter.add_argumentscCs.|j}|r*|jd|}|dd}|S)N r_)rHrarNsubstrip)r%rrr*r*r+ras  zHelpFormatter.format_helpcCsddd|DS)Nr^cSsg|]}|r|tk r|qSr*)r)rZpartr*r*r+r]!sz-HelpFormatter._join_parts..)r$)r%Z part_stringsr*r*r+r` s zHelpFormatter._join_partscs|dkrtd}|dk r,|t|jd}n|dkrL|sLdt|jd}n|dkrdt|jd}g}g}|D] }|jr||qr||qr|j} | |||} ddd|| fD}|j|jt |t |krd} | ||} | ||} t | | }t | | }dfdd }t |t |d krdt |t |d }|r|||g|||}| |||n |r||g|||}n|g}nZdt |}||}|||}t |d krg}| |||| ||||g|}d |}d ||fS)Nzusage: rOz%(prog)s cSsg|] }|r|qSr*r*rpr*r*r+r]Asz/HelpFormatter._format_usage..z%\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+csg}g}|dk rt|d}n t|d}|D]Z}|dt|krn|rn||d|g}t|d}|||t|d7}q.|r||d||dk r|dt|d|d<|S)NrSrr)ror r$)partsindentrllineslineZline_lenr} text_widthr*r+ get_linesUs"   z.HelpFormatter._format_usage..get_linesg?rSr_z%s%s )N) _dictr>option_stringsr _format_actions_usager$rCrDrorJfindallextend)r%rirjrkrlrO optionals positionalsrvformatZ action_usageZ part_regexpZ opt_usageZ pos_usageZ opt_partsZ pos_partsrrrrr*rr+rh%sX             zHelpFormatter._format_usagec Cst}i}|D]}z||jd}Wntk r@YqYqX|t|j}||||jkr|jD]}||qh|js||kr||d7<nd||<||kr||d7<nd||<nF||kr||d7<nd||<||kr||d7<nd||<t|d|D]} d || <qqg} t|D]"\} }|j t kr| d| | d krr| | n"| | dd krX| | dn|js||} ||| } ||kr| ddkr| d dkr| dd } | | nf|jd} |jdkrd | } n"||} ||| }d | |f} |jsN||krNd | } | | q6t|ddD]} || g| | | <qhddd| D}d}d}td|d|}td|d|}td||fd|}tdd|}|}|S)Nrz [[]z (()rS|%s%s %s[%s]T)reversercSsg|]}|dk r|qSr-r*)rZitemr*r*r+r]sz7HelpFormatter._format_actions_usage..z[\[(]z[\])]z(%s) z\1 (%s)z%s *%sr^z \(([^|]*)\))setindex_group_actions ValueErrorroaddrequiredrange enumeraterrrr getpopr#_get_default_metavar_for_positional _format_argsnargs!_get_default_metavar_for_optionalr.r$rJr{r|)r%rjrk group_actionsZinsertsgroupstartendrvirdefaultr} option_string args_stringrfopencloser*r*r+rsz                    z#HelpFormatter._format_actions_usagecCsFd|kr|t|jd}t|j|jd}d|j}||||dS)Nz%(prog)r~ rrz)rr>rArCrD _fill_text)r%rfrrr*r*r+res  zHelpFormatter._format_textc Cs:t|jd|j}t|j|d}||jd}||}|jsV|jd|f}d|}n@t||kr~|jd||f}d|}d}n|jd|f}d|}|}|g}|jr| |} | | |} | d|d| df| ddD]} | d|d| fqn| ds| d| |D]} | || q||S) Nr8rr^z%*s%s z %*s%-*s rrSr_)r@rFrBrArCrDrsrrro _expand_help _split_linesr endswithrtrur`) r%rvZ help_positionZ help_widthZ action_widthZ action_headertupZ indent_firstrZ help_textZ help_linesrrwr*r*r+rus8          zHelpFormatter._format_actioncCs|js&||}|||d\}|Sg}|jdkrB||jn4||}|||}|jD]}|d||fq^d|SdS)NrSrrr) rr_metavar_formatterrrrrr r$)r%rvrmetavarrrrr*r*r+rs"s     z'HelpFormatter._format_action_invocationcsP|jdk r|jn.|jdk rsz4HelpFormatter._metavar_formatter..z{%s},csttrSf|SdSr-) isinstancetuple)Z tuple_sizeresultr*r+rCs z0HelpFormatter._metavar_formatter..format)rchoicesr$)r%rvdefault_metavarZ choice_strsrr*rr+r:s   z HelpFormatter._metavar_formattercCs|||}|jdkr$d|d}n|jtkr.zinvalid nargs valuer) rrr rr rrrr TypeErrorrr$)r%rvrZ get_metavarrZformatsr*r*r+rJs*        zHelpFormatter._format_argscCstt||jd}t|D]}||tkr||=qt|D] }t||dr:||j||<q:|ddk rddd|dD}||d<| ||S)Nr~rrrcSsg|] }t|qSr*r)rZcr*r*r+r]ksz.HelpFormatter._expand_help..) rvarsr>r5rhasattrrrr$_get_help_string)r%rvZparamsr(Z choices_strr*r*r+rbs   zHelpFormatter._expand_helpccs@z |j}Wntk rYnX||EdH|dSr-)_get_subactionsAttributeErrorrUrV)r%rvZget_subactionsr*r*r+rtos  z'HelpFormatter._iter_indented_subactionscCs&|jd|}ddl}|||S)Nrr)rMr{r|textwrapZwrap)r%rfrPrr*r*r+ryszHelpFormatter._split_linescCs,|jd|}ddl}|j||||dS)Nrr)Zinitial_indentZsubsequent_indent)rMr{r|rZfill)r%rfrPrrr*r*r+rs zHelpFormatter._fill_textcCs|jSr-)rrr%rvr*r*r+rszHelpFormatter._get_help_stringcCs |jSr-)destupperrr*r*r+rsz/HelpFormatter._get_default_metavar_for_optionalcCs|jSr-)rrr*r*r+rsz1HelpFormatter._get_default_metavar_for_positional)r8r9N)N) rr2r3r4rQrUrVobjectrGrbrcrdrgrmrxryrar`rhrrerursrrrrtrrrrrr*r*r*r+rs>  `g/  c@seZdZdZddZdS)rzHelp message formatter which retains any formatting in descriptions. Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail. cs dfdd|jddDS)Nr^c3s|]}|VqdSr-r*)rZrrr*r+ sz9RawDescriptionHelpFormatter._fill_text..T)keepends)r$ splitlines)r%rfrPrr*rr+rsz&RawDescriptionHelpFormatter._fill_textN)rr2r3r4rr*r*r*r+rsc@seZdZdZddZdS)rzHelp message formatter which retains formatting of all help text. Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail. cCs|Sr-)r)r%rfrPr*r*r+rsz!RawTextHelpFormatter._split_linesN)rr2r3r4rr*r*r*r+rsc@seZdZdZddZdS)rzHelp message formatter which adds default values to argument help. Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail. cCs>|j}d|jkr:|jtk r:ttg}|js2|j|kr:|d7}|S)Nz %(default)z (default: %(default)s))rrrrr rrr)r%rvrrZdefaulting_nargsr*r*r+rs  z.ArgumentDefaultsHelpFormatter._get_help_stringN)rr2r3r4rr*r*r*r+rsc@s eZdZdZddZddZdS)r a Help message formatter which uses the argument 'type' as the default metavar value (instead of the argument 'dest') Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail. cCs|jjSr-rrrr*r*r+rsz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs|jjSr-rrr*r*r+rsz.r*r%namesr*r1r+r"?s zAction._get_kwargscCsttddS)Nz.__call__() not defined)NotImplementedErrorrr%parser namespacevaluesrr*r*r+__call__MszAction.__call__)NNNNNFNN)N)rr2r3r4rQr"rr*r*r*r+r s5 cs(eZdZdfdd ZdddZZS) _StoreActionNFc sT|dkrtd|dk r,|tkr,tdttt|j||||||||| | d dS)Nrznargs for store actions must be != 0; if you have nothing to store, actions such as store true or store const may be more appropriate nargs must be %r to supply constr)rr superrrQr __class__r*r+rQSs   z_StoreAction.__init__cCst||j|dSr-)setattrrrr*r*r+rpsz_StoreAction.__call__)NNNNNFNN)Nrr2r3rQr __classcell__r*r*rr+rQsrcs(eZdZdfdd ZdddZZS) _StoreConstActionNFc s"tt|j||d||||ddS)Nr)rrrrrrrr)rrrQr%rrrrrrrrrr*r+rQvs z_StoreConstAction.__init__cCst||j|jdSr-)rrrrr*r*r+rsz_StoreConstAction.__call__)NFNN)Nrr*r*rr+rts rcseZdZdfdd ZZS)_StoreTrueActionFNcs tt|j||d|||ddS)NTrrrrrrr)rrrQr%rrrrrrrr*r+rQs z_StoreTrueAction.__init__)FFNrr2r3rQrr*r*rr+rsrcseZdZdfdd ZZS)_StoreFalseActionTFNcs tt|j||d|||ddS)NFr)rrrQrrr*r+rQs z_StoreFalseAction.__init__)TFNrr*r*rr+rsrcs(eZdZdfdd ZdddZZS) _AppendActionNFc sT|dkrtd|dk r,|tkr,tdttt|j||||||||| | d dS)Nrznargs for append actions must be != 0; if arg strings are not supplying the value to append, the append const action may be more appropriaterr)rr rrrQrrr*r+rQs   z_AppendAction.__init__cCs2t||jd}t|}||t||j|dSr-)rrr7r rr%rrrrr0r*r*r+rs z_AppendAction.__call__)NNNNNFNN)Nrr*r*rr+rsrcs(eZdZdfdd ZdddZZS) _AppendConstActionNFc s$tt|j||d|||||ddS)Nr)rrrrrrrrr)rrrQrrr*r+rQs z_AppendConstAction.__init__cCs4t||jd}t|}||jt||j|dSr-)rrr7r rrrr*r*r+rs z_AppendConstAction.__call__)NFNN)Nrr*r*rr+rs rcs(eZdZdfdd ZdddZZS) _CountActionNFcs tt|j||d|||ddS)Nr)rrrrrrr)rrrQrrr*r+rQs z_CountAction.__init__cCs0t||jd}|dkrd}t||j|ddSNrrS)rrr)r%rrrrcountr*r*r+rsz_CountAction.__call__)NFN)Nrr*r*rr+rs rcs.eZdZeedffdd ZdddZZS) _HelpActionNcstt|j|||d|ddSNr)rrrrrr)rrrQ)r%rrrrrrr*r+rQs z_HelpAction.__init__cCs||dSr-) print_helpexitrr*r*r+rsz_HelpAction.__call__)Nrr2r3rrQrrr*r*rr+rs  rcs0eZdZdeedffdd ZdddZZS)_VersionActionNz&show program's version number and exitcs$tt|j|||d|d||_dSr)rrrQversion)r%rrrrrrrr*r+rQs z_VersionAction.__init__cCsD|j}|dkr|j}|}||||tj|dSr-)r_get_formatterrg_print_messagera_sysstdoutr)r%rrrrrrWr*r*r+r(s z_VersionAction.__call__)Nrr*r*rr+rs rcsPeZdZGdddeZedddffdd ZddZd d Zd d d Z Z S)_SubParsersActioncseZdZfddZZS)z&_SubParsersAction._ChoicesPseudoActioncs@|}}|r|dd|7}ttj|}|jg|||ddS)Nrr)rrrrr)r$rr _ChoicesPseudoActionrQ)r%r(aliasesrrrrZsuprr*r+rQ6s  z/_SubParsersAction._ChoicesPseudoAction.__init__rr*r*rr+r 4sr FNc s<||_||_i|_g|_tt|j||t|j|||ddS)N)rrrrrrrr) _prog_prefix _parser_class_name_parser_map_choices_actionsrr rQr)r%rrO parser_classrrrrrrr*r+rQ>s  z_SubParsersAction.__init__cKs|ddkr d|j|f|d<|dd}d|krX|d}||||}|j||jf|}||j|<|D]}||j|<qr|S)NrOrr r*rr)rr rr rr rr)r%r(kwargsr rrZ choice_actionraliasr*r*r+ add_parserUs      z_SubParsersAction.add_parsercCs|jSr-)rr1r*r*r+rlsz!_SubParsersAction._get_subactionsc Cs|d}|dd}|jtk r,t||j|z|j|}Wn<tk rv|d|jd}td|}t||YnX||d\} }t |  D]\} } t|| | q|rt | t gt |t |dS)NrrSr) parser_namerz5unknown parser %(parser_name)r (choices: %(choices)s))rrrrKeyErrorr$rrparse_known_argsrr0 setdefault_UNRECOGNIZED_ARGS_ATTRrr) r%rrrrrr&r\msgZ subnamespacekeyr)r*r*r+ros$     z_SubParsersAction.__call__)N) rr2r3r r rrQrrrrr*r*rr+r 2sr c@seZdZdddZdS) _ExtendActionNcCs2t||jd}t|}||t||j|dSr-)rrr7rrrr*r*r+rs z_ExtendAction.__call__)N)rr2r3rr*r*r*r+rsrc@s*eZdZdZd ddZddZd d ZdS) raFactory for creating file object types Instances of FileType are typically passed as type= arguments to the ArgumentParser add_argument() method. Keyword Arguments: - mode -- A string indicating how the file is to be opened. Accepts the same values as the builtin open() function. - bufsize -- The file's desired buffer size. Accepts the same values as the builtin open() function. - encoding -- The file's encoding. Accepts the same values as the builtin open() function. - errors -- A string indicating how encoding and decoding errors are to be handled. Accepts the same value as the builtin open() function. rrNcCs||_||_||_||_dSr-)_mode_bufsize _encoding_errors)r%modebufsizeencodingerrorsr*r*r+rQszFileType.__init__c Cs|dkr>d|jkrtjSd|jkr(tjStd|j}t|zt||j|j|j|j WSt k r}z"||d}td}t ||W5d}~XYnXdS)N-rwzargument "-" with mode %r)filenameerrorz$can't open '%(filename)s': %(error)s) rrstdinr rrrrr r!OSErrorr)r%stringrer\rr*r*r+rs   zFileType.__call__cCsT|j|jf}d|jfd|jfg}ddd|Ddd|D}dt|j|fS)Nr$r%rcSsg|]}|dkrt|qS)r)r!)rZr'r*r*r+r]sz%FileType.__repr__..cSs$g|]\}}|dk rd||fqS)Nrr*)rZkwr'r*r*r+r]sr)rrr r!r$rr)r%r\rZargs_strr*r*r+r,s   zFileType.__repr__)rrNN)rr2r3r4rQrr,r*r*r*r+rs c@s(eZdZdZddZddZddZdS) r zSimple object for storing attributes. Implements equality by attribute names and values, and provides a simple string representation. cKs|D]}t||||qdSr-)r)r%rr(r*r*r+rQszNamespace.__init__cCst|tstSt|t|kSr-)rr NotImplementedr)r%otherr*r*r+__eq__s zNamespace.__eq__cCs ||jkSr-)r/)r%rr*r*r+ __contains__szNamespace.__contains__N)rr2r3r4rQr1r2r*r*r*r+r scseZdZfddZddZd&ddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZd'ddZddZd d!Zd"d#Zd$d%ZZS)(_ActionsContainercstt|||_||_||_||_i|_|ddt |ddt |ddt |ddt |ddt |ddt |ddt|ddt|dd t|dd t|dd t|dd t|g|_i|_g|_g|_i|_td |_g|_dS)NrvZstoreZ store_const store_trueZ store_falser Z append_constrrrrparsersrz^-\d+$|^-\d*\.\d+$)rr3rQ descriptionargument_default prefix_charsconflict_handler _registriesregisterrrrrrrrrrr r _get_handler_actions_option_string_actions_action_groups_mutually_exclusive_groups _defaultsrJrK_negative_number_matcher_has_negative_number_optionals)r%r6r8r7r9rr*r+rQs4 z_ActionsContainer.__init__cCs|j|i}|||<dSr-)r:r)r% registry_namer)rregistryr*r*r+r;sz_ActionsContainer.registerNcCs|j|||Sr-)r:r)r%rDr)rr*r*r+ _registry_get sz_ActionsContainer._registry_getcKs2|j||jD]}|j|kr||j|_qdSr-)rAupdater=rr)r%rrvr*r*r+ set_defaults&s   z_ActionsContainer.set_defaultscCs8|jD]"}|j|kr|jdk r|jSq|j|dSr-)r=rrrAr)r%rrvr*r*r+ get_default/s  z_ActionsContainer.get_defaultcOsD|j}|r&t|dkrH|dd|krH|r:d|kr:td|j||}n |j||}d|kr|d}||jkr~|j||d<n|jdk r|j|d<||}t|std|f|f|}| d|j |j }t|std |f|t krtd |ft |d r:z| |dWntk r8td YnX||S) z add_argument(dest, ..., name=value, ...) add_argument(option_string, option_string, ..., name=value, ...) rSrrz+dest supplied twice for positional argumentrNzunknown action "%s"r%r is not callablez<%r is a FileType class object, instance of it must be passedrz,length of metavar tuple does not match nargs)r8ror_get_positional_kwargs_get_optional_kwargsrAr7_pop_action_classcallablerFrrrrrr _add_action)r%r\rcharsrZ action_classrv type_funcr*r*r+rx9s:          z_ActionsContainer.add_argumentcOs t|f||}|j||Sr-)_ArgumentGroupr?r )r%r\rrr*r*r+add_argument_groupls z$_ActionsContainer.add_argument_groupcKst|f|}|j||Sr-)_MutuallyExclusiveGroupr@r )r%rrr*r*r+add_mutually_exclusive_groupqs  z._ActionsContainer.add_mutually_exclusive_groupcCs`|||j|||_|jD]}||j|<q"|jD]"}|j|r8|js8|jdq8|S)NT) _check_conflictr=r containerrr>rBmatchrC)r%rvrr*r*r+rOvs      z_ActionsContainer._add_actioncCs|j|dSr-)r=removerr*r*r+_remove_actionsz _ActionsContainer._remove_actioncCsi}|jD].}|j|kr.td}t||j|||j<q i}|jD]D}|j|krn|j|j|j|jd||j<|jD]}||j||<qtqD|jD]&}|j |j d}|jD] }|||<qq|j D]}| || |qdS)Nz.cannot merge actions - two groups are named %r)titler6r9)r)r?r[rrrSr6r9rr@rUrr=rrO)r%rWZtitle_group_maprrZ group_maprv mutex_groupr*r*r+_add_container_actionss0           z(_ActionsContainer._add_container_actionscKs^d|krtd}t||dttfkr2d|d<|dtkrPd|krPd|d<t||gdS)Nrz1'required' is an invalid argument for positionalsrTrrr)rrrr rr)r%rrrr*r*r+rKsz(_ActionsContainer._get_positional_kwargsc Osg}g}|D]n}|d|jkr>||jd}td}t|||||d|jkr t|dkr |d|jkr ||q |dd}|dkr|r|d}n|d}||j}|std}t|||dd}t|||d S) Nr)optionr8zNinvalid option string %(option)r: must start with a character %(prefix_chars)rrSrz%dest= is required for options like %rr&rr^) r8rrr rorlstripreplacer) r%r\rrZlong_option_stringsrrrZdest_option_stringr*r*r+rLs2         z&_ActionsContainer._get_optional_kwargscCs|d|}|d||S)Nrv)rrF)r%rrrvr*r*r+rMs z#_ActionsContainer._pop_action_classcCsFd|j}z t||WStk r@td}t||jYnXdS)Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)r9rrrr)r%Zhandler_func_namerr*r*r+r<s   z_ActionsContainer._get_handlercCsLg}|jD]&}||jkr |j|}|||fq |rH|}|||dSr-)rr>r r<)r%rvZconfl_optionalsrZconfl_optionalr9r*r*r+rVs   z!_ActionsContainer._check_conflictcCs6tddt|}ddd|D}t|||dS)Nzconflicting option string: %szconflicting option strings: %srcSsg|] \}}|qSr*r*)rZrrvr*r*r+r] sz<_ActionsContainer._handle_conflict_error..)rror$r)r%rvconflicting_actionsrZconflict_stringr*r*r+_handle_conflict_errors z(_ActionsContainer._handle_conflict_errorcCs>|D]4\}}|j||j|d|js|j|qdSr-)rrYr>rrWrZ)r%rvrbrr*r*r+_handle_conflict_resolves   z*_ActionsContainer._handle_conflict_resolve)N)N)rr2r3rQr;rFrHrIrxrSrUrOrZr]rKrLrMr<rVrcrdrr*r*rr+r3s$ 5   3($   r3cs6eZdZdfdd ZfddZfddZZS) rRNc s|j}|d|j|d|j|d|jtt|j}|fd|i|||_g|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_dS)Nr9r8r7r6)rr9r8r7rrRrQr[rr:r=r>rArCr@)r%rWr[r6rrGZ super_initrr*r+rQs    z_ArgumentGroup.__init__cs tt||}|j||Sr-)rrRrOrr rrr*r+rO5s z_ArgumentGroup._add_actioncs tt|||j|dSr-)rrRrZrrYrrr*r+rZ:sz_ArgumentGroup._remove_action)NNrr2r3rQrOrZrr*r*rr+rRs rRcs.eZdZdfdd ZddZddZZS) rTFcs tt||||_||_dSr-)rrTrQr _container)r%rWrrr*r+rQAsz _MutuallyExclusiveGroup.__init__cCs2|jrtd}t||j|}|j||S)Nz-mutually exclusive arguments must be optional)rrrrfrOrr )r%rvrr*r*r+rOFs   z#_MutuallyExclusiveGroup._add_actioncCs|j||j|dSr-)rfrZrrYrr*r*r+rZNs z&_MutuallyExclusiveGroup._remove_action)Frer*r*rr+rT?srTc s*eZdZdZddddgeddddddf fdd Zdd Zd d Zd d ZddZ ddZ dAddZ dBddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%ZdCd&d'ZdDd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5ZdEd6d7ZdFd8d9ZdGd:d;ZdHd=d>Z d?d@Z!Z"S)IraObject for parsing command line strings into Python objects. Keyword Arguments: - prog -- The name of the program (default: sys.argv[0]) - usage -- A usage message (default: auto-generated from arguments) - description -- A description of what the program does - epilog -- Text following the argument descriptions - parents -- Parsers whose arguments should be copied into this one - formatter_class -- HelpFormatter class for printing help messages - prefix_chars -- Characters that prefix optional arguments - fromfile_prefix_chars -- Characters that prefix files containing additional arguments - argument_default -- The default value for all arguments - conflict_handler -- String indicating how to handle conflicts - add_help -- Add a -h/-help option - allow_abbrev -- Allow long options to be abbreviated unambiguously Nr&r)Tc  s"tt|j} | ||| | d|dkr6tjtjd}||_||_ ||_ ||_ ||_ | |_ | |_|j}|td|_|td|_d|_dd}|dd|d|krdn|d}|j r|j|d |d d d ttd d |D]<}||z |j}Wntk rYqX|j|qdS)N)r6r8r7r9rzpositional argumentszoptional argumentscSs|Sr-r*)r,r*r*r+identitysz)ArgumentParser.__init__..identityrr&hr8rrzshow this help message and exit)rvrrr)rrrQ_ospathbasenamerargvrOriepilogformatter_classfromfile_prefix_charsadd_help allow_abbrevrSr _positionals _optionals _subparsersr;rxrr]rArrG)r%rOrir6rmparentsrnr8ror7r9rprqZ superinitZ add_grouprgZdefault_prefixrXdefaultsrr*r+rQfsJ    zArgumentParser.__init__cs"ddddddg}fdd|DS) NrOrir6rnr9rpcsg|]}|t|fqSr*rrr1r*r+r]sz.ArgumentParser._get_kwargs..r*rr*r1r+r"szArgumentParser._get_kwargsc Ks|jdk r|td|dt|d|ks8d|krht|dd}t|dd}||||_n|j|_|ddkr| }| }|j }| |j ||d||d<||d}|fd gi|}|j||S) Nz(cannot have multiple subparser argumentsrr[r6Z subcommandsrOr^r5r)rtr)rrrrrSrrrr_get_positional_actionsr@rmrirar|rMrO) r%rr[r6rWrrkZ parsers_classrvr*r*r+add_subparserss$   zArgumentParser.add_subparserscCs$|jr|j|n |j||Sr-)rrsrOrrrr*r*r+rOs zArgumentParser._add_actioncCsdd|jDS)NcSsg|]}|jr|qSr*rrZrvr*r*r+r]sz8ArgumentParser._get_optional_actions..r=r1r*r*r+_get_optional_actionssz$ArgumentParser._get_optional_actionscCsdd|jDS)NcSsg|]}|js|qSr*ryrzr*r*r+r]sz:ArgumentParser._get_positional_actions..r{r1r*r*r+rwsz&ArgumentParser._get_positional_actionscCs4|||\}}|r0td}||d||SNzunrecognized arguments: %sr)rrr)r$r%r\rrlrr*r*r+ parse_argss zArgumentParser.parse_argscCs|dkrtjdd}nt|}|dkr.t}|jD]4}|jtk r4t||js4|jtk r4t ||j|jq4|j D] }t||spt |||j |qpz>| ||\}}t|t r| t|t t|t ||fWStk rtd}|t|YnXdSrR)rrlr5r r=rrrrrrA_parse_known_argsrrrdelattrrexc_infor)r)r%r\rrvrerrr*r*r+rs,          zArgumentParser.parse_known_argscs jdk r i jD]R}|j}t|jD]<\}}|g}||d||||ddq2qig}t} t| D]^\}} | dkr|d| D]} |dqq | } | dkrd} n | |<d} || qd |t t d fdd  fd d }  fd d }gd r`t }nd} |krt fddD} |kr| }| kr| qdn| kr҈ |}|| |  qd| }|dg} jD]|}|kr|jr(|t|nT|jdk rt|jtrt|jr|jt|jkrt|j ||jq|r tdd | jD]X}|jr|jD]}|krqqdd|jD}td} |d |qfS)NrS--r&AOr^cs||||}||jk rb||gD]*}|kr6td}t|}t|||q6|tk rx|||dS)Nznot allowed with argument %s)r _get_valuesrrrrrr)rvZargument_stringsrZargument_valuesZconflict_actionrZ action_name)action_conflictsr seen_actionsseen_non_default_actionsr%r*r+ take_action@s    z5ArgumentParser._parse_known_args..take_actioncs~|}|\}}}j}g}|dkr:||dS|dk r||d}j}|dkr|d|kr||g|f|d} | |d}|ddpd} j} || kr| |}| }ntd} t|| |nB|dkr|d} |g}||||fq\ntd} t|| |q|d}|d}|||}||} || }||||fq\q|D]\}}}|||q`| S)NrSrrzignored explicit argument %r)_match_argumentr r8r>rr) start_index option_tuplervr explicit_argZmatch_argumentZ action_tuples arg_countrPcharZnew_explicit_argZ optionals_maprstopr\rZselected_patterns)r&arg_strings_patternextrasoption_string_indicesr%rr*r+consume_optionalUsL       z:ArgumentParser._parse_known_args..consume_optionalcsnj}|d}||}t|D]*\}}|||}||7}||q&t|ddd<|Sr-)_match_arguments_partialzipro)rZ match_partialZselected_patternZ arg_countsrvrr\)r&rrr%rr*r+consume_positionalss   z=ArgumentParser._parse_known_args..consume_positionalsrrcsg|]}|kr|qSr*r*)rZr)rr*r+r]sz4ArgumentParser._parse_known_args..z(the following arguments are required: %srcSsg|]}|jtk rt|qSr*)rrrrrzr*r*r+r]s z#one of the arguments %s is requiredr)N)ro_read_args_from_filesr@rrrriterr _parse_optionalr$rrwrAr@r=rrrrrrrrr _get_valuer)r)r%r&rr\rrZ mutex_actionZ conflictsZarg_string_pattern_partsZarg_strings_iter arg_stringrpatternrrZmax_option_string_indexZnext_option_string_indexZpositionals_end_indexZstringsZ stop_indexZrequired_actionsrvrrrr*) rr&rrrrrrrr%rrr+rs        J                    z ArgumentParser._parse_known_argsc Csg}|D]}|r|d|jkr*||qzdt|ddJ}g}|D]}||D]}||q\qN||}||W5QRXWqtk rt d}| t |YqXq|Sr) ror rreadrconvert_arg_line_to_argsrrr+rrr)r)r%r&Znew_arg_stringsrZ args_filearg_liner'rr*r*r+rs    z$ArgumentParser._read_args_from_filescCs|gSr-r*)r%rr*r*r+r!sz'ArgumentParser.convert_arg_line_to_argscCsz||}t||}|dkrldtdttdttdi}||j}|dkrbtdd|j|j}t ||t | dS)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrS) _get_nargs_patternrJrXrr r rrrrror)r%rvr nargs_patternrXZ nargs_errorsrr*r*r+r$s(    zArgumentParser._match_argumentcsrg}tt|ddD]X}|d|}dfdd|D}t||}|dk r|dd|Dqnq|S)Nrrr^csg|]}|qSr*)rrzr1r*r+r]@sz;ArgumentParser._match_arguments_partial..cSsg|] }t|qSr*rn)rZr,r*r*r+r]Ds)rror$rJrXrrk)r%rjrrrZ actions_slicerrXr*r1r+r:s  z'ArgumentParser._match_arguments_partialc Cs|sdS|d|jkrdS||jkr8|j|}||dfSt|dkrHdSd|kr~|dd\}}||jkr~|j|}|||fS||}t|dkrddd|D}||d}td}|||nt|dkr|\} | S|j |r|j sdSd |krdSd|dfS) NrrS=rcSsg|]\}}}|qSr*r*)rZrvrrr*r*r+r]isz2ArgumentParser._parse_optional..)r_Zmatchesz4ambiguous option: %(option)s could match %(matches)sr) r8r>rosplit_get_option_tuplesr$rr)rBrXrC) r%rrvrrZ option_tuplesZoptionsr\rrr*r*r+rJs>              zArgumentParser._parse_optionalc Cs0g}|j}|d|kr|d|kr|jr~d|krB|dd\}}n|}d}|jD],}||rP|j|}|||f}||qPn|d|kr|d|kr|}d}|dd}|dd} |jD]T}||kr|j|}||| f}||q||r|j|}|||f}||qn|td||S)NrrSrr8zunexpected option string: %s)r8rqrr> startswithr r)r) r%rrrPZ option_prefixrrvrZshort_option_prefixZshort_explicit_argr*r*r+rs:             z!ArgumentParser._get_option_tuplescCs|j}|dkrd}nf|tkr"d}nX|tkr0d}nJ|tkr>d}n<|tkrLd}n.|tkrZd}n |tkrhd}ndd d |}|jr| d d }| d d }|S) Nz(-*A-*)z(-*A?-*)z (-*[A-]*)z (-*A[A-]*)z([-AO]*)z (-*A[-AO]*)z(-*-*)z(-*%s-*)z-*rr^r&) rr rr rrrr$rra)r%rvrrr*r*r+rs(  z!ArgumentParser._get_nargs_patterncCs4|||\}}|r0td}||d||Sr})parse_known_intermixed_argsrr)r$r~r*r*r+parse_intermixed_argss z$ArgumentParser.parse_intermixed_argsc s|ddD}|r,td|djfdd|jDrHtdzN|j}z|jdkrp|dd|_D] }|j|_t |_|j|_t |_qt| ||\}}D]J}t ||j rt ||j gkrddlm}|d |j |ft||j qW5D]}|j|_|j|_qX|}zJ|D]}|j|_d |_q$|jD]} | j| _d | _q@| ||\}} W5|D]}|j|_qn|jD]} | j| _qXW5||_X|| fS) NcSsg|]}|jttfkr|qSr*)rrrrzr*r*r+r]sz>ArgumentParser.parse_known_intermixed_args..z3parse_intermixed_args: positional arg with nargs=%srcs&g|]}|jD]}|kr|jqqSr*)rr)rZrrvrr*r+r]s z;parse_intermixed_args: positional in mutuallyExclusiveGroup)warnzDo not expect %s in %sF)rwrrr@riZ save_nargsZ save_defaultr format_usagerrrrrwarningsrrr|Z save_requiredr) r%r\raZ save_usagervZremaining_argsrrrrr*rr+rs`           z*ArgumentParser.parse_known_intermixed_argscsjttfkr2z|dWntk r0YnX|szjtkrzjrNj}nj}t |t rv |} |n|sjt krjsjdk rj}n|} |nt|dkrjdtfkr|\} |} |njtkrfdd|D}npjtkr@fdd|D} |dn>jtkrRt}n,fdd|D}|D]} |qj|S)NrrScsg|]}|qSr*rrZvrvr%r*r+r]Z sz.ArgumentParser._get_values..csg|]}|qSr*rrrr*r+r]^ srcsg|]}|qSr*rrrr*r+r]g s)rrrrYrr rrrrrr _check_valuerror)r%rvr&r)rrr*rr+r6 sD       zArgumentParser._get_valuesc Cs|d|j|j}t|s0td}t|||z ||}Wntk r~t|jdt|j}tt d}t||YnLt t fk rt|jdt|j}||d}td}t|||YnX|S)NrrJrrS)rr)z!invalid %(type)s value: %(value)r) rFrrNrrrrr!rrrrr)r%rvrrQrrr(r\r*r*r+rn s   zArgumentParser._get_valuecCsF|jdk rB||jkrB|dtt|jd}td}t|||dS)Nr)r)rz3invalid choice: %(value)r (choose from %(choices)s))rr$mapr!rr)r%rvr)r\rr*r*r+r s zArgumentParser._check_valuecCs$|}||j|j|j|Sr-)rrmrir=r@ra)r%rWr*r*r+r s  zArgumentParser.format_usagecCst|}||j|j|j||j|jD]0}||j ||j| |j | q.||j |Sr-)rrmrir=r@rgr6r?rcr[ryrrdrmra)r%rWZ action_groupr*r*r+ra s        zArgumentParser.format_helpcCs|j|jdS)Nr~)rnrOr1r*r*r+r szArgumentParser._get_formattercCs"|dkrtj}|||dSr-)rr rrr%filer*r*r+ print_usage szArgumentParser.print_usagecCs"|dkrtj}|||dSr-)rr rrarr*r*r+r szArgumentParser.print_helpcCs |r|dkrtj}||dSr-)rstderrwrite)r%rrr*r*r+r szArgumentParser._print_messagercCs |r||tjt|dSr-)rrrr)r%Zstatusrr*r*r+r szArgumentParser.exitcCs0|tj|j|d}|dtd|dS)zerror(message: string) Prints a usage message incorporating the message to stderr and exits. If you override this in a subclass, it should not return -- it should either exit or raise an exception. )rOrr8z%(prog)s: error: %(message)s N)rrrrOrr)r%rr\r*r*r+r) s  zArgumentParser.error)NN)NN)NN)NN)N)N)N)rN)#rr2r3r4rrQr"rxrOr|rwrrrrrrrrrrrrrrrrrarrrrrr)rr*r*rr+rSsV@  #w:-1  M8    )3r4 __version____all__osrirerJZshutilr;sysrrrrrr rr rrrrrr7rrrrr r Exceptionrrr rrrrrrrrrr rrr r3rRrTrr*r*r*r+s=z    [#&] 7:"