Comment 8 for bug 1031679

Revision history for this message
Oliver (oliver-assarbad) wrote :

Okay, found something worth noting and even though my Python and pdb foo may be weak compared to some of the pythonistas here, this looks like the root cause for the problem at hand.

Observe:

------------------------------
$ PYTHONIOENCODING=utf-8 python -m pdb $(which bzr) fast-export --plain ~/etc/
Breakpoint 1 at /usr/lib/python2.7/dist-packages/fastimport/commands.py:333
> /usr/bin/bzr(19)<module>()
-> from __future__ import absolute_import
(Pdb) import sys; print(sys.getdefaultencoding())
ascii
(Pdb) sys.setdefaultencoding('utf-8')
*** AttributeError: 'module' object has no attribute 'setdefaultencoding'
(Pdb) reload(sys)
<module 'sys' (built-in)>
(Pdb) sys.setdefaultencoding('utf-8')
(Pdb) print(sys.getdefaultencoding())
utf-8
------------------------------

So I tell Python explicitly to use utf-8 as the I/O encoding, which it obviously refuses. Worse, even, when I try to set it, I get the AttributeError.

However, if I reload the sys module, suddenly the function sys.setdefaultencoding becomes available and after I call it, I can see with

   print(sys.getdefaultencoding())

that it was successful.

Obviously, since the PYTHONIOENCODING environment variable is ignored, running this outside the debugger yields the same error as can be seen above. I am investigating possibilities for a workaround, but I reckon the info so far may be valuable, even if I get distracted or bored ;)