當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。