PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  lY`@sdZdZdddddddd d d d d dddddgZddlZddlZddlZddl Z ddl Z ddl ZddlmZmZdZdZdZdZdZdZdZGdddeZdd ZGd!ddeZGd"ddeZGd#d d eZGd$ddeZGd%d d eZ d&d'Z!Gd(dde"Z#Gd)dde"Z$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<d<e%Z.Gd=d>d>e%Z/Gd?ddeZ0Gd@d d eZ1GdAdBdBeZ2GdCdDdDe2Z3GdEdFdFe3Z4GdGddee2Z5dS)Ha 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}x'|jD]}|jt|q"Wx1|jD]#\}}|jd||fqLWd|dj|fS)Nz%s=%rz%s(%s)z, )type__name__ _get_argsappendrepr _get_kwargsjoin)self type_name arg_stringsargnamevaluer''/opt/python35/lib/python3.5/argparse.py__repr__vsz_AttributeHolder.__repr__cCst|jjS)N)sorted__dict__items)r!r'r'r(rsz_AttributeHolder._get_kwargscCsgS)Nr')r!r'r'r(rsz_AttributeHolder._get_argsN)r __module__ __qualname____doc__r)rrr'r'r'r(rms  rcCs5t||ddkr(t|||t||S)N)getattrsetattr) namespacer%r&r'r'r( _ensure_valuesr3c@speZdZdZdddddZddZd d ZGd d d eZd dZ ddZ ddZ ddZ dddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:ZdS);rzFormatter for generating usage messages and argument help strings. Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail. NcCs|dkrNyttjd}Wnttfk rCd}YnX|d8}||_||_||_t|t |d|d|_||_ d|_ d|_ d|_ |j|d|_|j|_tjdtj|_tjd|_dS)NCOLUMNSPr4rz\s+z\n\n\n+)int_osenvironKeyError ValueError_prog_indent_increment_max_help_positionminmax_width_current_indent_level_action_max_length_Section _root_section_current_section_recompileASCII_whitespace_matcher_long_break_matcher)r!progindent_incrementmax_help_positionwidthr'r'r(__init__s&           zHelpFormatter.__init__cCs%|j|j7_|jd7_dS)N)rDr?rE)r!r'r'r(_indentszHelpFormatter._indentcCs@|j|j8_|jdks-td|jd8_dS)NrzIndent decreased below 0.rT)rDr?AssertionErrorrE)r!r'r'r(_dedentszHelpFormatter._dedentc@s+eZdZdddZddZdS)zHelpFormatter._SectionNcCs(||_||_||_g|_dS)N) formatterparentheadingr,)r!rXrYrZr'r'r(rSs   zHelpFormatter._Section.__init__cCs|jdk r|jj|jj}x!|jD]\}}||q2W|dd|jD}|jdk r|jj|sdS|jtk r|jdk r|jj}d|d|jf}nd}|d||dgS)NcSs"g|]\}}||qSr'r').0funcargsr'r'r( s z6HelpFormatter._Section.format_help..z%*s%s:  ) rYrXrU _join_partsr,rWrZrrD)r!r r\r] item_helpcurrent_indentrZr'r'r( format_helps    z"HelpFormatter._Section.format_help)rr-r.rSrdr'r'r'r(rGs rGcCs|jjj||fdS)N)rIr,r)r!r\r]r'r'r( _add_itemszHelpFormatter._add_itemcCsB|j|j||j|}|j|jg||_dS)N)rUrGrIrerd)r!rZsectionr'r'r( start_sections zHelpFormatter.start_sectioncCs|jj|_|jdS)N)rIrYrW)r!r'r'r( end_sectionszHelpFormatter.end_sectioncCs2|tk r.|dk r.|j|j|gdS)N)rre _format_text)r!textr'r'r(add_textszHelpFormatter.add_textcCs5|tk r1||||f}|j|j|dS)N)rre _format_usage)r!usageactionsgroupsprefixr]r'r'r( add_usages zHelpFormatter.add_usagecCs|jtk r|j}||g}x*|j|D]}|j||q7Wtdd|D}||j}t|j||_|j|j |gdS)NcSsg|]}t|qSr')len)r[sr'r'r(r^s z.HelpFormatter.add_argument..) helpr_format_action_invocation_iter_indented_subactionsrrBrDrFre_format_action)r!actionget_invocation invocations subactioninvocation_length action_lengthr'r'r( add_arguments    zHelpFormatter.add_argumentcCs"x|D]}|j|qWdS)N)r~)r!rnrxr'r'r( add_argumentss zHelpFormatter.add_argumentscCsA|jj}|r=|jjd|}|jdd}|S)Nz r`)rHrdrNsubstrip)r!rtr'r'r(rds zHelpFormatter.format_helpcCsdjdd|DS)Nr_cSs(g|]}|r|tk r|qSr')r)r[partr'r'r(r^s z-HelpFormatter._join_parts..)r )r! part_stringsr'r'r(raszHelpFormatter._join_partscs|dkrtd}|dk r=|td|j}n|dkri| ridtd|j}n|dkrdtd|j}g}g}x4|D],}|jr|j|q|j|qW|j} | |||} djdd|| gD}|j|jt |t |krd} | ||} | ||} t j | | }t j | | }dj|| kst dj|| kst dfdd }t |t |d krodt |t |d }|rA||g|||}|j |||q|rc||g|||}q|g}nzdt |}||}|||}t |d krg}|j ||||j ||||g|}d j|}d ||fS)Nzusage: rOz%(prog)s cSsg|]}|r|qSr'r')r[rsr'r'r(r^=s z/HelpFormatter._format_usage..z\(.*?\)+|\[.*?\]+|\S+cs g}g}|dk r+t|d}nt|d}x|D]w}|dt|kr|r|j|dj|g}t|d}|j||t|d7}qBW|r|j|dj||dk r|dt|d|d<|S)NrTrr)rrrr )partsindentrplineslineline_lenr) text_widthr'r( get_linesMs"     z.HelpFormatter._format_usage..get_linesg?rTr`z%s%s )_dictr>option_stringsr_format_actions_usager rCrDrrrJfindallrVextend)r!rmrnrorprO optionals positionalsrxformat action_usage part_regexp opt_usage pos_usage opt_parts pos_partsrrrrr')rr(rl!sZ       "    zHelpFormatter._format_usagec Cst}i}x#|D]}y|j|jd}Wntk rMwYqX|t|j}||||jkrx|jD]}|j|qW|js||kr||d7.z[\[(]z[\])]z(%s) z\1z (%s)z%s *%sr_z \(([^|]*)\)r)setindex_group_actionsr=rraddrequiredrange enumeratertrrgetpopr#_get_default_metavar_for_positional _format_argsnargs!_get_default_metavar_for_optionalr*r rJrr)r!rnro group_actionsinsertsgroupstartendrxirdefaultr option_string args_stringrjopencloser'r'r(r}sr                  z#HelpFormatter._format_actions_usagecCs_d|kr"|td|j}t|j|jd}d|j}|j|||dS)Nz%(prog)rO rz )rr>rBrCrD _fill_text)r!rjrrr'r'r(ris   zHelpFormatter._format_textc Cst|jd|j}t|j|d}||jd}|j|}|jsw|jd|f}d|}n\t||kr|jd||f}d|}d}n"|jd|f}d|}|}|g}|jr\|j |} |j | |} |j d|d| dfxQ| ddD] } |j d|d| fq5Wn|j dsx|j dx-|j |D]} |j |j| qW|j|S) Nr4rr_z%*s%s z %*s%-*s rrTr`)rArFr@rBrCrDrurtrr _expand_help _split_linesrendswithrvrwra) r!rx help_position help_width action_width action_headertup indent_firstr help_text help_linesrr{r'r'r(rws6         ! zHelpFormatter._format_actioncCs|js7|j|}|j||d\}|Sg}|jdkr_|j|jnL|j|}|j||}x(|jD]}|jd||fqWdj|SdS)NrTrz%s %sz, ) rr_metavar_formatterrrrrrr )r!rxrmetavarrrrr'r'r(rus z'HelpFormatter._format_action_invocationcsr|jdk r|jnA|jdk rVdd|jD}ddj|n|fdd}|S)NcSsg|]}t|qSr')str)r[choicer'r'r(r^0s z4HelpFormatter._metavar_formatter..z{%s},cs"ttrSf|SdS)N) isinstancetuple) tuple_size)resultr'r(r5sz0HelpFormatter._metavar_formatter..format)rchoicesr )r!rxdefault_metavar choice_strsrr')rr(r,s z HelpFormatter._metavar_formattercCs|j||}|jdkr4d|d}n|jtkrVd|d}n|jtkrxd|d}n|jtkrd|d}nr|jtkrd}nZ|jtkrd|d}n8d d t|jD}d j|||j}|S) Nz%srTz[%s]z [%s [%s ...]]r4z %s [%s ...]z...z%s ...cSsg|] }dqS)z%sr')r[rr'r'r(r^Ks z.HelpFormatter._format_args..r) rrr rr rrrr )r!rxr get_metavarrformatsr'r'r(r<s  zHelpFormatter._format_argscCstt|d|j}x+t|D]}||tkr(||=q(Wx8t|D]*}t||drV||j||.) rvarsr>listrhasattrrrr _get_help_string)r!rxparamsr% choices_strr'r'r(rOs   zHelpFormatter._expand_helpc csFy |j}Wntk r!Yn!X|j|EdH|jdS)N)_get_subactionsAttributeErrorrUrW)r!rxget_subactionsr'r'r(rv\s    z'HelpFormatter._iter_indented_subactionscCs+|jjd|j}tj||S)Nr)rMrr _textwrapwrap)r!rjrRr'r'r(rfszHelpFormatter._split_linescCs7|jjd|j}tj||d|d|S)Nrinitial_indentsubsequent_indent)rMrrrfill)r!rjrRrr'r'r(rjszHelpFormatter._fill_textcCs|jS)N)rt)r!rxr'r'r(roszHelpFormatter._get_help_stringcCs |jjS)N)destupper)r!rxr'r'r(rrsz/HelpFormatter._get_default_metavar_for_optionalcCs|jS)N)r)r!rxr'r'r(rusz1HelpFormatter._get_default_metavar_for_positional) rr-r.r/rSrUrWobjectrGrergrhrkrqr~rrdrarlrrirwrurrrrvrrrrrr'r'r'r(rs<   !         \ a  /       c@s"eZdZdZddZdS)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,djfdd|jddDS)Nr_c3s|]}|VqdS)Nr')r[r)rr'r( sz9RawDescriptionHelpFormatter._fill_text..keependsT)r splitlines)r!rjrRrr')rr(rsz&RawDescriptionHelpFormatter._fill_textN)rr-r.r/rr'r'r'r(rys c@s"eZdZdZddZdS)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 |jS)N)r)r!rjrRr'r'r(rsz!RawTextHelpFormatter._split_linesN)rr-r.r/rr'r'r'r(rs c@s"eZdZdZddZdS)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. cCsY|j}d|jkrU|jtk rUttg}|jsK|j|krU|d7}|S)Nz %(default)z (default: %(default)s))rtrrr rrr)r!rxrtdefaulting_nargsr'r'r(rs   z.ArgumentDefaultsHelpFormatter._get_help_stringN)rr-r.r/rr'r'r'r(rs c@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 |jjS)N)rr)r!rxr'r'r(rsz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs |jjS)N)rr)r!rxr'r'r(rsz.r')r!namesr')r!r(r's zAction._get_kwargscCsttddS)Nz.__call__() not defined)NotImplementedErrorr)r!parserr2valuesrr'r'r(__call__5szAction.__call__)rr-r.r/rSrrr'r'r'r(r s 1 c sIeZdZddddddddfddZdddZS) _StoreActionNFc s|dkrtd|dk r@|tkr@tdttt|jd|d|d|d|d|d |d |d |d | 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 appropriatez nargs must be %r to supply constrrrrrrrrrtr)r=r superrrS) r!rrrrrrrrrtr) __class__r'r(rS;s  z_StoreAction.__init__cCst||j|dS)N)r1r)r!rr2rrr'r'r(rXsz_StoreAction.__call__)rr-r.rSrr'r')rr(r9s rcs=eZdZddddfddZdddZS)_StoreConstActionNFcsAtt|jd|d|ddd|d|d|d|dS) Nrrrrrrrrt)rrrS)r!rrrrrrtr)rr'r(rS^sz_StoreConstAction.__init__cCst||j|jdS)N)r1rr)r!rr2rrr'r'r(rosz_StoreConstAction.__call__)rr-r.rSrr'r')rr(r\s  rcs+eZdZdddfddZS)_StoreTrueActionFNc s;tt|jd|d|ddd|d|d|dS)NrrrTrrrt)rrrS)r!rrrrrt)rr'r(rSusz_StoreTrueAction.__init__)rr-r.rSr'r')rr(rss rcs+eZdZdddfddZS)_StoreFalseActionTFNc s;tt|jd|d|ddd|d|d|dS)NrrrFrrrt)rrrS)r!rrrrrt)rr'r(rSsz_StoreFalseAction.__init__)rr-r.rSr'r')rr(rs rc sIeZdZddddddddfddZdddZS) _AppendActionNFc s|dkrtd|dk r@|tkr@tdttt|jd|d|d|d|d|d |d |d |d | 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 appropriatez nargs must be %r to supply constrrrrrrrrrtr)r=r rrrS) r!rrrrrrrrrtr)rr'r(rSs  z_AppendAction.__init__cCsBtjt||jg}|j|t||j|dS)N)_copycopyr3rrr1)r!rr2rrr,r'r'r(rs z_AppendAction.__call__)rr-r.rSrr'r')rr(rs rcs=eZdZddddfddZdddZS)_AppendConstActionNFcsGtt|jd|d|ddd|d|d|d|d |dS) Nrrrrrrrrtr)rrrS)r!rrrrrrtr)rr'r(rSsz_AppendConstAction.__init__cCsEtjt||jg}|j|jt||j|dS)N)rrr3rrrr1)r!rr2rrr,r'r'r(rsz_AppendConstAction.__call__)rr-r.rSrr'r')rr(rs  rcs:eZdZdddfddZdddZS) _CountActionNFc s;tt|jd|d|ddd|d|d|dS)Nrrrrrrrt)rrrS)r!rrrrrt)rr'r(rSsz_CountAction.__init__cCs0t||jdd}t||j|dS)NrrT)r3rr1)r!rr2rr new_countr'r'r(rsz_CountAction.__call__)rr-r.rSrr'r')rr(rs  rcs:eZdZeedfddZdddZS) _HelpActionNc s5tt|jd|d|d|ddd|dS)Nrrrrrrt)rrrS)r!rrrrt)rr'r(rSs z_HelpAction.__init__cCs|j|jdS)N) print_helpexit)r!rr2rrr'r'r(rs z_HelpAction.__call__)rr-r.rrSrr'r')rr(rs rcs=eZdZdeedfddZdddZS)_VersionActionNz&show program's version number and exitc s>tt|jd|d|d|ddd|||_dS)Nrrrrrrt)rrrSversion)r!rrrrrt)rr'r(rSsz_VersionAction.__init__cCs^|j}|dkr|j}|j}|j||j|jtj|jdS)N)r_get_formatterrk_print_messagerd_sysstdoutr)r!rr2rrrrXr'r'r(r s     z_VersionAction.__call__)rr-r.rrSrr'r')rr(rs  rcsheZdZGdddeZeddfddZddZdd Zdd d Z S) _SubParsersActioncs"eZdZfddZS)z&_SubParsersAction._ChoicesPseudoActionc s_|}}|r'|ddj|7}ttj|}|jdgd|d|d|dS)Nz (%s)z, rrrtr)r rr _ChoicesPseudoActionrS)r!r%aliasesrtrrsup)rr'r(rSs  z/_SubParsersAction._ChoicesPseudoAction.__init__)rr-r.rSr'r')rr(rs rNc sh||_||_tj|_g|_tt|jd|d|dt d|jd|d|dS)Nrrrrrtr) _prog_prefix _parser_class _collections OrderedDict_name_parser_map_choices_actionsrr rSr)r!rrO parser_classrrtr)rr'r(rS"s    z_SubParsersAction.__init__cKs|jddkr,d|j|f|d<|jdf}d|kr~|jd}|j|||}|jj||j|}||j|.cSs2g|](\}}|dk rd||fqS)Nz%s=%rr')r[kwr$r'r'r(r^s z%s(%s))r$r%r&r'r rr)r!r]rargs_strr'r'r(r)s zFileType.__repr__r)rr-r.r/rSrr)r'r'r'r(rvs  c@s:eZdZdZddZddZddZdS) r zSimple object for storing attributes. Implements equality by attribute names and values, and provides a simple string representation. cKs)x"|D]}t||||qWdS)N)r1)r!rr%r'r'r(rSs zNamespace.__init__cCs)t|tstSt|t|kS)N)rr NotImplementedr)r!otherr'r'r(__eq__szNamespace.__eq__cCs ||jkS)N)r+)r!r"r'r'r( __contains__szNamespace.__contains__N)rr-r.r/rSr6r7r'r'r'r(r s   cseZdZfddZddZdddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZdddZddZd d!Zd"d#Zd$d%ZS)&_ActionsContainercsgtt|j||_||_||_||_i|_|jddt |jddt |jddt |jddt |jddt |jddt |jddt|jddt|jdd t|jdd t|jdd t|jg|_i|_g|_g|_i|_tjd |_g|_dS) Nrxstore store_const store_true store_falser append_constcountrtrparsersz^-\d+$|^-\d*\.\d+$)rr8rS descriptionargument_default prefix_charsconflict_handler _registriesregisterrrrrrrrrrr  _get_handler_actions_option_string_actions_action_groups_mutually_exclusive_groups _defaultsrJrK_negative_number_matcher_has_negative_number_optionals)r!r@rBrArC)rr'r(rSs2           z_ActionsContainer.__init__cCs#|jj|i}|||.)rrrr r)r!rxconflicting_actionsrconflict_stringr'r'r(_handle_conflict_errors  z(_ActionsContainer._handle_conflict_errorcCsWxP|D]H\}}|jj||jj|d|js|jj|qWdS)N)rrdrHrrbre)r!rxrsrr'r'r(_handle_conflict_resolves  z*_ActionsContainer._handle_conflict_resolve)rr-r.rSrErPrRrSr~r^r`rYrerjrTrUrVrFrarurvr'r')rr(r8s$ 4  /     (  $  r8csLeZdZddfddZfddZfddZS)r]Nc s|j}|d|j|d|j|d|jtt|j}|d||||_g|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_dS)NrCrBrAr@)rrCrBrArr]rSrfrrDrGrHrKrMrJ)r!rbrfr@rrQ super_init)rr'r(rSs        z_ArgumentGroup.__init__cs,tt|j|}|jj||S)N)rr]rYrr)r!rx)rr'r(rY sz_ArgumentGroup._add_actioncs*tt|j||jj|dS)N)rr]rerrd)r!rx)rr'r(resz_ArgumentGroup._remove_action)rr-r.rSrYrer'r')rr(r]s r]cs=eZdZdfddZddZddZS)r_Fcs,tt|j|||_||_dS)N)rr_rSr _container)r!rbr)rr'r(rSs z _MutuallyExclusiveGroup.__init__cCsG|jr!td}t||jj|}|jj||S)Nz-mutually exclusive arguments must be optional)rrr=rxrYrr)r!rxr r'r'r(rYs    z#_MutuallyExclusiveGroup._add_actioncCs$|jj||jj|dS)N)rxrerrd)r!rxr'r'r(re$sz&_MutuallyExclusiveGroup._remove_action)rr-r.rSrYrer'r')rr(r_s  r_cseZdZdZddddgeddddddfdd Zdd Zd d Zd d ZddZ ddZ ddddZ ddddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zdd2d3Zdd4d5Zdd6d7Zd8dd9d:Zd;d<ZS)=raObject 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,errorTc  stt|j} | d|d|d| d| |dkrVtjjtjd}||_||_ ||_ ||_ ||_ | |_ | |_|j}|td|_|td|_d|_dd }|jd d|d |krd n|d}|j rI|j|d |d ddddtdtdxM|D]E}|j|y |j}Wntk rYqPX|jj|qPWdS)Nr@rBrArCrzpositional argumentszoptional argumentscSs|S)Nr')r0r'r'r(identitybsz)ArgumentParser.__init__..identityrr,hr4rtrxrzshow this help message and exit)rrrSr:pathbasenamer argvrOrmepilogformatter_classfromfile_prefix_charsadd_help allow_abbrevr^r _positionals _optionals _subparsersrEr~rrjrKrrQ)r!rOrmr@rparentsrrBrrArCrr superinit add_grouprzdefault_prefixrYdefaults)rr'r(rS<sB                   zArgumentParser.__init__cs/ddddddg}fdd|DS) NrOrmr@rrCrcs%g|]}|t|fqSr')r0)r[r%)r!r'r(r^s z.ArgumentParser._get_kwargs..r')r!rr')r!r(r|s zArgumentParser._get_kwargsc KsA|jdk r"|jtd|jdt|d|ksPd|krt|jdd}t|jdd}|j|||_n |j|_|jddkr |j }|j }|j }|j |j ||d|jj|d<|j|d}|d g|}|jj||S) Nz(cannot have multiple subparser argumentsrrfr@ subcommandsrOr_r?r)rryrrrrr^rrr _get_positional_actionsrJrqrmrdrrVrY) r!rrfr@rXrro parsers_classrxr'r'r(add_subparserss$    zArgumentParser.add_subparserscCs0|jr|jj|n|jj||S)N)rrrYr)r!rxr'r'r(rYs zArgumentParser._add_actioncCsdd|jDS)NcSsg|]}|jr|qSr')r)r[rxr'r'r(r^s z8ArgumentParser._get_optional_actions..)rG)r!r'r'r(_get_optional_actionss z$ArgumentParser._get_optional_actionscCsdd|jDS)NcSsg|]}|js|qSr')r)r[rxr'r'r(r^s z:ArgumentParser._get_positional_actions..)rG)r!r'r'r(rs z&ArgumentParser._get_positional_actionscCsH|j||\}}|rDtd}|j|dj||S)Nzunrecognized arguments: %sr)rrryr )r!r]r2r~r r'r'r( parse_argss  zArgumentParser.parse_argsc Csk|dkr"tjdd}n t|}|dkrCt}xW|jD]L}|jtk rMt||jsM|jtk rMt ||j|jqMWx7|j D],}t||st |||j |qWyX|j ||\}}t|t r$|j t|t t|t ||fSWn5tk rftjd}|jt|YnXdS)NrT)r r~rr rGrrrrr1rK_parse_known_argsrrr0delattrrexc_inforyr)r!r]r2rxrerrr'r'r(rs,      zArgumentParser.parse_known_argscs. jdk r jix~ jD]s}|j}xat|jD]P\}}j|g}|j|d||j||ddqMWq.Wig}t} xt| D]\}} | dkr|jdx_| D]} |jdqWq j | } | dkr4d} n| |.take_actioncs|}|\}}}j}g}x|dkrPj||dS|dk ry||d}j}|dkr|d|kr|j|g|f|d} | |d}|ddpd} j} || kr| |}| }qvtd} t|| |q|dkrW|d} |g}|j|||fPqtd} t|| |q+|d}|d}|||}||} || }|j|||fPq+W|stx'|D]\}}}|||qW| S)NrTrrzignored explicit argument %r)_match_argumentrrBrHrrrV) start_index option_tuplerxr explicit_argmatch_argument action_tuples arg_countrZcharnew_explicit_arg optionals_mapr stopr]rselected_patterns)r#arg_strings_patternextrasoption_string_indicesr!rr'r(consume_optional+sP                  z:ArgumentParser._parse_known_args..consume_optionalcsj}|d}||}xHt|D]7\}}|||}||7}||q8Wt|ddd<|S)N)_match_arguments_partialziprr)r match_partialselected_pattern arg_countsrxrr])r#rrr!rr'r(consume_positionalsxs   z=ArgumentParser._parse_known_args..consume_positionalsrcs"g|]}|kr|qSr'r')r[r)rr'r(r^s z4ArgumentParser._parse_known_args..z(the following arguments are required: %sz, cSs+g|]!}|jtk rt|qSr')rtrr)r[rxr'r'r(r^s z#one of the arguments %s is requiredrr)r_read_args_from_filesrJrrrriterr_parse_optionalr rrrBrArGrrrrrrrr0r1 _get_valueryr)r!r#r2rirr mutex_action conflictsarg_string_pattern_partsarg_strings_iter arg_stringrpatternrrmax_option_string_indexnext_option_string_indexpositionals_end_indexstrings stop_indexrequired_actionsrxrrr r') rr#rrr2rrrrr!rrr(rs #         !!J                z ArgumentParser._parse_known_argscCsg}x|D]}| s-|d|jkr=|j|q yt|ddm}g}xA|jjD]-}x$|j|D]}|j|qWqrW|j|}|j|WdQRXWq tk rt j d}|j t |Yq Xq W|S)NrrT) rrrreadrconvert_arg_line_to_argsrrr/r rryr)r!r#new_arg_stringsr args_filearg_liner$rr'r'r(rs   z$ArgumentParser._read_args_from_filescCs|gS)Nr')r!rr'r'r(rsz'ArgumentParser.convert_arg_line_to_argscCs|j|}tj||}|dkrdtdttdttdi}tdd|j|j}|j|j|}t ||t |j dS)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrT) _get_nargs_patternrJrcrr r rrrrrrr)r!rxr nargs_patternrc nargs_errorsrr r'r'r(rs   zArgumentParser._match_argumentcsg}xtt|ddD]w}|d|}djfdd|D}tj||}|dk r|jdd|jDPqW|S)NrrTr_csg|]}j|qSr')r)r[rx)r!r'r(r^s z;ArgumentParser._match_arguments_partial..cSsg|]}t|qSr')rr)r[r0r'r'r(r^s r)rrrr rJrcrro)r!rnrrr actions_slicerrcr')r!r(rs   z'ArgumentParser._match_arguments_partialc Cs|s dS|d|jkr!dS||jkrJ|j|}||dfSt|dkr`dSd|kr|jdd\}}||jkr|j|}|||fS|jrD|j|}t|dkr%djdd|D}d|d|i}td }|j||nt|dkrD|\} | S|j j |rc|j scdSd |krsdSd|dfS) NrrT=z, cSsg|]\}}}|qSr'r')r[rxrrr'r'r(r^?s z2ArgumentParser._parse_optional..rkmatchesz4ambiguous option: %(option)s could match %(matches)sr) rBrHrrsplitr_get_option_tuplesr rryrLrcrM) r!rrxrr option_tuplesoptionsr]r rr'r'r(rs>           zArgumentParser._parse_optionalc Csg}|j}|d|kr|d|krd|krV|jdd\}}n |}d}x6|jD]>}|j|rl|j|}|||f}|j|qlWn|d|kr|d|kr|}d}|dd}|dd} x|jD]v}||krE|j|}||| f}|j|q|j|r|j|}|||f}|j|qWn|jtd||S)NrrTrr4zunexpected option string: %s)rBrrH startswithrryr) r!rrrZ option_prefixrrxrshort_option_prefixshort_explicit_argr'r'r(rZs8        z!ArgumentParser._get_option_tuplescCs|j}|dkrd}n|tkr3d}nk|tkrHd}nV|tkr]d}nA|tkrrd}n,|tkrd}nddjd |}|jr|jdd }|jd d }|S) Nz(-*A-*)z(-*A?-*)z (-*[A-]*)z (-*A[A-]*)z([-AO]*)z (-*A[-AO]*)z(-*%s-*)z-*rr_r,) rr rr rrr rrm)r!rxrrr'r'r(rs$              z!ArgumentParser._get_nargs_patternc sjttgkr;y|jdWntk r:YnX| rjtkrjrfj}n j}t |t rj |}j |nV| rjt krj rjdk rj}n|}j |nt|dkrLjdtgkrL|\}j |}j |njtkrzfdd|D}njtkrfdd|D}j |dn=fdd|D}x|D]}j |qW|S)Nz--rTcs"g|]}j|qSr')r)r[v)rxr!r'r(r^s z.ArgumentParser._get_values..cs"g|]}j|qSr')r)r[r)rxr!r'r(r^s rcs"g|]}j|qSr')r)r[r)rxr!r'r(r^s )rrrrdr=r rrrrrr _check_valuerrr)r!rxr#r&rrr')rxr!r(rs>      '  zArgumentParser._get_valuesc Cs|jd|j|j}t|sFtd}t|||y||}Wntk rt|jdt|j}tt j d}t||Yngt t fk rt|jdt|j}d|d|i}td}t|||YnX|S)Nrz%r is not callablerrTr&z!invalid %(type)s value: %(value)r) rPrrWrrrr0rrr rrXr=)r!rxrr\r rr%r]r'r'r(rs     zArgumentParser._get_valuecCsh|jdk rd||jkrdd|ddjtt|ji}td}t|||dS)Nr&rz, z3invalid choice: %(value)r (choose from %(choices)s))rr maprrr)r!rxr&r]r r'r'r(r s ! zArgumentParser._check_valuecCs2|j}|j|j|j|j|jS)N)r rqrmrGrJrd)r!rXr'r'r( format_usage s  zArgumentParser.format_usagecCs|j}|j|j|j|j|j|jxK|jD]@}|j|j |j|j|j |j |j qBW|j|j |jS)N)r rqrmrGrJrkr@rIrgrfrrrhrrd)r!rX action_groupr'r'r(rd s  zArgumentParser.format_helpcCs|jd|jS)NrO)rrO)r!r'r'r(r ( szArgumentParser._get_formattercCs/|dkrtj}|j|j|dS)N)r r r r)r!filer'r'r( print_usage. s  zArgumentParser.print_usagecCs/|dkrtj}|j|j|dS)N)r r r rd)r!rr'r'r(r3 s  zArgumentParser.print_helpcCs,|r(|dkrtj}|j|dS)N)r stderrwrite)r!rrr'r'r(r 8 s  zArgumentParser._print_messagercCs*|r|j|tjtj|dS)N)r r rr)r!statusrr'r'r(rA szArgumentParser.exitcCsC|jtjd|jd|i}|jdtd|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. rOrr4z%(prog)s: error: %(message)s N)rr rrOrr)r!rr]r'r'r(ryF s zArgumentParser.error) rr-r.r/rrSrrrYrrrrrrrrrrrrrrrrrdr rrr rryr'r')rr(r)sN 4     #     ; , , 4     )6r/ __version____all__ collectionsrrrosr:rerJsysr textwraprrrrrr rr rrrrrr3rrrrr r Exceptionrrr rrrrrrrrrr rr r8r]r_rr'r'r'r(>sz            [#%`64"