我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用click._compat.PY2。
def _get_windows_console_stream(f, encoding, errors): if get_buffer is not None and \ encoding in ('utf-16-le', None) \ and errors in ('strict', None) and \ hasattr(f, 'isatty') and f.isatty(): func = _stream_factories.get(f.fileno()) if func is not None: if not PY2: f = getattr(f, 'buffer') if f is None: return None else: # If we are on Python 2 we need to set the stream that we # deal with to binary mode as otherwise the exercise if a # bit moot. The same problems apply as for # get_binary_stdin and friends from _compat. msvcrt.setmode(f.fileno(), os.O_BINARY) return func(f)