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
=== modified file 'duplicity/commandline.py'
--- duplicity/commandline.py 2011-10-08 16:09:27 +0000
+++ duplicity/commandline.py 2011-10-10 14:13:26 +0000
@@ -169,6 +169,33 @@
169 optparse.Option.take_action(169 optparse.Option.take_action(
170 self, action, dest, opt, value, values, parser)170 self, action, dest, opt, value, values, parser)
171171
172"""
173Fix:
174 File "/usr/lib/pythonX.X/optparse.py", line XXXX, in print_help
175 file.write(self.format_help().encode(encoding, "replace"))
176 UnicodeDecodeError: 'ascii' codec can't decode byte 0xXX in position XXXX:
177See:
178 http://bugs.python.org/issue2931
179 http://mail.python.org/pipermail/python-dev/2006-May/065458.html
180"""
181class OPHelpFix(optparse.OptionParser):
182 def _get_encoding(self, file):
183 """
184 try to get the encoding or switch to UTF-8
185 which is default encoding in python3 and most recent unixes
186 """
187 encoding = getattr(file, "encoding", "UTF-8")
188 return encoding
189
190 def print_help(self, file=None):
191 """
192 overwrite method with proper utf-8 decoding
193 """
194 if file is None:
195 file = sys.stdout
196 encoding = self._get_encoding(file)
197 file.write(self.format_help().decode('utf-8').encode(encoding, "replace"))
198
172def parse_cmdline_options(arglist):199def parse_cmdline_options(arglist):
173 """Parse argument list"""200 """Parse argument list"""
174 global select_opts, select_files, full_backup201 global select_opts, select_files, full_backup
@@ -211,7 +238,7 @@
211 def add_rename(o, s, v, p):238 def add_rename(o, s, v, p):
212 globals.rename[os.path.normcase(os.path.normpath(v[0]))] = v[1]239 globals.rename[os.path.normcase(os.path.normpath(v[0]))] = v[1]
213240
214 parser = optparse.OptionParser(option_class=DupOption, usage=usage())241 parser = OPHelpFix( option_class=DupOption, usage=usage() )
215242
216 # If this is true, only warn and don't raise fatal error when backup243 # If this is true, only warn and don't raise fatal error when backup
217 # source directory doesn't match previous backup source directory.244 # source directory doesn't match previous backup source directory.

Subscribers

People subscribed via source and target branches

to all changes: