diff options
author | Georg Brandl <georg@python.org> | 2008-12-07 15:15:22 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-12-07 15:15:22 (GMT) |
commit | eee3116690e8c587fdf06af65427efabf4390554 (patch) | |
tree | d301c8e3f83ed604ba9fe85c29e0568964c415da /Lib | |
parent | 6485f247e44509536a0dfe173c47957cbadf04e1 (diff) | |
download | cpython-eee3116690e8c587fdf06af65427efabf4390554.zip cpython-eee3116690e8c587fdf06af65427efabf4390554.tar.gz cpython-eee3116690e8c587fdf06af65427efabf4390554.tar.bz2 |
Merged revisions 67463,67572,67576,67628 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67463 | skip.montanaro | 2008-12-01 02:55:22 +0100 (Mon, 01 Dec 2008) | 1 line
typo in comment
........
r67572 | georg.brandl | 2008-12-05 10:23:14 +0100 (Fri, 05 Dec 2008) | 2 lines
#4458: recognize "-" as an argument, not a malformed option in gnu_getopt().
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67628 | skip.montanaro | 2008-12-07 03:16:00 +0100 (Sun, 07 Dec 2008) | 1 line
muffed the default case
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/getopt.py | 2 | ||||
-rw-r--r-- | Lib/test/test_getopt.py | 5 | ||||
-rw-r--r-- | Lib/test/test_parser.py | 10 |
3 files changed, 16 insertions, 1 deletions
diff --git a/Lib/getopt.py b/Lib/getopt.py index 93777b4..13ef4d6 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 de3325d..11ae163 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/Lib/test/test_parser.py b/Lib/test/test_parser.py index 17d1988..2f1310b 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -193,6 +193,16 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): self.check_suite("with open('x'): pass\n") self.check_suite("with open('x') as f: pass\n") + def test_try_stmt(self): + self.check_suite("try: pass\nexcept: pass\n") + self.check_suite("try: pass\nfinally: pass\n") + self.check_suite("try: pass\nexcept A: pass\nfinally: pass\n") + self.check_suite("try: pass\nexcept A: pass\nexcept: pass\n" + "finally: pass\n") + self.check_suite("try: pass\nexcept: pass\nelse: pass\n") + self.check_suite("try: pass\nexcept: pass\nelse: pass\n" + "finally: pass\n") + def test_position(self): # An absolutely minimal test of position information. Better # tests would be a big project. |