SF.net SVN: docutils:[9819 ] trunk/docutils/test/allte sts.py
aa-turner--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9819
http://sourceforge.net/p/docutils/code/9819
Author: aa-turner
Date: 2024-08-01 18:42:09 +0000 (Thu, 01 Aug 2024)
Log Message:
-----------
Improve how ``Tee`` pretends to be a file
This also fixes ``test_publish_cmdline`` on Windows when using a
non-character device (not a TTY or the console device) and on UNIX
systems with non-UTF-8 locales.
Modified Paths:
--------------
trunk/docutils/test/alltests.py
Modified: trunk/docutils/test/alltests.py
===================================================================
--- trunk/docutils/test/alltests.py 2024-08-01 17:35:31 UTC (rev 9818)
+++ trunk/docutils/test/alltests.py 2024-08-01 18:42:09 UTC (rev 9819)
@@ -41,7 +41,9 @@
types.TracebackType,
]
+STDOUT = sys.__stdout__
+
class Tee:
"""Write to a file and stdout simultaneously."""
@@ -49,9 +51,8 @@
self.file: TextIO | None = open(
filename, 'w', encoding='utf-8', errors='backslashreplace',
)
+ self.encoding: str = 'utf-8'
atexit.register(self.close)
- self.stream = sys.__stdout__
- self.encoding: str = sys.__stdout__.encoding
def close(self) -> None:
if self.file is not None:
@@ -60,15 +61,15 @@
def write(self, string: str) -> None:
try:
- self.stream.write(string)
+ STDOUT.write(string)
except UnicodeEncodeError:
- bstring = string.encode(self.encoding, errors='backslashreplace')
- self.stream.write(bstring.decode())
+ bstring = string.encode(STDOUT.encoding, errors='backslashreplace')
+ STDOUT.buffer.write(bstring)
if self.file is not None:
self.file.write(string)
def flush(self) -> None:
- self.stream.flush()
+ STDOUT.flush()
if self.file is not None:
self.file.flush()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.