Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
optparse.OptionParser Class Reference
Inheritance diagram for optparse.OptionParser:
Inheritance graph
[legend]
Collaboration diagram for optparse.OptionParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def destroy
def set_usage
def enable_interspersed_args
def disable_interspersed_args
def set_process_default_values
def set_default
def set_defaults
def get_default_values
def add_option_group
def get_option_group
def parse_args
def check_values
def get_prog_name
def expand_prog_name
def get_description
def exit
def error
def get_usage
def print_usage
def get_version
def print_version
def format_option_help
def format_epilog
def format_help
def print_help
def set_conflict_handler
def set_description
def add_option
def add_options
def get_option
def has_option
def remove_option
def format_description

Public Attributes

 prog
 version
 allow_interspersed_args
 process_default_values
 formatter
 epilog
 option_list
 option_groups
 rargs
 largs
 values
 usage
 option_class
 defaults
 conflict_handler
 description

Static Public Attributes

list standard_option_list = []

Private Member Functions

def _create_option_list
def _add_help_option
def _add_version_option
def _populate_option_list
def _init_parsing_state
def _get_all_options
def _get_args
def _process_args
def _match_long_opt
def _process_long_opt
def _process_short_opts

Detailed Description

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.

Definition at line 1107 of file optparse.py.


Constructor & Destructor Documentation

def optparse.OptionParser.__init__ (   self,
  usage = None,
  option_list = None,
  option_class = Option,
  version = None,
  conflict_handler = "error",
  description = None,
  formatter = None,
  add_help_option = True,
  prog = None,
  epilog = None 
)

Definition at line 1189 of file optparse.py.

01189 
01190                  epilog=None):
01191         OptionContainer.__init__(
01192             self, option_class, conflict_handler, description)
01193         self.set_usage(usage)
01194         self.prog = prog
01195         self.version = version
01196         self.allow_interspersed_args = True
01197         self.process_default_values = True
01198         if formatter is None:
01199             formatter = IndentedHelpFormatter()
01200         self.formatter = formatter
01201         self.formatter.set_parser(self)
01202         self.epilog = epilog
01203 
01204         # Populate the option list; initial sources are the
01205         # standard_option_list class attribute, the 'option_list'
01206         # argument, and (if applicable) the _add_version_option() and
01207         # _add_help_option() methods.
01208         self._populate_option_list(option_list,
01209                                    add_help=add_help_option)
01210 
01211         self._init_parsing_state()
01212 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

def optparse.OptionParser._add_help_option (   self) [private]

Definition at line 1236 of file optparse.py.

01236 
01237     def _add_help_option(self):
01238         self.add_option("-h", "--help",
01239                         action="help",
01240                         help=_("show this help message and exit"))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1241 of file optparse.py.

01241 
01242     def _add_version_option(self):
01243         self.add_option("--version",
01244                         action="version",
01245                         help=_("show program's version number and exit"))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1231 of file optparse.py.

01231 
01232     def _create_option_list(self):
01233         self.option_list = []
01234         self.option_groups = []
01235         self._create_option_mappings()

Here is the caller graph for this function:

def optparse.OptionParser._get_all_options (   self) [private]

Definition at line 1301 of file optparse.py.

01301 
01302     def _get_all_options(self):
01303         options = self.option_list[:]
01304         for group in self.option_groups:
01305             options.extend(group.option_list)
01306         return options

Here is the caller graph for this function:

def optparse.OptionParser._get_args (   self,
  args 
) [private]

Definition at line 1350 of file optparse.py.

01350 
01351     def _get_args(self, args):
01352         if args is None:
01353             return sys.argv[1:]
01354         else:
01355             return args[:]              # don't modify caller's list

Here is the caller graph for this function:

Definition at line 1256 of file optparse.py.

01256 
01257     def _init_parsing_state(self):
01258         # These are set in parse_args() for the convenience of callbacks.
01259         self.rargs = None
01260         self.largs = None
01261         self.values = None
01262 

def optparse.OptionParser._match_long_opt (   self,
  opt 
) [private]
_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.

Definition at line 1459 of file optparse.py.

