]> granicus.if.org Git - python/commitdiff
Issue #21398: Fix an unicode error in the pydoc pager when the documentation
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 13 May 2014 00:05:35 +0000 (02:05 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 13 May 2014 00:05:35 +0000 (02:05 +0200)
contains characters not encodable to the stdout encoding.

Lib/pydoc.py
Misc/NEWS

index 5f128320d25060fb6791424731c24ce8c3289d9c..42f48e1d63080c439794f63c339799166fde5fd0 100755 (executable)
@@ -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)
 
index 0b00ecdbadcc0aa27e1d67f44786effe84599913..32004cb864ad20386c9672d9a44843030e2cb06d 100644 (file)
--- 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
 -----