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


Python os.O_BINARY属性代码示例

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


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

示例1: _get_windows_console_stream

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [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 os [as 别名]
# 或者: from os import O_BINARY [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 os [as 别名]
# 或者: from os import O_BINARY [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: _readflags

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [as 别名]
def _readflags(sequential, direct):
    flags = os.O_RDONLY
    try:
        flags |= os.O_BINARY
        if sequential is not None:
            flags |= os.O_SEQUENTIAL if sequential else os.O_RANDOM

    except AttributeError:
        pass

    try:
        if direct:
            flags |= os.O_DIRECT
            read = directio.read
        else:
            raise AttributeError

    except AttributeError:
        read = os.read

    return read, flags 
开发者ID:deplicate,项目名称:deplicate,代码行数:23,代码来源:common.py

示例5: _binary_stdio

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [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

示例6: _get_windows_console_stream

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [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

示例7: _get_windows_console_stream

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [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

示例8: writef_win32

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [as 别名]
def writef_win32(f,data,m='w',encoding='ISO8859-1'):
	if sys.hexversion>0x3000000 and not'b'in m:
		data=data.encode(encoding)
		m+='b'
	flags=os.O_CREAT|os.O_TRUNC|os.O_WRONLY|os.O_NOINHERIT
	if'b'in m:
		flags|=os.O_BINARY
	if'+'in m:
		flags|=os.O_RDWR
	try:
		fd=os.open(f,flags)
	except OSError:
		raise IOError('Cannot write to %r'%f)
	f=os.fdopen(fd,m)
	try:
		f.write(data)
	finally:
		f.close() 
开发者ID:MOSAIC-UA,项目名称:802.11ah-ns3,代码行数:20,代码来源:Utils.py

示例9: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [as 别名]
def __init__(self, name, mode):
        mode = {
            "r": os.O_RDONLY,
            "w": os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
        }[mode]
        if hasattr(os, "O_BINARY"):
            mode |= os.O_BINARY
        self.fd = os.open(name, mode, 0o666) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:10,代码来源:tarfile.py

示例10: set_binary_mode

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [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: _secure_open_write

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [as 别名]
def _secure_open_write(filename, fmode):
    # We only want to write to this file, so open it in write only mode
    flags = os.O_WRONLY

    # os.O_CREAT | os.O_EXCL will fail if the file already exists, so we only
    #  will open *new* files.
    # We specify this because we want to ensure that the mode we pass is the
    # mode of the file.
    flags |= os.O_CREAT | os.O_EXCL

    # Do not follow symlinks to prevent someone from making a symlink that
    # we follow and insecurely open a cache file.
    if hasattr(os, "O_NOFOLLOW"):
        flags |= os.O_NOFOLLOW

    # On Windows we'll mark this file as binary
    if hasattr(os, "O_BINARY"):
        flags |= os.O_BINARY

    # Before we open our file, we want to delete any existing file that is
    # there
    try:
        os.remove(filename)
    except (IOError, OSError):
        # The file must not exist already, so we can just skip ahead to opening
        pass

    # Open our file, the use of os.O_CREAT | os.O_EXCL will ensure that if a
    # race condition happens between the os.remove and this line, that an
    # error will be raised. Because we utilize a lockfile this should only
    # happen if someone is attempting to attack us.
    fd = os.open(filename, flags, fmode)
    try:
        return os.fdopen(fd, "wb")
    except:
        # An error occurred wrapping our FD in a file object
        os.close(fd)
        raise 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:40,代码来源:file_cache.py

示例12: set_binary_mode

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [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

示例13: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import O_BINARY [as 别名]
def __init__(self, name, mode):
        mode = {
            "r": os.O_RDONLY,
            "w": os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
        }[mode]
        if hasattr(os, "O_BINARY"):
            mode |= os.O_BINARY
        self.fd = os.open(name, mode, 0666) 
开发者ID:glmcdona,项目名称:meddle,代码行数:10,代码来源:tarfile.py

示例14: IfWIN32SetBinary

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


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