summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-12-05 09:23:14 (GMT)
committerGeorg Brandl <georg@python.org>2008-12-05 09:23:14 (GMT)
commita07435d3e3dfee3e4d8998baa7fadbfaf46f764d (patch)
tree1c749e787fde8e79d694630fcf18679835613d1a
parent8d6c49047f2725ebb67212689e7eef2388dfbcdc (diff)
downloadcpython-a07435d3e3dfee3e4d8998baa7fadbfaf46f764d.zip
cpython-a07435d3e3dfee3e4d8998baa7fadbfaf46f764d.tar.gz
cpython-a07435d3e3dfee3e4d8998baa7fadbfaf46f764d.tar.bz2
#4458: recognize "-" as an argument, not a malformed option in gnu_getopt().
-rw-r--r--Lib/getopt.py2
-rw-r--r--Lib/test/test_getopt.py5
-rw-r--r--Misc/NEWS3
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/getopt.py b/Lib/getopt.py
index 04e881e..7248f08 100644
--- a/Lib/getopt.py
+++ b/Lib/getopt.py
@@ -130,7 +130,7 @@ def gnu_getopt(args, shortopts, longopts = []):
if args[0][:2] == '--':
opts, args = do_longs(opts, args[0][2:], longopts, args[1:])
- elif args[0][:1] == '-':
+ elif args[0][:1] == '-' and args[0] != '-':
opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:])
else:
if all_options_first:
diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py
index 36d1688..aac720d 100644
--- a/Lib/test/test_getopt.py
+++ b/Lib/test/test_getopt.py
@@ -124,6 +124,11 @@ class GetoptTests(unittest.TestCase):
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
+ # recognize "-" as an argument
+ opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
+ self.assertEqual(args, ['-'])
+ self.assertEqual(opts, [('-a', ''), ('-b', '-')])
+
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
diff --git a/Misc/NEWS b/Misc/NEWS
index 55e123b..b1fe2e4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,9 @@ Core and Builtins
Library
-------
+- Issue #4458: getopt.gnu_getopt() now recognizes a single "-" as an argument,
+ not a malformed option.
+
- Added the subprocess.check_output() convenience function to get output
from a subprocess on success or raise an exception on error.