01459 
01460     def _match_long_opt(self, opt):
01461         """_match_long_opt(opt : string) -> string
01462 
01463         Determine which long option string 'opt' matches, ie. which one
01464         it is an unambiguous abbrevation for.  Raises BadOptionError if
01465         'opt' doesn't unambiguously match any long option string.
01466         """
01467         return _match_abbrev(opt, self._long_opt)

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser._populate_option_list (   self,
  option_list,
  add_help = True 
) [private]

Definition at line 1246 of file optparse.py.

01246 
01247     def _populate_option_list(self, option_list, add_help=True):
01248         if self.standard_option_list:
01249             self.add_options(self.standard_option_list)
01250         if option_list:
01251             self.add_options(option_list)
01252         if self.version:
01253             self._add_version_option()
01254         if add_help:
01255             self._add_help_option()

Here is the call graph for this function:

def optparse.OptionParser._process_args (   self,
  largs,
  rargs,
  values 
) [private]
_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'.

Definition at line 1408 of file optparse.py.

01408 
01409     def _process_args(self, largs, rargs, values):
01410         """_process_args(largs : [string],
01411                          rargs : [string],
01412                          values : Values)
01413 
01414         Process command-line arguments and populate 'values', consuming
01415         options and arguments from 'rargs'.  If 'allow_interspersed_args' is
01416         false, stop at the first non-option argument.  If true, accumulate any
01417         interspersed non-option arguments in 'largs'.
01418         """
01419         while rargs:
01420             arg = rargs[0]
01421             # We handle bare "--" explicitly, and bare "-" is handled by the
01422             # standard arg handler since the short arg case ensures that the
01423             # len of the opt string is greater than 1.
01424             if arg == "--":
01425                 del rargs[0]
01426                 return
01427             elif arg[0:2] == "--":
01428                 # process a single long option (possibly with value(s))
01429                 self._process_long_opt(rargs, values)
01430             elif arg[:1] == "-" and len(arg) > 1:
01431                 # process a cluster of short options (possibly with
01432                 # value(s) for the last one only)
01433                 self._process_short_opts(rargs, values)
01434             elif self.allow_interspersed_args:
01435                 largs.append(arg)
01436                 del rargs[0]
01437             else:
01438                 return                  # stop now, leave this arg in rargs
01439 
01440         # Say this is the original argument list:
01441         # [arg0, arg1, ..., arg(i-1), arg(i), arg(i+1), ..., arg(N-1)]
01442         #                            ^
01443         # (we are about to process arg(i)).
01444         #
01445         # Then rargs is [arg(i), ..., arg(N-1)] and largs is a *subset* of
01446         # [arg0, ..., arg(i-1)] (any options and their arguments will have
01447         # been removed from largs).
01448         #
01449         # The while loop will usually consume 1 or more arguments per pass.
01450         # If it consumes 1 (eg. arg is an option that takes no arguments),
01451         # then after _process_arg() is done the situation is:
01452         #
01453         #   largs = subset of [arg0, ..., arg(i)]
01454         #   rargs = [arg(i+1), ..., arg(N-1)]
01455         #
01456         # If allow_interspersed_args is false, largs will always be
01457         # *empty* -- still a subset of [arg0, ..., arg(i-1)], but
01458         # not a very interesting subset!

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser._process_long_opt (   self,
  rargs,
  values 
) [private]

Definition at line 1468 of file optparse.py.

01468 
01469     def _process_long_opt(self, rargs, values):
01470         arg = rargs.pop(0)
01471 
01472         # Value explicitly attached to arg?  Pretend it's the next
01473         # argument.
01474         if "=" in arg:
01475             (opt, next_arg) = arg.split("=", 1)
01476             rargs.insert(0, next_arg)
01477             had_explicit_value = True
01478         else:
01479             opt = arg
01480             had_explicit_value = False
01481 
01482         opt = self._match_long_opt(opt)
01483         option = self._long_opt[opt]
01484         if option.takes_value():
01485             nargs = option.nargs
01486             if len(rargs) < nargs:
01487                 if nargs == 1:
01488                     self.error(_("%s option requires an argument") % opt)
01489                 else:
01490                     self.error(_("%s option requires %d arguments")
01491                                % (opt, nargs))
01492             elif nargs == 1:
01493                 value = rargs.pop(0)
01494             else:
01495                 value = tuple(rargs[0:nargs])
01496                 del rargs[0:nargs]
01497 
01498         elif had_explicit_value:
01499             self.error(_("%s option does not take a value") % opt)
01500 
01501         else:
01502             value = None
01503 
01504         option.process(opt, value, values, self)

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser._process_short_opts (   self,
  rargs,
  values 
) [private]

