aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-02-27 14:37:21 +0000
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-02-27 14:37:21 +0000
commite94b221d5ed5d1f5efc6087623dbbe2916b478bc (patch)
tree0bacbe188fe5d48e6d4b7620cc0a1423d8502644 /Lib/doctest.py
parentMerged revisions 78491 via svnmerge from (diff)
downloadcpython-e94b221d5ed5d1f5efc6087623dbbe2916b478bc.tar.gz
cpython-e94b221d5ed5d1f5efc6087623dbbe2916b478bc.tar.bz2
cpython-e94b221d5ed5d1f5efc6087623dbbe2916b478bc.zip
Merged revisions 78493 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r78493 | florent.xicluna | 2010-02-27 15:21:57 +0100 (sam, 27 fév 2010) | 11 lines For 3.x, the "backslashreplace" error handling is plugged on the "write" method. Recorded merge of revisions 78488 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78488 | florent.xicluna | 2010-02-27 14:31:23 +0100 (sam, 27 fév 2010) | 2 lines Issue #1729305: Fix doctest to handle encode error with "backslashreplace". It fixes #7667 too. ........ ................
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index d6fb504eeaa..18bdc0ae72a 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -218,8 +218,8 @@ def _load_testfile(filename, package, module_relative, encoding):
def _indent(s, indent=4):
"""
- Add the given number of space characters to the beginning every
- non-blank line in `s`, and return the result.
+ Add the given number of space characters to the beginning of
+ every non-blank line in `s`, and return the result.
"""
# This regexp matches the start of non-blank lines:
return re.sub('(?m)^(?!$)', indent*' ', s)
@@ -1354,7 +1354,14 @@ class DocTestRunner:
save_stdout = sys.stdout
if out is None:
- out = save_stdout.write
+ encoding = save_stdout.encoding
+ if encoding is None or encoding.lower() == 'utf-8':
+ out = save_stdout.write
+ else:
+ # Use backslashreplace error handling on write
+ def out(s):
+ s = str(s.encode(encoding, 'backslashreplace'), encoding)
+ save_stdout.write(s)
sys.stdout = self._fakeout
# Patch pdb.set_trace to restore sys.stdout during interactive