From 77d6008254c6ef87f8189294cbaa6ce332e6ab77 Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Sat, 10 Jan 2009 14:45:01 +1300 Subject: [PATCH] automatically fall back to Latin-1 for old entries that aren't UTF-8 --- ChangeLog | 1 + ljdump.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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) -- 2.39.5