grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î ¤ f«_ã@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/python34/lib64/python3.4/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  rcCs8t||dƒdkr+t|||ƒnt||ƒ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ü|dkrQyttjdƒ}Wnttfk rCd}YnX|d8}n||_||_||_t|t |d|dƒƒ|_||_ d|_ d|_ d|_ |j|dƒ|_|j|_tjdƒ|_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Ú_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_|jd8_dS)NrN)rAr<rB)r r%r%r&Ú_dedent½szHelpFormatter._dedentc@s+eZdZddd„Zdd„ZdS)zHelpFormatter._SectionNcCs(||_||_||_g|_dS)N)Ú formatterÚparentÚheadingr*)r rQrRrSr%r%r&rMÄs   zHelpFormatter._Section.__init__cCsó|jdk r|jjƒn|jj}x!|jD]\}}||Œq5W|dd„|jDƒƒ}|jdk rŠ|jjƒn|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: Ú ) rRrQrOÚ _join_partsr*rPrSrrA)r rrUrVZ item_helpZcurrent_indentrSr%r%r&Ú format_helpÊs  z"HelpFormatter._Section.format_help)rr+r,rMr[r%r%r%r&rDÂs rDcCs|jjj||fƒdS)N)rFr*r)r rUrVr%r%r&Ú _add_itemãszHelpFormatter._add_itemcCsB|jƒ|j||j|ƒ}|j|jgƒ||_dS)N)rOrDrFr\r[)r rSZsectionr%r%r&Ú start_sectionés zHelpFormatter.start_sectioncCs|jj|_|jƒdS)N)rFrRrP)r r%r%r&Ú end_sectionïszHelpFormatter.end_sectioncCs5|tk r1|dk r1|j|j|gƒndS)N)rr\Ú _format_text)r Útextr%r%r&Úadd_textószHelpFormatter.add_textcCs8|tk r4||||f}|j|j|ƒndS)N)rr\Ú _format_usage)r ÚusageÚactionsÚgroupsÚprefixrVr%r%r&Ú add_usage÷s zHelpFormatter.add_usagecCs¬|jtk r¨|j}||ƒg}x*|j|ƒD]}|j||ƒƒq7Wtdd„|Dƒƒ}||j}t|j|ƒ|_|j|j |gƒndS)NcSsg|]}t|ƒ‘qSr%)Úlen)rTÚsr%r%r&rWs 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)rp)r rdrnr%r%r&Ú add_argumentss zHelpFormatter.add_argumentscCsD|jjƒ}|r@|jjd|ƒ}|jdƒd}n|S)Nz rY)rEr[rJÚsubÚstrip)r rjr%r%r&r[s zHelpFormatter.format_helpcCsdjdd„|DƒƒS)NrXcSs(g|]}|r|tk r|‘qSr%)r)rTÚpartr%r%r&rWs z-HelpFormatter._join_parts..)r)r Z part_stringsr%r%r&rZszHelpFormatter._join_partscsÜ|dkrtdƒ}n|dk r@|td|jƒ}nŽ|dkrl| rldtd|jƒ}nb|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 | | ƒ}d‡fdd †}t |ƒt |ƒd ˆkr<dt |ƒt |ƒd }|r||g|||ƒ}|j |||ƒƒq¹|r0||g|||ƒ}q¹|g}n}dt |ƒ}||}|||ƒ}t |ƒd kr¬g}|j |||ƒƒ|j |||ƒƒn|g|}d j|ƒ}qÎnd ||fS)Nzusage: rKz%(prog)sú cSsg|]}|r|‘qSr%r%)rTrir%r%r&rW=s z/HelpFormatter._format_usage..z\(.*?\)+|\[.*?\]+|\S+csg}g}|dk r+t|ƒd}nt|ƒd}x‚|D]z}|dt|ƒˆkr›|r›|j|dj|ƒƒg}t|ƒd}n|j|ƒ|t|ƒd7}qBW|rã|j|dj|ƒƒn|dk r|dt|ƒd…|d.get_linesgè?rNrYz%s%s ) Ú_Údictr;Úoption_stringsrÚ_format_actions_usagerr@rArhrGÚfindallÚextend)r rcrdrerfrKZ optionalsÚ positionalsrnÚformatZ action_usageZ part_regexpZ opt_usageZ pos_usageZ opt_partsZ pos_partsr{rwrxrvr%)rzr&rb!sV      "    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 *%srXz \(([^|]*)\)éÿÿÿÿr‹)ÚsetÚindexÚ_group_actionsr:rhÚaddÚrequiredÚrangeÚ enumeraterjrrÚgetÚpopr~Ú#_get_default_metavar_for_positionalÚ _format_argsÚnargsÚ!_get_default_metavar_for_optionalr(rrGrrrs)r rdreÚ group_actionsZinsertsÚgroupÚstartÚendrnÚirvÚdefaultrtÚ option_stringÚ args_stringr`ÚopenÚcloser%r%r&r}sr                  z#HelpFormatter._format_actions_usagecCsbd|kr%|td|jƒ}nt|j|jdƒ}d|j}|j|||ƒdS)Nz%(prog)rKé ruz )r}r;r?r@rAÚ _fill_text)r r`rzrwr%r%r&r_Þ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ƒxT| dd…D] } |j d|d| fƒq5Wn|j dƒs{|j dƒnx-|j |ƒD]} |j |j| ƒƒq‹W|j|ƒS) Nr2r£rXz%*s%s z %*s%-*s rrNrY)r>rCr=r?r@rArkrjrhÚ _expand_helpÚ _split_linesrÚendswithrlrmrZ) r rnZ help_positionZ help_widthZ action_widthZ action_headerÚtupZ indent_firstrvZ help_textZ help_linesryror%r%r&rmås6         !zHelpFormatter._format_actioncCs¼|js7|j|ƒ}|j||ƒdƒ\}|Sg}|jdkr_|j|jƒnL|j|ƒ}|j||ƒ}x(|jD]}|jd||fƒqŠWdj|ƒSdS)NrNrz%s %sz, ) r~r•Ú_metavar_formatterr—r�r˜r–rr)r rnržÚmetavarrvr rŸr%r%r&rks z'HelpFormatter._format_action_invocationcsr|jdk r|j‰nA|jdk rVdd„|jDƒ}ddj|ƒ‰n|‰‡fdd†}|S)NcSsg|]}t|ƒ‘qSr%)Ústr)rTZchoicer%r%r&rW0s 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 rnÚ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%srNz[%s]z [%s [%s ...]]r2z %s [%s ...]z...z%s ...cSsg|] }d‘qS)z%sr%)rTr|r%r%r&rWKs z.HelpFormatter._format_args..ru) r©r—r rr rrr‘r)r rnr±Z get_metavarr¯Zformatsr%r%r&r–<s  zHelpFormatter._format_argscCsÝtt|ƒd|jƒ}x.t|ƒD] }||tkr(||=q(q(Wx;t|ƒD]-}t||dƒrY||j||.) r}Úvarsr;ÚlistrÚhasattrrr“rÚ_get_help_string)r rnZparamsr#Z choices_strr%r%r&r¥Os  zHelpFormatter._expand_helpc csFy |j}Wntk r!Yn!X|jƒ|ƒDdH|jƒdS)N)Ú_get_subactionsÚAttributeErrorrOrP)r rnZget_subactionsr%r%r&rl\s    z'HelpFormatter._iter_indented_subactionscCs+|jjd|ƒjƒ}tj||ƒS)Nru)rIrrrsÚ _textwrapZwrap)r r`rLr%r%r&r¦fszHelpFormatter._split_linescCs7|jjd|ƒjƒ}tj||d|d|ƒS)NruZinitial_indentZsubsequent_indent)rIrrrsr¹Zfill)r r`rLrwr%r%r&r¤jszHelpFormatter._fill_textcCs|jS)N)rj)r rnr%r%r&r¶oszHelpFormatter._get_help_stringcCs |jjƒS)N)ÚdestÚupper)r rnr%r%r&r˜rsz/HelpFormatter._get_default_metavar_for_optionalcCs|jS)N)rº)r rnr%r%r&r•usz1HelpFormatter._get_default_metavar_for_positional) rr+r,r-rMrOrPÚobjectrDr\r]r^rargrprqr[rZrbrr_rmrkr©r–r¥rlr¦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)NrXc3s|]}ˆ|VqdS)Nr%)rTry)rwr%r&ú �sz9RawDescriptionHelpFormatter._fill_text..ÚkeependsT)rÚ splitlines)r r`rLrwr%)rwr&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 r`rLr%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. cCsb|j}d|jkr^|jtk r^ttg}|jsK|j|kr[|d7}q[q^n|S)Nz %(default)z (default: %(default)s))rjržrr rr~r—)r rnrjZdefaulting_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 rnr%r%r&r˜¨sz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs |jjS)N)rr)r rnr%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-rMrrËr%r%r%r&r Þs 1 c sIeZdZdddddddd‡fdd†Zddd„Z‡S)Ú _StoreActionNFc s™|dkrtdƒ‚n|dk rF|tkrFtdtƒ‚ntt|ƒ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�rjrª)r:r ÚsuperrÌrM) r r~rºr—rÆržrr°r�rjrª)Ú __class__r%r&rM;s z_StoreAction.__init__cCst||j|ƒdS)N)r/rº)r rÉr0rÊrŸr%r%r&rËXsz_StoreAction.__call__)rr+r,rMrË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�rj)rÍrÏrM)r r~rºrÆržr�rjrª)rÎr%r&rM^sz_StoreConstAction.__init__cCst||j|jƒdS)N)r/rºrÆ)r rÉr0rÊrŸr%r%r&rËosz_StoreConstAction.__call__)rr+r,rMrË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�rj)rÍrÐrM)r r~rºržr�rj)rÎr%r&rMusz_StoreTrueAction.__init__)rr+r,rMr%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�rj)rÍrÑrM)r r~rºržr�rj)rÎr%r&rM†sz_StoreFalseAction.__init__)rr+r,rMr%r%)rÎr&rÑ„s rÑc sIeZdZdddddddd‡fdd†Zddd„Z‡S)Ú _AppendActionNFc s™|dkrtdƒ‚n|dk rF|tkrFtdtƒ‚ntt|ƒ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�rjrª)r:r rÍrÒrM) r r~rºr—rÆržrr°r�rjrª)rÎr%r&rM—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,rMrË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�rjrª)rÍrÕrM)r r~rºrÆržr�rjrª)rÎr%r&rM¼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,rMrË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�rj)rÍrÖrM)r r~rºržr�rj)rÎr%r&rMÖsz_CountAction.__init__cCs0t||jdƒd}t||j|ƒdS)NrrN)r1rºr/)r rÉr0rÊrŸZ new_countr%r%r&rËäsz_CountAction.__call__)rr+r,rMrËr%r%)rÎr&rÖÔs  rÖcs:eZdZeed‡fdd†Zddd„Z‡S)Ú _HelpActionNc s5tt|ƒjd|d|d|ddd|ƒdS)Nr~rºržr—rrj)rÍr×rM)r r~rºržrj)rÎr%r&rMë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,rrMrË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—rrj)rÍrÚrMÚversion)r r~rÛrºržrj)rÎr%r&rMþsz_VersionAction.__init__cCsa|j}|dkr!|j}n|jƒ}|j|ƒ|j|jƒtjƒ|jƒdS)N)rÛÚ_get_formatterraÚ_print_messager[Ú_sysÚstdoutrÙ)r rÉr0rÊrŸrÛrQr%r%r&rË s     z_VersionAction.__call__)rr+r,rrMrË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 sb|}}|r*|ddj|ƒ7}nttj|ƒ}|jdgd|d|d|ƒdS)Nz (%s)z, r~rºrjrª)rrÍràÚ_ChoicesPseudoActionrM)r r#ÚaliasesrjrªrºZsup)rÎr%r&rMs  z/_SubParsersAction._ChoicesPseudoAction.__init__)rr+r,rMr%r%)rÎr&rás ráNc sh||_||_tjƒ|_g|_tt|ƒjd|d|dt d|jd|d|ƒdS)Nr~rºr—r°rjrª) Ú _prog_prefixÚ _parser_classÚ _collectionsÚ OrderedDictÚ_name_parser_mapÚ_choices_actionsrÍràrMr)r r~rKÚ parser_classrºrjrª)rÎr%r&rM"s    z_SubParsersAction.__init__cKsÂ|jdƒdkr/d|j|f|d.cSs2g|](\}}|dk rd||f‘qS)Nz%s=%rr%)rTÚkwr"r%r%r&rW¤s z%s(%s))rôrõrör÷rrr)r rVrêZargs_strr%r%r&r' s zFileType.__repr__r‹)rr+r,r-rMrËr'r%r%r%r&rvs  c@sFeZdZdZdd„Zdd„Zdd„Zdd „Zd S) 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&rM³s zNamespace.__init__cCs)t|tƒstSt|ƒt|ƒkS)N)r­r ÚNotImplementedr³)r Úotherr%r%r&Ú__eq__·szNamespace.__eq__cCst|tƒstS||k S)N)r­r r)r rr%r%r&Ú__ne__¼szNamespace.__ne__cCs ||jkS)N)r))r ròr%r%r&Ú __contains__ÁszNamespace.__contains__N)rr+r,r-rMrrrr%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) NrnZstoreZ store_constÚ store_trueZ store_falserZ append_constÚcountrjrÛÚparsersz^-\d+$|^-\d*\.\d+$)rÍrrMÚ 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 rr r)rÎr%r&rMÇs2           z_ActionsContainer.__init__cCs#|jj|iƒ}|||.)rrhrr)r rnÚconflicting_actionsrÄZconflict_stringr%r%r&Ú_handle_conflict_erroràs  z(_ActionsContainer._handle_conflict_errorcCsZxS|D]K\}}|jj|ƒ|jj|dƒ|js|jj|ƒqqWdS)N)r~r/rr”r-r0)r rnr7rŸr%r%r&Ú_handle_conflict_resolveés  z*_ActionsContainer._handle_conflict_resolve)rr+r,rMrrrrrpr)r+r%r0r3r r!r"rr,r8r9r%r%)rÎr&rÅs$ 4  /     (  $  rcsLeZdZdd‡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)Nrrr r )rïrrr rÍr(rMr1rŽrrrrrr)r r-r1r rêrZ super_init)rÎr%r&rMús        z_ArgumentGroup.__init__cs,tt|ƒj|ƒ}|jj|ƒ|S)N)rÍr(r%rŽr)r rn)rÎr%r&r%sz_ArgumentGroup._add_actioncs*tt|ƒj|ƒ|jj|ƒdS)N)rÍr(r0rŽr/)r rn)rÎr%r&r0sz_ArgumentGroup._remove_action)rr+r,rMr%r0r%r%)rÎr&r(øs r(cs=eZdZd‡fdd†Zdd„Zdd„Z‡S)r*Fcs,tt|ƒj|ƒ||_||_dS)N)rÍr*rMr�Ú _container)r r-r�)rÎr%r&rMs z _MutuallyExclusiveGroup.__init__cCsJ|jr$tdƒ}t|ƒ‚n|jj|ƒ}|jj|ƒ|S)Nz-mutually exclusive arguments must be optional)r�r|r:r:r%rŽr)r rnrñr%r%r&r%!s   z#_MutuallyExclusiveGroup._add_actioncCs$|jj|ƒ|jj|ƒdS)N)r:r0rŽr/)r rnr%r%r&r0)sz&_MutuallyExclusiveGroup._remove_action)rr+r,rMr%r0r%r%)rÎr&r*s  r*csœeZdZdZddddgeddddd‡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)=raaObject 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 NrüÚerrorTc  sštt|ƒj} | d|d|d| d| ƒ|dkrYtjjtjdƒ}n||_||_ ||_ ||_ ||_ | |_ |j} | tdƒƒ|_| tdƒƒ|_d|_dd „}|jd d|ƒd |krüd n|d}|j rF|j|d |d ddddtdtdƒƒnxM|D]E}|j|ƒy |j}Wntk r�YqMX|jj|ƒqMWdS)Nr rr rrzpositional argumentszoptional argumentscSs|S)Nr%)rr%r%r&Úidentitydsz)ArgumentParser.__init__..identityrrüÚhr2rjrnržzshow this help message and exit)rÍrrMr7ÚpathÚbasenamerÞÚargvrKrcÚepilogÚformatter_classÚfromfile_prefix_charsÚadd_helpr)r|Ú _positionalsÚ _optionalsÚ _subparsersrrprr3rr¸r)r rKrcr rAÚparentsrBrrCr rrDZ superinitZ add_groupr<Zdefault_prefixrRZdefaults)rÎr%r&rM@s@                  zArgumentParser.__init__cs/ddddddg}‡fdd†|DƒS) NrKrcr rBrrDcs%g|]}|tˆ|ƒf‘qSr%)r.)rTr#)r r%r&rW‡s z.ArgumentParser._get_kwargs..r%)r rÇr%)r r&r~s zArgumentParser._get_kwargsc KsG|jdk r%|jtdƒƒn|jdt|ƒƒd|ksSd|kr›t|jddƒƒ}t|jddƒƒ}|j||ƒ|_n |j|_|jdƒdkr|j ƒ}|j ƒ}|j }|j |j ||dƒ|jƒjƒ|d.)r)r r%r%r&Ú_get_optional_actions²s z$ArgumentParser._get_optional_actionscCsdd„|jDƒS)NcSsg|]}|js|‘qSr%)r~)rTrnr%r%r&rW¸s z:ArgumentParser._get_positional_actions..)r)r r%r%r&rI·s z&ArgumentParser._get_positional_actionscCsK|j||ƒ\}}|rGtdƒ}|j|dj|ƒƒn|S)Nzunrecognized arguments: %sru)rîr|r;r)r rVr0r@rñr%r%r&Ú parse_args¿s  zArgumentParser.parse_argsc Cs}|dkr"tjdd…}n t|ƒ}|dkrFtƒ}nx`|jD]U}|jtk rPt||jƒs¥|jtk r¢t ||j|jƒq¢q¥qPqPWx:|j D]/}t||ƒs³t |||j |ƒq³q³Wy[|j ||ƒ\}}t|t ƒr6|j t|t ƒƒt|t ƒn||fSWn5tk rxtjƒd}|jt|ƒƒYnXdS)NrN)rÞr@r´r rrºrrµržr/rÚ_parse_known_argsrðr�r.ÚdelattrrÚexc_infor;r«)r rVr0rnrºÚerrr%r%r&rîÆs,    # zArgumentParser.parse_known_argscsFˆ jdk r!ˆ jˆƒ‰ni‰x~ˆ jD]s}|j}xat|jƒD]P\}}ˆj|gƒ}|j|d|…ƒ|j||dd…ƒqPWq1Wi‰g}tˆƒ} x•t| ƒD]‡\}} | dkr|jdƒx_| D]} |jdƒqùWq͈ j | ƒ} | dkr7d} 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+Wx'|D]\}}}ˆ|||ƒqÞW| S)NrNrQrzignored explicit argument %r)Ú_match_argumentrrrr|r)Ú start_indexÚ option_tuplernrŸÚ explicit_argZmatch_argumentZ action_tuplesÚ arg_countr&ÚcharZnew_explicit_argZ optionals_maprñÚstoprVr›Zselected_patterns)r!Úarg_strings_patternÚextrasÚoption_string_indicesr rWr%r&Úconsume_optional-sN                 z:ArgumentParser._parse_known_args..consume_optionalcs—ˆj}ˆ|d…}|ˆ|ƒ}xHtˆ|ƒD]7\}}ˆ|||…}||7}ˆ||ƒq8Wˆt|ƒd…ˆdd…<|S)N)Ú_match_arguments_partialÚziprh)rYZ match_partialZselected_patternZ arg_countsrnr\rV)r!r_r‚r rWr%r&Úconsume_positionalszs   z=ArgumentParser._parse_known_args..consume_positionalsrcs"g|]}|ˆkr|‘qSr%r%)rTr�)rYr%r&rW˜s z4ArgumentParser._parse_known_args..z(the following arguments are required: %sz, cSs+g|]!}|jtk rt|ƒ‘qSr%)rjrrÂ)rTrnr%r%r&rWÖs z#one of the arguments %s is requiredrur‹)rCÚ_read_args_from_filesrrŽr’rïr�ÚiterrÚ_parse_optionalrrŒrIr?r>rr�rÂržr­r«rµrºr.r/Ú _get_valuer;r|)r r!r0r2r™r�Z mutex_actionZ conflictsZarg_string_pattern_partsZarg_strings_iterÚ arg_stringrZÚpatternrbreZmax_option_string_indexZnext_option_string_indexZpositionals_end_indexZstringsZ stop_indexZrequired_actionsrnršrÇrñr%) rTr!r_r`r0rar‚rUrVr rYrWr&rMé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|ƒWdQXWq tk rýt j ƒd}|j t |ƒƒYq Xq W|S)NrrN) rCrr¡Úreadr¿Úconvert_arg_line_to_argsrfr�rÿrÞrOr;r«)r r!Znew_arg_stringsrjZ args_fileÚarg_liner"rPr%r%r&rfßs   z$ArgumentParser._read_args_from_filescCs|gS)Nr%)r rnr%r%r&rmùsz'ArgumentParser.convert_arg_line_to_argscCs°|j|ƒ}tj||ƒ}|dkr�itdƒd6tdƒt6tdƒt6}tdd|jƒ|j}|j|j|ƒ}t ||ƒ‚nt |j dƒƒS)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrN) Ú_get_nargs_patternrGr.r|r r rr—r“rrhrš)r rnr_Ú nargs_patternr.Z nargs_errorsržrñr%r%r&rXüs   zArgumentParser._match_argumentcs¡g}x”tt|ƒddƒD]z}|d|…}dj‡fdd†|Dƒƒ}tj||ƒ}|dk r|jdd„|jƒDƒƒPqqW|S)NrrNrXcsg|]}ˆj|ƒ‘qSr%)ro)rTrn)r r%r&rWs z;ArgumentParser._match_arguments_partial..cSsg|]}t|ƒ‘qSr%)rh)rTrr%r%r&rWs r‹)r‘rhrrGr.r�re)r rdr_r¯r�Z actions_slicerkr.r%)r r&rcs   z'ArgumentParser._match_arguments_partialc Cs|s dS|d|jkr!dS||jkrJ|j|}||dfSt|ƒdkr`dSd|kr°|jddƒ\}}||jkr°|j|}|||fSn|j|ƒ}t|ƒdkr!djdd„|Dƒƒ}i|d6|d6}td ƒ}|j||ƒnt|ƒdkr@|\} | S|jj |ƒrb|j sbdSnd |krrdSd|dfS) NrrNú=z, cSsg|]\}}}|‘qSr%r%)rTrnrŸr[r%r%r&rW@s z2ArgumentParser._parse_optional..r4Zmatchesz4ambiguous option: %(option)s could match %(matches)sru) rrrhÚsplitÚ_get_option_tuplesrr|r;rr.r) r rjrnrŸr[Z option_tuplesZoptionsrVrñrZr%r%r&rh!s<         zArgumentParser._parse_optionalc Cs¥g}|j}|d|kr´|d|kr´d|krV|jddƒ\}}n |}d}x<|jD]A}|j|ƒrl|j|}|||f}|j|ƒqlqlWní|d|krŠ|d|krŠ|}d}|dd…}|dd…} xž|jD]y}||krH|j|}||| f}|j|ƒq |j|ƒr |j|}|||f}|j|ƒq q Wn|jtdƒ|ƒ|S)NrrNrqr2zunexpected option string: %s)rrrrÚ startswithrr;r|) r rŸr¯r&Z option_prefixr[rnr¨Zshort_option_prefixZshort_explicit_argr%r%r&rs[s8        z!ArgumentParser._get_option_tuplescCsÒ|j}|dkrd}n€|tkr3d}nk|tkrHd}nV|tkr]d}nA|tkrrd}n,|tkr‡d}nddjd |ƒ}|jrÎ|jdd ƒ}|jd d ƒ}n|S) Nz(-*A-*)z(-*A?-*)z (-*[A-]*)z (-*A[A-]*)z([-AO]*)z (-*A[-AO]*)z(-*%s-*)z-*rQrXrü) r—r rr rrrr~r6)r rnr—rpr%r%r&ro‡s$              z!ArgumentParser._get_nargs_patternc sˆjttgkr>y|jdƒWq>tk r:Yq>Xn| r©ˆjtkr©ˆjriˆj}n ˆj}t |t ƒrÿˆj ˆ|ƒ}ˆj ˆ|ƒqÿnV| rýˆjt krýˆj rýˆjdk räˆj}n|}ˆj ˆ|ƒnt|ƒdkrRˆjdtgkrR|\}ˆj ˆ|ƒ}ˆj ˆ|ƒn­ˆjtkr€‡‡fdd†|Dƒ}nˆjtkr‡‡fdd†|Dƒ}ˆj ˆ|dƒn=‡‡fdd†|Dƒ}x|D]}ˆj ˆ|ƒqåW|S)Nz--rNcs"g|]}ˆjˆ|ƒ‘qSr%)ri)rTÚv)rnr r%r&rW×s z.ArgumentParser._get_values..cs"g|]}ˆjˆ|ƒ‘qSr%)ri)rTru)rnr r%r&rWÛs rcs"g|]}ˆjˆ|ƒ‘qSr%)ri)rTru)rnr r%r&rWàs )r—rrr/r:r r~rÆržr­r«riÚ _check_valuerrh)r rnr!r$rjrur%)rnr r&rS³s>      '  zArgumentParser._get_valuesc Cs|jd|j|jƒ}t|ƒsItdƒ}t|||ƒ‚ny||ƒ}Wn½tk r°t|jdt|jƒƒ}tt j ƒdƒ}t||ƒ‚Ynit t fk rt|jdt|jƒƒ}i|d6|d6}tdƒ}t|||ƒ‚YnX|S)Nrz%r is not callablerrNr$z!invalid %(type)s value: %(value)r) rrr#r|rrr.rr«rÞrOr$r:)r rnrjr'rñr¯r#rVr%r%r&riçs     zArgumentParser._get_valuecCsm|jdk ri||jkrii|d6djtt|jƒƒd6}tdƒ}t|||ƒ‚ndS)Nr$z, r°z3invalid choice: %(value)r (choose from %(choices)s))r°rÚmaprr|r)r rnr$rVrñr%r%r&rv s   zArgumentParser._check_valuecCs2|jƒ}|j|j|j|jƒ|jƒS)N)rÜrgrcrrr[)r rQr%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Ürgrcrrrar rr]r1rqrŽr^rAr[)r rQZ action_groupr%r%r&r[ s  zArgumentParser.format_helpcCs|jd|jƒS)NrK)rBrK)r r%r%r&rÜ) szArgumentParser._get_formattercCs2|dkrtj}n|j|jƒ|ƒdS)N)rÞrßrÝrx)r Úfiler%r%r&Ú print_usage/ s  zArgumentParser.print_usagecCs2|dkrtj}n|j|jƒ|ƒdS)N)rÞrßrÝr[)r ryr%r%r&rØ4 s  zArgumentParser.print_helpcCs2|r.|dkrtj}n|j|ƒndS)N)rÞÚstderrÚwrite)r rÄryr%r%r&rÝ9 s  zArgumentParser._print_messagercCs-|r|j|tjƒntj|ƒdS)N)rÝrÞr{rÙ)r ZstatusrÄr%r%r&rÙB szArgumentParser.exitcCsE|jtjƒi|jd6|d6}|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. rKrÄr2z%(prog)s: error: %(message)s N)rzrÞr{rKrÙr|)r rÄrVr%r%r&r;G s zArgumentParser.error) rr+r,r-rrMrrJr%rKrIrLrîrMrfrmrXrcrhrsrorSrirvrxr[rÜrzrØrÝrÙr;r%r%)rÎr&r.sL 3     # ö     : , , 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 rr(r*rr%r%r%r&Ú>sz        ÿê    [#%`6ÿ4"