Definition at line 1505 of file optparse.py.

01505 
01506     def _process_short_opts(self, rargs, values):
01507         arg = rargs.pop(0)
01508         stop = False
01509         i = 1
01510         for ch in arg[1:]:
01511             opt = "-" + ch
01512             option = self._short_opt.get(opt)
01513             i += 1                      # we have consumed a character
01514 
01515             if not option:
01516                 raise BadOptionError(opt)
01517             if option.takes_value():
01518                 # Any characters left in arg?  Pretend they're the
01519                 # next arg, and stop consuming characters of arg.
01520                 if i < len(arg):
01521                     rargs.insert(0, arg[i:])
01522                     stop = True
01523 
01524                 nargs = option.nargs
01525                 if len(rargs) < nargs:
01526                     if nargs == 1:
01527                         self.error(_("%s option requires an argument") % opt)
01528                     else:
01529                         self.error(_("%s option requires %d arguments")
01530                                    % (opt, nargs))
01531                 elif nargs == 1:
01532                     value = rargs.pop(0)
01533                 else:
01534                     value = tuple(rargs[0:nargs])
01535                     del rargs[0:nargs]
01536 
01537             else:                       # option doesn't take a value
01538                 value = None
01539 
01540             option.process(opt, value, values, self)
01541 
01542             if stop:
01543                 break
01544 

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionContainer.add_option (   self,
  args,
  kwargs 
) [inherited]
add_option(Option)
   add_option(opt_str, ..., kwarg=val, ...)

Definition at line 996 of file optparse.py.

00996 
00997     def add_option(self, *args, **kwargs):
00998         """add_option(Option)
00999            add_option(opt_str, ..., kwarg=val, ...)
01000         """
01001         if isinstance(args[0], str):
01002             option = self.option_class(*args, **kwargs)
01003         elif len(args) == 1 and not kwargs:
01004             option = args[0]
01005             if not isinstance(option, Option):
01006                 raise TypeError("not an Option instance: %r" % option)
01007         else:
01008             raise TypeError("invalid arguments")
01009 
01010         self._check_conflict(option)
01011 
01012         self.option_list.append(option)
01013         option.container = self
01014         for opt in option._short_opts:
01015             self._short_opt[opt] = option
01016         for opt in option._long_opts:
01017             self._long_opt[opt] = option
01018 
01019         if option.dest is not None:     # option has a dest, we need a default
01020             if option.default is not NO_DEFAULT:
01021                 self.defaults[option.dest] = option.default
01022             elif option.dest not in self.defaults:
01023                 self.defaults[option.dest] = None
01024 
01025         return option

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser.add_option_group (   self,
  args,
  kwargs 
)

Definition at line 1324 of file optparse.py.

01324 
01325     def add_option_group(self, *args, **kwargs):
01326         # XXX lots of overlap with OptionContainer.add_option()
01327         if isinstance(args[0], str):
01328             group = OptionGroup(self, *args, **kwargs)
01329         elif len(args) == 1 and not kwargs:
01330             group = args[0]
01331             if not isinstance(group, OptionGroup):
01332                 raise TypeError("not an OptionGroup instance: %r" % group)
01333             if group.parser is not self:
01334                 raise ValueError("invalid OptionGroup (wrong parser)")
01335         else:
01336             raise TypeError("invalid arguments")
01337 
01338         self.option_groups.append(group)
01339         return group

def optparse.OptionContainer.add_options (   self,
  option_list 
) [inherited]

Definition at line 1026 of file optparse.py.

01026 
01027     def add_options(self, option_list):
01028         for option in option_list:
01029             self.add_option(option)

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser.check_values (   self,
  values,
  args 
)
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.

Definition at line 1395 of file optparse.py.

01395 
01396     def check_values(self, values, args):
01397         """
01398         check_values(values : Values, args : [string])
01399         -> (values : Values, args : [string])
01400 
01401         Check that the supplied option values and leftover arguments are
01402         valid.  Returns the option values and leftover arguments
01403         (possibly adjusted, possibly completely new -- whatever you
01404         like).  Default implementation just returns the passed-in
01405         values; subclasses may override as desired.
01406         """
01407         return (values, args)

