我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用msvcrt.setmode()。
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)
def GetPEObject(filename): if filename.lower().endswith('.zip'): try: oZipfile = zipfile.ZipFile(filename, 'r') file = oZipfile.open(oZipfile.infolist()[0], 'r', C2BIP3('infected')) except: print('Error opening file %s' % filename) print(sys.exc_info()[1]) sys.exit() oPE = pefile.PE(data=file.read()) file.close() oZipfile.close() elif filename == '': if sys.platform == "win32": import msvcrt msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) oPE = pefile.PE(data=sys.stdin.read()) else: oPE = pefile.PE(filename) return oPE