o w[e@sdZdZgdZdZddlZddlZddlZddZz ddlmZm Z Wne y5d d Zd d Z YnweZ Gd dde Z Gddde ZGdddeZGddde ZGddde ZGdddeZGdddZGdddeZGdddeZdd Zd!d"Zee d#fee d#fee d$fee d%fd&Zd'd(Zd)d*Zd+ZGd,d-d-Zd.Zd/Z Gd0d1d1Z!Gd2d3d3Z"Gd4d5d5e"Z#Gd6d7d7e"Z$d8d9Z%eZ&dS):aA powerful, extensible, and easy-to-use option parser. By Greg Ward Originally distributed as Optik. For support, use the optik-users@lists.sourceforge.net mailing list (http://lists.sourceforge.net/lists/listinfo/optik-users). Simple usage example: from optparse import OptionParser parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="write report to FILE", metavar="FILE") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print status messages to stdout") (options, args) = parser.parse_args() z1.5.3)Option make_option SUPPRESS_HELPSUPPRESS_USAGEValuesOptionContainer OptionGroup OptionParser HelpFormatterIndentedHelpFormatterTitledHelpFormatter OptParseError OptionErrorOptionConflictErrorOptionValueErrorBadOptionError check_choicea" Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved. Copyright (c) 2002-2006 Python Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NcCsd|jjt||fS)Nz<%s at 0x%x: %s>) __class____name__idselfr/usr/lib/python3.10/optparse.py_reprOr)gettextngettextcCs|SNr)messagerrrr\srcCs|dkr|S|SNr)singularpluralnrrrr_src@seZdZddZddZdS)r cC ||_dSrmsgrr'rrr__init__h zOptParseError.__init__cC|jSrr&rrrr__str__kzOptParseError.__str__N)r __module__ __qualname__r)r,rrrrr gs r c@ eZdZdZddZddZdS)r z] Raised if an Option instance is created with invalid or inconsistent arguments. cCs||_t||_dSr)r'str option_id)rr'optionrrrr)uszOptionError.__init__cCs|jr d|j|jfS|jS)Nz option %s: %s)r2r'rrrrr,yszOptionError.__str__Nrr.r/__doc__r)r,rrrrr os r c@eZdZdZdS)rzE Raised if conflicting options are added to an OptionParser. Nrr.r/r5rrrrrrc@r6)rzS Raised if an invalid option value is encountered on the command line. Nr7rrrrrr8rc@r0)rzB Raised if an invalid option is seen on the command line. cCr%r)opt_strrr9rrrr)r*zBadOptionError.__init__cCstd|jS)Nzno such option: %s)_r9rrrrr,zBadOptionError.__str__Nr4rrrrrs rc@r0)AmbiguousOptionErrorzD Raised if an ambiguous option is seen on the command line. cCst||||_dSr)rr) possibilities)rr9r>rrrr)s  zAmbiguousOptionError.__init__cCstd|jd|jfS)Nzambiguous option: %s (%s?), )r;r9joinr>rrrrr,szAmbiguousOptionError.__str__Nr4rrrrr=s r=c@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd!S)"r a Abstract base class for formatting option help. OptionParser instances should use one of the HelpFormatter subclasses for formatting help; by default IndentedHelpFormatter is used. Instance attributes: parser : OptionParser the controlling OptionParser instance indent_increment : int the number of columns to indent per nesting level max_help_position : int the maximum starting column for option help text help_position : int the calculated starting column for option help text; initially the same as the maximum width : int total number of columns for output (pass None to constructor for this value to be taken from the $COLUMNS environment variable) level : int current indentation level current_indent : int current indentation level (in columns) help_width : int number of columns available for option help text (calculated) default_tag : str text to replace with each option's default value, "%default" by default. Set to false value to disable default value expansion. option_strings : { Option : str } maps Option instances to the snippet of help text explaining the syntax of that option, e.g. "-h, --help" or "-fFILE, --file=FILE" _short_opt_fmt : str format string controlling how short options with values are printed in help text. Must be either "%s%s" ("-fFILE") or "%s %s" ("-f FILE"), because those are the two syntaxes that Optik supports. _long_opt_fmt : str similar but for long options; must be either "%s %s" ("--file FILE") or "%s=%s" ("--file=FILE"). nonec Csd|_||_|dur%z ttjd}Wn ttfy d}Ynw|d8}||_t|t |d|d|_ |_ d|_ d|_ d|_||_d|_i|_d|_d|_dS) NCOLUMNSPrz%defaultz%s %sz%s=%s)parserindent_incrementintosenvironKeyError ValueErrorwidthminmax help_positionmax_help_positioncurrent_indentlevel help_width short_first default_tagoption_strings_short_opt_fmt _long_opt_fmtrrGrQrMrUrrrr)s(  zHelpFormatter.__init__cCr%r)rFrrFrrr set_parserr*zHelpFormatter.set_parsercC&|dvr td|d|d|_dS)N) z/invalid metavar delimiter for short options: %r%s)rLrXrdelimrrrset_short_opt_delimiter z%HelpFormatter.set_short_opt_delimitercCr])N)=r_z.invalid metavar delimiter for long options: %rr`)rLrYrarrrset_long_opt_delimiterrdz$HelpFormatter.set_long_opt_delimitercCs"|j|j7_|jd7_dSr rRrGrSrrrrindentszHelpFormatter.indentcCs4|j|j8_|jdksJd|jd8_dS)NrzIndent decreased below 0.r!rgrrrrdedentszHelpFormatter.dedentcCtdNzsubclasses must implementNotImplementedErrorrusagerrr format_usagezHelpFormatter.format_usagecCrjrkrlrheadingrrrformat_headingrqzHelpFormatter.format_headingcCs.t|j|jd}d|j}tj||||dS)z Format a paragraph of free-form text for inclusion in the help output at the current indentation level. r_)initial_indentsubsequent_indent)rOrMrRtextwrapfill)rtext text_widthrhrrr _format_texts zHelpFormatter._format_textcCs|r ||dSdSN r^r|r descriptionrrrformat_descriptionsz HelpFormatter.format_descriptioncCs|r d||dSdSr}r)repilogrrr format_epilogszHelpFormatter.format_epilogcCsP|jdus|js |jS|jj|j}|tus|dur|j}|j|jt |Sr) rFrVhelpdefaultsgetdest NO_DEFAULTNO_DEFAULT_VALUEreplacer1)rr3 default_valuerrrexpand_defaults zHelpFormatter.expand_defaultcsg}j|}jjd}t||kr!djd|f}j}n djd||f}d}|||jr]|}t|j }|d|d|df| fdd|ddDn |d d krh|d d |S) NrD%*s%s r^z %*s%-*s rcsg|] }djd|fqS)rr^)rP).0linerrr Esz/HelpFormatter.format_option..r!r~) rWrPrRlenappendrrrxwraprTextendr@)rr3resultopts opt_width indent_first help_text help_linesrrr format_option(s&        zHelpFormatter.format_optioncCs|d}|jD]}||}||j|<t|t||j}q ||jD]}|jD]}||}||j|<t|t||j}q,q'||t |d|j |_ t|j |j d|_ dS)NrrDru)rh option_listformat_option_stringsrWrOrrR option_groupsrirNrQrPrMrT)rrFmax_lenoptstringsgrouprrrstore_option_stringsKs"       z"HelpFormatter.store_option_stringscst|r#|jp |jfdd|jD}fdd|jD}n|j}|j}jr1||}n||}d|S)z@Return a comma-separated list of option strings & metavariables.cg|] }j|fqSr)rX)rsoptmetavarrrrraz7HelpFormatter.format_option_strings..crr)rY)rloptrrrrcrr?) takes_valuerrupper _short_opts _long_optsrUr@)rr3 short_opts long_optsrrrrr]s    z#HelpFormatter.format_option_stringsN)rr.r/r5rr)r\rcrfrhrirprtr|rrrrrrrrrrr s$)  # r c@s2eZdZdZ    d ddZdd Zd d ZdS) r z.Format help with indented section bodies. rDNr!cCt|||||dSrr r)rZrrrr)t zIndentedHelpFormatter.__init__cCs td|S)Nz Usage: %s )r;rnrrrrp| z"IndentedHelpFormatter.format_usagecCsd|jd|fS)Nz%*s%s: r^)rRrrrrrrtz$IndentedHelpFormatter.format_heading)rDrNr!rr.r/r5r)rprtrrrrr p  r c@s2eZdZdZ    d ddZddZd d ZdS) r z1Format help with underlined section headers. rrNcCrrrrZrrrr)rzTitledHelpFormatter.__init__cCsd|td|fS)Nz%s %s Usage)rtr;rnrrrrprz TitledHelpFormatter.format_usagecCsd|d|jt|fS)Nz%s %s z=-)rSrrrrrrrtsz"TitledHelpFormatter.format_heading)rrNrrrrrrr rr cCsh|dddkr d}n"|dddkr"d}|ddp d}n |dddkr-d}nd}|||S) NrD0x0b0r! )lower)valtyperadixrrr _parse_nums rcCs t|tSr)rrH)rrrr _parse_intr*rintegerzfloating-pointcomplex)rHlongfloatrcCs>t|j\}}z||WStyttd|||fw)Nzoption %s: invalid %s value: %r) _builtin_cvtrrLrr;)r3rvaluecvtwhatrrr check_builtins  rcCs6||jvr|Sdtt|j}ttd|||f)Nr?z.option %s: invalid choice: %r (choose from %s))choicesr@mapreprrr;)r3rrrrrrrs r)NODEFAULTc@seZdZdZgdZdZdZdZdZdZ dZ e e e e e d Z d Zd d Zd dZddZddZddZddZddZddZddZddZdd ZeeeeeeegZd!d"ZeZd#d$Zd%d&Zd'd(Zd)d*Z d+d,Z!d-d.Z"d S)/rar Instance attributes: _short_opts : [string] _long_opts : [string] action : string type : string dest : string default : any nargs : int const : any choices : [string] callback : function callback_args : (any*) callback_kwargs : { string : any } help : string metavar : string ) actionrrdefaultnargsconstrcallback callback_argscallback_kwargsrr) store store_const store_true store_falser append_constcountrrversion)rrrrrrr)rrr)rr)rr)stringrHrrrchoice)rHrrrrNcOsBg|_g|_||}|||||jD]}||qdSr)rr_check_opt_strings_set_opt_strings _set_attrs CHECK_METHODS)rrattrscheckerrrrr)4s     zOption.__init__cCsdd|D}|s td|S)NcSsg|]}|r|qSrr)rrrrrrKz-Option._check_opt_strings..z+at least one option string must be supplied) TypeError)rrrrrrGszOption._check_opt_stringscCs|D]J}t|dkrtd||t|dkr1|ddkr#|ddks*td|||j|q|dddkr?|ddksFtd|||j|qdS) NrDz>invalid option string %r: must be at least two characters longr-r!zMinvalid short option string %r: must be of the form -x, (x any non-dash char)--zGinvalid long option string %r: must start with --, followed by non-dash)rr rrr)rrrrrrrPs4  zOption._set_opt_stringscCsv|jD]#}||vrt||||||=q|dkr t||tqt||dq|r9t|}tdd||dS)Nrzinvalid keyword arguments: %sr?)ATTRSsetattrrsortedkeysr r@)rrattrrrrres   zOption._set_attrscCs4|jdur d|_dS|j|jvrtd|j|dS)Nrzinvalid action: %r)rACTIONSr rrrr _check_actionxs   zOption._check_actioncCs|jdur|j|jvr|jdurd|_dSd|_dSdSt|jtr'|jj|_|jdkr/d|_|j|jvr=td|j||j|jvrKtd|j|dS)Nrrr1zinvalid option type: %rz$must not supply a type for action %r) rrALWAYS_TYPED_ACTIONSr isinstancerTYPESr TYPED_ACTIONSrrrr _check_type~s"          zOption._check_typecCsr|jdkr*|jdurtd|t|jttfs(tdtt|jdd|dS|jdur7td|j|dS)Nrz/must supply a list of choices for type 'choice'z1choices must be a list of strings ('%s' supplied)'r!z#must not supply choices for type %r)rrr rtuplelistr1splitrrrr _check_choices$    zOption._check_choicecCsf|j|jvp |jdu}|jdur/|r1|jr%|jddddd|_dS|jdd|_dSdSdS)NrrDrr;r!)r STORE_ACTIONSrrrrr)rrrrr _check_dests  zOption._check_destcCs.|j|jvr|jdurtd|j|dSdS)Nz*'const' must not be supplied for action %r)r CONST_ACTIONSrr rrrr _check_consts zOption._check_constcCsB|j|jvr|jdurd|_dSdS|jdurtd|j|dS)Nr!z*'nargs' must not be supplied for action %r)rrrr rrrr _check_nargss    zOption._check_nargscCs|jdkr.)rr r)rrrrrr convert_values   zOption.convert_valuecCs$|||}||j|j||||Sr)r take_actionrr)rrrvaluesrFrrrprocesss zOption.processc CsH|dkr t|||d S|dkrt|||jd S|dkr%t||dd S|dkr1t||dd S|dkr@||g|d S|dkrP||g|jd S|d krbt||||d d d S|d kr|jpjd }|jpoi}|j||||g|Ri|d S|dkr||d S|dkr| |d St d|j )NrrrTrFrrrrr!rrrrzunknown action %r) rr ensure_valuerrrr print_helpexit print_versionrLr) rrrrrrrFargskwargsrrrrsF      zOption.take_action)#rr.r/r5rrrrrrrrrr rr)rrrrrrrrrrr,r__repr__rr r rrrrrrrrsV       r SUPPRESSHELP SUPPRESSUSAGEc@s^eZdZdddZddZeZddZdd Zd d Z d d Z dddZ dddZ ddZ dS)rNcCs*|r|D] \}}t|||qdSdSr)itemsr)rrrrrrrr)9s zValues.__init__cCs t|jSr)r1__dict__rrrrr,>r*zValues.__str__cCs.t|tr |j|jkSt|tr|j|kStSr)rrrrNotImplemented)rotherrrr__eq__Cs    z Values.__eq__cCs6t|D]}||vr||}|durt|||qdS)z Update the option values from an arbitrary dictionary, but only use keys from dict that already have a corresponding attribute in self. Any keys in dict without a corresponding attribute are silently ignored. N)dirr)rrrdvalrrr_update_carefulKs  zValues._update_carefulcCs|j|dS)z Update the option values from an arbitrary dictionary, using all keys from the dictionary regardless of whether they have a corresponding attribute in self or not. N)rupdate)rrrrr _update_looseXszValues._update_loosecCs8|dkr ||dS|dkr||dStd|)Ncarefulloosezinvalid update mode: %r)r#r%rL)rrmoderrr_update`s  zValues._updater&cCs&t|tj|}|t||dSr) __import__sysmodulesr)vars)rmodnamer(modrrr read_modulehs zValues.read_modulecCs&i}tt|||||dSr)execopenreadr))rfilenamer(r-rrr read_filemszValues.read_filecCs.t||r t||durt|||t||Sr)hasattrgetattrr)rrrrrrrrs  zValues.ensure_valuer)r&)rr.r/r)r,rrr r#r%r)r0r5rrrrrr7s     rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"S)#ra Abstract base class. Class attributes: standard_option_list : [Option] list of standard options that will be accepted by all instances of this parser class (intended to be overridden by subclasses). Instance attributes: option_list : [Option] the list of Option objects contained by this OptionContainer _short_opt : { string : Option } dictionary mapping short option strings, eg. "-f" or "-X", to the Option instances that implement them. If an Option has multiple short option strings, it will appear in this dictionary multiple times. [1] _long_opt : { string : Option } dictionary mapping long option strings, eg. "--file" or "--exclude", to the Option instances that implement them. Again, a given Option can occur multiple times in this dictionary. [1] defaults : { string : any } dictionary mapping option destination names to default values for each destination [1] [1] These mappings are common to (shared by) all components of the controlling OptionParser, where they are initially created. cCs&|||_||||dSr)_create_option_list option_classset_conflict_handlerset_description)rr9conflict_handlerrrrrr)s zOptionContainer.__init__cCsi|_i|_i|_dSr _short_opt _long_optrrrrr_create_option_mappingss z'OptionContainer._create_option_mappingscCs|j|_|j|_|j|_dSrr=r[rrr_share_option_mappingss z&OptionContainer._share_option_mappingscCs|dvr td|||_dS)N)errorresolvez$invalid conflict_resolution value %r)rLr<)rhandlerrrrr:s  z$OptionContainer.set_conflict_handlercCr%rrrrrrr;r*zOptionContainer.set_descriptioncCr+rrErrrrget_descriptionr-zOptionContainer.get_descriptioncCs|`|`|`dSzsee OptionParser.destroy().Nr=rrrrdestroyszOptionContainer.destroycCsg}|jD]}||jvr|||j|fq|jD]}||jvr+|||j|fq|rv|j}|dkrDtdddd|D||dkrx|D]/\}}|dr^|j ||j|=n |j ||j|=|jsu|jsu|j j |qJdSdSdS)NrBz conflicting option string(s): %sr?cSsg|]}|dqS)rr)rcorrrrrz3OptionContainer._check_conflict..rCr) rr>rrr?r<rr@ startswithremove containerr)rr3 conflict_optsrrDc_optionrrr_check_conflicts>          zOptionContainer._check_conflictcOst|dtr|j|i|}nt|dkr(|s(|d}t|ts'td|ntd|||j|||_ |j D]}||j |<q=|j D]}||j |<qH|jduro|jturc|j|j|j<|S|j|jvrod|j|j<|S)zOadd_option(Option) add_option(opt_str, ..., kwarg=val, ...) rr!znot an Option instance: %rinvalid argumentsN)rr1r9rrrrOrrrLrr>rr?rrrr)rrrr3rrrr add_options,           zOptionContainer.add_optioncCs|D]}||qdSr)rQ)rrr3rrr add_optionss zOptionContainer.add_optionscCs|j|p |j|Sr)r>rr?r:rrr get_options  zOptionContainer.get_optioncCs||jvp ||jvSr)r>r?r:rrr has_option s zOptionContainer.has_optioncCsn|j|}|dur|j|}|durtd||jD]}|j|=q|jD]}|j|=q'|jj|dS)Nzno such option %r) r>rr?rLrrrLrrK)rr9r3rrrr remove_options       zOptionContainer.remove_optioncCs>|jsdSg}|jD]}|jtur|||q d|SNr^)rrrrrr@)r formatterrr3rrrformat_option_helps   z"OptionContainer.format_option_helpcCs||Sr)rrFrrWrrrr(r<z"OptionContainer.format_descriptioncCs:g}|jr ||||jr|||d|S)Nr~)rrrrrXr@rrWrrrr format_help+s  zOptionContainer.format_helpN)rr.r/r5r)r@rAr:r;rFrHrOrQrRrSrTrUrXrr[rrrrrxs$    rc@s6eZdZd ddZddZddZdd Zd d ZdS) rNcCs$||_t||j|j|||_dSr)rFrr)r9r<title)rrFr\rrrrr)6s   zOptionGroup.__init__cCsg|_||jdSr)rrArFrrrrr8<szOptionGroup._create_option_listcCr%r)r\)rr\rrr set_title@r*zOptionGroup.set_titlecCst||`dSrG)rrHrrrrrrHCs zOptionGroup.destroycCs0||j}||t||7}||Sr)rtr\rhrr[rirZrrrr[Js zOptionGroup.format_helpr)rr.r/r)r8r]rHr[rrrrr4s   rc @sbeZdZdZgZddedddddddf ddZddZd d Zd d Z d dZ dPddZ ddZ ddZ ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(ZdQd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z dRdd?Z"d@dAZ#dSdBdCZ$dDdEZ%dSdFdGZ&dSdHdIZ'dJdKZ(dSdLdMZ)dSdNdOZ*dS)Tra$ Class attributes: standard_option_list : [Option] list of standard options that will be accepted by all instances of this parser class (intended to be overridden by subclasses). Instance attributes: usage : string a usage string for your program. Before it is displayed to the user, "%prog" will be expanded to the name of your program (self.prog or os.path.basename(sys.argv[0])). prog : string the name of the current program (to override os.path.basename(sys.argv[0])). description : string A paragraph of text giving a brief overview of your program. optparse reformats this paragraph to fit the current terminal width and prints it when the user requests help (after usage, but before the list of options). epilog : string paragraph of help text to print after option help option_groups : [OptionGroup] list of option groups in this parser (option groups are irrelevant for parsing the command-line, but very useful for generating help) allow_interspersed_args : bool = true if true, positional arguments may be interspersed with options. Assuming -a and -b each take a single argument, the command-line -ablah foo bar -bboo baz will be interpreted the same as -ablah -bboo -- foo bar baz If this flag were false, that command line would be interpreted as -ablah -- foo bar -bboo baz -- ie. we stop processing options as soon as we see the first non-option argument. (This is the tradition followed by Python's getopt module, Perl's Getopt::Std, and other argument- parsing libraries, but it is generally annoying to users.) process_default_values : bool = true if true, option default values are processed similarly to option values from the command line: that is, they are passed to the type-checking function for the option's type (as long as the default value is a string). (This really only matters if you have defined custom types; see SF bug #955889.) Set it to false to restore the behaviour of Optik 1.4.1 and earlier. rargs : [string] the argument list currently being parsed. Only set when parse_args() is active, and continually trimmed down as we consume arguments. Mainly there for the benefit of callback options. largs : [string] the list of leftover arguments that we have skipped while parsing options. If allow_interspersed_args is false, this list is always empty. values : Values the set of option values currently being accumulated. Only set when parse_args() is active. Also mainly for callbacks. Because of the 'rargs', 'largs', and 'values' attributes, OptionParser is not thread-safe. If, for some perverse reason, you need to parse command-line arguments simultaneously in different threads, use different OptionParser instances. NrBTc Csrt||||||| |_||_d|_d|_|dur t}||_|j || |_ |j ||d| dS)NT)add_help) rr) set_usageprograllow_interspersed_argsprocess_default_valuesr rWr\r_populate_option_list_init_parsing_state) rrorr9rr<rrWadd_help_optionr`rrrrr)s"    zOptionParser.__init__cCs.t||jD]}|q|`|`|`dS)a Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable. N)rrHrrrW)rrrrrrHs   zOptionParser.destroycCsg|_g|_|dSr)rrr@rrrrr8s z OptionParser._create_option_listcCs|jdddtdddS)Nz-hz--helprzshow this help message and exitrrrQr;rrrr_add_help_options zOptionParser._add_help_optioncCs|jddtdddS)Nz --versionrz&show program's version number and exitrfrgrrrr_add_version_options z OptionParser._add_version_optioncCsB|jr ||j|r|||jr||r|dSdSr)standard_option_listrRrrirh)rrr^rrrrcs   z"OptionParser._populate_option_listcCsd|_d|_d|_dSr)rargslargsrrrrrrds z OptionParser._init_parsing_statecCsR|dur td|_dS|turd|_dS|dr$|dd|_dS||_dS)Nz%prog [options]zusage: )r;rorrrJrnrrrr_s  zOptionParser.set_usagecC d|_dS)aSet parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.TNrarrrrenable_interspersed_args z%OptionParser.enable_interspersed_argscCrn)zSet parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don't get confused. FNrorrrrdisable_interspersed_argsrqz&OptionParser.disable_interspersed_argscCr%r)rb)rrrrrset_process_default_values r*z'OptionParser.set_process_default_valuescCs||j|<dSr)r)rrrrrr set_defaultr<zOptionParser.set_defaultcKs|j|dSr)rr$)rrrrr set_defaultsrzOptionParser.set_defaultscCs*|jdd}|jD]}||jq |Sr)rrr)roptionsrrrr_get_all_optionss zOptionParser._get_all_optionscCs`|jst|jS|j}|D]}||j}t|tr+| }| ||||j<qt|Sr) rbrrcopyrwrrrr1r r )rrr3rr9rrrget_default_valuess     zOptionParser.get_default_valuescOst|dtrt|g|Ri|}n%t|dkr4|s4|d}t|ts*td||j|ur3tdntd|j||S)Nrr!znot an OptionGroup instance: %rz"invalid OptionGroup (wrong parser)rP) rr1rrrrFrLrr)rrrrrrradd_option_group+s    zOptionParser.add_option_groupcCs0|j|p |j|}|r|j|ur|jSdSr)r>rr?rL)rr9r3rrrget_option_group;s  zOptionParser.get_option_groupcCs"|dur tjddS|ddSr )r+argv)rrrrr _get_argsEs zOptionParser._get_argsc Cs||}|dur |}||_g|_}||_z ||||}Wnttfy<}z |t |WYd}~nd}~ww||}| ||S)aR parse_args(args : [string] = sys.argv[1:], values : Values = None) -> (values : Values, args : [string]) Parse the command-line options found in 'args' (default: sys.argv[1:]). Any errors result in a call to 'error()', which by default prints the usage message to stderr and calls sys.exit() with an error message. On success returns a pair (values, args) where 'values' is a Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options. N) r}ryrkrlr _process_argsrrrBr1 check_values)rrrrkrlstoperrrrr parse_argsKs   zOptionParser.parse_argscCs||fS)a check_values(values : Values, args : [string]) -> (values : Values, args : [string]) Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired. r)rrrrrrrrs zOptionParser.check_valuescCs|rE|d}|dkr|d=dS|dddkr|||n#|dddkr3t|dkr3|||n|jr?|||d=ndS|sdSdS)a_process_args(largs : [string], rargs : [string], values : Values) Process command-line arguments and populate 'values', consuming options and arguments from 'rargs'. If 'allow_interspersed_args' is false, stop at the first non-option argument. If true, accumulate any interspersed non-option arguments in 'largs'. rrNrDr!r)_process_long_optr_process_short_optsrar)rrlrkrargrrrr~s   zOptionParser._process_argscCs t||jS)a_match_long_opt(opt : string) -> string Determine which long option string 'opt' matches, ie. which one it is an unambiguous abbreviation for. Raises BadOptionError if 'opt' doesn't unambiguously match any long option string. ) _match_abbrevr?)rrrrr_match_long_opts zOptionParser._match_long_optc Cs|d}d|vr|dd\}}|d|d}n|}d}||}|j|}|r\|j}t||krD|t dd|||dn&|dkrN|d} nt |d|} |d|=n|rh|t d |nd} | || ||dS) Nrrer!TF.%(option)s option requires %(number)d argument/%(option)s option requires %(number)d argumentsr3numberz%s option does not take a value) poprinsertrr?rrrrBrrr;r) rrkrrrnext_arghad_explicit_valuer3rrrrrrs6       zOptionParser._process_long_optc Cs|d}d}d}|ddD]k}d|}|j|}|d7}|s%t||rk|t|kr;|d||dd}|j} t|| krS|t dd| || dn| dkr]|d} nt |d| } |d| =nd} | || |||rzdSqdS) NrFr!rTrrr) rr>rrrrrrrBrrr) rrkrrrichrr3rrrrrrs@      z OptionParser._process_short_optscCs"|jdurtjtjdS|jSr )r`rIpathbasenamer+r|rrrr get_prog_names zOptionParser.get_prog_namecCs|d|S)Nz%prog)rr)rsrrrexpand_prog_namerzOptionParser.expand_prog_namecCs ||jSr)rrrrrrrFrzOptionParser.get_descriptionrcCs|rtj|t|dSr)r+stderrwriter)rstatusr'rrrrs zOptionParser.exitcCs(|tj|dd||fdS)zerror(msg : string) Print a usage message incorporating 'msg' to stderr and exit. If you override this in a subclass, it should not return -- it should either exit or raise an exception. rDz%s: error: %s N) print_usager+rrrr(rrrrBs zOptionParser.errorcCs|jr |j||jSdSrV)rorWrprrrrr get_usage#s  zOptionParser.get_usagecC|jr t||ddSdS)aaprint_usage(file : file = stdout) Print the usage message for the current program (self.usage) to 'file' (default stdout). Any occurrence of the string "%prog" in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined. fileN)roprintrrrrrrr*s zOptionParser.print_usagecCs|jr ||jSdSrV)rrrrrr get_version6s zOptionParser.get_versioncCr)aEprint_version(file : file = stdout) Print the version message for this program (self.version) to 'file' (default stdout). As with print_usage(), any occurrence of "%prog" in self.version is replaced by the current program's name. Does nothing if self.version is empty or undefined. rN)rrrrrrrr<szOptionParser.print_versioncCs|dur|j}||g}||td||jr-|t|||d|j D]}|| ||dq0| d |ddS)NOptionsr~r^r) rWrrrtr;rhrrrXrr[rir@)rrWrrrrrrXGs    zOptionParser.format_option_helpcCs ||jSr)rrrYrrrrXrzOptionParser.format_epilogcCsn|dur|j}g}|jr||d|jr"|||d||||||d|Sr}) rWrorrrrrXrr@rZrrrr[[s zOptionParser.format_helpcCs |durtj}||dS)zprint_help(file : file = stdout) Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout). N)r+stdoutrr[rrrrrgszOptionParser.print_help)T)NN)rNr)+rr.r/r5rjrr)rHr8rhrircrdr_rprrrsrtrurwryrzr{r}rrr~rrrrrrFrrBrrrrrXrr[rrrrrrRsdD "     ' 3 $)      rcsT|vrSfdd|D}t|dkr|dS|s!t|t|)z_match_abbrev(s : string, wordmap : {string : Option}) -> string Return the string key in 'wordmap' for which 's' is an unambiguous abbreviation. If 's' is found to be ambiguous or doesn't match any of 'words', raise BadOptionError. csg|] }|r|qSr)rJ)rwordrrrrs z!_match_abbrev..r!r)rrrsortr=)rwordmapr>rrrrts  r)'r5 __version____all__ __copyright__r+rIrxrrr ImportErrorr; Exceptionr r rrrr=r r r rrrrrrrrrrrrrrrrrrrrrsd       P     uA=&