Here is the caller graph for this function:

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.

Reimplemented from optparse.OptionContainer.

Definition at line 1213 of file optparse.py.

01213 
01214     def destroy(self):
01215         """
01216         Declare that you are done with this OptionParser.  This cleans up
01217         reference cycles so the OptionParser (and all objects referenced by
01218         it) can be garbage-collected promptly.  After calling destroy(), the
01219         OptionParser is unusable.
01220         """
01221         OptionContainer.destroy(self)
01222         for group in self.option_groups:
01223             group.destroy()
01224         del self.option_list
01225         del self.option_groups
01226         del self.formatter
01227 

Here is the caller graph for this function:

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.

Definition at line 1284 of file optparse.py.

01284 
01285     def disable_interspersed_args(self):
01286         """Set parsing to stop on the first non-option. Use this if
01287         you have a command processor which runs another command that
01288         has options of its own and you want to make sure these options
01289         don't get confused.
01290         """
01291         self.allow_interspersed_args = False

Set 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.

Definition at line 1276 of file optparse.py.

01276 
01277     def enable_interspersed_args(self):
01278         """Set parsing to not stop on the first non-option, allowing
01279         interspersing switches with command arguments. This is the
01280         default behavior. See also disable_interspersed_args() and the
01281         class documentation description of the attribute
01282         allow_interspersed_args."""
01283         self.allow_interspersed_args = True

def optparse.OptionParser.error (   self,
  msg 
)
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.

Definition at line 1564 of file optparse.py.

01564 
01565     def error(self, msg):
01566         """error(msg : string)
01567 
01568         Print a usage message incorporating 'msg' to stderr and exit.
01569         If you override this in a subclass, it should not return -- it
01570         should either exit or raise an exception.
01571         """
01572         self.print_usage(sys.stderr)
01573         self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser.exit (   self,
  status = 0,
  msg = None 
)

Definition at line 1559 of file optparse.py.

01559 
01560     def exit(self, status=0, msg=None):
01561         if msg:
01562             sys.stderr.write(msg)
01563         sys.exit(status)

Here is the caller graph for this function:

def optparse.OptionParser.expand_prog_name (   self,
  s 
)

Definition at line 1553 of file optparse.py.

01553 
01554     def expand_prog_name(self, s):
01555         return s.replace("%prog", self.get_prog_name())

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionContainer.format_description (   self,
  formatter 
) [inherited]

Definition at line 1065 of file optparse.py.

01065 
01066     def format_description(self, formatter):
01067         return formatter.format_description(self.get_description())

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser.format_epilog (   self,
  formatter 
)

Definition at line 1627 of file optparse.py.

01627 
01628     def format_epilog(self, formatter):
01629         return formatter.format_epilog(self.epilog)

Here is the caller graph for this function:

def optparse.OptionParser.format_help (   self,
  formatter = None 
)

Reimplemented from optparse.OptionContainer.

Definition at line 1630 of file optparse.py.

01630 
01631     def format_help(self, formatter=None):
01632         if formatter is None:
01633             formatter = self.formatter
01634         result = []
01635         if self.usage:
01636             result.append(self.get_usage() + "\n")
01637         if self.description:
01638             result.append(self.format_description(formatter) + "\n")
01639         result.append(self.format_option_help(formatter))
01640         result.append(self.format_epilog(formatter))
01641         return "".join(result)

Here is the call graph for this function:

def optparse.OptionParser.format_option_help (   self,
  formatter = None 
)

Reimplemented from optparse.OptionContainer.

Definition at line 1610 of file optparse.py.

01610 
01611     def format_option_help(self, formatter=None):
01612         if formatter is None:
01613             formatter = self.formatter
01614         formatter.store_option_strings(self)
01615         result = []
01616         result.append(formatter.format_heading(_("Options")))
01617         formatter.indent()
01618         if self.option_list:
01619             result.append(OptionContainer.format_option_help(self, formatter))
01620             result.append("\n")
01621         for group in self.option_groups:
01622             result.append(group.format_help(formatter))
01623             result.append("\n")
01624         formatter.dedent()
01625         # Drop the last "\n", or the header if no options or option groups:
01626         return "".join(result[:-1])

Definition at line 1307 of file optparse.py.

