[Python-checkins] cpython (merge 3.4 -> default): (Merge 3.4) Issue #21398: Fix an unicode error in the pydoc pager when the

victor.stinner python-checkins at python.org
Tue May 13 02:06:45 CEST 2014


http://hg.python.org/cpython/rev/3424d65ad5ce
changeset:   90672:3424d65ad5ce
parent:      90670:53cf343c4fff
parent:      90671:89a29e92416f
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue May 13 02:06:33 2014 +0200
summary:
  (Merge 3.4) Issue #21398: Fix an unicode error in the pydoc pager when the
documentation contains characters not encodable to the stdout encoding.

files:
  Lib/pydoc.py |  3 +++
  Misc/NEWS    |  3 +++
  2 files changed, 6 insertions(+), 0 deletions(-)


diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1404,6 +1404,9 @@
 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -84,6 +84,9 @@
 Library
 -------
 
+- Issue #21398: Fix an unicode error in the pydoc pager when the documentation
+  contains characters not encodable to the stdout encoding.
+
 - Issue #16531: ipaddress.IPv4Network and ipaddress.IPv6Network now accept
   an (address, netmask) tuple argument, so as to easily construct network
   objects from existing addresses.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list