Merge lp:~aaron-whitehouse/duplicity/08-uexc-fix into lp:~duplicity-team/duplicity/0.8-series

Proposed by Aaron Whitehouse
Status: Merged
Merged at revision: 1353
Proposed branch: lp:~aaron-whitehouse/duplicity/08-uexc-fix
Merge into: lp:~duplicity-team/duplicity/0.8-series
Diff against target: 72 lines (+52/-1)
2 files modified
duplicity/util.py (+11/-1)
testing/unit/test_util.py (+41/-0)
To merge this branch: bzr merge lp:~aaron-whitehouse/duplicity/08-uexc-fix
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+364217@code.launchpad.net

Commit message

Fix for Bug #1770929 with associated test cases (thanks to Pete Zaitcev (zaitcev) in Bug #1797928 for the head start).

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'duplicity/util.py'
2--- duplicity/util.py 2018-11-29 19:00:15 +0000
3+++ duplicity/util.py 2019-03-10 23:02:34 +0000
4@@ -105,11 +105,21 @@
5
6
7 def uexc(e):
8+ u"""Returns the exception message in Unicode"""
9 # Exceptions in duplicity often have path names in them, which if they are
10 # non-ascii will cause a UnicodeDecodeError when implicitly decoding to
11 # unicode. So we decode manually, using the filesystem encoding.
12 # 99.99% of the time, this will be a fine encoding to use.
13- return fsdecode(str(e).encode(u'utf-8'))
14+ if e.args:
15+ m = e.args[0] # exception.message is deprecated, but this is equivalent
16+ if isinstance(m, str):
17+ # Already unicode
18+ return m
19+ else:
20+ # Encoded, likely in filesystem encoding
21+ return fsdecode(m)
22+ else:
23+ return None
24
25
26 def maybe_ignore_errors(fn):
27
28=== added file 'testing/unit/test_util.py'
29--- testing/unit/test_util.py 1970-01-01 00:00:00 +0000
30+++ testing/unit/test_util.py 2019-03-10 23:02:34 +0000
31@@ -0,0 +1,41 @@
32+#
33+# This file is part of duplicity.
34+#
35+# Duplicity is free software; you can redistribute it and/or modify it
36+# under the terms of the GNU General Public License as published by the
37+# Free Software Foundation; either version 2 of the License, or (at your
38+# option) any later version.
39+#
40+# Duplicity is distributed in the hope that it will be useful, but
41+# WITHOUT ANY WARRANTY; without even the implied warranty of
42+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43+# General Public License for more details.
44+#
45+# You should have received a copy of the GNU General Public License
46+# along with duplicity; if not, write to the Free Software Foundation,
47+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48+
49+import unittest
50+import duplicity
51+
52+class TestExc(unittest.TestCase):
53+
54+ def test_uexc(self):
55+
56+ e = Exception('test')
57+ msg = duplicity.util.uexc(e)
58+ self.assertEqual(msg, 'test')
59+
60+ # Test for Bug #1770929
61+ # https://bugs.launchpad.net/duplicity/+bug/1770929
62+ e = Exception(b'\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88')
63+ msg = duplicity.util.uexc(e)
64+ self.assertEqual(msg, u'\u30c6\u30b9\u30c8')
65+
66+ e = Exception(u'\u30c6\u30b9\u30c8')
67+ msg = duplicity.util.uexc(e)
68+ self.assertEqual(msg, u'\u30c6\u30b9\u30c8')
69+
70+
71+if __name__ == '__main__':
72+ unittest.main()

Subscribers

People subscribed via source and target branches