[Zope3-checkins] SVN: zope.testing/branches/regebro-doctest-patching/src/zope/testing/doctest/__init__.py A further bug that needed patching.
Lennart Regebro
regebro at gmail.com
Mon Apr 26 12:33:54 EDT 2010
Log message for revision 111446:
A further bug that needed patching.
Changed:
U zope.testing/branches/regebro-doctest-patching/src/zope/testing/doctest/__init__.py
-=-
Modified: zope.testing/branches/regebro-doctest-patching/src/zope/testing/doctest/__init__.py
===================================================================
--- zope.testing/branches/regebro-doctest-patching/src/zope/testing/doctest/__init__.py 2010-04-26 16:28:28 UTC (rev 111445)
+++ zope.testing/branches/regebro-doctest-patching/src/zope/testing/doctest/__init__.py 2010-04-26 16:33:53 UTC (rev 111446)
@@ -65,6 +65,25 @@
doctest._SpoofOut = _patched_SpoofOut
+# Patching a unicode error that has been fixed in Python 2.6.5:
+import sys
+if sys.version < '2.6.5':
+ import re
+ doctest._encoding = getattr(sys.__stdout__, 'encoding', None) or 'utf-8'
+
+ def _indent(s, indent=4):
+ """
+ Add the given number of space characters to the beginning of
+ every non-blank line in `s`, and return the result.
+ If the string `s` is Unicode, it is encoded using the stdout
+ encoding and the `backslashreplace` error handler.
+ """
+ if isinstance(s, unicode):
+ s = s.encode(doctest._encoding, 'backslashreplace')
+ # This regexp matches the start of non-blank lines:
+ return re.sub('(?m)^(?!$)', indent*' ', s)
+
+ doctest._indent = _indent
# Patch to fix tests that has mixed line endings:
# Reported as #8473: http://bugs.python.org/issue8473
More information about the Zope3-Checkins
mailing list