Show More
@@ -80,12 +80,32 b' io.BufferedIOBase.register(LineBufferedW' | |||
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | def make_line_buffered(stream): |
|
83 | if not isinstance(stream, io.BufferedIOBase): | |
|
84 | # On Python 3, buffered streams can be expected to subclass | |
|
85 | # BufferedIOBase. This is definitively the case for the streams | |
|
86 | # initialized by the interpreter. For unbuffered streams, we don't need | |
|
87 | # to emulate line buffering. | |
|
83 | # First, check if we need to wrap the stream. | |
|
84 | check_stream = stream | |
|
85 | while True: | |
|
86 | if isinstance(check_stream, WriteAllWrapper): | |
|
87 | check_stream = check_stream.orig | |
|
88 | elif pycompat.iswindows and isinstance( | |
|
89 | check_stream, | |
|
90 | # pytype: disable=module-attr | |
|
91 | platform.winstdout | |
|
92 | # pytype: enable=module-attr | |
|
93 | ): | |
|
94 | check_stream = check_stream.fp | |
|
95 | else: | |
|
96 | break | |
|
97 | if isinstance(check_stream, io.RawIOBase): | |
|
98 | # The stream is unbuffered, we don't need to emulate line buffering. | |
|
88 | 99 | return stream |
|
100 | elif isinstance(check_stream, io.BufferedIOBase): | |
|
101 | # The stream supports some kind of buffering. We can't assume that | |
|
102 | # lines are flushed. Fall back to wrapping the stream. | |
|
103 | pass | |
|
104 | else: | |
|
105 | raise NotImplementedError( | |
|
106 | "can't determine whether stream is buffered or not" | |
|
107 | ) | |
|
108 | ||
|
89 | 109 | if isinstance(stream, LineBufferedWrapper): |
|
90 | 110 | return stream |
|
91 | 111 | return LineBufferedWrapper(stream) |
General Comments 0
You need to be logged in to leave comments.
Login now