From: Radek Czajka Date: Wed, 22 Aug 2012 09:20:16 +0000 (+0200) Subject: Better Unicode handling in errors. X-Git-Tag: 1.7~147 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/fb1bbfe622abeaaea2a2dfc459d8b779b2d369a2 Better Unicode handling in errors. --- diff --git a/librarian/__init__.py b/librarian/__init__.py index 8a69d00..616e351 100644 --- a/librarian/__init__.py +++ b/librarian/__init__.py @@ -12,11 +12,16 @@ import shutil class UnicodeException(Exception): def __str__(self): """ Dirty workaround for Python Unicode handling problems. """ - return self.message + return unicode(self).encode('utf-8') def __unicode__(self): """ Dirty workaround for Python Unicode handling problems. """ - return self.message + args = self.args[0] if len(self.args) == 1 else self.args + try: + message = unicode(args) + except UnicodeDecodeError: + message = unicode(args, encoding='utf-8', errors='ignore') + return message class ParseError(UnicodeException): pass