summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-10-16 18:33:08 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-10-16 18:34:11 +0100
commitd262628e89115bbcc33c439c77d33733c4a23491 (patch)
treed6d3199a0541f8746d45caf09b7d349d6343b2d2
parent544e05a16e55dad7e666baabfb665997a79d6580 (diff)
downloaddbus-python-d262628e89115bbcc33c439c77d33733c4a23491.tar.gz
DBusException: override both __str__ and __unicode__
Avoid chaining up to the superclass, because that behaves particularly oddly. This fixes regression test failures: str(some_dbus_exception) was no longer prefixed with the D-Bus error name under Python 2. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55899
-rw-r--r--dbus/exceptions.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/dbus/exceptions.py b/dbus/exceptions.py
index 21efb06..0930425 100644
--- a/dbus/exceptions.py
+++ b/dbus/exceptions.py
@@ -51,15 +51,21 @@ class DBusException(Exception):
% ', '.join(kwargs.keys()))
Exception.__init__(self, *args)
- def __unicode_for_py2(self):
+ def __unicode__(self):
"""Return a unicode error"""
- s = Exception.__unicode__(self)
+ # We can't just use Exception.__unicode__ because it chains up weirdly.
+ # https://code.launchpad.net/~mvo/ubuntu/quantal/dbus-python/lp846044/+merge/129214
+ if len(self.args) > 1:
+ s = unicode(self.args)
+ else:
+ s = ''.join(self.args)
+
if self._dbus_error_name is not None:
return '%s: %s' % (self._dbus_error_name, s)
else:
return s
- def __str_for_py3(self):
+ def __str__(self):
"""Return a str error"""
s = Exception.__str__(self)
if self._dbus_error_name is not None:
@@ -67,18 +73,18 @@ class DBusException(Exception):
else:
return s
- if is_py3:
- __str__ = __str_for_py3
- else:
- __unicode__ = __unicode_for_py2
-
def get_dbus_message(self):
- if is_py3:
- s = Exception.__str__(self)
+ if len(self.args) > 1:
+ if is_py3:
+ s = str(self.args)
+ else:
+ s = unicode(self.args)
else:
- s = Exception.__unicode__(self)
+ s = ''.join(self.args)
+
if isinstance(s, bytes):
return s.decode('utf-8', 'replace')
+
return s
def get_dbus_name(self):