Merge lp:~ed.so/duplicity/UnicodeDecodeError into lp:duplicity/0.6

Proposed by edso
Status: Merged
Merged at revision: 794
Proposed branch: lp:~ed.so/duplicity/UnicodeDecodeError
Merge into: lp:duplicity/0.6
Diff against target: 46 lines (+28/-1)
1 file modified
duplicity/commandline.py (+28/-1)
To merge this branch: bzr merge lp:~ed.so/duplicity/UnicodeDecodeError
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+78840@code.launchpad.net
To post a comment you must log in.
795. By edso

some links for UnicodeDecodeError

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'duplicity/commandline.py'
2--- duplicity/commandline.py 2011-10-08 16:09:27 +0000
3+++ duplicity/commandline.py 2011-10-10 14:13:26 +0000
4@@ -169,6 +169,33 @@
5 optparse.Option.take_action(
6 self, action, dest, opt, value, values, parser)
7
8+"""
9+Fix:
10+ File "/usr/lib/pythonX.X/optparse.py", line XXXX, in print_help
11+ file.write(self.format_help().encode(encoding, "replace"))
12+ UnicodeDecodeError: 'ascii' codec can't decode byte 0xXX in position XXXX:
13+See:
14+ http://bugs.python.org/issue2931
15+ http://mail.python.org/pipermail/python-dev/2006-May/065458.html
16+"""
17+class OPHelpFix(optparse.OptionParser):
18+ def _get_encoding(self, file):
19+ """
20+ try to get the encoding or switch to UTF-8
21+ which is default encoding in python3 and most recent unixes
22+ """
23+ encoding = getattr(file, "encoding", "UTF-8")
24+ return encoding
25+
26+ def print_help(self, file=None):
27+ """
28+ overwrite method with proper utf-8 decoding
29+ """
30+ if file is None:
31+ file = sys.stdout
32+ encoding = self._get_encoding(file)
33+ file.write(self.format_help().decode('utf-8').encode(encoding, "replace"))
34+
35 def parse_cmdline_options(arglist):
36 """Parse argument list"""
37 global select_opts, select_files, full_backup
38@@ -211,7 +238,7 @@
39 def add_rename(o, s, v, p):
40 globals.rename[os.path.normcase(os.path.normpath(v[0]))] = v[1]
41
42- parser = optparse.OptionParser(option_class=DupOption, usage=usage())
43+ parser = OPHelpFix( option_class=DupOption, usage=usage() )
44
45 # If this is true, only warn and don't raise fatal error when backup
46 # source directory doesn't match previous backup source directory.

Subscribers

People subscribed via source and target branches

to all changes: