From fb1bbfe622abeaaea2a2dfc459d8b779b2d369a2 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 22 Aug 2012 11:20:16 +0200 Subject: [PATCH 1/1] Better Unicode handling in errors. --- librarian/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 -- 2.20.1