grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ”qc`ã@sdZdZdddddddd d d d d dddddgZddlZddlZddlZddl Z ddl Z ddl ZddlmZmZdZdZdZdZdZdZdZGdd„deƒZdd „ZGd!d„deƒZGd"d„deƒZGd#d „d eƒZGd$d„deƒZGd%d „d eƒZ d&d'„Z!Gd(d„de"ƒZ#Gd)d„de"ƒZ$Gd*d „d eƒZ%Gd+d,„d,e%ƒZ&Gd-d.„d.e%ƒZ'Gd/d0„d0e'ƒZ(Gd1d2„d2e'ƒZ)Gd3d4„d4e%ƒZ*Gd5d6„d6e%ƒZ+Gd7d8„d8e%ƒZ,Gd9d:„d:e%ƒZ-Gd;d<„d<e%ƒZ.Gd=d>„d>e%ƒZ/Gd?d„deƒZ0Gd@d „d eƒZ1GdAdB„dBeƒZ2GdCdD„dDe2ƒZ3GdEdF„dFe3ƒZ4GdGd„dee2ƒZ5dS)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.1ÚArgumentParserÚ ArgumentErrorÚArgumentTypeErrorÚFileTypeÚ HelpFormatterÚArgumentDefaultsHelpFormatterÚRawDescriptionHelpFormatterÚRawTextHelpFormatterÚMetavarTypeHelpFormatterÚ NamespaceÚActionÚ ONE_OR_MOREÚOPTIONALÚPARSERÚ REMAINDERÚSUPPRESSÚ ZERO_OR_MOREéN)ÚgettextÚngettextz ==SUPPRESS==ú?Ú*ú+zA...z...Z_unrecognized_argsc@s:eZdZdZdd„Zdd„Zdd„ZdS) Ú_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__. cCsŠt|ƒj}g}x'|jƒD]}|jt|ƒƒq"Wx1|jƒD]#\}}|jd||fƒqLWd|dj|ƒfS)Nz%s=%rz%s(%s)z, )ÚtypeÚ__name__Ú _get_argsÚappendÚreprÚ _get_kwargsÚjoin)ÚselfZ type_nameÚ arg_stringsÚargÚnameÚvalue©r%ú-/opt/alt/python35/lib64/python3.5/argparse.pyÚ__repr__vsz_AttributeHolder.__repr__cCst|jjƒƒS)N)ÚsortedÚ__dict__Úitems)r r%r%r&rsz_AttributeHolder._get_kwargscCsgS)Nr%)r r%r%r&r‚sz_AttributeHolder._get_argsN)rÚ __module__Ú __qualname__Ú__doc__r'rrr%r%r%r&rms  rcCs5t||dƒdkr(t|||ƒt||ƒS)N)ÚgetattrÚsetattr)Ú namespacer#r$r%r%r&Ú _ensure_value†sr1c@speZdZdZddddd„Zdd„Zd d „ZGd d „d eƒZd d„Z dd„Z dd„Z dd„Z ddd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„ZdS);rz×Formatter 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)NZCOLUMNSéPr2érz\s+z\n\n\n+)ÚintÚ_osÚenvironÚKeyErrorÚ ValueErrorÚ_progÚ_indent_incrementÚ_max_help_positionÚminÚmaxÚ_widthÚ_current_indentÚ_levelÚ_action_max_lengthÚ_SectionÚ _root_sectionÚ_current_sectionÚ_reÚcompileÚASCIIÚ_whitespace_matcherÚ_long_break_matcher)r ÚprogZindent_incrementZmax_help_positionÚwidthr%r%r&Ú__init__—s&           zHelpFormatter.__init__cCs%|j|j7_|jd7_dS)Né)rAr<rB)r r%r%r&Ú_indent¹szHelpFormatter._indentcCs@|j|j8_|jdks-tdƒ‚|jd8_dS)NrzIndent decreased below 0.rO)rAr<ÚAssertionErrorrB)r r%r%r&Ú_dedent½szHelpFormatter._dedentc@s+eZdZddd„Zdd„ZdS)zHelpFormatter._SectionNcCs(||_||_||_g|_dS)N)Ú formatterÚparentÚheadingr*)r rSrTrUr%r%r&rNÄs   zHelpFormatter._Section.__init__cCsí|jdk r|jjƒ|jj}x!|jD]\}}||Œq2W|dd„|jDƒƒ}|jdk r„|jjƒ|sŽdS|jtk rÑ|jdk rÑ|jj}d|d|jf}nd}|d||dgƒS)NcSs"g|]\}}||Œ‘qSr%r%)Ú.0ÚfuncÚargsr%r%r&ú Ñs z6HelpFormatter._Section.format_help..Úz%*s%s: Ú ) rTrSrPÚ _join_partsr*rRrUrrA)r rrWrXZ item_helpZcurrent_indentrUr%r%r&Ú format_helpÊs    z"HelpFormatter._Section.format_help)rr+r,rNr]r%r%r%r&rDÂs rDcCs|jjj||fƒdS)N)rFr*r)r rWrXr%r%r&Ú _add_itemãszHelpFormatter._add_itemcCsB|jƒ|j||j|ƒ}|j|jgƒ||_dS)N)rPrDrFr^r])r rUZsectionr%r%r&Ú start_sectionés zHelpFormatter.start_sectioncCs|jj|_|jƒdS)N)rFrTrR)r r%r%r&Ú end_sectionïszHelpFormatter.end_sectioncCs2|tk r.|dk r.|j|j|gƒdS)N)rr^Ú _format_text)r Útextr%r%r&Úadd_textószHelpFormatter.add_textcCs5|tk r1||||f}|j|j|ƒdS)N)rr^Ú _format_usage)r ÚusageÚactionsÚgroupsÚprefixrXr%r%r&Ú add_usage÷s zHelpFormatter.add_usagecCs©|jtk r¥|j}||ƒg}x*|j|ƒD]}|j||ƒƒq7Wtdd„|Dƒƒ}||j}t|j|ƒ|_|j|j |gƒdS)NcSsg|]}t|ƒ‘qSr%)Úlen)rVÚsr%r%r&rYs z.HelpFormatter.add_argument..) ÚhelprÚ_format_action_invocationÚ_iter_indented_subactionsrr?rArCr^Ú_format_action)r ÚactionZget_invocationZ invocationsÚ subactionZinvocation_lengthZ action_lengthr%r%r&Ú add_argumentüs    zHelpFormatter.add_argumentcCs"x|D]}|j|ƒqWdS)N)rr)r rfrpr%r%r&Ú add_argumentss zHelpFormatter.add_argumentscCsA|jjƒ}|r=|jjd|ƒ}|jdƒd}|S)Nz r[)rEr]rKÚsubÚstrip)r rlr%r%r&r]s zHelpFormatter.format_helpcCsdjdd„|DƒƒS)NrZcSs(g|]}|r|tk r|‘qSr%)r)rVÚpartr%r%r&rYs z-HelpFormatter._join_parts..)r)r Z part_stringsr%r%r&r\szHelpFormatter._join_partscs|dkrtdƒ}|dk r=|td|jƒ}n»|dkri| ridtd|jƒ}n�|dkrødtd|jƒ}g}g}x4|D],}|jr½|j|ƒqž|j|ƒqžW|j} | |||ƒ} djdd„|| gDƒƒ}|j|j‰t |ƒt |ƒˆkrød} | ||ƒ} | ||ƒ} t j | | ƒ}t j | | ƒ}dj|ƒ| ks›t ‚dj|ƒ| ks¶t ‚d‡fdd †}t |ƒt |ƒd ˆkrodt |ƒt |ƒd }|rA||g|||ƒ}|j |||ƒƒqé|rc||g|||ƒ}qé|g}nzdt |ƒ}||}|||ƒ}t |ƒd krÜg}|j |||ƒƒ|j |||ƒƒ|g|}d j|ƒ}d ||fS)Nzusage: rLz%(prog)sú cSsg|]}|r|‘qSr%r%)rVrkr%r%r&rY=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)NrOrwr)rjrr)ÚpartsÚindentrhÚlinesÚlineZline_lenrv)Ú text_widthr%r&Ú get_linesMs"     z.HelpFormatter._format_usage..get_linesgè?rOr[z%s%s )Ú_Údictr;Úoption_stringsrÚ_format_actions_usagerr@rArjrGÚfindallrQÚextend)r rerfrgrhrLZ optionalsÚ positionalsrpÚformatZ action_usageZ part_regexpZ opt_usageZ pos_usageZ opt_partsZ pos_partsr}ryrzrxr%)r|r&rd!sZ       "    zHelpFormatter._format_usagec Cs•tƒ}i}x#|D]}y|j|jdƒ}Wntk rMwYqX|t|jƒ}|||…|jkrx|jD]}|j|ƒq„W|jsØ||krÁ||d7.z[\[(]z[\])]z(%s) z\1z (%s)z%s *%srZz \(([^|]*)\)éÿÿÿÿr�)ÚsetÚindexÚ_group_actionsr:rjÚaddÚrequiredÚrangeÚ enumeraterlrrÚgetÚpopr€Ú#_get_default_metavar_for_positionalÚ _format_argsÚnargsÚ!_get_default_metavar_for_optionalr(rrGrtru)r rfrgÚ group_actionsZinsertsÚgroupÚstartÚendrpÚirxÚdefaultrvÚ option_stringÚ args_stringrbÚopenÚcloser%r%r&r�}sr                  z#HelpFormatter._format_actions_usagecCs_d|kr"|td|jƒ}t|j|jdƒ}d|j}|j|||ƒdS)Nz%(prog)rLé rwz )rr;r?r@rAÚ _fill_text)r rbr|ryr%r%r&raÞs   zHelpFormatter._format_textc Csµt|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| dfƒxQ| dd…D] } |j d|d| fƒq5Wn|j dƒsx|j dƒx-|j |ƒD]} |j |j| ƒƒqˆW|j|ƒS) Nr2r¥rZz%*s%s z %*s%-*s rrOr[)r>rCr=r?r@rArmrlrjÚ _expand_helpÚ _split_linesrÚendswithrnror\) r rpZ help_positionZ help_widthZ action_widthZ action_headerÚtupZ indent_firstrxZ help_textZ help_linesr{rqr%r%r&roås6         ! zHelpFormatter._format_actioncCs¼|js7|j|ƒ}|j||ƒdƒ\}|Sg}|jdkr_|j|jƒnL|j|ƒ}|j||ƒ}x(|jD]}|jd||fƒqŠWdj|ƒSdS)NrOrz%s %sz, ) r€r—Ú_metavar_formatterr™rƒršr˜rr)r rpr Úmetavarrxr¢r¡r%r%r&rms z'HelpFormatter._format_action_invocationcsr|jdk r|j‰nA|jdk rVdd„|jDƒ}ddj|ƒ‰n|‰‡fdd†}|S)NcSsg|]}t|ƒ‘qSr%)Ústr)rVZchoicer%r%r&rY0s z4HelpFormatter._metavar_formatter..z{%s}ú,cs"tˆtƒrˆSˆf|SdS)N)Ú isinstanceÚtuple)Z tuple_size)Úresultr%r&r…5sz0HelpFormatter._metavar_formatter..format)r¬Úchoicesr)r rpÚdefault_metavarZ choice_strsr…r%)r±r&r«,s z HelpFormatter._metavar_formattercCs|j||ƒ}|jdkr4d|dƒ}nØ|jtkrVd|dƒ}n¶|jtkrxd|dƒ}n”|jtkršd|dƒ}nr|jtkr²d}nZ|jtkrÔd|dƒ}n8d d „t|jƒDƒ}d j|ƒ||jƒ}|S) Nz%srOz[%s]z [%s [%s ...]]r2z %s [%s ...]z...z%s ...cSsg|] }d‘qS)z%sr%)rVr~r%r%r&rYKs z.HelpFormatter._format_args..rw) r«r™r rr rrr“r)r rpr³Z get_metavarr±Zformatsr%r%r&r˜<s  zHelpFormatter._format_argscCsÔtt|ƒd|jƒ}x+t|ƒD]}||tkr(||=q(Wx8t|ƒD]*}t||dƒrV||j||.) rÚvarsr;ÚlistrÚhasattrrr•rÚ_get_help_string)r rpZparamsr#Z choices_strr%r%r&r§Os   zHelpFormatter._expand_helpc csFy |j}Wntk r!Yn!X|jƒ|ƒEdH|jƒdS)N)Ú_get_subactionsÚAttributeErrorrPrR)r rpZget_subactionsr%r%r&rn\s    z'HelpFormatter._iter_indented_subactionscCs+|jjd|ƒjƒ}tj||ƒS)Nrw)rJrtruÚ _textwrapZwrap)r rbrMr%r%r&r¨fszHelpFormatter._split_linescCs7|jjd|ƒjƒ}tj||d|d|ƒS)NrwZinitial_indentZsubsequent_indent)rJrtrur»Zfill)r rbrMryr%r%r&r¦jszHelpFormatter._fill_textcCs|jS)N)rl)r rpr%r%r&r¸oszHelpFormatter._get_help_stringcCs |jjƒS)N)ÚdestÚupper)r rpr%r%r&ršrsz/HelpFormatter._get_default_metavar_for_optionalcCs|jS)N)r¼)r rpr%r%r&r—usz1HelpFormatter._get_default_metavar_for_positional) rr+r,r-rNrPrRÚobjectrDr^r_r`rcrirrrsr]r\rdr�rarormr«r˜r§rnr¨r¦r¸ršr—r%r%r%r&r�s<   !         \ a  /       c@s"eZdZdZdd„ZdS)rzÙHelp 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,dj‡fdd†|jddƒDƒƒS)NrZc3s|]}ˆ|VqdS)Nr%)rVr{)ryr%r&ú �sz9RawDescriptionHelpFormatter._fill_text..ÚkeependsT)rÚ splitlines)r rbrMryr%)ryr&r¦€sz&RawDescriptionHelpFormatter._fill_textN)rr+r,r-r¦r%r%r%r&rys c@s"eZdZdZdd„ZdS)rzÖHelp 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 |jƒS)N)rÁ)r rbrMr%r%r&r¨‹sz!RawTextHelpFormatter._split_linesN)rr+r,r-r¨r%r%r%r&r„s c@s"eZdZdZdd„ZdS)rz×Help 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))rlr rr rr€r™)r rprlZdefaulting_nargsr%r%r&r¸–s   z.ArgumentDefaultsHelpFormatter._get_help_stringN)rr+r,r-r¸r%r%r%r&r�s c@s.eZdZdZdd„Zdd„ZdS)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 rpr%r%r&rš¨sz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs |jjS)N)rr)r rpr%r%r&r—«sz.r%)r Únamesr%)r r&r's zAction._get_kwargscCsttdƒƒ‚dS)Nz.__call__() not defined)ÚNotImplementedErrorr~)r Úparserr0Úvaluesr¡r%r%r&Ú__call__5szAction.__call__)rr+r,r-rNrrÍr%r%r%r&r Þs 1 c sIeZdZdddddddd‡fdd†Zddd„Z‡S)Ú _StoreActionNFc s“|dkrtdƒ‚|dk r@|tkr@tdtƒ‚tt|ƒjd|d|d|d|d|d |d |d |d | d | ƒ dS)Nrz„nargs 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 constr€r¼r™rÈr rr²r’rlr¬)r:r ÚsuperrÎrN) r r€r¼r™rÈr rr²r’rlr¬)Ú __class__r%r&rN;s  z_StoreAction.__init__cCst||j|ƒdS)N)r/r¼)r rËr0rÌr¡r%r%r&rÍXsz_StoreAction.__call__)rr+r,rNrÍr%r%)rÐr&rÎ9s rÎcs=eZdZdddd‡fdd†Zddd„Z‡S)Ú_StoreConstActionNFcsAtt|ƒjd|d|ddd|d|d|d|ƒdS) Nr€r¼r™rrÈr r’rl)rÏrÑrN)r r€r¼rÈr r’rlr¬)rÐr%r&rN^sz_StoreConstAction.__init__cCst||j|jƒdS)N)r/r¼rÈ)r rËr0rÌr¡r%r%r&rÍosz_StoreConstAction.__call__)rr+r,rNrÍr%r%)rÐr&rÑ\s  rÑcs+eZdZddd‡fdd†Z‡S)Ú_StoreTrueActionFNc s;tt|ƒjd|d|ddd|d|d|ƒdS)Nr€r¼rÈTr r’rl)rÏrÒrN)r r€r¼r r’rl)rÐr%r&rNusz_StoreTrueAction.__init__)rr+r,rNr%r%)rÐr&rÒss rÒcs+eZdZddd‡fdd†Z‡S)Ú_StoreFalseActionTFNc s;tt|ƒjd|d|ddd|d|d|ƒdS)Nr€r¼rÈFr r’rl)rÏrÓrN)r r€r¼r r’rl)rÐr%r&rN†sz_StoreFalseAction.__init__)rr+r,rNr%r%)rÐr&rÓ„s rÓc sIeZdZdddddddd‡fdd†Zddd„Z‡S)Ú _AppendActionNFc s“|dkrtdƒ‚|dk r@|tkr@tdtƒ‚tt|ƒjd|d|d|d|d|d |d |d |d | d | ƒ dS)Nrz‹nargs 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 constr€r¼r™rÈr rr²r’rlr¬)r:r rÏrÔrN) r r€r¼r™rÈr rr²r’rlr¬)rÐr%r&rN—s  z_AppendAction.__init__cCsBtjt||jgƒƒ}|j|ƒt||j|ƒdS)N)Ú_copyÚcopyr1r¼rr/)r rËr0rÌr¡r*r%r%r&rÍ´s z_AppendAction.__call__)rr+r,rNrÍr%r%)rÐr&rÔ•s rÔcs=eZdZdddd‡fdd†Zddd„Z‡S)Ú_AppendConstActionNFcsGtt|ƒjd|d|ddd|d|d|d|d |ƒdS) Nr€r¼r™rrÈr r’rlr¬)rÏr×rN)r r€r¼rÈr r’rlr¬)rÐr%r&rN¼sz_AppendConstAction.__init__cCsEtjt||jgƒƒ}|j|jƒt||j|ƒdS)N)rÕrÖr1r¼rrÈr/)r rËr0rÌr¡r*r%r%r&rÍÎsz_AppendConstAction.__call__)rr+r,rNrÍr%r%)rÐr&r׺s  r×cs:eZdZddd‡fdd†Zddd„Z‡S)Ú _CountActionNFc s;tt|ƒjd|d|ddd|d|d|ƒdS)Nr€r¼r™rr r’rl)rÏrØrN)r r€r¼r r’rl)rÐr%r&rNÖsz_CountAction.__init__cCs0t||jdƒd}t||j|ƒdS)NrrO)r1r¼r/)r rËr0rÌr¡Z new_countr%r%r&rÍäsz_CountAction.__call__)rr+r,rNrÍr%r%)rÐr&rØÔs  rØcs:eZdZeed‡fdd†Zddd„Z‡S)Ú _HelpActionNc s5tt|ƒjd|d|d|ddd|ƒdS)Nr€r¼r r™rrl)rÏrÙrN)r r€r¼r rl)rÐr%r&rNës z_HelpAction.__init__cCs|jƒ|jƒdS)N)Ú print_helpÚexit)r rËr0rÌr¡r%r%r&rÍ÷s z_HelpAction.__call__)rr+r,rrNrÍr%r%)rÐr&rÙés rÙcs=eZdZdeed‡fdd†Zddd„Z‡S)Ú_VersionActionNz&show program's version number and exitc s>tt|ƒjd|d|d|ddd|ƒ||_dS)Nr€r¼r r™rrl)rÏrÜrNÚversion)r r€rÝr¼r rl)rÐr%r&rNþsz_VersionAction.__init__cCs^|j}|dkr|j}|jƒ}|j|ƒ|j|jƒtjƒ|jƒdS)N)rÝÚ_get_formatterrcÚ_print_messager]Ú_sysÚstdoutrÛ)r rËr0rÌr¡rÝrSr%r%r&rÍ s     z_VersionAction.__call__)rr+r,rrNrÍr%r%)rÐr&rÜüs  rÜcsheZdZGdd„deƒZedd‡fdd†Zdd„Zdd „Zdd d „Z ‡S) Ú_SubParsersActioncs"eZdZ‡fdd†Z‡S)z&_SubParsersAction._ChoicesPseudoActionc s_|}}|r'|ddj|ƒ7}ttj|ƒ}|jdgd|d|d|ƒdS)Nz (%s)z, r€r¼rlr¬)rrÏrâÚ_ChoicesPseudoActionrN)r r#Úaliasesrlr¬r¼Zsup)rÐr%r&rNs  z/_SubParsersAction._ChoicesPseudoAction.__init__)rr+r,rNr%r%)rÐr&rãs rãNc sh||_||_tjƒ|_g|_tt|ƒjd|d|dt d|jd|d|ƒdS)Nr€r¼r™r²rlr¬) Ú _prog_prefixÚ _parser_classÚ _collectionsÚ OrderedDictÚ_name_parser_mapÚ_choices_actionsrÏrârNr)r r€rLÚ parser_classr¼rlr¬)rÐr%r&rN"s    z_SubParsersAction.__init__cKs¼|jdƒdkr,d|j|f|d<|jdfƒ}d|kr~|jdƒ}|j|||ƒ}|jj|ƒ|j|�}||j|.cSs2g|](\}}|dk rd||f‘qS)Nz%s=%rr%)rVÚkwr"r%r%r&rY¤s z%s(%s))rör÷rørùrrr)r rXrìZargs_strr%r%r&r' s zFileType.__repr__r�)rr+r,r-rNrÍr'r%r%r%r&rvs  c@s:eZdZdZdd„Zdd„Zdd„ZdS) r z“Simple object for storing attributes. Implements equality by attribute names and values, and provides a simple string representation. cKs)x"|D]}t||||ƒqWdS)N)r/)r rìr#r%r%r&rN³s zNamespace.__init__cCs)t|tƒstSt|ƒt|ƒkS)N)r¯r ÚNotImplementedrµ)r Úotherr%r%r&Ú__eq__·szNamespace.__eq__cCs ||jkS)N)r))r rôr%r%r&Ú __contains__¼szNamespace.__contains__N)rr+r,r-rNrrr%r%r%r&r ¬s   csôeZdZ‡fdd†Zdd„Zddd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zddd„Zdd„Zd d!„Zd"d#„Zd$d%„Z‡S)&Ú_ActionsContainercsgtt|ƒjƒ||_||_||_||_i|_|jddt ƒ|jddt ƒ|jddt ƒ|jddt ƒ|jddt ƒ|jddt ƒ|jddtƒ|jddtƒ|jdd tƒ|jdd tƒ|jdd tƒ|jƒg|_i|_g|_g|_i|_tjd ƒ|_g|_dS) NrpZstoreZ store_constÚ store_trueZ store_falserZ append_constÚcountrlrÝÚparsersz^-\d+$|^-\d*\.\d+$)rÏr rNÚ descriptionÚargument_defaultÚ prefix_charsÚconflict_handlerÚ _registriesÚregisterrÎrÑrÒrÓrÔr×rØrÙrÜrâÚ _get_handlerÚ_actionsÚ_option_string_actionsÚ_action_groupsÚ_mutually_exclusive_groupsÚ _defaultsrGrHÚ_negative_number_matcherÚ_has_negative_number_optionals)r r rrr)rÐr%r&rNÂs2           z_ActionsContainer.__init__cCs#|jj|iƒ}|||.)rrjrr)r rpÚconflicting_actionsrÆZconflict_stringr%r%r&Ú_handle_conflict_errorÛs  z(_ActionsContainer._handle_conflict_errorcCsWxP|D]H\}}|jj|ƒ|jj|dƒ|js|jj|ƒqWdS)N)r€r0rr–r.r1)r rpr8r¡r%r%r&Ú_handle_conflict_resolveäs  z*_ActionsContainer._handle_conflict_resolve)rr+r,rNrrrr rrr*r,r&r1r4r!r"r#rr-r9r:r%r%)rÐr&r Às$ 4  /     (  $  r csLeZdZdd‡fdd†Z‡fdd†Z‡fdd†Z‡S)r)Nc s¹|j}|d|jƒ|d|jƒ|d|jƒtt|ƒj}|d||�||_g|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_dS)Nrrrr )rñrrrrÏr)rNr2r�rrrrrr)r r.r2r rìrZ super_init)rÐr%r&rNõs        z_ArgumentGroup.__init__cs,tt|ƒj|ƒ}|jj|ƒ|S)N)rÏr)r&r�r)r rp)rÐr%r&r& sz_ArgumentGroup._add_actioncs*tt|ƒj|ƒ|jj|ƒdS)N)rÏr)r1r�r0)r rp)rÐr%r&r1sz_ArgumentGroup._remove_action)rr+r,rNr&r1r%r%)rÐr&r)ós r)cs=eZdZd‡fdd†Zdd„Zdd„Z‡S)r+Fcs,tt|ƒj|ƒ||_||_dS)N)rÏr+rNr’Ú _container)r r.r’)rÐr%r&rNs z _MutuallyExclusiveGroup.__init__cCsG|jr!tdƒ}t|ƒ‚|jj|ƒ}|jj|ƒ|S)Nz-mutually exclusive arguments must be optional)r’r~r:r;r&r�r)r rprór%r%r&r&s    z#_MutuallyExclusiveGroup._add_actioncCs$|jj|ƒ|jj|ƒdS)N)r;r1r�r0)r rpr%r%r&r1$sz&_MutuallyExclusiveGroup._remove_action)rr+r,rNr&r1r%r%)rÐr&r+s  r+csŸeZdZdZddddgedddddd‡fdd† Zdd „Zd d „Zd d „Zdd„Z dd„Z dddd„Z dddd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zdd2d3„Zdd4d5„Zdd6d7„Zd8dd9d:„Zd;d<„Z‡S)=ra®Object 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  s�tt|ƒj} | d|d|d| d| ƒ|dkrVtjjtjdƒ}||_||_ ||_ ||_ ||_ | |_ | |_|j}|tdƒƒ|_|tdƒƒ|_d|_dd „}|jd d|ƒd |krd n|d}|j rI|j|d |d ddddtdtdƒƒxM|D]E}|j|ƒy |j}Wntk r„YqPX|jj|ƒqPWdS)Nr rrrrzpositional argumentszoptional argumentscSs|S)Nr%)rr%r%r&Úidentitybsz)ArgumentParser.__init__..identityrrþÚhr2rlrpr zshow this help message and exit)rÏrrNr7ÚpathÚbasenameràÚargvrLreÚepilogÚformatter_classÚfromfile_prefix_charsÚadd_helpÚ allow_abbrevr*r~Ú _positionalsÚ _optionalsÚ _subparsersrrrrr4rrºr)r rLrer rBÚparentsrCrrDrrrErFZ superinitZ add_groupr=Zdefault_prefixrTZdefaults)rÐr%r&rN<sB                   zArgumentParser.__init__cs/ddddddg}‡fdd†|DƒS) NrLrer rCrrEcs%g|]}|tˆ|ƒf‘qSr%)r.)rVr#)r r%r&rY…s z.ArgumentParser._get_kwargs..r%)r rÉr%)r r&r|s zArgumentParser._get_kwargsc KsA|jdk r"|jtdƒƒ|jdt|ƒƒd|ksPd|kr˜t|jddƒƒ}t|jddƒƒ}|j||ƒ|_n |j|_|jdƒdkr |j ƒ}|j ƒ}|j }|j |j ||dƒ|jƒjƒ|d<|j|dƒ}|d g|�}|jj|ƒ|S) Nz(cannot have multiple subparser argumentsrër2r Z subcommandsrLrZr r€)rIr<r~rñrr–r*rGr•rÞÚ_get_positional_actionsrrirer]rur#r&) r rìr2r rSr„rgZ parsers_classrpr%r%r&Úadd_subparsersŠs$    zArgumentParser.add_subparserscCs0|jr|jj|ƒn|jj|ƒ|S)N)r€rHr&rG)r rpr%r%r&r&©s zArgumentParser._add_actioncCsdd„|jDƒS)NcSsg|]}|jr|‘qSr%)r€)rVrpr%r%r&rY±s z8ArgumentParser._get_optional_actions..)r)r r%r%r&Ú_get_optional_actions°s z$ArgumentParser._get_optional_actionscCsdd„|jDƒS)NcSsg|]}|js|‘qSr%)r€)rVrpr%r%r&rY¶s z:ArgumentParser._get_positional_actions..)r)r r%r%r&rKµs z&ArgumentParser._get_positional_actionscCsH|j||ƒ\}}|rDtdƒ}|j|dj|ƒƒ|S)Nzunrecognized arguments: %srw)rðr~r<r)r rXr0rArór%r%r&Ú parse_args½s  zArgumentParser.parse_argsc Csk|dkr"tjdd…}n t|ƒ}|dkrCtƒ}xW|jD]L}|jtk rMt||jƒsM|jtk rMt ||j|jƒqMWx7|j D],}t||ƒs§t |||j |ƒq§WyX|j ||ƒ\}}t|t ƒr$|j t|t ƒƒt|t ƒ||fSWn5tk rftjƒd}|jt|ƒƒYnXdS)NrO)ràrAr¶r rr¼rr·r r/rÚ_parse_known_argsròrƒr.ÚdelattrrÚexc_infor<r­)r rXr0rpr¼Úerrr%r%r&rðÄs,      zArgumentParser.parse_known_argscs.ˆ jdk rˆ jˆƒ‰i‰x~ˆ jD]s}|j}xat|jƒD]P\}}ˆj|gƒ}|j|d|…ƒ|j||dd…ƒqMWq.Wi‰g}tˆƒ} x•t| ƒD]‡\}} | dkr|jdƒx_| D]} |jdƒqöWqʈ j | ƒ} | dkr4d} n| ˆ|.take_actioncsˆ|}|\}}}ˆj}g}x¬|dkrPˆjˆ|ƒ|dS|dk ry||dƒ}ˆj}|dkr|d|kr|j|g|fƒ|d} | |d}|dd…pÑd} ˆj} || krü| |}| }qvtdƒ} t|| |ƒ‚qÓ|dkrW|d} |g}|j|||fƒPqÓtdƒ} t|| |ƒ‚q+|d}ˆ|d…}|||ƒ}||} ˆ|| …}|j|||fƒPq+W|sãt‚x'|D]\}}}ˆ|||ƒqêW| S)NrOrSrzignored explicit argument %r)Ú_match_argumentrrrr~rrQ)Ú start_indexÚ option_tuplerpr¡Ú explicit_argZmatch_argumentZ action_tuplesÚ arg_countr'ÚcharZnew_explicit_argZ optionals_mapróÚstoprXr�Zselected_patterns)r!Úarg_strings_patternÚextrasÚoption_string_indicesr rYr%r&Úconsume_optional+sP                  z:ArgumentParser._parse_known_args..consume_optionalcs—ˆj}ˆ|d…}|ˆ|ƒ}xHtˆ|ƒD]7\}}ˆ|||…}||7}ˆ||ƒq8Wˆt|ƒd…ˆdd…<|S)N)Ú_match_arguments_partialÚziprj)r[Z match_partialZselected_patternZ arg_countsrpr^rX)r!rar„r rYr%r&Úconsume_positionalsxs   z=ArgumentParser._parse_known_args..consume_positionalsrcs"g|]}|ˆkr|‘qSr%r%)rVr�)r[r%r&rY–s z4ArgumentParser._parse_known_args..z(the following arguments are required: %sz, cSs+g|]!}|jtk rt|ƒ‘qSr%)rlrrÄ)rVrpr%r%r&rYÔs z#one of the arguments %s is requiredrwr�)rDÚ_read_args_from_filesrr�r”rñrƒÚiterrÚ_parse_optionalrrŽrKr?r>rr’rÄr r¯r­r·r¼r.r/Ú _get_valuer<r~)r r!r0r3r›rŸZ mutex_actionZ conflictsZarg_string_pattern_partsZarg_strings_iterÚ arg_stringr\ÚpatternrdrgZmax_option_string_indexZnext_option_string_indexZpositionals_end_indexZstringsZ stop_indexZrequired_actionsrprœrÉrór%) rVr!rarbr0rcr„rWrXr r[rYr&rOçs˜ #         !!J                z ArgumentParser._parse_known_argscCsg}xú|D]ò}| s-|d|jkr=|j|ƒq yŠt|dd…ƒ�m}g}xA|jƒjƒD]-}x$|j|ƒD]}|j|ƒqˆWqrW|j|ƒ}|j|ƒWdQRXWq tk rþt j ƒd}|j t |ƒƒYq Xq W|S)NrrO) rDrr£ÚreadrÁÚconvert_arg_line_to_argsrhrƒrràrQr<r­)r r!Znew_arg_stringsrlZ args_fileÚarg_liner"rRr%r%r&rhÝs   z$ArgumentParser._read_args_from_filescCs|gS)Nr%)r rpr%r%r&ro÷sz'ArgumentParser.convert_arg_line_to_argscCsª|j|ƒ}tj||ƒ}|dkr—dtdƒttdƒttdƒi}tdd|jƒ|j}|j|j|ƒ}t ||ƒ‚t |j dƒƒS)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrO) Ú_get_nargs_patternrGr/r~r r rr™r•rrjrœ)r rpraÚ nargs_patternr/Z nargs_errorsr rór%r%r&rZús   zArgumentParser._match_argumentcsžg}x‘tt|ƒddƒD]w}|d|…}dj‡fdd†|Dƒƒ}tj||ƒ}|dk r|jdd„|jƒDƒƒPqW|S)NrrOrZcsg|]}ˆj|ƒ‘qSr%)rq)rVrp)r r%r&rYs z;ArgumentParser._match_arguments_partial..cSsg|]}t|ƒ‘qSr%)rj)rVrr%r%r&rYs r�)r“rjrrGr/rƒrg)r rfrar±rŸZ actions_slicermr/r%)r r&res   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) NrrOú=z, cSsg|]\}}}|‘qSr%r%)rVrpr¡r]r%r%r&rY?s z2ArgumentParser._parse_optional..r5Zmatchesz4ambiguous option: %(option)s could match %(matches)srw) rrrjÚsplitrFÚ_get_option_tuplesrr~r<rr/r) r rlrpr¡r]Z option_tuplesZoptionsrXrór\r%r%r&rjs>           zArgumentParser._parse_optionalc CsŸg}|j}|d|kr±|d|kr±d|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)NrrOrsr2zunexpected option string: %s)rrtrÚ startswithrr<r~) r r¡r±r'Z option_prefixr]rprªZshort_option_prefixZshort_explicit_argr%r%r&ruZs8        z!ArgumentParser._get_option_tuplescCsÏ|j}|dkrd}n€|tkr3d}nk|tkrHd}nV|tkr]d}nA|tkrrd}n,|tkr‡d}nddjd |ƒ}|jrË|jdd ƒ}|jd d ƒ}|S) Nz(-*A-*)z(-*A?-*)z (-*[A-]*)z (-*A[A-]*)z([-AO]*)z (-*A[-AO]*)z(-*%s-*)z-*rSrZrþ) r™r rr rrrr€r7)r rpr™rrr%r%r&rq†s$              z!ArgumentParser._get_nargs_patternc sýˆjttgkr;y|jdƒWntk r:YnX| r£ˆjtkr£ˆjrfˆj}n ˆj}t |t ƒrùˆj ˆ|ƒ}ˆj ˆ|ƒnV| r÷ˆjt kr÷ˆj r÷ˆjdk rÞˆj}n|}ˆj ˆ|ƒnt|ƒdkrLˆjdtgkrL|\}ˆj ˆ|ƒ}ˆj ˆ|ƒn­ˆjtkrz‡‡fdd†|Dƒ}nˆjtkr¼‡‡fdd†|Dƒ}ˆj ˆ|dƒn=‡‡fdd†|Dƒ}x|D]}ˆj ˆ|ƒqßW|S)Nz--rOcs"g|]}ˆjˆ|ƒ‘qSr%)rk)rVÚv)rpr r%r&rYÖs z.ArgumentParser._get_values..cs"g|]}ˆjˆ|ƒ‘qSr%)rk)rVrw)rpr r%r&rYÚs rcs"g|]}ˆjˆ|ƒ‘qSr%)rk)rVrw)rpr r%r&rYßs )r™rrr0r:r r€rÈr r¯r­rkÚ _check_valuerrj)r rpr!r$rlrwr%)rpr r&rU²s>      '  zArgumentParser._get_valuesc Cs|jd|j|jƒ}t|ƒsFtdƒ}t|||ƒ‚y||ƒ}Wn»tk r­t|jdt|jƒƒ}tt j ƒdƒ}t||ƒ‚Yngt t fk rt|jdt|jƒƒ}d|d|i}tdƒ}t|||ƒ‚YnX|S)Nrz%r is not callablerrOr$z!invalid %(type)s value: %(value)r) rrr$r~rrr.rr­ràrQr%r:)r rprlr(rór±r#rXr%r%r&rkæs     zArgumentParser._get_valuecCsh|jdk rd||jkrdd|ddjtt|jƒƒi}tdƒ}t|||ƒ‚dS)Nr$r²z, z3invalid choice: %(value)r (choose from %(choices)s))r²rÚmaprr~r)r rpr$rXrór%r%r&rx s ! zArgumentParser._check_valuecCs2|jƒ}|j|j|j|jƒ|jƒS)N)rÞrirerrr])r rSr%r%r&Ú format_usage s  zArgumentParser.format_usagecCs |jƒ}|j|j|j|jƒ|j|jƒxK|jD]@}|j|j ƒ|j|jƒ|j |j ƒ|j ƒqBW|j|j ƒ|jƒS)N)rÞrirerrrcr rr_r2rsr�r`rBr])r rSZ action_groupr%r%r&r] s  zArgumentParser.format_helpcCs|jd|jƒS)NrL)rCrL)r r%r%r&rÞ( szArgumentParser._get_formattercCs/|dkrtj}|j|jƒ|ƒdS)N)ràrárßrz)r Úfiler%r%r&Ú print_usage. s  zArgumentParser.print_usagecCs/|dkrtj}|j|jƒ|ƒdS)N)ràrárßr])r r{r%r%r&rÚ3 s  zArgumentParser.print_helpcCs,|r(|dkrtj}|j|ƒdS)N)ràÚstderrÚwrite)r rÆr{r%r%r&rß8 s  zArgumentParser._print_messagercCs*|r|j|tjƒtj|ƒdS)N)rßràr}rÛ)r ZstatusrÆr%r%r&rÛA szArgumentParser.exitcCsC|jtjƒd|jd|i}|jdtdƒ|ƒdS)zðerror(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. rLrÆr2z%(prog)s: error: %(message)s N)r|ràr}rLrÛr~)r rÆrXr%r%r&r<F s zArgumentParser.error) rr+r,r-rrNrrLr&rMrKrNrðrOrhrorZrerjrurqrUrkrxrzr]rÞr|rÚrßrÛr<r%r%)rÐr&r)sN 4     # ö     ; , , 4     )6r-Ú __version__Ú__all__Ú collectionsrçrÖrÕÚosr7ÚrerGÚsysràÚtextwrapr»rr~rrr rr rrròr¾rr1rrrrr rÄÚ Exceptionrrr rÎrÑrÒrÓrÔr×rØrÙrÜrârr r r)r+rr%r%r%r&Ú>sz        ÿê    [#%`6ÿ4"