[Python-checkins] python/dist/src/Lib optparse.py,1.2,1.3

gward@users.sourceforge.net gward@users.sourceforge.net
Sun, 20 Apr 2003 19:40:37 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv13506/Lib

Modified Files:
	optparse.py 
Log Message:
Update to Optik 1.4.1; here are the relevant bits of the change log:

  * Fixed some long-hidden bugs revealed by the new PyUnit-based
    test suite (thanks to Johannes Gijsbers the new test suite,
    improved tests that caught the bugs, and the bug fixes).

  * Make store_true/store_false store True/False rather than 1/0.

Details available in Optik's CVS repository.


Index: optparse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/optparse.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** optparse.py	4 Jan 2003 21:54:26 -0000	1.2
--- optparse.py	21 Apr 2003 02:40:34 -0000	1.3
***************
*** 3,13 ****
  By Greg Ward <gward@python.net>
  
! Originally distributed as Optik.
  
! See http://optik.sourceforge.net/
  """
  
  __copyright__ = """
! Copyright (c) 2001-2002 Gregory P. Ward.  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without
--- 3,25 ----
  By Greg Ward <gward@python.net>
  
! Originally distributed as Optik; see http://optik.sourceforge.net/ .
  
! If you have problems with this module, please do not files bugs,
! patches, or feature requests with Python; instead, use Optik's
! SourceForge project page:
!   http://sourceforge.net/projects/optik
! 
! For support, use the optik-users@lists.sourceforge.net mailing list
! (http://lists.sourceforge.net/lists/listinfo/optik-users).
  """
  
+ # Python developers: please do not make changes to this file, since
+ # it is automatically generated from the Optik source code.
+ 
+ 
+ __version__ = "1.4.1"
+ 
  __copyright__ = """
! Copyright (c) 2001-2003 Gregory P. Ward.  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without
***************
*** 43,48 ****
  import textwrap
  
- __version__ = "1.4+"
- 
  class OptParseError (Exception):
      def __init__ (self, msg):
--- 55,58 ----
***************
*** 52,55 ****
--- 62,66 ----
          return self.msg
  
+ 
  class OptionError (OptParseError):
      """
***************
*** 83,86 ****
--- 94,99 ----
      Raised if an invalid or ambiguous option is seen on the command-line.
      """
+ 
+ 
  class HelpFormatter:
  
***************
*** 119,126 ****
          self.level = 0
          self.help_width = width - max_help_position
!         if short_first:
!             self.format_option_strings = self.format_option_strings_short_first
!         else:
!             self.format_option_strings = self.format_option_strings_long_first
  
      def indent (self):
--- 132,136 ----
          self.level = 0
          self.help_width = width - max_help_position
!         self.short_first = short_first
  
      def indent (self):
***************
*** 199,234 ****
      def format_option_strings (self, option):
          """Return a comma-separated list of option strings & metavariables."""
!         raise NotImplementedError(
!             "abstract method: use format_option_strings_short_first or "
!             "format_option_strings_long_first instead.")
! 
!     def format_option_strings_short_first (self, option):
!         opts = []                       # list of "-a" or "--foo=FILE" strings
!         takes_value = option.takes_value()
!         if takes_value:
              metavar = option.metavar or option.dest.upper()
!             for sopt in option._short_opts:
!                 opts.append(sopt + metavar)
!             for lopt in option._long_opts:
!                 opts.append(lopt + "=" + metavar)
          else:
!             for opt in option._short_opts + option._long_opts:
!                 opts.append(opt)
!         return ", ".join(opts)
  
!     def format_option_strings_long_first (self, option):
!         opts = []                       # list of "-a" or "--foo=FILE" strings
!         takes_value = option.takes_value()
!         if takes_value:
!             metavar = option.metavar or option.dest.upper()
!             for lopt in option._long_opts:
!                 opts.append(lopt + "=" + metavar)
!             for sopt in option._short_opts:
!                 opts.append(sopt + metavar)
          else:
!             for opt in option._long_opts + option._short_opts:
!                 opts.append(opt)
!         return ", ".join(opts)
  
  
  class IndentedHelpFormatter (HelpFormatter):
--- 209,226 ----
      def format_option_strings (self, option):
          """Return a comma-separated list of option strings & metavariables."""
!         if option.takes_value():
              metavar = option.metavar or option.dest.upper()
!             short_opts = [sopt + metavar for sopt in option._short_opts]
!             long_opts = [lopt + "=" + metavar for lopt in option._long_opts]
          else:
!             short_opts = option._short_opts
!             long_opts = option._long_opts
  
!         if self.short_first:
!             opts = short_opts + long_opts
          else:
!             opts = long_opts + short_opts
  
+         return ", ".join(opts)
  
  class IndentedHelpFormatter (HelpFormatter):
***************
*** 268,271 ****
--- 260,265 ----
      def format_heading (self, heading):
          return "%s\n%s\n" % (heading, "=-"[self.level] * len(heading))
+ 
+ 
  _builtin_cvt = { "int" : (int, "integer"),
                   "long" : (long, "long integer"),
***************
*** 401,405 ****
  
      def __init__ (self, *opts, **attrs):
!         # Set _short_opts, _long_opts attrs from 'opts' tuple
          opts = self._check_opt_strings(opts)
          self._set_opt_strings(opts)
--- 395,402 ----
  
      def __init__ (self, *opts, **attrs):
!         # Set _short_opts, _long_opts attrs from 'opts' tuple.
!         # Have to be set now, in case no option strings are supplied.
!         self._short_opts = []
!         self._long_opts = []
          opts = self._check_opt_strings(opts)
          self._set_opt_strings(opts)
***************
*** 422,432 ****
          opts = filter(None, opts)
          if not opts:
!             raise OptionError("at least one option string must be supplied",
!                               self)
          return opts
  
      def _set_opt_strings (self, opts):
-         self._short_opts = []
-         self._long_opts = []
          for opt in opts:
              if len(opt) < 2:
--- 419,426 ----
          opts = filter(None, opts)
          if not opts:
!             raise TypeError("at least one option string must be supplied")
          return opts
  
      def _set_opt_strings (self, opts):
          for opt in opts:
              if len(opt) < 2:
***************
*** 570,577 ****
  
      def __str__ (self):
!         if self._short_opts or self._long_opts:
!             return "/".join(self._short_opts + self._long_opts)
!         else:
!             raise RuntimeError, "short_opts and long_opts both empty!"
  
      def takes_value (self):
--- 564,568 ----
  
      def __str__ (self):
!         return "/".join(self._short_opts + self._long_opts)
  
      def takes_value (self):
***************
*** 610,616 ****
              setattr(values, dest, self.const)
          elif action == "store_true":
!             setattr(values, dest, 1)
          elif action == "store_false":
!             setattr(values, dest, 0)
          elif action == "append":
              values.ensure_value(dest, []).append(value)
--- 601,607 ----
              setattr(values, dest, self.const)
          elif action == "store_true":
!             setattr(values, dest, True)
          elif action == "store_false":
!             setattr(values, dest, False)
          elif action == "append":
              values.ensure_value(dest, []).append(value)
***************
*** 633,636 ****
--- 624,629 ----
  
  # class Option
+ 
+ 
  def get_prog_name ():
      return os.path.basename(sys.argv[0])
***************
*** 923,927 ****
          a usage string for your program.  Before it is displayed
          to the user, "%prog" will be expanded to the name of
!         your program (os.path.basename(sys.argv[0])).
  
        allow_interspersed_args : boolean = true
--- 916,923 ----
          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])).
  
        allow_interspersed_args : boolean = true
***************
*** 968,975 ****
                    description=None,
                    formatter=None,
!                   add_help_option=1):
          OptionContainer.__init__(
              self, option_class, conflict_handler, description)
          self.set_usage(usage)
          self.version = version
          self.allow_interspersed_args = 1
--- 964,973 ----
                    description=None,
                    formatter=None,
!                   add_help_option=1,
!                   prog=None):
          OptionContainer.__init__(
              self, option_class, conflict_handler, description)
          self.set_usage(usage)
+         self.prog = prog
          self.version = version
          self.allow_interspersed_args = 1
***************
*** 1383,1384 ****
--- 1381,1383 ----
  # classes.
  make_option = Option
+