[Checkins] SVN: zope.testing/branches/regebro-python3/src/zope/testing/doctest.py py3: StringIO can now deal with unicode directly

Wolfgang Schnerring wosc at wosc.de
Sun Sep 13 04:38:34 EDT 2009


Log message for revision 103886:
  py3: StringIO can now deal with unicode directly
  

Changed:
  U   zope.testing/branches/regebro-python3/src/zope/testing/doctest.py

-=-
Modified: zope.testing/branches/regebro-python3/src/zope/testing/doctest.py
===================================================================
--- zope.testing/branches/regebro-python3/src/zope/testing/doctest.py	2009-09-13 08:32:06 UTC (rev 103885)
+++ zope.testing/branches/regebro-python3/src/zope/testing/doctest.py	2009-09-13 08:38:33 UTC (rev 103886)
@@ -283,8 +283,9 @@
             del self.softspace
 
     def write(self, value):
-        if isinstance(value, unicode):
-            value = value.encode('utf8')
+        if sys.version_info < (3,):
+            if isinstance(value, unicode):
+                value = value.encode('utf8')
         StringIO.write(self, value)
 
 # Worst-case linear-time ellipsis matching.
@@ -2304,6 +2305,14 @@
         test = self._dt_test
         old = sys.stdout
         new = StringIO()
+        if sys.version_info < (3,):
+            def write(value):
+                if isinstance(value, unicode):
+                    value = value.encode('utf8')
+                new.write(value)
+        else:
+            write = new.write
+
         optionflags = self._dt_optionflags
 
         if not (optionflags & REPORTING_FLAGS):
@@ -2316,10 +2325,6 @@
 
         runner = DocTestRunner(optionflags=optionflags,
                                checker=self._dt_checker, verbose=False)
-        def write(value):
-            if isinstance(value, unicode):
-                value = value.encode('utf8')
-            new.write(value)
 
         try:
             runner.DIVIDER = "-"*70



More information about the checkins mailing list