diff --git a/optik/option.py b/optik/option.py index bfd553b..7f7bc93 100644 --- a/optik/option.py +++ b/optik/option.py @@ -272,7 +272,7 @@ class Option: self.type = "string" else: # Allow type objects as an alternative to their names. - if type(self.type) is type: + if hasattr(self.type, "__name__"): self.type = self.type.__name__ if self.type == "str": self.type = "string" diff --git a/optik/option_parser.py b/optik/option_parser.py index a716a5c..eccaddf 100644 --- a/optik/option_parser.py +++ b/optik/option_parser.py @@ -27,11 +27,9 @@ try: True, False except NameError: (True, False) = (1, 0) -try: - basestring -except NameError: - basestring = (str, unicode) +def isbasestring(x): + return isinstance(x, types.StringType) or isinstance(x, types.UnicodeType) class Values: @@ -45,16 +43,13 @@ class Values: __repr__ = _repr - def __eq__(self, other): + def __cmp__(self, other): if isinstance(other, Values): - return self.__dict__ == other.__dict__ - elif isinstance(other, dict): - return self.__dict__ == other + return cmp(self.__dict__, other.__dict__) + elif isinstance(other, types.DictType): + return cmp(self.__dict__, other) else: - return False - - def __ne__(self, other): - return not (self == other) + return -1 def _update_careful(self, dict): """ @@ -480,7 +475,7 @@ class OptionParser (OptionContainer): defaults = self.defaults.copy() for option in self._get_all_options(): default = defaults.get(option.dest) - if isinstance(default, basestring): + if isbasestring(default): opt_str = option.get_opt_string() defaults[option.dest] = option.check_value(opt_str, default) diff --git a/optik/textwrap.py b/optik/textwrap.py index 47cd9f7..6bcf005 100644 --- a/optik/textwrap.py +++ b/optik/textwrap.py @@ -8,6 +8,7 @@ __revision__ = "$Id: textwrap.py,v 1.35 2004/06/03 01:59:40 gward Exp $" import string, re +import types # Do the right thing with boolean values for all known Python versions # (so this module can be copied to projects that don't depend on Python @@ -120,9 +121,9 @@ class TextWrapper: if self.expand_tabs: text = text.expandtabs() if self.replace_whitespace: - if isinstance(text, str): + if isinstance(text, types.StringType): text = text.translate(self.whitespace_trans) - elif isinstance(text, unicode): + elif isinstance(text, types.UnicodeType): text = text.translate(self.unicode_whitespace_trans) return text