B ïY6dÓëã@sÒdZdZdddddddd d d d d dddddgZdZddlZddlZddlZdd„ZyddlmZm Z Wn$e k rŠdd„Zdd„Z YnXeZ Gdd „d e ƒZ Gdd„de ƒZGdd„deƒZGd d„de ƒZGd!d„de ƒZGd"d#„d#eƒZGd$d „d ƒZGd%d „d eƒZGd&d „d eƒZd'd(„Zd)d*„Zee d+ƒfee d+ƒfee d,ƒfee d-ƒfd.œZd/d0„Zd1d„Zd2ZGd3d„dƒZd4Zd5Z Gd6d„dƒZ!Gd7d„dƒZ"Gd8d„de"ƒZ#Gd9d „d e"ƒZ$d:d;„Z%eZ&dS) 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_HELPÚSUPPRESS_USAGEÚValuesÚOptionContainerÚ OptionGroupÚ OptionParserÚ HelpFormatterÚIndentedHelpFormatterÚTitledHelpFormatterÚ OptParseErrorÚ OptionErrorÚOptionConflictErrorÚOptionValueErrorÚBadOptionErrorÚ 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__Úid)Úself©rú$/usr/local/lib/python3.7/optparse.pyÚ_reprOsr)ÚgettextÚngettextcCs|S)Nr)Úmessagerrrr\srcCs|dkr |S|S)Nér)ÚsingularÚpluralÚnrrrr_src@seZdZdd„Zdd„ZdS)r cCs ||_dS)N)Úmsg)rr!rrrÚ__init__hszOptParseError.__init__cCs|jS)N)r!)rrrrÚ__str__kszOptParseError.__str__N)rÚ __module__Ú __qualname__r"r#rrrrr gsc@s eZdZdZdd„Zdd„ZdS)r z] Raised if an Option instance is created with invalid or inconsistent arguments. cCs||_t|ƒ|_dS)N)r!ÚstrÚ option_id)rr!Úoptionrrrr"uszOptionError.__init__cCs |jrd|j|jfS|jSdS)Nz option %s: %s)r'r!)rrrrr#yszOptionError.__str__N)rr$r%Ú__doc__r"r#rrrrr osc@seZdZdZdS)rzE Raised if conflicting options are added to an OptionParser. N)rr$r%r)rrrrrsc@seZdZdZdS)rzS Raised if an invalid option value is encountered on the command line. N)rr$r%r)rrrrr„sc@s eZdZdZdd„Zdd„ZdS)rzB Raised if an invalid option is seen on the command line. cCs ||_dS)N)Úopt_str)rr*rrrr"ŽszBadOptionError.__init__cCstdƒ|jS)Nzno such option: %s)Ú_r*)rrrrr#‘szBadOptionError.__str__N)rr$r%r)r"r#rrrrrŠsc@s eZdZdZdd„Zdd„ZdS)ÚAmbiguousOptionErrorzD Raised if an ambiguous option is seen on the command line. cCst ||¡||_dS)N)rr"Ú possibilities)rr*r-rrrr"˜s zAmbiguousOptionError.__init__cCstdƒ|jd |j¡fS)Nzambiguous option: %s (%s?)z, )r+r*Újoinr-)rrrrr#œszAmbiguousOptionError.__str__N)rr$r%r)r"r#rrrrr,”sr,c@sŒeZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd „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 Cs¦d|_||_|dkrLyttjdƒ}Wnttfk rBd}YnX|d8}||_t|t |d|dƒƒ|_ |_ d|_ d|_ d|_||_d|_i|_d|_d|_dS) NÚCOLUMNSéPéérz%defaultz%s %sz%s=%s)ÚparserÚindent_incrementÚintÚosÚenvironÚKeyErrorÚ ValueErrorÚwidthÚminÚmaxÚ help_positionÚmax_help_positionÚcurrent_indentÚlevelÚ help_widthÚ short_firstÚ default_tagÚoption_stringsÚ_short_opt_fmtÚ _long_opt_fmt)rr5r?r;rCrrrr"Îs$  zHelpFormatter.__init__cCs ||_dS)N)r4)rr4rrrÚ set_parserçszHelpFormatter.set_parsercCs&|dkrtd|ƒ‚d|d|_dS)N)Úú z/invalid metavar delimiter for short options: %rz%s)r:rF)rÚdelimrrrÚset_short_opt_delimiterês z%HelpFormatter.set_short_opt_delimitercCs&|dkrtd|ƒ‚d|d|_dS)N)ú=rJz.invalid metavar delimiter for long options: %rz%s)r:rG)rrKrrrÚset_long_opt_delimiterðs z$HelpFormatter.set_long_opt_delimitercCs"|j|j7_|jd7_dS)Nr)r@r5rA)rrrrÚindentöszHelpFormatter.indentcCs4|j|j8_|jdks"tdƒ‚|jd8_dS)NrzIndent decreased below 0.r)r@r5ÚAssertionErrorrA)rrrrÚdedentúszHelpFormatter.dedentcCs tdƒ‚dS)Nzsubclasses must implement)ÚNotImplementedError)rÚusagerrrÚ format_usageÿszHelpFormatter.format_usagecCs tdƒ‚dS)Nzsubclasses must implement)rR)rÚheadingrrrÚformat_headingszHelpFormatter.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. é rJ)Úinitial_indentÚsubsequent_indent)r=r;r@ÚtextwrapÚfill)rÚtextÚ text_widthrOrrrÚ _format_texts  zHelpFormatter._format_textcCs|r| |¡dSdSdS)NÚ rI)r^)rÚ descriptionrrrÚformat_descriptionsz HelpFormatter.format_descriptioncCs|rd| |¡dSdSdS)Nr_rI)r^)rÚepilogrrrÚ format_epilogszHelpFormatter.format_epilogcCsP|jdks|js|jS|jj |j¡}|tks6|dkr<|j}|j |jt |ƒ¡S)N) r4rDÚhelpÚdefaultsÚgetÚdestÚ NO_DEFAULTÚNO_DEFAULT_VALUEÚreplacer&)rr(Ú default_valuerrrÚexpand_defaults zHelpFormatter.expand_defaultcsÚg}ˆj|}ˆjˆjd}t|ƒ|krBdˆjd|f}ˆj}ndˆjd||f}d}| |¡|jrºˆ |¡}t |ˆj ¡}| d|d|df¡|  ‡fdd„|dd…Dƒ¡n|d d krÐ| d ¡d  |¡S) Nr2z%*s%s rIz %*s%-*s rcsg|]}dˆjd|f‘qS)z%*s%s rI)r>)Ú.0Úline)rrrú Esz/HelpFormatter.format_option..réÿÿÿÿr_) rEr>r@ÚlenÚappendrdrlrZÚwraprBÚextendr.)rr(ÚresultÚoptsÚ opt_widthÚ indent_firstÚ help_textÚ help_linesr)rrÚ format_option(s$      zHelpFormatter.format_optioncCsÎ| ¡d}x6|jD],}| |¡}||j|<t|t|ƒ|jƒ}qW| ¡xF|jD]<}x6|jD],}| |¡}||j|<t|t|ƒ|jƒ}q`WqTW| ¡| ¡t |d|j ƒ|_ t|j |j dƒ|_ dS)Nrr2rW)rOÚ option_listÚformat_option_stringsrEr=rqr@Ú option_groupsrQr<r?r>r;rB)rr4Úmax_lenÚoptÚstringsÚgrouprrrÚstore_option_stringsKs        z"HelpFormatter.store_option_stringscst| ¡rF|jp|j ¡‰‡‡fdd„|jDƒ}‡‡fdd„|jDƒ}n |j}|j}ˆjrb||}n||}d |¡S)z@Return a comma-separated list of option strings & metavariables.csg|]}ˆj|ˆf‘qSr)rF)rmZsopt)Úmetavarrrrroasz7HelpFormatter.format_option_strings..csg|]}ˆj|ˆf‘qSr)rG)rmZlopt)r„rrrrocsz, )Ú takes_valuer„rgÚupperÚ _short_optsÚ _long_optsrCr.)rr(Ú short_optsÚ long_optsrvr)r„rrr}]s     z#HelpFormatter.format_option_stringsN)rr$r%r)rir"rHrLrNrOrQrTrVr^rarcrlr{rƒr}rrrrr ¡s")  #c@s*eZdZdZd dd„Zdd „Zd d „ZdS) r z.Format help with indented section bodies. r2éNrcCst |||||¡dS)N)r r")rr5r?r;rCrrrr"tszIndentedHelpFormatter.__init__cCs tdƒ|S)Nz Usage: %s )r+)rrSrrrrT|sz"IndentedHelpFormatter.format_usagecCsd|jd|fS)Nz%*s%s: rI)r@)rrUrrrrVsz$IndentedHelpFormatter.format_heading)r2r‹Nr)rr$r%r)r"rTrVrrrrr ps c@s*eZdZdZd dd„Zdd„Zd d „ZdS) r z1Format help with underlined section headers. rr‹NcCst |||||¡dS)N)r r")rr5r?r;rCrrrr"‡szTitledHelpFormatter.__init__cCsd| tdƒ¡|fS)Nz%s %s ZUsage)rVr+)rrSrrrrTsz TitledHelpFormatter.format_usagecCsd|d|jt|ƒfS)Nz%s %s z=-)rArq)rrUrrrrV’sz"TitledHelpFormatter.format_heading)rr‹Nr)rr$r%r)r"rTrVrrrrr ƒs cCsh|dd… ¡dkrd}nD|dd… ¡dkrDd}|dd…p@d}n|dd…dkrZd}nd}|||ƒS) Nr2Ú0xéÚ0bÚ0réé )Úlower)ÚvalÚtypeÚradixrrrÚ _parse_num–sr–cCs t|tƒS)N)r–r6)r“rrrÚ _parse_int£sr—Úintegerzfloating-pointÚcomplex)r6ÚlongÚfloatr™cCsFt|j\}}y||ƒStk r@ttdƒ|||fƒ‚YnXdS)Nzoption %s: invalid %s value: %r)Ú _builtin_cvtr”r:rr+)r(r€ÚvalueZcvtÚwhatrrrÚ check_builtin«s rŸcCs:||jkr|Sd tt|jƒ¡}ttdƒ|||fƒ‚dS)Nz, z.option %s: invalid choice: %r (choose from %s))Úchoicesr.ÚmapÚreprrr+)r(r€rr rrrr³s  )ÚNOÚDEFAULTc @sþeZdZdZdddddddd d d d d g ZdZdZdZdZdZ dZ e e e e e dœZ dZdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„ZeeeeeeegZd,d-„ZeZd.d/„Zd0d1„Zd2d3„Zd4d5„Z d6d7„Z!d8d9„Z"dS):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 Úactionr”rgÚdefaultÚnargsÚconstr ÚcallbackÚ callback_argsÚcallback_kwargsrdr„) ÚstoreÚ store_constÚ store_trueÚ store_falserrÚ append_constÚcountr©rdÚversion)r¬r­r®r¯rrr°r±)r¬rrr©)r¬rr)r­r°)Ústringr6ršr›r™Úchoice)r6ršr›r™r´NcOsFg|_g|_| |¡}| |¡| |¡x|jD] }||ƒq2WdS)N)r‡rˆÚ_check_opt_stringsÚ_set_opt_stringsÚ _set_attrsÚ CHECK_METHODS)rrvÚattrsÚcheckerrrrr"4s    zOption.__init__cCsdd„|Dƒ}|stdƒ‚|S)NcSsg|] }|r|‘qSrr)rmr€rrrroKsz-Option._check_opt_strings..z+at least one option string must be supplied)Ú TypeError)rrvrrrrµGszOption._check_opt_stringscCs¤xž|D]–}t|ƒdkr&td||ƒ‚qt|ƒdkrf|ddkrJ|ddksXtd||ƒ‚|j |¡q|dd…dkr‚|ddkstd||ƒ‚|j |¡qWdS) Nr2z>invalid option string %r: must be at least two characters longrú-rzMinvalid short option string %r: must be of the form -x, (x any non-dash char)z--zGinvalid long option string %r: must start with --, followed by non-dash)rqr r‡rrrˆ)rrvr€rrrr¶Ps$    zOption._set_opt_stringscCszxP|jD]F}||kr,t||||ƒ||=q|dkrBt||tƒqt||dƒqW|rvt| ¡ƒ}tdd |¡|ƒ‚dS)Nr¦zinvalid keyword arguments: %sz, )ÚATTRSÚsetattrrhÚsortedÚkeysr r.)rr¹Úattrrrrr·es   zOption._set_attrscCs2|jdkrd|_n|j|jkr.td|j|ƒ‚dS)Nr¬zinvalid action: %r)r¥ÚACTIONSr )rrrrÚ _check_actionxs  zOption._check_actioncCs’|jdkr0|j|jkrŽ|jdk r(d|_qŽd|_n^t|jtƒrF|jj|_|jdkrVd|_|j|jkrrtd|j|ƒ‚|j|jkrŽtd|j|ƒ‚dS)Nr´r³r&zinvalid option type: %rz$must not supply a type for action %r) r”r¥ÚALWAYS_TYPED_ACTIONSr Ú isinstancerÚTYPESr Ú TYPED_ACTIONS)rrrrÚ _check_type~s        zOption._check_typecCsr|jdkrT|jdkr td|ƒ‚qnt|jttfƒsntdtt|jƒƒ d¡d|ƒ‚n|jdk rntd|j|ƒ‚dS)Nr´z/must supply a list of choices for type 'choice'z1choices must be a list of strings ('%s' supplied)ú'rz#must not supply choices for type %r)r”r r rÅÚtupleÚlistr&Úsplit)rrrrÚ _check_choice–s     zOption._check_choicecCs\|j|jkp|jdk }|jdkrX|rX|jrH|jddd… dd¡|_n|jdd|_dS)Nrr2r¼r+r)r¥Ú STORE_ACTIONSr”rgrˆrjr‡)rr…rrrÚ _check_dest£s   zOption._check_destcCs*|j|jkr&|jdk r&td|j|ƒ‚dS)Nz*'const' must not be supplied for action %r)r¥Ú CONST_ACTIONSr¨r )rrrrÚ _check_const²szOption._check_constcCs<|j|jkr|jdkr8d|_n|jdk r8td|j|ƒ‚dS)Nrz*'nargs' must not be supplied for action %r)r¥rÇr§r )rrrrÚ _check_nargs¸s   zOption._check_nargscCs¸|jdkrrt|jƒs$td|j|ƒ‚|jdk rJt|jtƒsJtd|j|ƒ‚|jdk r´t|jtƒs´td|j|ƒ‚nB|jdk rŒtd|j|ƒ‚|jdk r td|ƒ‚|jdk r´td|ƒ‚dS)Nr©zcallback not callable: %rz3callback_args, if supplied, must be a tuple: not %rz4callback_kwargs, if supplied, must be a dict: not %rz.callback supplied (%r) for non-callback optionz.callback_args supplied for non-callback optionz0callback_kwargs supplied for non-callback option) r¥Úcallabler©r rªrÅrÊr«Údict)rrrrÚ_check_callbackÁs0           zOption._check_callbackcCsd |j|j¡S)Nú/)r.r‡rˆ)rrrrr#èszOption.__str__cCs |jdk S)N)r”)rrrrr…íszOption.takes_valuecCs|jr|jdS|jdSdS)Nr)rˆr‡)rrrrÚget_opt_stringðs zOption.get_opt_stringcCs*|j |j¡}|dkr|S||||ƒSdS)N)Ú TYPE_CHECKERrfr”)rr€rrºrrrÚ check_valueùszOption.check_valuecs:|dk r6ˆjdkrˆ ˆ|¡St‡‡fdd„|DƒƒSdS)Nrcsg|]}ˆ ˆ|¡‘qSr)rÙ)rmÚv)r€rrrrosz(Option.convert_value..)r§rÙrÊ)rr€rr)r€rrÚ convert_values  zOption.convert_valuecCs$| ||¡}| |j|j||||¡S)N)rÛÚ take_actionr¥rg)rr€rÚvaluesr4rrrÚprocesss zOption.processc Cs:|dkrt|||ƒn|dkr2t|||jƒn|dkrHt||dƒnî|dkr^t||dƒnØ|dkrz| |g¡ |¡n¼|dkr˜| |g¡ |j¡nž|d krºt||| |d ¡d ƒn||d krð|jpÊd }|jpÔi}|j||||f|ž|ŽnF|dkr | ¡| ¡n*|dkr(|  ¡| ¡nt d|j ƒ‚d S)Nr¬r­r®Tr¯Frrr°r±rrr©rrdr²zunknown action %r) r¾r¨Ú ensure_valuerrrªr«r©Ú print_helpÚexitÚ print_versionr:r¥) rr¥rgr€rrÝr4ÚargsÚkwargsrrrrÜs4      zOption.take_action)#rr$r%r)r½rÂrÎrÇrÄrÐrÆrŸrrØr¸r"rµr¶r·rÃrÈrÍrÏrÑrÒrÕr#rÚ__repr__r…r×rÙrÛrÞrÜrrrrrÁsf       Z SUPPRESSHELPZ SUPPRESSUSAGEc@s^eZdZddd„Zdd„ZeZdd„Zdd „Zd d „Z d d „Z ddd„Z ddd„Z dd„Z dS)rNcCs*|r&x | ¡D]\}}t|||ƒqWdS)N)Úitemsr¾)rrerÁr“rrrr"9szValues.__init__cCs t|jƒS)N)r&Ú__dict__)rrrrr#>szValues.__str__cCs2t|tƒr|j|jkSt|tƒr*|j|kStSdS)N)rÅrrçrÔÚNotImplemented)rÚotherrrrÚ__eq__Cs     z Values.__eq__cCs:x4t|ƒD](}||kr ||}|dk r t|||ƒq WdS)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¾)rrÔrÁÚdvalrrrÚ_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)rçÚupdate)rrÔrrrÚ _update_looseXszValues._update_loosecCs8|dkr| |¡n |dkr(| |¡n td|ƒ‚dS)NÚcarefulÚloosezinvalid update mode: %r)rírïr:)rrÔÚmoderrrÚ_update`s   zValues._updaterðcCs&t|ƒtj|}| t|ƒ|¡dS)N)Ú __import__ÚsysÚmodulesróÚvars)rÚmodnameròÚmodrrrÚ read_modulehs zValues.read_modulecCs&i}tt|ƒ ¡|ƒ| ||¡dS)N)ÚexecÚopenÚreadró)rÚfilenameròr÷rrrÚ read_filemszValues.read_filecCs.t||ƒrt||ƒdkr$t|||ƒt||ƒS)N)ÚhasattrÚgetattrr¾)rrÁrrrrrßrs zValues.ensure_value)N)rð)rð)rr$r%r"r#rrårêrírïrórúrÿrßrrrrr7s    c@seZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd 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&| ¡||_| |¡| |¡dS)N)Ú_create_option_listÚ option_classÚset_conflict_handlerÚset_description)rrÚconflict_handlerr`rrrr"˜s zOptionContainer.__init__cCsi|_i|_i|_dS)N)Ú _short_optÚ _long_optre)rrrrÚ_create_option_mappings£sz'OptionContainer._create_option_mappingscCs|j|_|j|_|j|_dS)N)rrre)rr4rrrÚ_share_option_mappings¬sz&OptionContainer._share_option_mappingscCs|dkrtd|ƒ‚||_dS)N)ÚerrorÚresolvez$invalid conflict_resolution value %r)r:r)rÚhandlerrrrr³s z$OptionContainer.set_conflict_handlercCs ||_dS)N)r`)rr`rrrr¸szOptionContainer.set_descriptioncCs|jS)N)r`)rrrrÚget_description»szOptionContainer.get_descriptioncCs|`|`|`dS)zsee OptionParser.destroy().N)rrre)rrrrÚdestroy¿szOptionContainer.destroycCsþg}x,|jD]"}||jkr | ||j|f¡q Wx,|jD]"}||jkr:| ||j|f¡q:W|rú|j}|dkr’tdd dd„|Dƒ¡|ƒ‚nh|dkrúx^|D]V\}}| d¡rÈ|j  |¡|j|=n|j  |¡|j|=|js |js |j j   |¡q WdS)Nr z conflicting option string(s): %sz, cSsg|] }|d‘qS)rr)rmÚcorrrroÖsz3OptionContainer._check_conflict..r z--) r‡rrrrˆrrrr.Ú startswithÚremoveÚ containerr|)rr(Z conflict_optsr€r Zc_optionrrrÚ_check_conflictÈs.         zOptionContainer._check_conflictcOsät|dtƒr|j||Ž}n8t|ƒdkrL|sL|d}t|tƒsTtd|ƒ‚ntdƒ‚| |¡|j |¡||_ x|j D]}||j |<qxWx|j D]}||j |<q’W|jdk rà|jtk rÈ|j|j|j<n|j|jkràd|j|j<|S)zOadd_option(Option) add_option(opt_str, ..., kwarg=val, ...) rrznot an Option instance: %rzinvalid argumentsN)rÅr&rrqrr»rr|rrrr‡rrˆrrgr¦rhre)rrãrär(r€rrrÚ add_optionãs(         zOptionContainer.add_optioncCsx|D]}| |¡qWdS)N)r)rr|r(rrrÚ add_optionss zOptionContainer.add_optionscCs|j |¡p|j |¡S)N)rrfr)rr*rrrÚ get_options zOptionContainer.get_optioncCs||jkp||jkS)N)rr)rr*rrrÚ has_option s zOptionContainer.has_optioncCsv|j |¡}|dkr |j |¡}|dkr4td|ƒ‚x|jD] }|j|=qd?„Z"d@dA„Z#dSdBdC„Z$dDdE„Z%dTdFdG„Z&dUdHdI„Z'dJdK„Z(dVdLdM„Z)dWdNdO„Z*dS)Xra$ 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. Nr Tc Csrt ||||¡| |¡| |_||_d|_d|_|dkr@tƒ}||_|j  |¡| |_ |j ||d|  ¡dS)NT)Úadd_help) rr"Ú set_usageÚprogr²Úallow_interspersed_argsÚprocess_default_valuesr rrHrbÚ_populate_option_listÚ_init_parsing_state) rrSr|rr²rr`rÚadd_help_optionr!rbrrrr"šs    zOptionParser.__init__cCs2t |¡x|jD] }| ¡qW|`|`|`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)rrr~r|r)rr‚rrrr¼s    zOptionParser.destroycCsg|_g|_| ¡dS)N)r|r~r )rrrrrÎsz OptionParser._create_option_listcCs|jdddtdƒddS)Nz-hz--helprdzshow this help message and exit)r¥rd)rr+)rrrrÚ_add_help_optionÓszOptionParser._add_help_optioncCs|jddtdƒddS)Nz --versionr²z&show program's version number and exit)r¥rd)rr+)rrrrÚ_add_version_optionØsz OptionParser._add_version_optioncCs>|jr| |j¡|r | |¡|jr.| ¡|r:| ¡dS)N)Ústandard_option_listrr²r(r')rr|rrrrr$Ýs  z"OptionParser._populate_option_listcCsd|_d|_d|_dS)N)ÚrargsÚlargsrÝ)rrrrr%çsz OptionParser._init_parsing_statecCsL|dkrtdƒ|_n4|tkr$d|_n$| ¡ d¡rB|dd…|_n||_dS)Nz%prog [options]zusage: é)r+rSrr’r)rrSrrrr ðs zOptionParser.set_usagecCs 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.TN)r")rrrrÚenable_interspersed_argsûsz%OptionParser.enable_interspersed_argscCs d|_dS)zéSet 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. FN)r")rrrrÚdisable_interspersed_argssz&OptionParser.disable_interspersed_argscCs ||_dS)N)r#)rrÞrrrÚset_process_default_values sz'OptionParser.set_process_default_valuescCs||j|<dS)N)re)rrgrrrrÚ set_defaultszOptionParser.set_defaultcKs|j |¡dS)N)rerî)rrärrrÚ set_defaultsszOptionParser.set_defaultscCs.|jdd…}x|jD]}| |j¡qW|S)N)r|r~rt)rÚoptionsr‚rrrÚ_get_all_optionss zOptionParser._get_all_optionscCsd|jst|jƒS|j ¡}x@| ¡D]4}| |j¡}t|tƒr$|  ¡}|  ||¡||j<q$Wt|ƒS)N) r#rreÚcopyr3rfrgrÅr&r×rÙ)rrer(r¦r*rrrÚget_default_valuess    zOptionParser.get_default_valuescOszt|dtƒr t|f|ž|Ž}nJt|ƒdkrb|sb|d}t|tƒsNtd|ƒ‚|j|k rjtdƒ‚ntdƒ‚|j |¡|S)Nrrznot an OptionGroup instance: %rz"invalid OptionGroup (wrong parser)zinvalid arguments) rÅr&rrqr»r4r:r~rr)rrãrär‚rrrÚadd_option_group+s     zOptionParser.add_option_groupcCs0|j |¡p|j |¡}|r,|j|k r,|jSdS)N)rrfrr)rr*r(rrrÚget_option_group;s   zOptionParser.get_option_groupcCs&|dkrtjdd…S|dd…SdS)Nr)rõÚargv)rrãrrrÚ _get_argsEszOptionParser._get_argsc CsŒ| |¡}|dkr| ¡}||_g|_}||_y| |||¡}Wn4ttfk rv}z| t |ƒ¡Wdd}~XYnX||}|  ||¡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) r9r5r*r+rÝÚ _process_argsrrr r&Ú check_values)rrãrÝr*r+ÚstopÚerrrrrÚ 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)rrÝrãrrrr;rs zOptionParser.check_valuescCsŒx†|r†|d}|dkr |d=dS|dd…dkr>| ||¡q|dd…dkrht|ƒdkrh| ||¡q|jr€| |¡|d=qdSqWdS)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'. rz--Nr2rr¼)Ú_process_long_optrqÚ_process_short_optsr"rr)rr+r*rÝÚargrrrr:s  zOptionParser._process_argscCs t||jƒS)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)rr€rrrÚ_match_long_opt²szOptionParser._match_long_optc Csè| d¡}d|kr4| dd¡\}}| d|¡d}n|}d}| |¡}|j|}| ¡r¸|j}t|ƒ|krˆ| t dd|ƒ||dœ¡qÔ|dkrœ| d¡} qÔt |d|…ƒ} |d|…=n|rÐ| t d ƒ|¡nd} |  || ||¡dS) NrrMrTFz.%(option)s option requires %(number)d argumentz/%(option)s option requires %(number)d arguments)r(Únumberz%s option does not take a value) ÚpoprÌÚinsertrCrr…r§rqr rrÊr+rÞ) rr*rÝrAr€Znext_argZhad_explicit_valuer(r§rrrrr?»s0       zOptionParser._process_long_optc Csú| d¡}d}d}xâ|dd…D]Ò}d|}|j |¡}|d7}|sLt|ƒ‚| ¡rØ|t|ƒkrx| d||d…¡d}|j} t|ƒ| kr¨| t dd| ƒ|| dœ¡qÜ| dkr¼| d¡} qÜt |d| …ƒ} |d| …=nd} |  || ||¡|r Pq WdS) NrFrr¼Tz.%(option)s option requires %(number)d argumentz/%(option)s option requires %(number)d arguments)r(rD) rErrfrr…rqrFr§r rrÊrÞ) rr*rÝrAr<ÚiÚchr€r(r§rrrrr@ßs6      z OptionParser._process_short_optscCs&|jdkrtj tjd¡S|jSdS)Nr)r!r7ÚpathÚbasenamerõr8)rrrrÚ get_prog_names zOptionParser.get_prog_namecCs| d| ¡¡S)Nz%prog)rjrK)rÚsrrrÚexpand_prog_nameszOptionParser.expand_prog_namecCs | |j¡S)N)rMr`)rrrrrszOptionParser.get_descriptionrcCs|rtj |¡t |¡dS)N)rõÚstderrÚwriterá)rÚstatusr!rrrrás zOptionParser.exitcCs(| tj¡| dd| ¡|f¡dS)zÜerror(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. r2z%s: error: %s N)Ú print_usagerõrNrárK)rr!rrrr s zOptionParser.errorcCs"|jr|j | |j¡¡SdSdS)NrI)rSrrTrM)rrrrÚ get_usage#szOptionParser.get_usagecCs|jrt| ¡|ddS)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)rSÚprintrR)rrSrrrrQ*s zOptionParser.print_usagecCs|jr| |j¡SdSdS)NrI)r²rM)rrrrÚ get_version6s zOptionParser.get_versioncCs|jrt| ¡|ddS)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. )rSN)r²rTrU)rrSrrrrâ<szOptionParser.print_versioncCsž|dkr|j}| |¡g}| | tdƒ¡¡| ¡|jrZ| t ||¡¡| d¡x(|j D]}| |  |¡¡| d¡qbW|  ¡d  |dd…¡S)NÚOptionsr_rIrp) rrƒrrrVr+rOr|rrr~rrQr.)rrrur‚rrrrGs   zOptionParser.format_option_helpcCs | |j¡S)N)rcrb)rrrrrrcXszOptionParser.format_epilogcCsn|dkr|j}g}|jr*| | ¡d¡|jrD| | |¡d¡| | |¡¡| | |¡¡d |¡S)Nr_rI) rrSrrrRr`rarrcr.)rrrurrrr[szOptionParser.format_helpcCs |dkrtj}| | ¡¡dS)z°print_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õÚstdoutrOr)rrSrrrràgszOptionParser.print_help)T)NN)rN)N)N)N)N)N)+rr$r%r)r)rr"rrr'r(r$r%r r-r.r/r0r1r3r5r6r7r9r>r;r:rCr?r@rKrMrrár rRrQrUrârrcrràrrrrrRs`D      ' 3 $)     csZˆ|kr ˆS‡fdd„| ¡Dƒ}t|ƒdkr6|dS|sDtˆƒ‚n| ¡tˆ|ƒ‚dS)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)r)rmÚword)rLrrro€sz!_match_abbrev..rrN)rÀrqrÚsortr,)rLZwordmapr-r)rLrrBts  rB)'r)Ú __version__Ú__all__Ú __copyright__rõr7rZrrrÚ ImportErrorr+Ú Exceptionr r rrrr,r r r r–r—r›r™rœrŸrrhrrrrrrrrBrrrrrÚs~    P     uA=&