[issue1065986] Fix pydoc crashing on unicode strings
Stefano Taschini
report at bugs.python.org
Tue Apr 24 17:26:42 CEST 2012
Stefano Taschini <taschini at ieee.org> added the comment:
Oh well, in that case I guess we'll have to work around it.
Here's the monkey patch I use to overcome this limitation in pydoc, in case others wish to add it to their PYTHONSTARTUP or sitecustomize:
def pipepager(text, cmd):
"""Page through text by feeding it to another program."""
try:
import locale
except ImportError:
encoding = "ascii"
else:
encoding = locale.getpreferredencoding()
pipe = os.popen(cmd, 'w')
try:
pipe.write(text.encode(encoding, 'xmlcharrefreplace') if isinstance(text, unicode) else text)
pipe.close()
except IOError:
pass # Ignore broken pipes caused by quitting the pager program.
import pydoc
pydoc.pipepager = pipepager
del pydoc, pipepager
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1065986>
_______________________________________
More information about the Python-bugs-list
mailing list