| Index: third_party/logilab/common/optik_ext.py
|
| diff --git a/third_party/logilab/common/optik_ext.py b/third_party/logilab/common/optik_ext.py
|
| index 1fd2a7f8cc02eeb037671a9d4a59f8daf38de5a2..39bbe18d1598522d33c4ba8f54180ea74a260483 100644
|
| --- a/third_party/logilab/common/optik_ext.py
|
| +++ b/third_party/logilab/common/optik_ext.py
|
| @@ -46,8 +46,6 @@ It also defines three new types for optik/optparse command line parser :
|
| argument of this type will be converted to a float value in bytes
|
| according to byte units (b, kb, mb, gb, tb)
|
| """
|
| -from __future__ import print_function
|
| -
|
| __docformat__ = "restructuredtext en"
|
|
|
| import re
|
| @@ -67,9 +65,10 @@ try:
|
| except ImportError:
|
| HAS_MX_DATETIME = False
|
|
|
| -from logilab.common.textutils import splitstrip, TIME_UNITS, BYTE_UNITS, \
|
| - apply_units
|
|
|
| +OPTPARSE_FORMAT_DEFAULT = sys.version_info >= (2, 4)
|
| +
|
| +from logilab.common.textutils import splitstrip
|
|
|
| def check_regexp(option, opt, value):
|
| """check a regexp value by trying to compile it
|
| @@ -169,15 +168,18 @@ def check_color(option, opt, value):
|
| raise OptionValueError(msg % (opt, value))
|
|
|
| def check_time(option, opt, value):
|
| + from logilab.common.textutils import TIME_UNITS, apply_units
|
| if isinstance(value, (int, long, float)):
|
| return value
|
| return apply_units(value, TIME_UNITS)
|
|
|
| def check_bytes(option, opt, value):
|
| + from logilab.common.textutils import BYTE_UNITS, apply_units
|
| if hasattr(value, '__int__'):
|
| return value
|
| return apply_units(value, BYTE_UNITS)
|
|
|
| +import types
|
|
|
| class Option(BaseOption):
|
| """override optik.Option to add some new option types
|
| @@ -212,7 +214,7 @@ class Option(BaseOption):
|
| if self.choices is None:
|
| raise OptionError(
|
| "must supply a list of choices for type 'choice'", self)
|
| - elif not isinstance(self.choices, (tuple, list)):
|
| + elif type(self.choices) not in (types.TupleType, types.ListType):
|
| raise OptionError(
|
| "choices must be a list of strings ('%s' supplied)"
|
| % str(type(self.choices)).split("'")[1], self)
|
| @@ -225,7 +227,10 @@ class Option(BaseOption):
|
| def process(self, opt, value, values, parser):
|
| # First, convert the value(s) to the right type. Howl if any
|
| # value(s) are bogus.
|
| - value = self.convert_value(opt, value)
|
| + try:
|
| + value = self.convert_value(opt, value)
|
| + except AttributeError: # py < 2.4
|
| + value = self.check_value(opt, value)
|
| if self.type == 'named':
|
| existant = getattr(values, self.dest)
|
| if existant:
|
| @@ -383,9 +388,9 @@ def generate_manpage(optparser, pkginfo, section=1, stream=sys.stdout, level=0):
|
| formatter = ManHelpFormatter()
|
| formatter.output_level = level
|
| formatter.parser = optparser
|
| - print(formatter.format_head(optparser, pkginfo, section), file=stream)
|
| - print(optparser.format_option_help(formatter), file=stream)
|
| - print(formatter.format_tail(pkginfo), file=stream)
|
| + print >> stream, formatter.format_head(optparser, pkginfo, section)
|
| + print >> stream, optparser.format_option_help(formatter)
|
| + print >> stream, formatter.format_tail(pkginfo)
|
|
|
|
|
| __all__ = ('OptionParser', 'Option', 'OptionGroup', 'OptionValueError',
|
|
|