[Python-checkins] CVS: python/dist/src/Lib getopt.py,1.12,1.13

Tim Peters python-dev@python.org
Thu, 28 Dec 2000 18:17:58 -0800


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

Modified Files:
	getopt.py 
Log Message:
getopt used to sort the long option names, in an attempt to simplify
the logic.  That resulted in a bug.  My previous getopt checkin repaired
the bug but left the sorting.  The solution is significantly simpler if
we don't bother sorting at all, so this checkin gets rid of the sort and
the code that relied on it.


Index: getopt.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/getopt.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** getopt.py	2000/12/27 08:05:05	1.12
--- getopt.py	2000/12/29 02:17:56	1.13
***************
*** 66,70 ****
      else:
          longopts = list(longopts)
-     longopts.sort()
      while args and args[0].startswith('-') and args[0] != '-':
          if args[0] == '--':
--- 66,69 ----
***************
*** 100,116 ****
  #   has_arg?
  #   full option name
- # Assumes longopts has been sorted (ASCII order).
  def long_has_args(opt, longopts):
!     for i in range(len(longopts)):
!         if longopts[i].startswith(opt):
!             break
!     else:
          raise GetoptError('option --%s not recognized' % opt, opt)
-     # opt is a prefix of longopts[i]; find j s.t. opt is a prefix of
-     # each possibility in longopts[i:j]
-     j = i+1
-     while j < len(longopts) and longopts[j].startswith(opt):
-         j += 1
-     possibilities = longopts[i:j]
      # Is there an exact match?
      if opt in possibilities:
--- 99,106 ----
  #   has_arg?
  #   full option name
  def long_has_args(opt, longopts):
!     possibilities = [o for o in longopts if o.startswith(opt)]
!     if not possibilities:
          raise GetoptError('option --%s not recognized' % opt, opt)
      # Is there an exact match?
      if opt in possibilities: