Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48aa84b

Browse files
committed
Update optparse module and test suite to Optik 1.5a2.
1 parent 99b5548 commit 48aa84b

2 files changed

Lines changed: 237 additions & 210 deletions

File tree

Lib/optparse.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Python developers: please do not make changes to this file, since
1717
# it is automatically generated from the Optik source code.
1818

19-
__version__ = "1.5a1"
19+
__version__ = "1.5a2"
2020

2121
__all__ = ['Option',
2222
'SUPPRESS_HELP',
@@ -76,10 +76,10 @@ def _repr(self):
7676

7777

7878
# This file was generated from:
79-
# Id: option_parser.py,v 1.67 2004/07/24 23:21:21 gward Exp
80-
# Id: option.py,v 1.33 2004/07/24 23:21:21 gward Exp
81-
# Id: help.py,v 1.15 2004/07/24 23:21:21 gward Exp
82-
# Id: errors.py,v 1.9 2004/07/24 23:21:21 gward Exp
79+
# Id: option_parser.py 421 2004-10-26 00:45:16Z greg
80+
# Id: option.py 422 2004-10-26 00:53:47Z greg
81+
# Id: help.py 367 2004-07-24 23:21:21Z gward
82+
# Id: errors.py 367 2004-07-24 23:21:21Z gward
8383

8484
class OptParseError (Exception):
8585
def __init__(self, msg):
@@ -436,11 +436,16 @@ class Option:
436436
"count")
437437

438438
# The set of actions for which it makes sense to supply a value
439-
# type, ie. where we expect an argument to this option.
439+
# type, ie. which may consume an argument from the command line.
440440
TYPED_ACTIONS = ("store",
441441
"append",
442442
"callback")
443443

444+
# The set of actions which *require* a value type, ie. that
445+
# always consume an argument from the command line.
446+
ALWAYS_TYPED_ACTIONS = ("store",
447+
"append")
448+
444449
# The set of known types for option parsers. Again, listed here for
445450
# constructor argument validation.
446451
TYPES = ("string", "int", "long", "float", "complex", "choice")
@@ -557,9 +562,7 @@ def _check_action(self):
557562

558563
def _check_type(self):
559564
if self.type is None:
560-
# XXX should factor out another class attr here: list of
561-
# actions that *require* a type
562-
if self.action in ("store", "append"):
565+
if self.action in self.ALWAYS_TYPED_ACTIONS:
563566
if self.choices is not None:
564567
# The "choices" attribute implies "choice" type.
565568
self.type = "choice"
@@ -723,10 +726,10 @@ def take_action(self, action, dest, opt, value, values, parser):
723726
self.callback(self, opt, value, parser, *args, **kwargs)
724727
elif action == "help":
725728
parser.print_help()
726-
sys.exit(0)
729+
parser.exit()
727730
elif action == "version":
728731
parser.print_version()
729-
sys.exit(0)
732+
parser.exit()
730733
else:
731734
raise RuntimeError, "unknown action %r" % self.action
732735

@@ -877,7 +880,7 @@ def _share_option_mappings(self, parser):
877880
self.defaults = parser.defaults
878881

879882
def set_conflict_handler(self, handler):
880-
if handler not in ("ignore", "error", "resolve"):
883+
if handler not in ("error", "resolve"):
881884
raise ValueError, "invalid conflict_resolution value %r" % handler
882885
self.conflict_handler = handler
883886

@@ -901,14 +904,12 @@ def _check_conflict(self, option):
901904

902905
if conflict_opts:
903906
handler = self.conflict_handler
904-
if handler == "ignore": # behaviour for Optik 1.0, 1.1
905-
pass
906-
elif handler == "error": # new in 1.2
907+
if handler == "error":
907908
raise OptionConflictError(
908909
"conflicting option string(s): %s"
909910
% ", ".join([co[0] for co in conflict_opts]),
910911
option)
911-
elif handler == "resolve": # new in 1.2
912+
elif handler == "resolve":
912913
for (opt, c_option) in conflict_opts:
913914
if opt.startswith("--"):
914915
c_option._long_opts.remove(opt)
@@ -1442,6 +1443,11 @@ def expand_prog_name(self, s):
14421443
def get_description(self):
14431444
return self.expand_prog_name(self.description)
14441445

1446+
def exit(self, status=0, msg=None):
1447+
if msg:
1448+
sys.stderr.write(msg)
1449+
sys.exit(status)
1450+
14451451
def error(self, msg):
14461452
"""error(msg : string)
14471453
@@ -1450,8 +1456,7 @@ def error(self, msg):
14501456
should either exit or raise an exception.
14511457
"""
14521458
self.print_usage(sys.stderr)
1453-
sys.stderr.write("%s: error: %s\n" % (self.get_prog_name(), msg))
1454-
sys.exit(2) # command-line usage error
1459+
self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
14551460

14561461
def get_usage(self):
14571462
if self.usage:

0 commit comments

Comments
 (0)