Index: help.py =================================================================== --- help.py (.../optik) (revision 4862) +++ help.py (.../pythonpath/optik) (revision 15947) @@ -3,6 +3,7 @@ Provides HelpFormatter and subclasses -- used by OptionParser to generate formatted help text. """ +from __future__ import division # Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved. # See the README.txt distributed with Optik for licensing terms. @@ -127,7 +128,7 @@ def format_description(self, description): if description: - return self._format_text(description) + "\n" + return description # self._format_text(description) + "\n" else: return "" Index: option.py =================================================================== --- option.py (.../optik) (revision 4862) +++ option.py (.../pythonpath/optik) (revision 15947) @@ -2,6 +2,7 @@ Defines the Option class and some standard value-checking functions. """ +from __future__ import division # Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved. # See the README.txt distributed with Optik for licensing terms. @@ -191,6 +192,7 @@ # Have to be set now, in case no option strings are supplied. self._short_opts = [] self._long_opts = [] + self._long_opts_had_minus = False opts = self._check_opt_strings(opts) self._set_opt_strings(opts) @@ -233,7 +235,9 @@ "invalid long option string %r: " "must start with --, followed by non-dash" % opt, self) - self._long_opts.append(opt) + self._long_opts.append("--" + opt[2:].replace("_", "-")) + if (not self._long_opts_had_minus): + self._long_opts_had_minus = (opt[2:].find("-") >= 0) def _set_attrs(self, attrs): for attr in self.ATTRS: @@ -314,6 +318,11 @@ if self._long_opts: # eg. "--foo-bar" -> "foo_bar" self.dest = self._long_opts[0][2:].replace('-', '_') + if (self._long_opts_had_minus): + raise OptionError( + "If dest is not specified explicitly, long options" + " must be given with underscores instead of" + " minus signs.", self) else: self.dest = self._short_opts[0][1] @@ -432,6 +441,7 @@ elif action == "callback": args = self.callback_args or () kwargs = self.callback_kwargs or {} + if (opt[:2] == "--"): opt = "--" + opt[2:].replace("-","_") self.callback(self, opt, value, parser, *args, **kwargs) elif action == "help": parser.print_help() Index: errors.py =================================================================== --- errors.py (.../optik) (revision 4862) +++ errors.py (.../pythonpath/optik) (revision 15947) @@ -2,6 +2,7 @@ Exception classes used by Optik. """ +from __future__ import division # Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved. # See the README.txt distributed with Optik for licensing terms. Index: textwrap.py =================================================================== --- textwrap.py (.../optik) (revision 4862) +++ textwrap.py (.../pythonpath/optik) (revision 15947) @@ -1,5 +1,6 @@ """Text wrapping and filling. """ +from __future__ import division # Copyright (C) 1999-2001 Gregory P. Ward. # Copyright (C) 2002, 2003 Python Software Foundation. Index: __init__.py =================================================================== --- __init__.py (.../optik) (revision 4862) +++ __init__.py (.../pythonpath/optik) (revision 15947) @@ -6,6 +6,7 @@ See http://optik.sourceforge.net/ """ +from __future__ import division # Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved. # See the README.txt distributed with Optik for licensing terms. Index: option_parser.py =================================================================== --- option_parser.py (.../optik) (revision 4862) +++ option_parser.py (.../pythonpath/optik) (revision 15947) @@ -2,6 +2,7 @@ Provides the OptionParser and Values classes. """ +from __future__ import division # Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved. # See the README.txt distributed with Optik for licensing terms. @@ -143,7 +144,7 @@ # option mappings used by this OptionParser and all # OptionGroups that it owns. self._short_opt = {} # single letter -> Option instance - self._long_opt = {} # long option -> Option instance + self._long_opt = _long_opt_dict() # long option -> Option instance self.defaults = {} # maps option dest -> default value @@ -868,3 +869,27 @@ else: # More than one possible completion: ambiguous prefix. raise AmbiguousOptionError(s, possibilities) + +def _long_opt_no_underscores(s): + return s[:2] + s[2:].replace("_", "-") + +class _long_opt_dict: + + def __init__(self): + self._data = {} + + def keys(self): + return self._data.keys() + + def __setitem__(self, key, value): + assert key[2:].find("_") < 0 + self._data[key] = value + + def __getitem__(self, key): + return self._data[_long_opt_no_underscores(key)] + + def get(self, key, default=None): + return self._data.get(_long_opt_no_underscores(key), default) + + def has_key(self, key): + return self._data.has_key(_long_opt_no_underscores(key))