01307 
01308     def get_default_values(self):
01309         if not self.process_default_values:
01310             # Old, pre-Optik 1.5 behaviour.
01311             return Values(self.defaults)
01312 
01313         defaults = self.defaults.copy()
01314         for option in self._get_all_options():
01315             default = defaults.get(option.dest)
01316             if isinstance(default, str):
01317                 opt_str = option.get_opt_string()
01318                 defaults[option.dest] = option.check_value(opt_str, default)
01319 
01320         return Values(defaults)
01321 

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from optparse.OptionContainer.

Definition at line 1556 of file optparse.py.

01556 
01557     def get_description(self):
01558         return self.expand_prog_name(self.description)

Here is the call graph for this function:

def optparse.OptionContainer.get_option (   self,
  opt_str 
) [inherited]

Definition at line 1032 of file optparse.py.

01032 
01033     def get_option(self, opt_str):
01034         return (self._short_opt.get(opt_str) or
01035                 self._long_opt.get(opt_str))

def optparse.OptionParser.get_option_group (   self,
  opt_str 
)

Definition at line 1340 of file optparse.py.

01340 
01341     def get_option_group(self, opt_str):
01342         option = (self._short_opt.get(opt_str) or
01343                   self._long_opt.get(opt_str))
01344         if option and option.container is not self:
01345             return option.container
01346         return None
01347 

Definition at line 1547 of file optparse.py.

01547 
01548     def get_prog_name(self):
01549         if self.prog is None:
01550             return os.path.basename(sys.argv[0])
01551         else:
01552             return self.prog

Here is the caller graph for this function:

Definition at line 1574 of file optparse.py.

01574 
01575     def get_usage(self):
01576         if self.usage:
01577             return self.formatter.format_usage(
01578                 self.expand_prog_name(self.usage))
01579         else:
01580             return ""

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1593 of file optparse.py.

01593 
01594     def get_version(self):
01595         if self.version:
01596             return self.expand_prog_name(self.version)
01597         else:
01598             return ""

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionContainer.has_option (   self,
  opt_str 
) [inherited]

Definition at line 1036 of file optparse.py.

01036 
01037     def has_option(self, opt_str):
01038         return (opt_str in self._short_opt or
01039                 opt_str in self._long_opt)

def optparse.OptionParser.parse_args (   self,
  args = None,
  values = None 
)
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 an Values instance (with all
your option values) and 'args' is the list of arguments left
over after parsing options.

Definition at line 1356 of file optparse.py.

01356 
01357     def parse_args(self, args=None, values=None):
01358         """
01359         parse_args(args : [string] = sys.argv[1:],
01360                    values : Values = None)
01361         -> (values : Values, args : [string])
01362 
01363         Parse the command-line options found in 'args' (default:
01364         sys.argv[1:]).  Any errors result in a call to 'error()', which
01365         by default prints the usage message to stderr and calls
01366         sys.exit() with an error message.  On success returns a pair
01367         (values, args) where 'values' is an Values instance (with all
01368         your option values) and 'args' is the list of arguments left
01369         over after parsing options.
01370         """
01371         rargs = self._get_args(args)
01372         if values is None:
01373             values = self.get_default_values()
01374 
01375         # Store the halves of the argument list as attributes for the
01376         # convenience of callbacks:
01377         #   rargs
01378         #     the rest of the command-line (the "r" stands for
01379         #     "remaining" or "right-hand")
01380         #   largs
01381         #     the leftover arguments -- ie. what's left after removing
01382         #     options and their arguments (the "l" stands for "leftover"
01383         #     or "left-hand")
01384         self.rargs = rargs
01385         self.largs = largs = []
01386         self.values = values
01387 
01388         try:
01389             stop = self._process_args(largs, rargs, values)
01390         except (BadOptionError, OptionValueError) as err:
01391             self.error(str(err))
01392 
01393         args = largs + rargs
01394         return self.check_values(values, args)

Here is the call graph for this function:

def optparse.OptionParser.print_help (   self,
  file = None 
)
print_help(file : file = stdout)

Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).

Definition at line 1642 of file optparse.py.

01642 
01643     def print_help(self, file=None):
01644         """print_help(file : file = stdout)
01645 
01646         Print an extended help message, listing all options and any
01647         help text provided with them, to 'file' (default stdout).
01648         """
01649         if file is None:
01650             file = sys.stdout
01651         file.write(self.format_help())
01652 
01653 # class OptionParser
01654 

