Rework the "Not enough space" workaround for Python 2 on Windows 7 and below
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Segev Finer · committed by David Lord · parent 6c0d585 · Browse files · 2 files·+17 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+17 added−10 removed
- other:+17 added−10 removed
Provenance
- Commit
6cafd32- Tree
fe01227- Author
Segev Finer <segev208@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
6c0d585
2 files changed+17 added−10 removed
modified:click/_compat.py+6 added-1 removed
222 unmodified lines223 def get_binary_stdin():224 return set_binary_mode(sys.stdin)225 226 def get_binary_stdout():227+ _wrap_std_stream('stdout')228 return set_binary_mode(sys.stdout)229 230 def get_binary_stderr():231+ _wrap_std_stream('stderr')232 return set_binary_mode(sys.stderr)233 234 def get_text_stdin(encoding=None, errors=None):235 rv = _get_windows_console_stream(sys.stdin, encoding, errors)2 unmodified lines238 return _make_text_stream(sys.stdin, encoding, errors,239 force_readable=True)240 241 def get_text_stdout(encoding=None, errors=None):242+ _wrap_std_stream('stdout')243 rv = _get_windows_console_stream(sys.stdout, encoding, errors)244 if rv is not None:245 return rv246 return _make_text_stream(sys.stdout, encoding, errors,247 force_writable=True)248 249 def get_text_stderr(encoding=None, errors=None):250+ _wrap_std_stream('stderr')251 rv = _get_windows_console_stream(sys.stderr, encoding, errors)252 if rv is not None:253 return rv254 return _make_text_stream(sys.stderr, encoding, errors,330 unmodified lines585 if WIN:586 # Windows has a smaller terminal587 DEFAULT_COLUMNS = 79588 585- from ._winconsole import _get_windows_console_stream589+ from ._winconsole import _get_windows_console_stream, _wrap_std_stream590 591 def _get_argv_encoding():592 import locale593 return locale.getpreferredencoding()53 unmodified lines647 def _get_argv_encoding():648 return getattr(sys.stdin, 'encoding', None) or get_filesystem_encoding()649 650 _get_windows_console_stream = lambda *x: None651+ _wrap_std_stream = lambda *x: None652 653 654 def term_len(x):655 return len(strip_ansi(x))48 unmodified linesmodified:click/_winconsole.py+11 added-9 removed
199 unmodified lines200 self.encoding,201 )202 203 204-class StreamWrapper(object):204+class WindowsChunkedWriter(object):205 """206 Wraps a stream (such as stdout), acting as a transparent proxy for all207 attribute access apart from method 'write()' which we wrap to write in208 limited chunks due to a Windows limitation on binary console streams.15 unmodified lines224 self.__wrapped.write(text[written:written+to_write])225 written += to_write226 227 228+_wrapped_std_streams = set()229+230+231+def _wrap_std_stream(name):232+ # Python 2 & Windows 7 and below233+ if PY2 and sys.getwindowsversion()[:2] <= (6, 1) and name not in _wrapped_std_streams:234+ setattr(sys, name, WindowsChunkedWriter(getattr(sys, name)))235+ _wrapped_std_streams.add(name)236+237+238 def _get_text_stdin(buffer_stream):239 text_stream = _NonClosingTextIOWrapper(240 io.BufferedReader(_WindowsConsoleReader(STDIN_HANDLE)),241 'utf-16-le', 'strict', line_buffering=True)242 return ConsoleStream(text_stream, buffer_stream)243 244 245 def _get_text_stdout(buffer_stream):236- if PY2:237- buffer_stream = StreamWrapper(buffer_stream)238- sys.stdout = StreamWrapper(sys.stdout)239-246 text_stream = _NonClosingTextIOWrapper(247 io.BufferedWriter(_WindowsConsoleWriter(STDOUT_HANDLE)),248 'utf-16-le', 'strict', line_buffering=True)249 return ConsoleStream(text_stream, buffer_stream)250 251 252 def _get_text_stderr(buffer_stream):247- if PY2:248- buffer_stream = StreamWrapper(buffer_stream)249- sys.stderr = StreamWrapper(sys.stderr)250-253 text_stream = _NonClosingTextIOWrapper(254 io.BufferedWriter(_WindowsConsoleWriter(STDERR_HANDLE)),255 'utf-16-le', 'strict', line_buffering=True)256 return ConsoleStream(text_stream, buffer_stream)51 unmodified lines