From: Victor Stinner Date: Tue, 13 May 2014 00:05:35 +0000 (+0200) Subject: Issue #21398: Fix an unicode error in the pydoc pager when the documentation X-Git-Tag: v3.5.0a1~1671^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0cc45baa3d160810f371ef7b69f4b56437bde790;p=python Issue #21398: Fix an unicode error in the pydoc pager when the documentation contains characters not encodable to the stdout encoding. --- diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 5f128320d2..42f48e1d63 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1404,6 +1404,9 @@ class _PlainTextDoc(TextDoc): def pager(text): """The first time this is called, determine what kind of pager to use.""" global pager + # Escape non-encodable characters to avoid encoding errors later + encoding = sys.getfilesystemencoding() + text = text.encode(encoding, 'backslashreplace').decode(encoding) pager = getpager() pager(text) diff --git a/Misc/NEWS b/Misc/NEWS index 0b00ecdbad..32004cb864 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -26,6 +26,9 @@ Library - Issue #21396: Fix TextIOWrapper(..., write_through=True) to not force a flush() on the underlying binary stream. Patch by akira. +- Issue #21398: Fix an unicode error in the pydoc pager when the documentation + contains characters not encodable to the stdout encoding. + Tests -----