Here is the call graph for this function:

def optparse.OptionParser.print_usage (   self,
  file = None 
)
print_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.

Definition at line 1581 of file optparse.py.

01581 
01582     def print_usage(self, file=None):
01583         """print_usage(file : file = stdout)
01584 
01585         Print the usage message for the current program (self.usage) to
01586         'file' (default stdout).  Any occurrence of the string "%prog" in
01587         self.usage is replaced with the name of the current program
01588         (basename of sys.argv[0]).  Does nothing if self.usage is empty
01589         or not defined.
01590         """
01591         if self.usage:
01592             print(self.get_usage(), file=file)

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.OptionParser.print_version (   self,
  file = None 
)
print_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.

Definition at line 1599 of file optparse.py.

01599 
01600     def print_version(self, file=None):
01601         """print_version(file : file = stdout)
01602 
01603         Print the version message for this program (self.version) to
01604         'file' (default stdout).  As with print_usage(), any occurrence
01605         of "%prog" in self.version is replaced by the current program's
01606         name.  Does nothing if self.version is empty or undefined.
01607         """
01608         if self.version:
01609             print(self.get_version(), file=file)

Here is the call graph for this function:

def optparse.OptionContainer.remove_option (   self,
  opt_str 
) [inherited]

Definition at line 1040 of file optparse.py.

01040 
01041     def remove_option(self, opt_str):
01042         option = self._short_opt.get(opt_str)
01043         if option is None:
01044             option = self._long_opt.get(opt_str)
01045         if option is None:
01046             raise ValueError("no such option %r" % opt_str)
01047 
01048         for opt in option._short_opts:
01049             del self._short_opt[opt]
01050         for opt in option._long_opts:
01051             del self._long_opt[opt]
01052         option.container.option_list.remove(option)
01053 

def optparse.OptionContainer.set_conflict_handler (   self,
  handler 
) [inherited]

Definition at line 948 of file optparse.py.

00948 
00949     def set_conflict_handler(self, handler):
00950         if handler not in ("error", "resolve"):
00951             raise ValueError("invalid conflict_resolution value %r" % handler)
00952         self.conflict_handler = handler

def optparse.OptionParser.set_default (   self,
  dest,
  value 
)

Definition at line 1295 of file optparse.py.

01295 
01296     def set_default(self, dest, value):
01297         self.defaults[dest] = value

def optparse.OptionParser.set_defaults (   self,
  kwargs 
)

Definition at line 1298 of file optparse.py.

01298 
01299     def set_defaults(self, **kwargs):
01300         self.defaults.update(kwargs)

def optparse.OptionContainer.set_description (   self,
  description 
) [inherited]

Definition at line 953 of file optparse.py.

00953 
00954     def set_description(self, description):
00955         self.description = description

def optparse.OptionParser.set_process_default_values (   self,
  process 
)

Definition at line 1292 of file optparse.py.

01292 
01293     def set_process_default_values(self, process):
01294         self.process_default_values = process

def optparse.OptionParser.set_usage (   self,
  usage 
)

Definition at line 1265 of file optparse.py.

01265 
01266     def set_usage(self, usage):
01267         if usage is None:
01268             self.usage = _("%prog [options]")
01269         elif usage is SUPPRESS_USAGE:
01270             self.usage = None
01271         # For backwards compatibility with Optik 1.3 and earlier.
01272         elif usage.lower().startswith("usage: "):
01273             self.usage = usage[7:]
01274         else:
01275             self.usage = usage

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1195 of file optparse.py.

Definition at line 951 of file optparse.py.

Definition at line 938 of file optparse.py.

Definition at line 954 of file optparse.py.

Definition at line 1201 of file optparse.py.

Definition at line 1199 of file optparse.py.

Definition at line 1259 of file optparse.py.

Definition at line 928 of file optparse.py.

Definition at line 1233 of file optparse.py.

Definition at line 1232 of file optparse.py.

Definition at line 1196 of file optparse.py.

Definition at line 1193 of file optparse.py.

Definition at line 1258 of file optparse.py.

Definition at line 1177 of file optparse.py.

Definition at line 1267 of file optparse.py.

Definition at line 1260 of file optparse.py.

Definition at line 1194 of file optparse.py.


The documentation for this class was generated from the following file: