Skip to content
Myr

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

2 files+17 added−10 removed

modified:click/_compat.py+6 added-1 removed
222 unmodified lines
223 def get_binary_stdin():224 return set_binary_mode(sys.stdin)225226 def get_binary_stdout():227 _wrap_std_stream('stdout')228 return set_binary_mode(sys.stdout)229230 def get_binary_stderr():231 _wrap_std_stream('stderr')232 return set_binary_mode(sys.stderr)233234 def get_text_stdin(encoding=None, errors=None):235 rv = _get_windows_console_stream(sys.stdin, encoding, errors)
2 unmodified lines
238 return _make_text_stream(sys.stdin, encoding, errors,239 force_readable=True)240241 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)248249 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 lines
585if WIN:586 # Windows has a smaller terminal587 DEFAULT_COLUMNS = 79588585 from ._winconsole import _get_windows_console_stream589 from ._winconsole import _get_windows_console_stream, _wrap_std_stream590591 def _get_argv_encoding():592 import locale593 return locale.getpreferredencoding()
53 unmodified lines
647 def _get_argv_encoding():648 return getattr(sys.stdin, 'encoding', None) or get_filesystem_encoding()649650 _get_windows_console_stream = lambda *x: None651 _wrap_std_stream = lambda *x: None652653654def term_len(x):655 return len(strip_ansi(x))
48 unmodified lines
modified:click/_winconsole.py+11 added-9 removed
199 unmodified lines
200 self.encoding,201 )202203204class StreamWrapper(object):204class 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 lines
224 self.__wrapped.write(text[written:written+to_write])225 written += to_write226227228_wrapped_std_streams = set()229230231def _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)236237238def _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)243244245def _get_text_stdout(buffer_stream):236 if PY2:237 buffer_stream = StreamWrapper(buffer_stream)238 sys.stdout = StreamWrapper(sys.stdout)239246 text_stream = _NonClosingTextIOWrapper(247 io.BufferedWriter(_WindowsConsoleWriter(STDOUT_HANDLE)),248 'utf-16-le', 'strict', line_buffering=True)249 return ConsoleStream(text_stream, buffer_stream)250251252def _get_text_stderr(buffer_stream):247 if PY2:248 buffer_stream = StreamWrapper(buffer_stream)249 sys.stderr = StreamWrapper(sys.stderr)250253 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