当前位置: 首页>>代码示例>>Python>>正文


Python msvcrt.setmode方法代码示例

本文整理汇总了Python中msvcrt.setmode方法的典型用法代码示例。如果您正苦于以下问题:Python msvcrt.setmode方法的具体用法?Python msvcrt.setmode怎么用?Python msvcrt.setmode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在msvcrt的用法示例。


在下文中一共展示了msvcrt.setmode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_windows_console_stream

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
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', None)
                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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:_winconsole.py

示例2: _get_windows_console_stream

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
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) 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:_winconsole.py

示例3: adapter_connect

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def adapter_connect(self):
        if not self.state.connected:
            if self.args.port is not None:
                self._wait_for_connection()
            else:
                if PY2:
                    self.__write_to = sys.stdout
                    self.__read_from = sys.stdin
                    if WIN32:
                        # must read streams as binary on windows
                        import msvcrt
                        msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
                        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
                else:
                    self.__write_to = sys.stdout.buffer
                    self.__read_from = sys.stdin.buffer
            self.reader = ReaderThread(self.__read_from, self.__command_processor)
            self.writer = WriterThread(self.__write_to, self.__write_queue)
            self.state.connected = True
        else:
            log.debug('Already connected') 
开发者ID:espressif,项目名称:vscode-esp-idf-extension,代码行数:23,代码来源:debug_adapter.py

示例4: _binary_stdio

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def _binary_stdio():
    """Construct binary stdio streams (not text mode).
    This seems to be different for Window/Unix Python2/3, so going by:
        https://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin
    """
    PY3K = sys.version_info >= (3, 0)

    if PY3K:
        stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
    else:
        # Python 2 on Windows opens sys.stdin in text mode, and
        # binary data that read from it becomes corrupted on \r\n
        if sys.platform == "win32":
            # set sys.stdin to binary mode
            import os
            import msvcrt
            msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
            msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
        stdin, stdout = sys.stdin, sys.stdout

    return stdin, stdout 
开发者ID:hansec,项目名称:fortran-language-server,代码行数:23,代码来源:__init__.py

示例5: _get_windows_console_stream

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
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()
    ):
        if isinstance(f, ConsoleStream):
            return f
        func = _stream_factories.get(f.fileno())
        if func is not None:
            if not PY2:
                f = getattr(f, "buffer", None)
                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) 
开发者ID:pypa,项目名称:pipenv,代码行数:25,代码来源:_winconsole.py

示例6: _get_windows_console_stream

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
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 _is_console(f)
    ):
        func = _stream_factories.get(f.fileno())
        if func is not None:
            if not PY2:
                f = getattr(f, "buffer", None)
                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) 
开发者ID:pypa,项目名称:pipenv,代码行数:22,代码来源:_winconsole.py

示例7: main

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def main():

    PY3K = sys.version_info >= (3, 0)

    if PY3K:
        output = sys.stdout.buffer
    else:
        # Python 2 on Windows opens sys.stdin in text mode, and
        # binary data that read from it becomes corrupted on \r\n
        if sys.platform == "win32":
            # set sys.stdin to binary mode
            import os
            import msvcrt
            msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
        output = sys.stdout

    items_to_bin(sys.stdin, output) 
开发者ID:OasisLMF,项目名称:OasisLMF,代码行数:19,代码来源:complex_items_to_bin.py

示例8: main

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def main():
    PY3K = sys.version_info >= (3, 0)

    if PY3K:
        source = sys.stdin.buffer
    else:
        # Python 2 on Windows opens sys.stdin in text mode, and
        # binary data that read from it becomes corrupted on \r\n
        if sys.platform == "win32":
            # set sys.stdin to binary mode
            import os
            import msvcrt

            msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
        source = sys.stdin

    items_to_csv(source, sys.stdout) 
开发者ID:OasisLMF,项目名称:OasisLMF,代码行数:19,代码来源:complex_items_to_csv.py

示例9: _binaryStdio

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def _binaryStdio():  # pragma: no cover
    """
    (from https://github.com/palantir/python-language-server)

    This seems to be different for Window/Unix Python2/3, so going by:
        https://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin
    """

    if six.PY3:
        # pylint: disable=no-member
        stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
    else:
        # Python 2 on Windows opens sys.stdin in text mode, and
        # binary data that read from it becomes corrupted on \r\n
        if sys.platform == "win32":
            # set sys.stdin to binary mode
            # pylint: disable=no-member,import-error
            import msvcrt

            msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
            msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
        stdin, stdout = sys.stdin, sys.stdout

    return stdin, stdout 
开发者ID:suoto,项目名称:hdl_checker,代码行数:26,代码来源:server.py

示例10: set_binary_mode

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def set_binary_mode(fh):
    """ Helper method to set up binary mode for file handles.
    Emphasis being sys.stdin, sys.stdout, sys.stderr.
    For python3, we want to return .buffer
    For python2+windows we want to set os.O_BINARY
    """
    typefile = TextIOWrapper if sys.version_info >= (3, 0) else file
    # check for file handle
    if not isinstance(fh, typefile):
        return fh

    # check for python3 and buffer
    if sys.version_info >= (3, 0) and hasattr(fh, 'buffer'):
        return fh.buffer
    # check for python3
    elif sys.version_info >= (3, 0):
        pass
    # check for windows python2. SPL-175233 -- python3 stdout is already binary
    elif sys.platform == 'win32':
        # Work around the fact that on Windows '\n' is mapped to '\r\n'. The typical solution is to simply open files in
        # binary mode, but stdout is already open, thus this hack. 'CPython' and 'PyPy' work differently. We assume that
        # all other Python implementations are compatible with 'CPython'. This might or might not be a valid assumption.
        from platform import python_implementation
        implementation = python_implementation()
        if implementation == 'PyPy':
            return os.fdopen(fh.fileno(), 'wb', 0)
        else:
            import msvcrt
            msvcrt.setmode(fh.fileno(), os.O_BINARY)
    return fh 
开发者ID:remg427,项目名称:misp42splunk,代码行数:32,代码来源:internals.py

示例11: set_binary_mode

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def set_binary_mode(f):
            try:
                fileno = f.fileno()
            except Exception:
                pass
            else:
                msvcrt.setmode(fileno, os.O_BINARY)
            return f 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:_compat.py

示例12: IfWIN32SetBinary

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def IfWIN32SetBinary(io):
    if sys.platform == 'win32':
        import msvcrt
        msvcrt.setmode(io.fileno(), os.O_BINARY) 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:6,代码来源:pdf-parser.py

示例13: ifWIN32SetBinary

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import setmode [as 别名]
def ifWIN32SetBinary(io):
    if sys.platform == 'win32':
        import msvcrt, os
        msvcrt.setmode(io.fileno(), os.O_BINARY) 
开发者ID:nolze,项目名称:msoffcrypto-tool,代码行数:6,代码来源:__main__.py


注:本文中的msvcrt.setmode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。