summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-12-29 02:17:56 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-12-29 02:17:56 (GMT)
commitd31b6328e180af4b10e2c942a1437d5b8cb2c2e6 (patch)
tree043fafc54861c3cc2690995f77723874b45d2506
parent36cdad12ddb2d70cc260d2a03e2b7e2f8ebb9a73 (diff)
downloadcpython-d31b6328e180af4b10e2c942a1437d5b8cb2c2e6.zip
cpython-d31b6328e180af4b10e2c942a1437d5b8cb2c2e6.tar.gz
cpython-d31b6328e180af4b10e2c942a1437d5b8cb2c2e6.tar.bz2
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.
-rw-r--r--Lib/getopt.py14
1 files changed, 2 insertions, 12 deletions
diff --git a/Lib/getopt.py b/Lib/getopt.py
index c93aad1..a8ad645 100644
--- a/Lib/getopt.py
+++ b/Lib/getopt.py
@@ -65,7 +65,6 @@ def getopt(args, shortopts, longopts = []):
longopts = [longopts]
else:
longopts = list(longopts)
- longopts.sort()
while args and args[0].startswith('-') and args[0] != '-':
if args[0] == '--':
args = args[1:]
@@ -99,19 +98,10 @@ def do_longs(opts, opt, longopts, args):
# Return:
# 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:
+ possibilities = [o for o in longopts if o.startswith(opt)]
+ if not possibilities:
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:
return 0, opt