Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
 lŽŒY¸ëã@s¡dZdZdddddddd d d d d ddddgZdZddlZddlZddlZdd„ZyddlmZm Z Wn*e k r¾dd„Zdd„Z YnXeZ Gdd „d e ƒZ Gdd„de ƒZGdd„deƒZGdd„de ƒZGd d„de ƒZGd!d"„d"eƒZGd#d „d ƒZGd$d „d eƒZGd%d „d eƒZd&d'„Zd(d)„Zd*ee d+ƒfd,ee d+ƒfd-ee d.ƒfd/ee d/ƒfiZd0d1„Zd2d3„Zd4d5fZGd6d„dƒZd7d8Zd7d9Z Gd:d„dƒZ!Gd;d„dƒZ"Gd<d„de"ƒZ#Gd=d „d e"ƒZ$d>d?„Z%eZ&dS)@a§A 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_HELPÚSUPPRESS_USAGEÚValuesÚOptionContainerÚ OptionGroupÚ OptionParserÚ HelpFormatterÚIndentedHelpFormatterÚTitledHelpFormatterÚ OptParseErrorÚ OptionErrorÚOptionConflictErrorÚOptionValueErrorÚBadOptionErrora" 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ú'/opt/python35/lib/python3.5/optparse.pyÚ_reprNsr)ÚgettextÚngettextcCs|S)Nr)Úmessagerrrr[srcCs|dkr|S|S)Nér)ZsingularÚpluralÚnrrrr^s rc@s(eZdZdd„Zdd„ZdS)r cCs ||_dS)N)Úmsg)rrrrrÚ__init__gszOptParseError.__init__cCs|jS)N)r)rrrrÚ__str__jszOptParseError.__str__N)rÚ __module__Ú __qualname__r r!rrrrr fs  c@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 ts zOptionError.__init__cCs(|jrd|j|jfS|jSdS)Nz option %s: %s)r%r)rrrrr!xs zOptionError.__str__N)rr"r#Ú__doc__r r!rrrrr ns  c@seZdZdZdS)rzE Raised if conflicting options are added to an OptionParser. N)rr"r#r'rrrrr~s c@seZdZdZdS)rzS Raised if an invalid option value is encountered on the command line. N)rr"r#r'rrrrrƒs c@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‰s  c@s.eZdZdZdd„Zdd„ZdS)ÚAmbiguousOptionErrorzD Raised if an ambiguous option is seen on the command line. cCstj||ƒ||_dS)N)rr Ú possibilities)rr(r+rrrr —szAmbiguousOptionError.__init__cCs#tdƒ|jdj|jƒfS)Nzambiguous option: %s (%s?)z, )r)r(Újoinr+)rrrrr!›s zAmbiguousOptionError.__str__N)rr"r#r'r r!rrrrr*“s  r*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"). ZnonecCsßd|_||_|dkr`yttjdƒ}Wnttfk rUd}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)rr2r<r8r@rrrr Ís$      *       zHelpFormatter.__init__cCs ||_dS)N)r1)rr1rrrÚ set_parseræszHelpFormatter.set_parsercCs1|dkrtd|ƒ‚d|d|_dS)NÚú z/invalid metavar delimiter for short options: %rz%s)rFrG)r7rC)rÚdelimrrrÚset_short_opt_delimiterés  z%HelpFormatter.set_short_opt_delimitercCs1|dkrtd|ƒ‚d|d|_dS)Nú=rGz.invalid metavar delimiter for long options: %rz%s)rJrG)r7rD)rrHrrrÚset_long_opt_delimiterïs  z$HelpFormatter.set_long_opt_delimitercCs%|j|j7_|jd7_dS)Nr)r=r2r>)rrrrÚindentõszHelpFormatter.indentcCs@|j|j8_|jdks-tdƒ‚|jd8_dS)NrzIndent decreased below 0.r)r=r2ÚAssertionErrorr>)rrrrÚdedentùszHelpFormatter.dedentcCstdƒ‚dS)Nzsubclasses must implement)ÚNotImplementedError)rÚusagerrrÚ format_usageþszHelpFormatter.format_usagecCstdƒ‚dS)Nzsubclasses must implement)rO)rÚheadingrrrÚformat_headingszHelpFormatter.format_headingcCsBt|j|jdƒ}d|j}tj||d|d|ƒS)z� Format a paragraph of free-form text for inclusion in the help output at the current indentation level. é rGÚinitial_indentÚsubsequent_indent)r:r8r=ÚtextwrapÚfill)rÚtextÚ text_widthrLrrrÚ _format_texts   zHelpFormatter._format_textcCs|r|j|ƒdSdSdS)NÚ rF)r[)rÚ descriptionrrrÚformat_descriptionsz HelpFormatter.format_descriptioncCs#|rd|j|ƒdSdSdS)Nr\rF)r[)rÚepilogrrrÚ format_epilogszHelpFormatter.format_epilogcCsu|jdks|j r |jS|jjj|jƒ}|tksP|dkrY|j}|jj|jt |ƒƒS)N) r1rAÚhelpÚdefaultsÚgetÚdestÚ NO_DEFAULTÚNO_DEFAULT_VALUEÚreplacer$)rr&Z default_valuerrrÚexpand_defaults  zHelpFormatter.expand_defaultcs)g}ˆj|}ˆjˆjd}t|ƒ|kr[dˆjd|f}ˆj}ndˆjd||f}d}|j|ƒ|jrÿˆj|ƒ}tj|ˆj ƒ}|jd|d|dfƒ|j ‡fdd†|dd…Dƒƒn|d d kr|jd ƒdj |ƒS) Nr/z%*s%s rFz %*s%-*s rcs&g|]}dˆjd|f‘qS)z%*s%s rF)r;)Ú.0Úline)rrrú Ds z/HelpFormatter.format_option..rr\éÿÿÿÿ) rBr;r=ÚlenÚappendrarhrWÚwrapr?Úextendr,)rr&ÚresultÚoptsZ opt_widthÚ indent_firstÚ help_textÚ help_linesr)rrÚ format_option's$     zHelpFormatter.format_optioncCs|jƒd}xI|jD]>}|j|ƒ}||j|}|j|ƒ}||j|.cs#g|]}ˆj|ˆf‘qSr)rD)riZlopt)r~rrrrkbs z, )Ú takes_valuer~rdÚupperÚ _short_optsÚ _long_optsr@r,)rr&Z short_optsZ long_optsrrr)r~rrrx\s       z#HelpFormatter.format_option_stringsN)rr"r#r'rfr rErIrKrLrNrQrSr[r^r`rhrvr}rxrrrrr  s" )           # c@sFeZdZdZdddddd„Zdd „Zd d „ZdS) r z.Format help with indented section bodies. r/éNrcCstj|||||ƒdS)N)r r )rr2r<r8r@rrrr sszIndentedHelpFormatter.__init__cCstdƒ|S)Nz Usage: %s )r))rrPrrrrQ{sz"IndentedHelpFormatter.format_usagecCsd|jd|fS)Nz%*s%s: rF)r=)rrRrrrrS~sz$IndentedHelpFormatter.format_heading)rr"r#r'r rQrSrrrrr os  c@sFeZdZdZdddddd„Zdd„Zd d „ZdS) r z1Format help with underlined section headers. rrƒNcCstj|||||ƒdS)N)r r )rr2r<r8r@rrrr †szTitledHelpFormatter.__init__cCsd|jtdƒƒ|fS)Nz%s %s ZUsage)rSr))rrPrrrrQŽsz TitledHelpFormatter.format_usagecCsd|d|jt|ƒfS)Nz%s %s z=-)r>rm)rrRrrrrS‘sz"TitledHelpFormatter.format_heading)rr"r#r'r rQrSrrrrr ‚s  cCs’|dd…jƒdkr%d}n`|dd…jƒdkr`d}|dd…pZd}n%|dd…dkrd}nd}|||ƒS) Nr/Ú0xéZ0bÚ0réé )Úlower)ÚvalÚtypeÚradixrrrÚ _parse_num•s  r�cCs t|tƒS)N)r�r3)rŠrrrÚ _parse_int¢srŽr3ZintegerÚlongÚfloatzfloating-pointÚcomplexc CsYt|j\}}y||ƒSWn1tk rTttdƒ|||fƒ‚YnXdS)Nzoption %s: invalid %s value: %r)Ú _builtin_cvtr‹r7rr))r&rzÚvalueZcvtZwhatrrrÚ check_builtinªs  r”cCsQ||jkr|Sdjtt|jƒƒ}ttdƒ|||fƒ‚dS)Nz, z.option %s: invalid choice: %r (choose from %s))Úchoicesr,ÚmapÚreprrr))r&rzr“r•rrrÚ check_choice²s  r˜ZNOZDEFAULTc @s‡eZdZdZdddddddd d d d d g ZdAZdBZdCZdDZdEZ dFZ de de de de de iZ dZdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„ZeeeeeeegZd3d4„ZeZd5d6„Zd7d8„Zd9d:„Zd;d<„Z d=d>„Z!d?d@„Z"dS)Grar 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‹rdÚdefaultÚnargsÚconstr•ÚcallbackÚ callback_argsÚcallback_kwargsrar~ÚstoreÚ store_constÚ store_trueÚ store_falsernÚ append_constÚcountÚversionÚstringr3r�r�r‘ÚchoiceNcOs]g|_g|_|j|ƒ}|j|ƒ|j|ƒx|jD]}||ƒqEWdS)N)r�r‚Ú_check_opt_stringsÚ_set_opt_stringsÚ _set_attrsÚ CHECK_METHODS)rrrÚattrsÚcheckerrrrr 3s    zOption.__init__cCs)dd„|Dƒ}|s%tdƒ‚|S)NcSsg|]}|r|‘qSrr)rirzrrrrkJs z-Option._check_opt_strings..z+at least one option string must be supplied)Ú TypeError)rrrrrrr©Fs zOption._check_opt_stringscCsÞx×|D]Ï}t|ƒdkr5td||ƒ‚qt|ƒdkr�|ddkod|ddksztd||ƒ‚|jj|ƒq|dd…dko°|ddksÆtd||ƒ‚|jj|ƒqWdS) Nr/z>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)rmr r�rnr‚)rrrrzrrrrªOs$   & zOption._set_opt_stringscCs¥xj|jD]_}||kr:t||||ƒ||=q |dkrYt||tƒq t||dƒq W|r¡t|jƒƒ}tddj|ƒ|ƒ‚dS)Nršzinvalid keyword arguments: %sz, )ÚATTRSÚsetattrreÚsortedÚkeysr r,)rr­Úattrrrrr«ds   zOption._set_attrscCsG|jdkrd|_n(|j|jkrCtd|j|ƒ‚dS)Nr zinvalid action: %r)r™ÚACTIONSr )rrrrÚ _check_actionws zOption._check_actioncCsÕ|jdkrH|j|jkrÑ|jdk r<d|_qÑd|_n‰t|jtƒri|jj|_|jdkr�d|_|j|jkr©td|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_typecCs£|jdkrz|jdkr0td|ƒ‚qŸt|jttfƒsŸtdtt|jƒƒjdƒd|ƒ‚n%|jdk rŸtd|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 }|jdkr||r||jrh|jddd…jddƒ|_n|jdd|_dS)Nrr/r°r)r)r™Ú STORE_ACTIONSr‹rdr‚rgr�)rrrrrÚ _check_dest¢s  )zOption._check_destcCs;|j|jkr7|jdk r7td|j|ƒ‚dS)Nz*'const' must not be supplied for action %r)r™Ú CONST_ACTIONSrœr )rrrrÚ _check_const±s! zOption._check_constcCsV|j|jkr-|jdkrRd|_n%|jdk rRtd|j|ƒ‚dS)Nrz*'nargs' must not be supplied for action %r)r™r»r›r )rrrrÚ _check_nargs·s  zOption._check_nargscCs |jdkr§t|jƒs4td|j|ƒ‚|jdk rlt|jtƒ rltd|j|ƒ‚|jdk rt|jtƒ rtd|j|ƒ‚na|jdk rÌtd|j|ƒ‚|jdk rêtd|ƒ‚|jdk rtd|ƒ‚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_callbackcCsdj|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_stringcCs9|jj|jƒ}|dkr%|S||||ƒSdS)N)Ú TYPE_CHECKERrcr‹)rrzr“r®rrrÚ check_valueøs zOption.check_valuecsO|dk rKˆjdkr+ˆjˆ|ƒSt‡‡fdd†|DƒƒSdS)Nrcs"g|]}ˆjˆ|ƒ‘qSr)rÍ)riÚv)rzrrrrks z(Option.convert_value..)r›rÍr¾)rrzr“r)rzrrÚ convert_valueÿs zOption.convert_valuecCs4|j||ƒ}|j|j|j||||ƒS)N)rÏÚ take_actionr™rd)rrzr“Úvaluesr1rrrÚprocessszOption.processc Cs§|dkrt|||ƒn„|dkrAt|||jƒnb|dkr`t||dƒnC|dkrt||dƒn$|dkr§|j|gƒj|ƒnü|dkrÒ|j|gƒj|jƒnÑ|d krt|||j|d ƒd ƒn¢|d krJ|jpf}|jp(i}|j||||||ŽnY|d krm|jƒ|jƒn6|dkr�|j ƒ|jƒnt d|j ƒ‚d S)Nr r¡r¢Tr£Frnr¤r¥rrr�rar¦zunknown action %r) r²rœÚ ensure_valuernržrŸr�Ú print_helpÚexitÚ print_versionr7r™) rr™rdrzr“rÑr1ÚargsÚkwargsrrrrÐs4       #       zOption.take_action) r r¡r¢r£rnr¤r¥r�rar¦)r r¡r¢r£rnr¤r¥)r rnr�)r rn)r¡r¤)r§r3r�r�r‘r¨)#rr"r#r'r±r¶rÂr»r¸rÄrºr”r˜rÌr¬r r©rªr«r·r¼rÁrÃrÅrÆrÉr!rÚ__repr__rrËrÍrÏrÒrÐrrrrrÀsŒ                 ÚSUPPRESSZHELPZUSAGEc@s‹eZdZddd„Zdd„ZeZdd„Zdd „Zd d „Z d d „Z ddd„Z ddd„Z dd„Z dS)rNcCs7|r3x*|jƒD]\}}t|||ƒqWdS)N)Úitemsr²)rrbrµrŠrrrr 8szValues.__init__cCs t|jƒS)N)r$Ú__dict__)rrrrr!=szValues.__str__cCsCt|tƒr|j|jkSt|tƒr;|j|kStSdS)N)r¹rrÜrÈÚNotImplemented)rÚotherrrrÚ__eq__Bs  z Values.__eq__cCsMxFt|ƒD]8}||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µZdvalrrrÚ_update_carefulJs    zValues._update_carefulcCs|jj|ƒ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_looseWszValues._update_loosecCsL|dkr|j|ƒn,|dkr8|j|ƒntd|ƒ‚dS)NÚcarefulZloosezinvalid update mode: %r)rárãr7)rrÈÚmoderrrÚ_update_s   zValues._updateräcCs1t|ƒtj|}|jt|ƒ|ƒdS)N)Ú __import__ÚsysÚmodulesræÚvars)rÚmodnameråÚmodrrrÚ read_modulegs  zValues.read_modulecCs3i}tt|ƒjƒ|ƒ|j||ƒdS)N)ÚexecÚopenÚreadræ)rÚfilenamerårêrrrÚ read_filelszValues.read_filecCsBt||ƒ s%t||ƒdkr5t|||ƒt||ƒS)N)ÚhasattrÚgetattrr²)rrµr“rrrrÓqs%zValues.ensure_value)rr"r#r r!rrÙrßrárãræríròrÓrrrrr6s     c@sÖeZdZdZdd„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. cCs1|jƒ||_|j|ƒ|j|ƒ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_optrb)rrrrÚ_create_option_mappings¢s  z'OptionContainer._create_option_mappingscCs(|j|_|j|_|j|_dS)N)rúrûrb)rr1rrrÚ_share_option_mappings«s  z&OptionContainer._share_option_mappingscCs)|dkrtd|ƒ‚||_dS)NÚerrorÚresolvez$invalid conflict_resolution value %r)rþrÿ)r7rù)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)rúrûrb)rrrrÚdestroy¾szOptionContainer.destroycCsYg}x:|jD]/}||jkr|j||j|fƒqWx:|jD]/}||jkrM|j||j|fƒqMW|rU|j}|dkrÇtddjdd„|Dƒƒ|ƒ‚nŽ|dkrUx|D]w\}}|jdƒr|jj |ƒ|j|=n|jj |ƒ|j|=|jp;|jsÚ|j j j |ƒqÚWdS)Nrþz conflicting option string(s): %sz, cSsg|]}|d‘qS)rr)riÚcorrrrkÕs z3OptionContainer._check_conflict..rÿz--) r�rúrnr‚rûrùrr,Ú startswithÚremoveÚ containerrw)rr&Z conflict_optsrzrZc_optionrrrÚ_check_conflictÇs.      zOptionContainer._check_conflictcOs;t|dtƒr(|j||Ž}nQt|ƒdkrm| rm|d}t|tƒsytd|ƒ‚n tdƒ‚|j|ƒ|jj|ƒ||_ x|j D]}||j |d?„Z"d@dA„Z#ddBdC„Z$dDdE„Z%ddFdG„Z&ddHdI„Z'dJdK„Z(ddLdM„Z)ddNdO„Z*dS)Pra$ 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 CsŸtj||||ƒ|j|ƒ| |_||_d|_d|_|dkr\tƒ}||_|jj |ƒ| |_ |j |d|ƒ|j ƒdS)NTÚadd_help) rr Ú set_usageÚprogr¦Úallow_interspersed_argsÚprocess_default_valuesr r rEr_Ú_populate_option_listÚ_init_parsing_state) rrPrwrör¦rùr]r Zadd_help_optionrr_rrrr ™s           zOptionParser.__init__cCsAtj|ƒx|jD]}|jƒ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)rrryrwr )rr|rrrr»s  zOptionParser.destroycCs g|_g|_|jƒdS)N)rwryrü)rrrrrõÍs  z OptionParser._create_option_listcCs&|jdddddtdƒƒdS)Nz-hz--helpr™razshow this help message and exit)rr))rrrrÚ_add_help_optionÒszOptionParser._add_help_optioncCs#|jddddtdƒƒdS)Nz --versionr™r¦raz&show program's version number and exit)rr))rrrrÚ_add_version_option×s z OptionParser._add_version_optioncCsS|jr|j|jƒ|r,|j|ƒ|jr?|jƒ|rO|jƒdS)N)Ústandard_option_listr r¦rr)rrwrrrrrÜs    z"OptionParser._populate_option_listcCsd|_d|_d|_dS)N)ÚrargsÚlargsrÑ)rrrrræs  z OptionParser._init_parsing_statecCsn|dkrtdƒ|_nL|tkr6d|_n4|jƒjdƒra|dd…|_n ||_dS)Nz%prog [options]zusage: é)r)rPrr‰r)rrPrrrrï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|ttfk rŸ}z|jt |ƒƒWYdd}~XnX||}|j ||ƒ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+r'rrrÑÚ _process_argsrrrþr$Ú check_values)rr×rÑrrÚstopÚerrrrrÚ parse_argsJs    & 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-qs zOptionParser.check_valuescCsºx³|rµ|d}|dkr*|d=dS|dd…dkrS|j||ƒq|dd…dkrŽt|ƒdkrŽ|j||ƒq|jr®|j|ƒ|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--Nr/rr°)Ú_process_long_optrmÚ_process_short_optsrrn)rrrrÑÚargrrrr,~s   (   zOptionParser._process_argscCst||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û)rrzrrrÚ_match_long_opt±szOptionParser._match_long_optc CsK|jdƒ}d|krL|jddƒ\}}|jd|ƒd}n |}d}|j|ƒ}|j|}|jƒr |j}t|ƒ|krÇ|jt dd|ƒd|d |iƒq1|dkrå|jdƒ} q1t |d|…ƒ} |d|…=n&|r+|jt d ƒ|ƒnd} |j || ||ƒdS) NrrJrTFz.%(option)s option requires %(number)d argumentz/%(option)s option requires %(number)d argumentsr&Únumberz%s option does not take a value) ÚpoprÀÚinsertr5rûrr›rmrþrr¾r)rÒ) rrrÑr3rzZnext_argZhad_explicit_valuer&r›r“rrrr1ºs0       zOptionParser._process_long_optc Cs^|jdƒ}d}d}x<|dd…D]*}d|}|jj|ƒ}|d7}|sjt|ƒ‚|jƒr3|t|ƒkr¨|jd||d…ƒd}|j} t|ƒ| krï|jt dd| ƒd|d | iƒq9| dkr |jdƒ} q9t |d| …ƒ} |d| …=nd} |j || ||ƒ|r,Pq,WdS) NrFrr°Tz.%(option)s option requires %(number)d argumentz/%(option)s option requires %(number)d argumentsr&r6) r7rúrcrrrmr8r›rþrr¾rÒ) rrrÑr3r.ÚiZchrzr&r›r“rrrr2Þs6       z OptionParser._process_short_optscCs1|jdkr&tjjtjdƒS|jSdS)Nr)rr4ÚpathÚbasenamerèr*)rrrrÚ get_prog_nameszOptionParser.get_prog_namecCs|jd|jƒƒS)Nz%prog)rgr<)rÚsrrrÚexpand_prog_name szOptionParser.expand_prog_namecCs|j|jƒS)N)r>r])rrrrrszOptionParser.get_descriptionrcCs'|rtjj|ƒtj|ƒdS)N)rèÚstderrÚwriterÕ)rÚstatusrrrrrÕszOptionParser.exitcCs4|jtjƒ|jdd|jƒ|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. r/z%s: error: %s N)Ú print_usagerèr?rÕr<)rrrrrrþszOptionParser.errorcCs-|jr%|jj|j|jƒƒSdSdS)NrF)rPr rQr>)rrrrÚ get_usage"s  zOptionParser.get_usagecCs#|jrt|jƒd|ƒdS)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)rPÚprintrC)rrDrrrrB)s zOptionParser.print_usagecCs!|jr|j|jƒSdSdS)NrF)r¦r>)rrrrÚ get_version5s zOptionParser.get_versioncCs#|jrt|jƒd|ƒdS)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. rDN)r¦rErF)rrDrrrrÖ;s zOptionParser.print_versioncCsÕ|dkr|j}|j|ƒg}|j|jtdƒƒƒ|jƒ|jr}|jtj||ƒƒ|jdƒx4|j D])}|j|j |ƒƒ|jdƒq‡W|j ƒdj |dd…ƒS)NZOptionsr\rFrrl) r r}rnrSr)rLrwrrryrrNr,)rr rqr|rrrrFs       zOptionParser.format_option_helpcCs|j|jƒS)N)r`r_)rr rrrr`WszOptionParser.format_epilogcCs—|dkr|j}g}|jr;|j|jƒdƒ|jr^|j|j|ƒdƒ|j|j|ƒƒ|j|j|ƒƒdj|ƒS)Nr\rF) r rPrnrCr]r^rr`r,)rr rqrrrrZs    zOptionParser.format_helpcCs,|dkrtj}|j|jƒƒ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èÚstdoutr@r)rrDrrrrÔfs  zOptionParser.print_help)+rr"r#r'rrr rrõrrrrrrr r!r"r#r%r'r(r)r+r0r-r,r5r1r2r<r>rrÕrþrCrBrFrÖrr`rrÔrrrrrQs` D             ' 3 $ )        cs{ˆ|krˆS‡fdd†|jƒDƒ}t|ƒdkrI|dS|s^tˆƒ‚n|jƒ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. cs%g|]}|jˆƒr|‘qSr)r)riZword)r=rrrks z!_match_abbrev..rrN)r´rmrÚsortr*)r=Zwordmapr+r)r=rr4ss  r4)'r'Ú __version__Ú__all__Z __copyright__rèr4rWrrrÚ ImportErrorr)Ú Exceptionr r rrrr*r r r r�rŽr�r‘r’r”r˜rerrrrrrrr4rrrrrÚsr       Ï   ÿt  A¼ÿÿ$