m %UIc@sdZdZdddddddd d d d d dddgZdZdkZdkZdkZdkZdklZ dZ d e fdYZ d e fdYZ de fdYZde fdYZde fdYZd fdYZd efdYZd efdYZhdee df<dee d f<d!ee d"f<d#ee d#f Originally distributed as Optik; see http://optik.sourceforge.net/ . If you have problems with this module, please do not file bugs, patches, or feature requests with Python; instead, use Optik's SourceForge project page: http://sourceforge.net/projects/optik For support, use the optik-users@lists.sourceforge.net mailing list (http://lists.sourceforge.net/lists/listinfo/optik-users). s1.5a2tOptiont SUPPRESS_HELPtSUPPRESS_USAGEtValuestOptionContainert OptionGroupt OptionParsert HelpFormattertIndentedHelpFormattertTitledHelpFormattert OptParseErrort OptionErrortOptionConflictErrortOptionValueErrortBadOptionErrors" Copyright (c) 2001-2004 Gregory P. Ward. All rights reserved. Copyright (c) 2002-2004 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. N(sgettextcCsd|iit||fS(Ns<%s at 0x%x: %s>(tselft __class__t__name__tid(R((t%/data/zmath/lib/python2.4/optparse.pyt_reprJscBstZdZdZRS(NcCs ||_dS(N(tmsgR(RR((Rt__init__UscCs|iS(N(RR(R((Rt__str__Xs(Rt __module__RR(((RR Ts cBs tZdZdZdZRS(s] Raised if an Option instance is created with invalid or inconsistent arguments. cCs||_t||_dS(N(RRtstrtoptiont option_id(RRR((RRbs cCs-|iod|i|ifSn|iSdS(Ns option %s: %s(RRR(R((RRfs (RRt__doc__RR(((RR \s  cBstZdZRS(sE Raised if conflicting options are added to an OptionParser. (RRR(((RR ls cBstZdZRS(sS Raised if an invalid option value is encountered on the command line. (RRR(((RR qs cBstZdZRS(sO Raised if an invalid or ambiguous option is seen on the command-line. (RRR(((RRws cBstZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZRS(s 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"). tnonecCsd|_||_||_|_|djoGytti d}Wnt t fj o d}nX|d8}n||_d|_ d|_ d|_||_d|_h|_d|_d|_dS(NtCOLUMNSiPiis%defaults%s %ss%s=%s(tNoneRtparsertindent_incrementtmax_help_positiont help_positiontwidthtinttostenvirontKeyErrort ValueErrortcurrent_indenttlevelt help_widtht short_firstt default_tagtoption_stringst_short_opt_fmtt _long_opt_fmt(RR!R"R$R-((RRs$            cCs ||_dS(N(R R(RR ((Rt set_parserscCs6|djotd|nd|d|_dS(Ntt s/invalid metavar delimiter for short options: %rs%s(R3R4(tdelimR)RR0(RR5((Rtset_short_opt_delimiters cCs6|djotd|nd|d|_dS(Nt=R4s.invalid metavar delimiter for long options: %rs%s(R7R4(R5R)RR1(RR5((Rtset_long_opt_delimiters cCs%|i|i7_|id7_dS(Ni(RR*R!R+(R((RtindentscCs?|i|i8_|idjp td|id8_dS(NisIndent decreased below 0.i(RR*R!tAssertionErrorR+(R((RtdedentscCs tddS(Nssubclasses must implement(tNotImplementedError(Rtusage((Rt format_usagescCs tddS(Nssubclasses must implement(R<(Rtheading((Rtformat_headingscCsL|pdSn|i|i}d|i}ti||d|d|dS(NR3R4tinitial_indenttsubsequent_indents (t descriptionRR$R*t desc_widthR9ttextwraptfill(RRCRDR9((Rtformat_descriptions  cCs|idjp |i o |iSn|iii|i}|t jp |djo |i }n|ii |it |S(N(RR RR.Rthelptdefaultstgettdestt default_valuet NO_DEFAULTtNO_DEFAULT_VALUEtreplaceR(RRRL((Rtexpand_defaults   c CsDg}|i|}|i|id}t||jo#d|id|f}|i}n d|id||f}d}|i ||i o|i |}ti||i} |i d|d| df|ig}| dD]}|d|id|fq~n#|ddjo|i dndi|S( Nis%*s%s R3s %*s%-*s iiis (tresultRR/RtoptsR#R*t opt_widthtlent indent_firsttappendRHRPt help_textREtwrapR,t help_linestextendt_[1]tlinetjoin( RRRUR[RSRQRWR\RRRY((Rt format_options"    @cCs |id}xI|iD]>}|i|}||i|}|i|}||i|R@RGRPR^RhRb(((RR}s )         # cBs5tZdZddeddZdZdZRS(s.Format help with indented section bodies. iiicCsti|||||dS(N(RRRR!R"R$R-(RR!R"R$R-((RR@scCstd|S(Ns usage: %s (t_R=(RR=((RR>HscCsd|id|fS(Ns%*s%s: R3(RR*R?(RR?((RR@Ks(RRRRRR>R@(((RR<s  cBs5tZdZddeddZdZdZRS(s1Format help with underlined section headers. iicCsti|||||dS(N(RRRR!R"R$R-(RR!R"R$R-((RRSscCsd|itd|fS(Ns%s %s tUsage(RR@RrR=(RR=((RR>[scCsd|d|it|fS(Ns%s %s s=-(R?RR+RT(RR?((RR@^s(RRRRRR>R@(((RR Os  R%tintegertlongs long integertfloatsfloating-pointtcomplexcCsZt|i\}}y||SWn2tj o&ttd|||fnXdS(Nsoption %s: invalid %s value: %r( t _builtin_cvtRttypetcvttwhattvalueR)R RrRa(RRaR|R{Rz((Rt check_builtings cCsV||ijo|Sn;ditt|i}ttd|||fdS(Ns, s.option %s: invalid choice: %r (choose from %s)( R|RtchoicesR]tmaptreprR RrRa(RRaR|R~((Rt check_choiceostNOtDEFAULTc BsRtZdZddddddddd d d d g Zd,Zd-Zd.Zd/Zd0Zhde <de <de <de <de invalid option string %r: must be at least two characters longit-isMinvalid short option string %r: must be of the form -x, (x any non-dash char)s--sGinvalid long option string %r: must start with --, followed by non-dash(RRRaRTR RRlRVRo(RRRRa((RRs  "  %  cCsxq|iD]f}|i|ot||||||=q |djot||tq t||dq W|o6|i}|i t ddi ||ndS(NRsinvalid keyword arguments: %ss, ( RtATTRStattrRthas_keytsetattrRMRtkeystsortR R](RRR((RRs     cCsN|idjo d|_n.|i|ijotd|i|ndS(NRsinvalid action: %r(RRRtACTIONSR (R((Rt _check_action/s cCs|idjoA|i|ijo*|idj o d|_qMd|_qnt|itjo|ii|_n|idjo d|_n|i|ijotd|i|n|i|i jotd|i|ndS(NRRRsinvalid option type: %rs$must not supply a type for action %r( RRyRRtALWAYS_TYPED_ACTIONSR~RtTYPESR t TYPED_ACTIONS(R((Rt _check_type5s  cCs|idjo||idjotd|qt|ititifjo3tdtt|ii dd|qn+|idj otd|i|ndS(NRs/must supply a list of choices for type 'choice's1choices must be a list of strings ('%s' supplied)t'is#must not supply choices for type %r( RRyR~RR ttypest TupleTypetListTypeRtsplit(R((Rt _check_choiceKs"&cCs|i|ijp |idj }|idjoM|oF|io$|iddidd|_q|i dd|_ndS(NiiRRri( RRt STORE_ACTIONSRyRRiRKRoRORl(RRi((Rt _check_destXs " $cCs>|idjo*|idj otd|i|ndS(NRs*'const' must not be supplied for action %r(RRRRR (R((Rt _check_constgs  cCsb|i|ijo!|idjo d|_q^n+|idj otd|i|ndS(Nis*'nargs' must not be supplied for action %r(RRRRRR (R((Rt _check_nargsms  cCs8|idjot|iptd|i|n|idj o3t|iti j otd|i|n|i dj o3t|i ti j otd|i |q4nq|idj otd|i|n|idj otd|n|i dj otd|ndS(NRscallback not callable: %rs3callback_args, if supplied, must be a tuple: not %rs4callback_kwargs, if supplied, must be a dict: not %rs.callback supplied (%r) for non-callback options.callback_args supplied for non-callback options0callback_kwargs supplied for non-callback option( RRtcallableRR RRRyRRRtDictType(R((Rt_check_callbackvs )  )   cCsdi|i|iS(Nt/(R]RRlRo(R((RRscCs |idj S(N(RRyR(R((RRiscCs(|io|idSn |idSdS(Ni(RRoRl(R((Rtget_opt_strings cCs>|ii|i}|djo|Sn||||SdS(N(Rt TYPE_CHECKERRJRyRRR|Ra(RRaR|R((Rt check_values cCsj|dj oY|idjo|i||Sqftg}|D]}||i||q?~SndS(Ni( R|RRRRRattupleR[tv(RRaR|R[R((Rt convert_values cCs4|i||}|i|i|i||||S(N( RRRaR|t take_actionRRKtvaluesR (RRaR|RR ((Rtprocesssc Cs|djot|||ni|djot|||inE|djot||tn$|djot||tn|djo|i |gi |n|djo$t|||i |ddn|d jo@|i pf}|i ph}|i||||||n[|d jo|i|in6|d jo|i|intd |idS( NRRRRRVRiiRRHRsunknown action %r(RRRRKR|RRtTruetFalset ensure_valueRVRtargsRtkwargsRRaR t print_helptexitt print_versiont RuntimeError( RRRKRaR|RR RR((RRs0      $      ( sstores store_consts store_trues store_falsesappendscountscallbackshelpsversion(sstores store_consts store_trues store_falsesappendscount(sstoresappendscallback(sstoresappend(sstringsintslongsfloatscomplexschoice("RRRRRRRRRR}RRRRRRRRRRRRRRRRRt__repr__RiRRRRR(((RR}s: *  3             tSUPPRESStHELPtUSAGEiicBsqtZddZdZeZdZdZdZ dZ dZ dd Z dd Z d ZRS( NcCs<|o1x.|iD]\}}t|||qWndS(N(RItitemsRtvalRR(RRIRR((RRs cCs t|iS(N(RRt__dict__(R((RRscCsMt|to|i|ijSn&t|to|i|jSntSdS(N(t isinstancetotherRRRtdictR(RR((Rt__eq__s cCs ||j S(N(RR(RR((Rt__ne__ scCsZxSt|D]E}|i|o/||}|dj ot|||qRq q WdS(s 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(tdirRRRRtdvalRR(RRRR((Rt_update_careful s   cCs|ii|dS(s 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(RRtupdateR(RR((Rt _update_loosescCsM|djo|i|n,|djo|i|ntd|dS(Ntcarefultloosesinvalid update mode: %r(tmodeRRRRR)(RRR((Rt_update!s   RcCs1t|ti|}|it||dS(N( t __import__tmodnametsystmodulestmodRRtvarsR(RRRR((Rt read_module)s  cCs'h}t|||i||dS(N(RtexecfiletfilenameRRR(RRRR((Rt read_file.s cCsHt|| pt||djot|||nt||S(N(thasattrRRtgetattrRRR|(RRR|((RR3s'(RRRRRRRRRRRRRRR(((RRs        cBstZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZRS(s 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 appears 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. cCs1|i||_|i||i|dS(N(Rt_create_option_listt option_classtset_conflict_handlertconflict_handlertset_descriptionRC(RRRRC((RRYs   cCsh|_h|_h|_dS(N(Rt _short_optt _long_optRI(R((Rt_create_option_mappingsds  cCs(|i|_|i|_|i|_dS(N(R RRRRI(RR ((Rt_share_option_mappingsms  cCs+|djotd|n||_dS(Nterrortresolves$invalid conflict_resolution value %r(serrorR(thandlerR)RR(RR((RRts cCs ||_dS(N(RCR(RRC((RRyscCs|iS(N(RRC(R((Rtget_description|scCsg}xB|iD]7}|ii|o|i||i|fqqWxB|iD]7}|i i|o|i||i |fqUqUW|o|i }|djo?t ddi g}|D]}||dq~|q|djox|D]\}}|ido|ii||i |=n|ii||i|=|ip|ip|iii|qqWqndS(NRs conflicting option string(s): %ss, iRs--(t conflict_optsRRlRaRRRRVRoRRRR R]R[tcotc_optiont startswithtremovet containerR`(RRRaRR[RRR((Rt_check_conflicts0 " "  2    cOsTt|dtijo|i||}nTt|djo7| o/|d}t |t pt d|qn t d|i ||i i|||_x|iD]}||i| (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 an Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options. N(RR#RRRRRRt _process_argststopRR terrRRt check_values(RRRR&RR%R((Rt parse_argss      cCs ||fS(s 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. N(RR(RRR((RR's cCsx|o|d}|djo|d=dSq|dd!djo|i||q|d djo't|djo|i||q|io|i ||d=qdSqWdS(s_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'. is--NiiR( RtargRt_process_long_optRRTt_process_short_optsR RRV(RRRRR)((RR$s   $   cCst||iS(s_match_long_opt(opt : string) -> string Determine which long option string 'opt' matches, ie. which one it is an unambiguous abbrevation for. Raises BadOptionError if 'opt' doesn't unambiguously match any long option string. N(t _match_abbrevRaRR(RRa((Rt_match_long_optDsc Csk|id} d| jo2| idd\}}|id|t}n | }t }|i |}|i |}|io|i}t||joI|djo|itd|q%|itd||fqQ|djo|id}qQt|d|!}|d|5n)|o|itd|nd}|i||||dS(NiR7is%s option requires an arguments%s option requires %d argumentss%s option does not take a value(RtpopR)RRatnext_argtinsertRthad_explicit_valueRRR-RRRiRRTRRrR|RRRR( RRRRaRR/RR1R|R)((RR*Ms.      ! c Cs|id} t}d}xf| dD]Z}d|}|i i |}|d7}|p|i t d|n|io|t| jo|id| |t}n|i}t||joI|djo|i t d|qT|i t d||fq^|djo|id} q^t|d|!} |d|5nd} |i|| |||oPq&q&WdS(NiiRsno such option: %ss%s option requires an arguments%s option requires %d arguments(RR.R)RR%titchRaRRRJRRRrRiRTR0RRR|RRRR( RRRRaR3RR2RR%R|R)((RR+rs6       ! cCs6|idjotiitidSn|iSdS(Ni(RR RR&tpathtbasenameRR"(R((Rt get_prog_namescCs|id|iS(Ns%prog(tsRORR6(RR7((Rtexpand_prog_namescCs|i|iS(N(RR8RC(R((RRsicCs,|otii|nti|dS(N(RRtstderrtwriteRtstatus(RR;R((RRscCs4|iti|idd|i|fdS(serror(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. is%s: error: %s N(Rt print_usageRR9RR6R(RR((RRscCs2|io |ii|i|iSndSdS(NR3(RR=RR>R8(R((Rt get_usages  cCs"|io||iIJndS(s`print_usage(file : file = stdout) Print the usage message for the current program (self.usage) to 'file' (default stdout). Any occurence 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. N(RR=tfileR=(RR>((RR<s cCs&|io|i|iSndSdS(NR3(RRR8(R((Rt get_versions cCs"|io||iIJndS(sDprint_version(file : file = stdout) Print the version message for this program (self.version) to 'file' (default stdout). As with print_usage(), any occurence of "%prog" in self.version is replaced by the current program's name. Does nothing if self.version is empty or undefined. N(RRR>R?(RR>((RRs cCs|djo |i}n|i|g}|i|itd|i|i o*|it i |||idnx4|i D])}|i|i||idqW|idi|d S(NRs R3i(RRRRhRQRVR@RrR9R`RRReRfRR;R](RRRfRQ((RRs       cCs|djo |i}ng}|io|i|idn|io|i|i|dn|i|i |di |S(Ns R3( RRRRQR=RVR=RCRGRR](RRRQ((RRs    cCs1|djo ti}n|i|idS(sprint_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>RRtstdoutR:RR(RR>((RRs  (*RRRRRRRRRRRRRR RRRRRRRR R!R#R(R'R$R-R*R+R6R8RRRR=R<R?RRRR(((RRsJ =$"            ' 3 % *       cCs|i|o|Sng}|iD]!}|i|o ||q)q)~}t|djo |dSnQ|pt t d|n0|i t t d|di |fdS(s_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. iisno such option: %ssambiguous option: %s (%s?)s, N( twordmapRR7R[RtwordRt possibilitiesRTRRrRR](R7RAR[RBRC((RR,s;  (+Rt __version__t__all__t __copyright__RR&RREtgettextRrRt ExceptionR R R R RRRR R%RuRvRwRxR}RRMRRRRRt NameErrorRRtunicodeRRRRR,t make_option(!RR}RxRR R RRRER RRDRRRRRERR RRMRRRrRRFR RR,RRKRR&((Rt?sN3     Z  k  D