From: Greg Hewgill Date: Sat, 10 Jan 2009 01:45:01 +0000 (+1300) Subject: automatically fall back to Latin-1 for old entries that aren't UTF-8 X-Git-Tag: ljdump-1.3.3~2 X-Git-Url: https://www.wagner.pp.ru/gitweb/?a=commitdiff_plain;h=77d6008254c6ef87f8189294cbaa6ce332e6ab77;p=oss%2Fljdump.git automatically fall back to Latin-1 for old entries that aren't UTF-8 --- diff --git a/ChangeLog b/ChangeLog index bc062fd..ba273d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ ChangeLog - ljdump Version 1.3.3 - 2009-01-10 - Feature: ljdump now prompts for login info if ljdump.config does not exist +- Bugfix: Automatically handle UnicodeDecodeError for old entries Version 1.3.2 - 2009-01-09 diff --git a/ljdump.py b/ljdump.py index a6d7db3..6a7e3a2 100755 --- a/ljdump.py +++ b/ljdump.py @@ -74,7 +74,11 @@ def dumpelement(f, name, e): if isinstance(e[k], {}.__class__): dumpelement(f, k, e[k]) else: - s = unicode(str(e[k]), "UTF-8") + try: + s = unicode(str(e[k]), "UTF-8") + except UnicodeDecodeError: + # fall back to Latin-1 for old entries that aren't UTF-8 + s = unicode(str(e[k]), "cp1252") f.write("<%s>%s\n" % (k, saxutils.escape(s), k)) f.write("\n" % name)