#
if len(self.args) == 1:
text = self.args[0]
+
if as_unicode and isinstance(text, compat.binary_types):
- return compat.decode_backslashreplace(text, "utf-8")
+ text = compat.decode_backslashreplace(text, "utf-8")
+
+ # This is for when the argument is not a string of any sort.
+ # Otherwise, converting this exception to string would fail for
+ # non-string arguments.
+ if compat.py3k or not as_unicode:
+ text = str(text)
else:
- return self.args[0]
+ text = compat.text_type(text)
+
+ return text
else:
# this is not a normal case within SQLAlchemy but is here for
# compatibility with Exception.args - the str() comes out as
pass
+class Foo(object):
+
+ def __str__(self):
+ return "foo"
+
+ def __unicode__(self):
+ return util.u("fóó")
+
+
class ExecuteTest(fixtures.TablesTest):
__backend__ = True
else:
eq_(str(err), util.u("some message méil"))
+ def test_stmt_exception_object_arg(self):
+ err = tsa.exc.SQLAlchemyError(Foo())
+ eq_(str(err), "foo")
+
+ if util.py2k:
+ eq_(unicode(err), util.u("fóó")) # noqa
+
def test_stmt_exception_str_multi_args(self):
err = tsa.exc.SQLAlchemyError("some message", 206)
eq_(str(err), "('some message', 206)")