Skip to content
Myr

Make pypy a bit happier on windows

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 412e34d · Browse files · 1 file+23 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−14 removed

  • other:+23 added−14 removed

1 file+23 added−14 removed

modified:click/_winconsole.py+23 added-14 removed
14 unmodified lines
15import time16import ctypes17import msvcrt18from click._compat import _NonClosingTextIOWrapper, text_type, PY219from ctypes import byref, POINTER, pythonapi, c_int, c_char, c_char_p, \19from ctypes import byref, POINTER, c_int, c_char, c_char_p, \20 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE21try:22 from ctypes import pythonapi23 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer24 PyBuffer_Release = pythonapi.PyBuffer_Release25except ImportError:26 pythonapi = None27from ctypes.wintypes import LPWSTR, LPCWSTR282930c_ssize_p = POINTER(c_ssize_t)3126PyObject_GetBuffer = pythonapi.PyObject_GetBuffer27PyBuffer_Release = pythonapi.PyBuffer_Release2832kernel32 = windll.kernel3233GetStdHandle = kernel32.GetStdHandle34ReadConsoleW = kernel32.ReadConsoleW35WriteConsoleW = kernel32.WriteConsoleW
43 unmodified lines
79 if PY2:80 _fields_.insert(-1, ('smalltable', c_ssize_t * 2))818283# On PyPy we cannot get buffers so our ability to operate here is84# serverly limited.85if pythonapi is None:86 get_buffer = None87else:80def get_buffer(obj, writable=False):81 buf = Py_buffer()82 flags = PyBUF_WRITABLE if writable else PyBUF_SIMPLE83 PyObject_GetBuffer(py_object(obj), byref(buf), flags)84 try:85 buffer_type = c_char * buf.len86 return buffer_type.from_address(buf.buf)87 finally:88 PyBuffer_Release(byref(buf))88 def get_buffer(obj, writable=False):89 buf = Py_buffer()90 flags = PyBUF_WRITABLE if writable else PyBUF_SIMPLE91 PyObject_GetBuffer(py_object(obj), byref(buf), flags)92 try:93 buffer_type = c_char * buf.len94 return buffer_type.from_address(buf.buf)95 finally:96 PyBuffer_Release(byref(buf))979899class _WindowsConsoleRawIOBase(io.RawIOBase):100
152 unmodified lines
253}254255256def _get_windows_console_stream(f, encoding, errors):257 if get_buffer is not None and \249 if encoding in ('utf-16-le', None) \258 encoding in ('utf-16-le', None) \259 and errors in ('strict', None) and \260 hasattr(f, 'isatty') and f.isatty():261 func = _stream_factories.get(f.fileno())262 if func is not None:
11 unmodified lines