\ddZdZgdZdZddlZddlZddlZdZ ddlmZm Z n#e $r dZd Z YnwxYweZ Gd d e Z Gd d e ZGddeZGdde ZGdde ZGddeZGddZGddeZGddeZdZdZee dfee dfee dfee d fd!Zd"Zd#Zd$ZGd%d&Zd'Zd(Z Gd)d*Z!Gd+d,Z"Gd-d.e"Z#Gd/d0e"Z$d1Z%eZ&dS)2aA 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. Nc@d|jjt||fzS)Nz<%s at 0x%x: %s>) __class____name__idselfs ..\python\lib\optparse.py_reprrOs !8"T((D I II)gettextngettextc|SN)messages rrr\src|dkr|S|SNr!)singularpluralns rrr_s 66O rceZdZdZdZdS)r c||_dSr msgrr,s r__init__zOptParseError.__init__hs rc|jSr r+rs r__str__zOptParseError.__str__ks xrN)r __module__ __qualname__r.r0r!rrr r gs2rr ceZdZdZdZdZdS)rz] Raised if an Option instance is created with invalid or inconsistent arguments. c<||_t||_dSr )r,str option_id)rr,options rr.zOptionError.__init__usVrcB|jrd|jd|jS|jS)Nzoption z: )r6r,rs rr0zOptionError.__str__ys- >  &*nnndhh? ?8OrNrr1r2__doc__r.r0r!rrrros< %%%rrceZdZdZdS)rzE Raised if conflicting options are added to an OptionParser. Nrr1r2r:r!rrrrsrrceZdZdZdS)rzS Raised if an invalid option value is encountered on the command line. Nr<r!rrrrsrrceZdZdZdZdZdS)rzB Raised if an invalid option is seen on the command line. c||_dSr )opt_strrr@s rr.zBadOptionError.__init__s  rc0td|jzS)Nzno such option: %s)_r@rs rr0zBadOptionError.__str__s%&&55rNr9r!rrrrs<66666rrceZdZdZdZdZdS)AmbiguousOptionErrorzD Raised if an ambiguous option is seen on the command line. cJt||||_dSr )rr. possibilities)rr@rGs rr.zAmbiguousOptionError.__init__s&g...*rcdtd|jd|jfzS)Nzambiguous option: %s (%s?), )rCr@joinrGrs rr0zAmbiguousOptionError.__str__s3.//<4+=!>!>?@ ArNr9r!rrrErEsA+++AAAAArrEcpeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdS)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"). nonecd|_||_|? ttjd}n#t t f$rd}YnwxYw|dz}||_t|t|dz |dzx|_ |_ 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_fmtrrSr]rYras rr.zHelpFormatter.__init__s  0 = BJy122j)     QJE %s52:7G!7K'L'LMM NT3 &% %$s2AAc||_dSr )rRrrRs r set_parserzHelpFormatter.set_parsers  rcL|dvrtd|zd|zdz|_dS)N) z/invalid metavar delimiter for short options: %r%s)rXrdrdelims rset_short_opt_delimiterz%HelpFormatter.set_short_opt_delimitersA  ! !AEIKK K"UlT1rcL|dvrtd|zd|zdz|_dS)N)=rlz.invalid metavar delimiter for long options: %rrm)rXrerns rset_long_opt_delimiterz$HelpFormatter.set_long_opt_delimitersA  " "@5HJJ J!E\D0rcP|xj|jz c_|xjdz c_dSr$r^rSr_rs rindentzHelpFormatter.indents, t44 a rcz|xj|jzc_|jdks Jd|xjdzc_dS)NrzIndent decreased below 0.r%rurs rdedentzHelpFormatter.dedentsI t44"a''')D''' a rc tdNzsubclasses must implementNotImplementedErrorrusages r format_usagezHelpFormatter.format_usage!"=>>>rc tdrzr{rheadings rformat_headingzHelpFormatter.format_headingrrct|j|jz d}d|jz}tj||||S)z Format a paragraph of free-form text for inclusion in the help output at the current indentation level. rl)initial_indentsubsequent_indent)r[rYr^textwrapfill)rtext text_widthrvs r _format_textzHelpFormatter._format_textsN d&992>> T((}T',2/5777 7rc:|r||dzSdSN rkrr descriptions rformat_descriptionz HelpFormatter.format_descriptions(  $$[11D8 82rc@|rd||zdzSdSrr)repilogs r format_epilogzHelpFormatter.format_epilogs-  $++F333d: :2rc|j|js|jS|jj|j}|t us||j}|j|jt|Sr ) rRrbhelpdefaultsgetdest NO_DEFAULTNO_DEFAULT_VALUEreplacer5)rr7 default_values rexpand_defaultzHelpFormatter.expand_defaultso ; d&6 ;  ,00== J & &-*? 1M{""4#3S5G5GHHHrcNg}j|}jjz dz }t||krdjd|fz}j}ndjd||fz}d}|||jrz|}tj|j }|d|d|dfz| fd|ddDn!|dd kr|d d |S) NrP%*s%s rkz %*s%-*s rc*g|]}djd|fzS)rrk)r\).0liners r z/HelpFormatter.format_option..Es8777#%(:B'EE777rr%r) rcr\r^lenappendrrrwrapr`extendrJ)rr7resultopts opt_width indent_first help_text help_liness` r format_optionzHelpFormatter.format_option(sT"6*&)<>D-LL$"5r9d!KKDL d ; ++F33I!y$/BBJ MM)|RA&GG H H H MM7777'1!""~777 8 8 8 8 "X   MM$   wwvrct|d}|jD]F}||}||j|<t |t ||jz}G||jD]P}|jD]F}||}||j|<t |t ||jz}GQ||t|dz|j |_ t |j |j z d|_ dS)NrrPr)rv option_listformat_option_stringsrcr[rr^ option_groupsrxrZr]r\rYr`)rrRmax_lenoptstringsgroups rstore_option_stringsz"HelpFormatter.store_option_stringsKs5 % G GC0055G'.D  $'3w<<$2E#EFFGG ) K KE( K K44S99+2#C(gs7||d6I'IJJ K   1d.DEEdj4+==rBBrc*|rI|jp|jfd|jD}fd|jD}n|j}|j}jr||z}n||z}d|S)z@Return a comma-separated list of option strings & metavariables.c(g|]}j|fzSr!)rd)rsoptmetavarrs rrz7HelpFormatter.format_option_strings..as5:::"-w?:::rc(g|]}j|fzSr!)re)rloptrrs rrz7HelpFormatter.format_option_strings..cs5888!+tWo=888rrI) takes_valuerrupper _short_opts _long_optsrarJ)rr7 short_opts long_optsrrs` @rrz#HelpFormatter.format_option_strings]s      *n; (9(9(;(;G:::::&,&8:::J88888%+%6888II +J)I   * )DDz)DyyrN)rr1r2r:rr.rirprsrvrxrrrrrrrrrr!rrr r s''R%%%2222 111  ?????? 7 7 7 III!!!FCCC$rr c.eZdZdZ d dZdZdZdS) r z.Format help with indented section bodies. rPNr%cBt|||||dSr r r.rfs rr.zIndentedHelpFormatter.__init__t8  "$5uk K K K K Krc&td|zS)Nz Usage: %s )rCr}s rrz"IndentedHelpFormatter.format_usage|s%''rcd|jd|fzS)Nz%*s%s: rk)r^rs rrz$IndentedHelpFormatter.format_headingsT0"g>>>r)rPrNr%rr1r2r:r.rrr!rrr r psb#$#% KKKK(((?????rr c.eZdZdZ ddZdZdZdS) r z1Format help with underlined section headers. rrNcBt|||||dSr rrfs rr.zTitledHelpFormatter.__init__rrcR|tdd|dS)NUsagez r)rrCr}s rrz TitledHelpFormatter.format_usages+!007<<< ? ?E7# $%% %r)NODEFAULTceZdZdZgdZdZdZdZdZdZ dZ e e e e e d Z d Zd Zd Zd ZdZdZdZdZdZdZdZdZeeeeeeegZdZeZdZdZdZdZ dZ!dZ"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)stringrTrrrchoice)rTrrrrNcg|_g|_||}|||||jD] }||dSr )rr_check_opt_strings_set_opt_strings _set_attrs CHECK_METHODS)rrattrscheckers rr.zOption.__init__4s{&&t,, d### )  G GDMMMM  rc@d|D}|std|S)Ncg|]}||Sr!r!)rrs rrz-Option._check_opt_strings..Ks+++s++++rz+at least one option string must be supplied) TypeError)rrs rrzOption._check_opt_stringsGs4,+t+++ KIJJ J rc|D]}t|dkrtd|z|t|dkrF|ddkr |ddkstd|z||j||dddkr |ddkstd|z||j|dS) NrPz>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)rrrrr)rrrs rrzOption._set_opt_stringsPs , ,C3xx!||!;=@ABFHHHSQA# #a&C--%HJMN '',,,,AaCD((SVs]]%CEHI&&s++++% , ,rcF|jD]O}||vrt||||||=!|dkrt||t>t||dP|rGt|}t dd|z|dS)Nrzinvalid keyword arguments: %srI)ATTRSsetattrrsortedkeysrrJ)rr attrs rrzOption._set_attrsesJ . .Du}}dE$K000$KK9$$D$ 3333D$----  5::<<((E/$))E2B2BB   rcr|j d|_dS|j|jvrtd|jz|dS)Nrzinvalid action: %r)rACTIONSrrs r _check_actionzOption._check_actionxsD ; !DKKK [ , ,2T[@$GG G- ,rcx|j)|j|jvr|j d|_dSd|_dSdSt |jtr|jj|_|jdkrd|_|j|jvrtd|jz||j|jvrtd|jz|dS)Nrrr5zinvalid option type: %rz$must not supply a type for action %r) rrALWAYS_TYPED_ACTIONSr isinstancerTYPESr TYPED_ACTIONSrs r _check_typezOption._check_type~s 9 {d777<+ (DIII!)DIII 87$)T** / I. yE!!$ y **!";di"GNNN{$"444!:T[H$PPP54rcd|jdkr|jtd|t|jtt fsKtdt t|jddz|dS|jtd|jz|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)rrrrtuplelistr5splitrs r _check_choicezOption._check_choices 9 |#!EtMMM udm<< C!G$t|,,--33C88;<=ACCC C C\ %5 A4II I& %rc|j|jvp|jdu}|jS|rS|jr0|jddddd|_dS|jdd|_dSdSdS)NrrPrrCr%)r STORE_ACTIONSrrrrr)rrs r _check_destzOption._check_dests{d&88-y,  9   3 OA.qrr2::3DD  ,Q/2     rcd|j|jvr|jtd|jz|dSdS)Nz*'const' must not be supplied for action %r)r CONST_ACTIONSrrrs r _check_constzOption._check_constsF ;d0 0 0TZ5K.s)FFF1d..sA66FFFr)rr;r#)rrrs`` r convert_valuezOption.convert_valuesY  zQ''U333FFFFFFFFGGG  rcv|||}||j|j||||Sr )r? take_actionrr)rrrvaluesrRs rprocesszOption.processsG""3..  KC@@ @rcF|dkrt|||n|dkrt|||jni|dkrt||dnP|dkrt||dn7|dkr+||g|n|dkr/||g|jn|d kr)t||||d d zn|d kr'|jpd }|jpi}|j||||g|Ri|nu|dkr)||nF|dkr)| |ntd|j zd S)NrrrTrFrrrrr%rr!rrzunknown action %r) rr ensure_valuerrrr print_helpexit print_versionrXr) rrrrrrBrRargskwargss rrAzOption.take_actions W   FD% ( ( ( ( } $ $ FD$* - - - - | # # FD$ ' ' ' ' } $ $ FD% ( ( ( ( x     b ) ) 0 0 7 7 7 7 ~ % %   b ) ) 0 0 < < < < w   FD&"5"5dA">">"B C C C C z ! !%+D)/RF DM$UF DT D D DV D D D D v         KKMMMM y  " " " KKMMMM04;>?? ?qr)#rr1r2r:rrr(rrr+rrrr:r r.rrrrr r&r)r,r.r2r0r__repr__rr8r;r?rCrAr!rrrrs*   E GM!M &%M DE$!. - - - , L M &,,,*&HHH PPP0 I I I 3 3 3 NNN8# " !!$ &M<<<H%%%'''---HHH @ @ @rr SUPPRESSHELP SUPPRESSUSAGEcNeZdZd dZdZeZdZdZdZ dZ d d Z d d Z d Z dS)rNcd|r+|D]\}}t|||dSdSr )itemsr)rrrrs rr.zValues.__init__9sP  )'~~// ) ) sdC(((( ) ) ) )rc*t|jSr )r5__dict__rs rr0zValues.__str__>s4=!!!rct|tr|j|jkSt|tr |j|kStSr )rrrRr1NotImplemented)rothers r__eq__z Values.__eq__CsH eV $ $ "=EN2 2 t $ $ "=E) )! !rcht|D]!}||vr||}|t|||"dS)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)rr1rdvals r_update_carefulzValues._update_carefulKsNII . .Dt||Dz#D$---  . .rc:|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)rRupdate)rr1s r _update_loosezValues._update_looseXs T"""""rc|dkr||dS|dkr||dStd|z)Ncarefulloosezinvalid update mode: %r)rZr]rX)rr1modes r_updatezValues._update`s^ 9     & & & & & W__   t $ $ $ $ $6=>> >rr_ct|tj|}|t ||dSr ) __import__sysmodulesrbvars)rmodnameramods r read_modulezValues.read_modulehs<7k'" T#YY%%%%%rci}tt|||||dSr )execopenreadrb)rfilenamerargs r read_filezValues.read_filemsC T(^^ " "D))) T4     rct||rt||t|||t||Sr )hasattrgetattrr)rrrs rrEzValues.ensure_valuersEtT"" 'gdD&9&9&A D$ & & &tT"""rr )r_)rr1r2r.r0rrKrVrZr]rbrjrprEr!rrrr7s)))) """H""" . . .###???&&&& !!!! #####rrcreZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdS)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. c|||_||||dSr )_create_option_list option_classset_conflict_handlerset_description)rrwconflict_handlerrs rr.zOptionContainer.__init__sM   """( !!"2333 [)))))rc0i|_i|_i|_dSr  _short_opt _long_optrrs r_create_option_mappingsz'OptionContainer._create_option_mappingss rcN|j|_|j|_|j|_dSr r|rhs r_share_option_mappingsz&OptionContainer._share_option_mappingss%!+) rc@|dvrtd|z||_dS)N)errorresolvez$invalid conflict_resolution value %r)rXrz)rhandlers rrxz$OptionContainer.set_conflict_handlers0 . . .CgMNN N 'rc||_dSr rrs rryzOptionContainer.set_descriptions&rc|jSr rrs rget_descriptionzOptionContainer.get_descriptions rc|`|`|`dSzsee OptionParser.destroy().Nr|rs rdestroyzOptionContainer.destroys O N MMMrcg}|jD]-}||jvr"|||j|f.|jD]-}||jvr"|||j|f.|r|j}|dkr0t ddd|Dz||dkr|D]\}}|dr#|j ||j|=n"|j ||j|=|js&|js|j j |dSdSdS)Nrz conflicting option string(s): %srIcg|] }|d S)rr!)rcos rrz3OptionContainer._check_conflict..s ? ? ?2A ? ? ?rrr) rr}rrr~rzrrJ startswithremove containerr)rr7 conflict_optsrrc_options r_check_conflictzOptionContainer._check_conflicts % B BCdo%%$$c4?3+?%@AAA$ A ACdn$$$$c4>#+>%?@@@  H+G'!!)6ii ? ? ? ? ?@@AI%%'4HHOS(~~d++1 +223777 N3// ,33C888 OC0$0HH4GH *6==hGGG! H H&%HHrcJt|dtr|j|i|}nTt|dkr2|s0|d}t|tst d|znt d|||j|||_ |j D] }||j |< |j D] }||j |< |j@|jt ur|j|j|j<n|j|jvrd|j|j<|S)zOadd_option(Option) add_option(opt_str, ..., kwarg=val, ...) rr%znot an Option instance: %rinvalid argumentsN)rr5rwrrrrrrrrr}rr~rrrr)rrIrJr7rs r add_optionzOptionContainer.add_optionsL d1gs # # 1&T&777FF YY!^^F^!WFff-- G ) +rc |j|}||j|}|td|z|jD] }|j|= |jD] }|j|= |jj|dS)Nzno such option %r) r}rr~rXrrrrr)rr@r7rs r remove_optionzOptionContainer.remove_options$$W-- >^''00F >07:;; ;% % %C$$$ $ $Cs##$++F33333rc|jsdSg}|jD]8}|jtur(|||9d|SNrk)rrrrrrJ)r formatterrr7s rformat_option_helpz"OptionContainer.format_option_helpsg 2& ? ?F;-// i55f==>>>wwvrcP||Sr )rrrrs rrz"OptionContainer.format_description(s"++D,@,@,B,BCCCrcg}|jr(||||jr(|||d|S)Nr)rrrrrrJrrrs r format_helpzOptionContainer.format_help+so   > MM$11)<< = = =   > MM$11)<< = = =yy   rN)rr1r2r:r.rrrxryrrrrrrrrrrrr!rrrrxs< * * *(((((( '''   HHH6<$$$ ---+++ 4 4 4 DDD!!!!!rrc.eZdZddZdZdZdZdZdS)rNcp||_t||j|j|||_dSr )rRrr.rwrztitle)rrRrrs rr.zOptionGroup.__init__6s>   &%v'>  M M M rcHg|_||jdSr )rrrRrs rrvzOptionGroup._create_option_list<s& ##DK00000rc||_dSr )r)rrs r set_titlezOptionGroup.set_title@s  rc>t||`dSr)rrrrs rrzOptionGroup.destroyCs"%%%    rc||j}||t||z }||Sr )rrrvrrrxrs rrzOptionGroup.format_helpJsZ))$*55/--dI>>> rr )rr1r2r.rvrrrr!rrrr4sd 111rrc eZdZdZgZddedddddddf dZdZdZdZ d Z d+d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZd,dZdZdZdZdZdZdZdZdZ d-d!Z!d"Z"d#Z#d.d$Z$d%Z%d.d&Z&d.d'Z'd(Z(d.d)Z)d.d*Z*dS)/r a$ 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. NrTc ht||||||| |_||_d|_d|_|t}||_|j || |_ | ||| dS)NT)add_help) rr. set_usageprograllow_interspersed_argsprocess_default_valuesr rrir_populate_option_list_init_parsing_state) rr~rrwrrzrradd_help_optionrrs rr.zOptionParser.__init__s   , 0+ ? ? ? u  '+$&*#  -//I" !!$''' "";,; # = = =   """""rct||jD]}||`|`|`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)rrrrr)rrs rrzOptionParser.destroysN %%%'  E MMOOOO     NNNrcJg|_g|_|dSr )rrrrs rrvz OptionParser._create_option_lists* $$&&&&&rcR|dddtddS)Nz-hz--helprzshow this help message and exitrrrrCrs r_add_help_optionzOptionParser._add_help_options? h%@AA  C C C C CrcP|ddtddS)Nz --versionrz&show program's version number and exitrrrs r_add_version_optionz OptionParser._add_version_options=  (GHH  J J J J Jrc|jr||j|r|||jr||r|dSdSr )standard_option_listrrrr)rrrs rrz"OptionParser._populate_option_lists  $ 8   T6 7 7 7  *   [ ) ) ) < '  $ $ & & &  $  ! ! # # # # # $ $rc0d|_d|_d|_dSr )rargslargsrBrs rrz OptionParser._init_parsing_states   rc|td|_dS|tur d|_dS|dr|dd|_dS||_dS)Nz%prog [options]zusage: )rCr~rrrr}s rrzOptionParser.set_usagesm =,--DJJJ n $ $DJJJ [[]] % %i 0 0 qrrDJJJDJJJrcd|_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.TNrrs renable_interspersed_argsz%OptionParser.enable_interspersed_argss (,$$$rcd|_dS)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. FNrrs rdisable_interspersed_argsz&OptionParser.disable_interspersed_argss (-$$$rc||_dSr )r)rrCs rset_process_default_valuesz'OptionParser.set_process_default_values s&-###rc||j|<dSr )r)rrrs r set_defaultzOptionParser.set_defaults# drc :|j|dSr )rr\)rrJs r set_defaultszOptionParser.set_defaultss V$$$$$rcl|jdd}|jD]}||j|Sr )rrr)roptionsrs r_get_all_optionszOptionParser._get_all_optionssB"111%' . .E NN5, - - - -rcx|jst|jS|j}|D]c}||j}t|tr2| }| ||||j<dt|Sr ) rrrcopyrrrrr5r8r;)rrr7rr@s rget_default_valueszOptionParser.get_default_valuess* )$-(( (=%%''++-- M MFll6;//G'3'' M //11(.(:(:7G(L(L%hrcjt|dtrt|g|Ri|}nlt|dkrJ|sH|d}t|tst d|z|j|urt dnt d|j||S)Nrr%znot an OptionGroup instance: %rz"invalid OptionGroup (wrong parser)r) rr5rrrrRrXrr)rrIrJrs radd_option_groupzOptionParser.add_option_group+s d1gs # # 16t666v66EE YY!^^F^GEe[11 K AE IJJJ|4'' !EFFF(/00 0 !!%((( rc|j|p|j|}|r|j|ur|jSdSr )r}rr~r)rr@r7s rget_option_groupzOptionParser.get_option_group;sU/%%g....$$W--   $f&d22# #trcB|tjddS|ddSr$)reargv)rrIs r _get_argszOptionParser._get_argsEs$ <8ABB< 7Nrcn||}||}||_gx|_}||_ ||||}n@#t tf$r,}|t|Yd}~nd}~wwxYw||z}| ||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) rrrrrB _process_argsrrrr5 check_values)rrIrBrrstoperrs r parse_argszOptionParser.parse_argsKst$$ >,,..F  U  !%%eUF;;DD 01 ! ! ! JJs3xx  !u}  ...sAB-"BBc ||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!)rrBrIs rrzOptionParser.check_valuesrs~rc6|r|d}|dkr|d=dS|dddkr|||nZ|dddkr*t|dkr|||n"|jr|||d=ndS|dSdS)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'. rrNrPr%r)_process_long_optr_process_short_optsrr)rrrrBargs rrzOptionParser._process_argss (Cd{{!HQqST!!&&uf5555RaRCCHHqLL((7777-  S!!!!HH'     rc,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~)rrs r_match_long_optzOptionParser._match_long_optsS$.111rc|d}d|vr2|dd\}}|d|d}n|}d}||}|j|}|r~|j}t||kr+|tdd|||dznc|dkr|d} nGt|d|} |d|=n*|r&|td |znd} | || ||dS) Nrrrr%TF.%(option)s option requires %(number)d argument/%(option)s option requires %(number)d argumentsr7numberz%s option does not take a value) popr%insertrr~rrrrrr#rCrC) rrrBrrnext_arghad_explicit_valuer7rrs rrzOptionParser._process_long_optsviill #::!iiQ//OS( LLH % % %!%  C!& ""3''$      LE5zzE!! 8DE),u==>????! ! eAeGn--!E'NN   JJq:;;cA B B B BEsE6400000rc|d}d}d}|ddD]}d|z}|j|}|dz }|st||r|t |kr |d||dd}|j} t || kr+|tdd| || dzn;| dkr|d} nt|d| } |d| =nd} | || |||rdSdS) NrFr%rTrrr) rr}rrrrrrrrr#rC) rrrBrrichrr7rrs rrz OptionParser._process_short_optssiill abb'  B(C_((--F FA *$S)))!!## s3xx<<LLCG,,,D u::%%JJxHI  -05!A!A BCCCCaZZ!IIaLLEE!%%.11Eag NN3vt 4 4 4  ?  rc||j/tjtjdS|jSr7)rrUpathbasenamererrs r get_prog_namezOptionParser.get_prog_names. 9 7##CHQK00 09 rcR|d|S)Nz%prog)rr)rss rexpand_prog_namezOptionParser.expand_prog_names"yy$"4"4"6"6777rc6||jSr )rrrs rrzOptionParser.get_descriptions$$T%5666rrcp|rtj|tj|dSr )restderrwriterG)rstatusr,s rrGzOptionParser.exits6  " J  S ! ! ! rc|tj|d|d|ddS)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. rPz : error: rN) print_usagererrGrr-s rrzOptionParser.errorsO $$$ !$*<*<*>*>*>*>DEEEEErcx|jr2|j||jSdSr)r~rrrrs r get_usagezOptionParser.get_usage#s@ : >..%%dj1133 32rc^|jr%t||dSdS)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)r~printr rrs rr zOptionParser.print_usage*s; : / $.."" . . . . . . / /rcH|jr||jSdSr)rrrs r get_versionzOptionParser.get_version6s' < ((66 62rc^|jr%t||dSdS)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)rrrrs rrHzOptionParser.print_version<s= < 1 $""$$4 0 0 0 0 0 0 1 1rcX||j}||g}||t d||jrC|t|||d|j D]?}|| ||d@| d |ddS)NOptionsrrkr) rrrrrCrvrrrrrrxrJ)rrrrs rrzOptionParser.format_option_helpGs  I&&t,,, i..q||<<===   MM/< 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. c>g|]}||Sr!)r)rwordrs rrz!_match_abbrev..s9000$ OOA..0000rr%r)rrrsortrE)rwordmaprGs` rrrts G||0000',,..000  }   " " # # 9 ## #    &q-88 8r)'r: __version____all__ __copyright__rerUrrrr ImportErrorrC Exceptionr rrrrrEr r r rrrrrrrrrrrrrrr rrr!rrr%s.    $ @JJJ )))))))))  Y= ;   66666m666 A A A A AN A A AMMMMMMMM^?????]???&GGGGG=GGG&      %aa ll3%qq||4!11%5#6#67%qq||477 GGG%%% nnnnnnnnf " #>#>#>#>#>#>#>#>#By!y!y!y!y!y!y!y!x?<]']']']']'O]']']'D999: s $ 22