mfc@sdZdZdddddddd d d d d ddddgZddlZddlZddlZddl Z ddl Z ddl ZddlmZdZdZdZdZdZdZdZdZdefdYZdZdefd YZdefd!YZd efd"YZdefd#YZd$Z de!fd%YZ"de!fd&YZ#d efd'YZ$d(e$fd)YZ%d*e$fd+YZ&d,e&fd-YZ'd.e&fd/YZ(d0e$fd1YZ)d2e$fd3YZ*d4e$fd5YZ+d6e$fd7YZ,d8e$fd9YZ-d:e$fd;YZ.defd<YZ/d efd=YZ0d>efd?YZ1d@e1fdAYZ2dBe2fdCYZ3dee1fdDYZ4dS(Es 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.) s1.1tArgumentParsert ArgumentErrortArgumentTypeErrortFileTypet HelpFormattertArgumentDefaultsHelpFormattertRawDescriptionHelpFormattertRawTextHelpFormattert NamespacetActiont ONE_OR_MOREtOPTIONALtPARSERt REMAINDERtSUPPRESSt ZERO_OR_MOREiN(tgettextcCst|dpt|dS(Nt__call__t __bases__(thasattr(tobj((s /usr/lib64/python2.7/argparse.pyt _callable_ss ==SUPPRESS==t?t*t+sA...s...t_unrecognized_argst_AttributeHoldercBs)eZdZdZdZdZRS(sAbstract 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(Ns%s=%rs%s(%s)s, (ttypet__name__t _get_argstappendtreprt _get_kwargstjoin(tselft type_namet arg_stringstargtnametvalue((s /usr/lib64/python2.7/argparse.pyt__repr__yscCst|jjS(N(tsortedt__dict__titems(R"((s /usr/lib64/python2.7/argparse.pyR scCsgS(N((R"((s /usr/lib64/python2.7/argparse.pyRs(Rt __module__t__doc__R(R R(((s /usr/lib64/python2.7/argparse.pyRps cCs8t||ddkr+t|||nt||S(N(tgetattrtNonetsetattr(t namespaceR&R'((s /usr/lib64/python2.7/argparse.pyt _ensure_valuescBseZdZddddZdZdZdefdYZdZ d Z d Z d Z dd Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZRS(sFormatter 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. iicCs|dkrPyttjd}Wnttfk rBd}nX|d8}n||_||_||_||_ d|_ d|_ d|_ |j |d|_|j|_tjd|_tjd|_dS(NtCOLUMNSiPiis\s+s\n\n\n+(R/tintt_ostenvirontKeyErrort ValueErrort_progt_indent_incrementt_max_help_positiont_widtht_current_indentt_levelt_action_max_lengtht_Sectiont _root_sectiont_current_sectiont_retcompilet_whitespace_matchert_long_break_matcher(R"tprogtindent_incrementtmax_help_positiontwidth((s /usr/lib64/python2.7/argparse.pyt__init__s"           cCs%|j|j7_|jd7_dS(Ni(R=R:R>(R"((s /usr/lib64/python2.7/argparse.pyt_indentscCs%|j|j8_|jd8_dS(Ni(R=R:R>(R"((s /usr/lib64/python2.7/argparse.pyt_dedentsR@cBseZddZdZRS(cCs(||_||_||_g|_dS(N(t formattertparenttheadingR+(R"RNRORP((s /usr/lib64/python2.7/argparse.pyRKs   cCs|jdk r|jjn|jj}x!|jD]\}}||q5W|g|jD]\}}||^q\}|jdk r|jjn|sdS|jtk r|jdk r|jj }d|d|jf}nd}|d||dgS(Nts%*s%s: s ( ROR/RNRLt _join_partsR+RMRPRR=(R"R!tfunctargst item_helptcurrent_indentRP((s /usr/lib64/python2.7/argparse.pyt format_helps . N(RR,R/RKRW(((s /usr/lib64/python2.7/argparse.pyR@s cCs|jjj||fdS(N(RBR+R(R"RSRT((s /usr/lib64/python2.7/argparse.pyt _add_itemscCsB|j|j||j|}|j|jg||_dS(N(RLR@RBRXRW(R"RPtsection((s /usr/lib64/python2.7/argparse.pyt start_sections cCs|jj|_|jdS(N(RBRORM(R"((s /usr/lib64/python2.7/argparse.pyt end_sectionscCs5|tk r1|dk r1|j|j|gndS(N(RR/RXt _format_text(R"ttext((s /usr/lib64/python2.7/argparse.pytadd_textscCs8|tk r4||||f}|j|j|ndS(N(RRXt _format_usage(R"tusagetactionstgroupstprefixRT((s /usr/lib64/python2.7/argparse.pyt add_usages cCs|jtk r|j}||g}x*|j|D]}|j||q7Wtg|D]}t|^q^}||j}t|j||_|j |j |gndS(N( thelpRt_format_action_invocationt_iter_indented_subactionsRtmaxtlenR=R?RXt_format_action(R"tactiontget_invocationt invocationst subactiontstinvocation_lengtht action_length((s /usr/lib64/python2.7/argparse.pyt add_arguments %   cCs"x|D]}|j|qWdS(N(Rr(R"RaRk((s /usr/lib64/python2.7/argparse.pyt add_argumentss cCsD|jj}|r@|jjd|}|jdd}n|S(Ns s (RARWRFtsubtstrip(R"Re((s /usr/lib64/python2.7/argparse.pyRWs cCs2djg|D]}|r |tk r |^q S(NRQ(R!R(R"t part_stringstpart((s /usr/lib64/python2.7/argparse.pyRRs  cs|dkrtd}n|dk r@|td|j}n|dkrl| rldtd|j}nk|dkrdtd|j}g}g}x4|D],}|jr|j|q|j|qW|j} | |||} djg|| gD]} | r| ^q}|j|j t |t |krd} | ||} | ||}t j | | }t j | |}dfd}t |t |dkrEdt |t |d}|r||g|||}|j |||q|r9||g|||}q|g}n}dt |}||}|||}t |dkrg}|j ||||j |||n|g|}d j|}qnd ||fS( Nsusage: RGs%(prog)st s\(.*?\)+|\[.*?\]+|\S+csg}g}|dk r+t|d}nt|d}x||D]t}|dt|kr|j|dj|g}t|d}n|j||t|d7}qBW|r|j|dj|n|dk r|dt||dgt|jD] }d^q}d j |||j}|S( Ns%sis[%s]s [%s [%s ...]]is %s [%s ...]s...s%s ...Rx( RRR/R RR R R RR!(R"RkRt get_metavarRRtformats((s /usr/lib64/python2.7/argparse.pyR;s  "cCstt|d|j}x.t|D] }||tkr(||=q(q(Wx;t|D]-}t||drY||j|| 0; if you have nothing to store, actions such as store true or store const may be more appropriates nargs must be %r to supply constRRRRRRRRReR(R8R/R tsuperRRK( R"RRRRRRRRReR((s /usr/lib64/python2.7/argparse.pyRK%s cCst||j|dS(N(R0R(R"RR1RR((s /usr/lib64/python2.7/argparse.pyRBsN(RR,R/RRKR(((s /usr/lib64/python2.7/argparse.pyR#s t_StoreConstActioncBs)eZdedddZddZRS(cCsAtt|jd|d|ddd|d|d|d|dS( NRRRiRRRRe(RRRK(R"RRRRRReR((s /usr/lib64/python2.7/argparse.pyRKHscCst||j|jdS(N(R0RR(R"RR1RR((s /usr/lib64/python2.7/argparse.pyRYsN(RR,R/RRKR(((s /usr/lib64/python2.7/argparse.pyRFs  t_StoreTrueActioncBseZeeddZRS(c Cs;tt|jd|d|dtd|d|d|dS(NRRRRRRe(RRRKR(R"RRRRRe((s /usr/lib64/python2.7/argparse.pyRK_sN(RR,RR/RK(((s /usr/lib64/python2.7/argparse.pyR]st_StoreFalseActioncBseZeeddZRS(c Cs;tt|jd|d|dtd|d|d|dS(NRRRRRRe(RRRKR(R"RRRRRe((s /usr/lib64/python2.7/argparse.pyRKpsN(RR,RRR/RK(((s /usr/lib64/python2.7/argparse.pyRnst _AppendActionc Bs5eZdddddedddZddZRS(c Cs|dkrtdn|dk rF|tkrFtdtntt|jd|d|d|d|d|d |d |d |d | d | dS(Nisnargs for append actions must be > 0; if arg strings are not supplying the value to append, the append const action may be more appropriates nargs must be %r to supply constRRRRRRRRReR(R8R/R RRRK( R"RRRRRRRRReR((s /usr/lib64/python2.7/argparse.pyRKs cCsBtjt||jg}|j|t||j|dS(N(t_copytcopyR2RRR0(R"RR1RRR+((s /usr/lib64/python2.7/argparse.pyRs N(RR,R/RRKR(((s /usr/lib64/python2.7/argparse.pyRs t_AppendConstActioncBs)eZdedddZddZRS(cCsGtt|jd|d|ddd|d|d|d|d |dS( NRRRiRRRReR(RRRK(R"RRRRRReR((s /usr/lib64/python2.7/argparse.pyRKscCsEtjt||jg}|j|jt||j|dS(N(RRR2RRRR0(R"RR1RRR+((s /usr/lib64/python2.7/argparse.pyRsN(RR,R/RRKR(((s /usr/lib64/python2.7/argparse.pyRs  t _CountActioncBs&eZdeddZddZRS(c Cs;tt|jd|d|ddd|d|d|dS(NRRRiRRRe(RRRK(R"RRRRRe((s /usr/lib64/python2.7/argparse.pyRKscCs0t||jdd}t||j|dS(Nii(R2RR0(R"RR1RRt new_count((s /usr/lib64/python2.7/argparse.pyRsN(RR,R/RRKR(((s /usr/lib64/python2.7/argparse.pyRs t _HelpActioncBs&eZeeddZddZRS(c Cs5tt|jd|d|d|ddd|dS(NRRRRiRe(RRRK(R"RRRRe((s /usr/lib64/python2.7/argparse.pyRKs cCs|j|jdS(N(t print_helptexit(R"RR1RR((s /usr/lib64/python2.7/argparse.pyRs N(RR,RR/RKR(((s /usr/lib64/python2.7/argparse.pyRs t_VersionActioncBs)eZdeeddZddZRS(s&show program's version number and exitc Cs>tt|jd|d|d|ddd|||_dS(NRRRRiRe(RRRKtversion(R"RRRRRe((s /usr/lib64/python2.7/argparse.pyRKscCsT|j}|dkr!|j}n|j}|j||jd|jdS(NR(RR/t_get_formatterR^RRW(R"RR1RRRRN((s /usr/lib64/python2.7/argparse.pyRs      N(RR,R/RRKR(((s /usr/lib64/python2.7/argparse.pyRs  t_SubParsersActioncBsNeZdefdYZedddZdZdZddZ RS(t_ChoicesPseudoActioncBseZdZRS(cCs2ttj|}|jdgd|d|dS(NRRRe(RRRRK(R"R&Retsup((s /usr/lib64/python2.7/argparse.pyRKs(RR,RK(((s /usr/lib64/python2.7/argparse.pyRsc Csh||_||_tj|_g|_tt|jd|d|dt d|jd|d|dS(NRRRRReR( t _prog_prefixt _parser_classt _collectionst OrderedDictt_name_parser_mapt_choices_actionsRRRKR (R"RRGt parser_classRReR((s /usr/lib64/python2.7/argparse.pyRKs    cKs|jddkr/d|j|f|dqss%s(%s)(R R R!RR(R"RTtargs_str((s /usr/lib64/python2.7/argparse.pyR(os(RR,R-RKRR((((s /usr/lib64/python2.7/argparse.pyRLs  cBs8eZdZdZdZdZdZdZRS(sSimple object for storing attributes. Implements equality by attribute names and values, and provides a simple string representation. cKs)x"|D]}t||||qWdS(N(R0(R"RR&((s /usr/lib64/python2.7/argparse.pyRKs cCst|t|kS(N(R(R"tother((s /usr/lib64/python2.7/argparse.pyt__eq__scCs ||k S(N((R"R((s /usr/lib64/python2.7/argparse.pyt__ne__scCs ||jkS(N(R*(R"tkey((s /usr/lib64/python2.7/argparse.pyt __contains__sN( RR,R-RKR/t__hash__RRR(((s /usr/lib64/python2.7/argparse.pyRxs    t_ActionsContainercBseZdZdZddZdZdZdZdZ dZ dZ d Z d Z d Zd Zdd ZdZdZdZdZRS(cCsgtt|j||_||_||_||_i|_|jddt |jddt |jddt |jddt |jddt |jddt|jddt|jddt|jdd t|jdd t|jdd t|jg|_i|_g|_g|_i|_tjd |_g|_dS( NRktstoret store_constt store_truet store_falseRt append_consttcountReRtparserss^-\d+$|^-\d*\.\d+$(RRRKt descriptiontargument_defaultt prefix_charstconflict_handlert _registriestregisterR/RRRRRRRRRRt _get_handlert_actionst_option_string_actionst_action_groupst_mutually_exclusive_groupst _defaultsRCRDt_negative_number_matchert_has_negative_number_optionals(R"R'R)R(R*((s /usr/lib64/python2.7/argparse.pyRKs2           cCs#|jj|i}|||RR RRR(R"RRR ((s /usr/lib64/python2.7/argparse.pyR;[s   ! c OsVg}g}x|D]}|d|jkrZtd}||jf}t||n|j||d|jkrt|dkr|d|jkr|j|qqqqW|jdd}|dkr@|r|d} n |d} | j|j}|s+td}t||n|jdd}nt |d|d|S( Nis8invalid option string %r: must start with a character %riRs%dest= is required for options like %rRRR( R)RR8RRiRR/tlstriptreplaceR( R"RTRRtlong_option_stringsRR RRtdest_option_string((s /usr/lib64/python2.7/argparse.pyR<ks.       cCs%|jd|}|jd||S(NRk(RR7(R"RRRk((s /usr/lib64/python2.7/argparse.pyR=scCsUd|j}yt||SWn0tk rPtd}t||jnXdS(Ns_handle_conflict_%ss%invalid conflict_resolution value: %r(R*R.RRR8(R"thandler_func_nameR ((s /usr/lib64/python2.7/argparse.pyR-s    cCsrg}xC|jD]8}||jkr|j|}|j||fqqW|rn|j}|||ndS(N(RR/RR-(R"Rktconfl_optionalsRtconfl_optionalR*((s /usr/lib64/python2.7/argparse.pyRGs  cCsKtd}djg|D]\}}|^q}t|||dS(Ns conflicting option string(s): %ss, (RR!R(R"Rktconflicting_actionsRRtconflict_string((s /usr/lib64/python2.7/argparse.pyt_handle_conflict_errors  cCsZxS|D]K\}}|jj||jj|d|js|jj|qqWdS(N(RRJR/RR/RHRK(R"RkRXR((s /usr/lib64/python2.7/argparse.pyt_handle_conflict_resolves  N(RR,RKR,R/R7R9R:RrRDRFR?RKRPR;R<R=R-RGRZR[(((s /usr/lib64/python2.7/argparse.pyRs$ 4   /     (  #   RCcBs)eZdddZdZdZRS(cKs|j}|d|j|d|j|d|jtt|j}|d||||_g|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_dS(NR*R)R(R'(RR*R)R(RRCRKRLRR+R.R/R2R4R1(R"RHRLR'RR8t super_init((s /usr/lib64/python2.7/argparse.pyRKs        cCs,tt|j|}|jj||S(N(RRCR?RR(R"Rk((s /usr/lib64/python2.7/argparse.pyR?scCs*tt|j||jj|dS(N(RRCRKRRJ(R"Rk((s /usr/lib64/python2.7/argparse.pyRKsN(RR,R/RKR?RK(((s /usr/lib64/python2.7/argparse.pyRCs REcBs&eZedZdZdZRS(cCs,tt|j|||_||_dS(N(RRERKRt _container(R"RHR((s /usr/lib64/python2.7/argparse.pyRKs cCsJ|jr$td}t|n|jj|}|jj||S(Ns-mutually exclusive arguments must be optional(RRR8R]R?RR(R"RkR ((s /usr/lib64/python2.7/argparse.pyR?s   cCs$|jj||jj|dS(N(R]RKRRJ(R"Rk((s /usr/lib64/python2.7/argparse.pyRKs(RR,RRKR?RK(((s /usr/lib64/python2.7/argparse.pyREs  c BsUeZdZd!d!d!d!d!gedd!d!ded ZdZdZdZ dZ dZ d!d!d Z d!d!d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZd!dZd!dZd!dZd!dZ dd!dZ!d Z"RS("saObject 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 Rterrorc  Cs|dk r+ddl} | jdtntt|j}|d|d|d| d| |dkrtjj t j d}n||_ ||_ ||_||_||_| |_| |_|j}|td|_|td |_d|_d }|jd d|d |kr-d n|d}|jrw|j|d |dddddtdtdn|jr|j|d|dddddtd|jdtdnxL|D]D}|j|y |j}Wntk rqX|jj|qWdS(NisThe "version" argument to ArgumentParser is deprecated. Please use "add_argument(..., action='version', version="N", ...)" insteadR'R)R(R*ispositional argumentssoptional argumentscSs|S(N((R((s /usr/lib64/python2.7/argparse.pytidentity5sRRthiReRkRsshow this help message and exittvRs&show program's version number and exit(R/twarningstwarntDeprecationWarningRRRKR5tpathtbasenameRtargvRGR`tepilogRtformatter_classtfromfile_prefix_charstadd_helpRDRt _positionalst _optionalst _subparsersR,RrRRPR2RR8(R"RGR`R'RhRtparentsRiR)RjR(R*RkRbt superinitt add_groupR_tdefault_prefixROtdefaults((s /usr/lib64/python2.7/argparse.pyRKsX                        cCsAdddddddg}g|D]}|t||f^q"S(NRGR`R'RRiR*Rk(R.(R"RR&((s /usr/lib64/python2.7/argparse.pyR Us c KsG|jdk r%|jtdn|jdt|d|ksSd|krt|jdd}t|jdd}|j|||_n |j|_|j ddkr|j }|j }|j }|j |j||d|jj|d      ' (%% cCs |jd|j|j}t|sItd}t|||ny||}Wntk rt|jdt|j}tt j d}t||nZt t fk rt|jdt|j}td}t||||fnX|S(NRs%r is not callableRisinvalid %s value: %r( R7RRRRRR.RRRR|R>R8(R"RkRRBR RR&((s /usr/lib64/python2.7/argparse.pyRs    cCse|jdk ra||jkra|djtt|jf}td|}t||ndS(Ns, s#invalid choice: %r (choose from %s)(RR/R!tmapRRR(R"RkR'RR ((s /usr/lib64/python2.7/argparse.pyRs!cCs2|j}|j|j|j|j|jS(N(RRdR`R.R1RW(R"RN((s /usr/lib64/python2.7/argparse.pyt format_usages  cCs|j}|j|j|j|j|j|jxK|jD]@}|j|j |j|j|j |j |j qBW|j|j |jS(N(RRdR`R.R1R^R'R0RZRLRsRR[RhRW(R"RNt action_group((s /usr/lib64/python2.7/argparse.pyRWs  cCsBddl}|jdt|j}|j|j|jS(NiskThe format_version method is deprecated -- the "version" argument to ArgumentParser is no longer supported.(RbRcRdRR^RRW(R"RbRN((s /usr/lib64/python2.7/argparse.pytformat_versions  cCs|jd|jS(NRG(RiRG(R"((s /usr/lib64/python2.7/argparse.pyR scCs2|dkrtj}n|j|j|dS(N(R/RRt_print_messageR(R"tfile((s /usr/lib64/python2.7/argparse.pyt print_usage s  cCs2|dkrtj}n|j|j|dS(N(R/RRRRW(R"R((s /usr/lib64/python2.7/argparse.pyR s  cCs6ddl}|jdt|j|j|dS(NisjThe print_version method is deprecated -- the "version" argument to ArgumentParser is no longer supported.(RbRcRdRR(R"RRb((s /usr/lib64/python2.7/argparse.pyt print_version s  cCs2|r.|dkrtj}n|j|ndS(N(R/Rtstderrtwrite(R"RR((s /usr/lib64/python2.7/argparse.pyR! s  icCs-|r|j|tjntj|dS(N(RRRR(R"tstatusR((s /usr/lib64/python2.7/argparse.pyR* scCs7|jtj|jdtd|j|fdS(serror(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. is%s: error: %s N(RRRRRRG(R"R((s /usr/lib64/python2.7/argparse.pyR^/ s N(#RR,R-R/RRRKR RwR?RxRuRyRRzRRRRRRRRRRRRWRRRRRRRR^(((s /usr/lib64/python2.7/argparse.pyRsR B     #     9 , , 4        (5R-t __version__t__all__t collectionsRRRtosR5treRCtsysRttextwrapRRRRRR RR R R RRRR2RRRRRt ExceptionRRR RRRRRRRRRRRRRRCRER(((s /usr/lib64/python2.7/argparse.pyt>sx             [#%M,1"