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


Python os.O_RDONLY属性代码示例

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


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

示例1: start

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def start(self):
        try:
            os.fstat(self._savefd)
        except OSError:
            raise ValueError("saved filedescriptor not valid, "
                "did you call start() twice?")
        if self.targetfd == 0 and not self.tmpfile:
            fd = os.open(devnullpath, os.O_RDONLY)
            os.dup2(fd, 0)
            os.close(fd)
            if hasattr(self, '_oldsys'):
                setattr(sys, patchsysdict[self.targetfd], DontReadFromInput())
        else:
            os.dup2(self.tmpfile.fileno(), self.targetfd)
            if hasattr(self, '_oldsys'):
                setattr(sys, patchsysdict[self.targetfd], self.tmpfile) 
开发者ID:pytest-dev,项目名称:py,代码行数:18,代码来源:capture.py

示例2: start

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def start(self) -> None:
        self.current_frame = [0 for _ in range(self.bars)]
        self.growing_frame = b""
        try:
            # delete old contents of the pipe
            os.remove(self.cava_fifo_path)
        except FileNotFoundError:
            # the file does not exist
            pass
        try:
            os.mkfifo(self.cava_fifo_path)
        except FileExistsError:
            # the file already exists
            logging.info("%s already exists while starting", self.cava_fifo_path)

        self.cava_process = subprocess.Popen(
            ["cava", "-p", os.path.join(settings.BASE_DIR, "config/cava.config")],
            cwd=settings.BASE_DIR,
        )
        # cava_fifo = open(cava_fifo_path, 'r')
        self.cava_fifo = os.open(self.cava_fifo_path, os.O_RDONLY | os.O_NONBLOCK) 
开发者ID:raveberry,项目名称:raveberry,代码行数:23,代码来源:programs.py

示例3: _get_terminal_size_linux

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def _get_terminal_size_linux():
    def ioctl_GWINSZ(fd):
        try:
            import fcntl
            import termios
            cr = struct.unpack('hh',
                               fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
            return cr
        except:
            pass
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    if not cr:
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = ioctl_GWINSZ(fd)
            os.close(fd)
        except:
            pass
    if not cr:
        try:
            cr = (os.environ['LINES'], os.environ['COLUMNS'])
        except:
            return None
    return int(cr[1]), int(cr[0]) 
开发者ID:aaronjanse,项目名称:asciidots,代码行数:26,代码来源:terminalsize.py

示例4: test_fcntl_64_bit

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def test_fcntl_64_bit(self):
        # Issue #1309352: fcntl shouldn't fail when the third arg fits in a
        # C 'long' but not in a C 'int'.
        try:
            cmd = fcntl.F_NOTIFY
            # This flag is larger than 2**31 in 64-bit builds
            flags = fcntl.DN_MULTISHOT
        except AttributeError:
            self.skipTest("F_NOTIFY or DN_MULTISHOT unavailable")
        fd = os.open(os.path.dirname(os.path.abspath(TESTFN)), os.O_RDONLY)
        try:
            # This will raise OverflowError if issue1309352 is present.
            fcntl.fcntl(fd, cmd, flags)
        except IOError:
            pass  # Running on a system that doesn't support these flags.
        finally:
            os.close(fd) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_fcntl.py

示例5: test_huntrleaks_fd_leak

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def test_huntrleaks_fd_leak(self):
        # test --huntrleaks for file descriptor leak
        code = textwrap.dedent("""
            import os
            import unittest
            from test import support

            class FDLeakTest(unittest.TestCase):
                def test_leak(self):
                    fd = os.open(__file__, os.O_RDONLY)
                    # bug: never close the file descriptor

            def test_main():
                support.run_unittest(FDLeakTest)
        """)
        self.check_leak(code, 'file descriptors') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_regrtest.py

示例6: main

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def main():
        '''
        Run code specified by data received over pipe
        '''
        assert is_forking(sys.argv)

        handle = int(sys.argv[-1])
        fd = msvcrt.open_osfhandle(handle, os.O_RDONLY)
        from_parent = os.fdopen(fd, 'rb')

        process.current_process()._inheriting = True
        preparation_data = load(from_parent)
        prepare(preparation_data)
        self = load(from_parent)
        process.current_process()._inheriting = False

        from_parent.close()

        exitcode = self._bootstrap()
        exit(exitcode) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:forking.py

示例7: test_write

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def test_write(self):
        test_filename = "tmp.write.test"
        
        # trivial write
        fd = os.open(test_filename, flags)
        self.assertEqual(os.write(fd, "42"), 2)
        os.close(fd)
        os.unlink(test_filename)

        # write to closed file
        fd = os.open(test_filename, flags)
        os.close(fd)
        self.assertRaisesMessage(OSError, "[Errno 9] Bad file descriptor", os.write, fd, "42")
        os.unlink(test_filename)
        
        # write to file with wrong permissions
        fd = os.open(test_filename, os.O_CREAT | os.O_TRUNC | os.O_RDONLY)
        self.assertRaisesMessage(OSError, "[Errno -2146232800] Can not write to " + test_filename,  os.write, fd, "42")
        os.close(fd)
        os.unlink(test_filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_fd.py

示例8: redirect_io

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def redirect_io(log_file='/dev/null'):
    # Always redirect stdin.
    in_fd = os.open('/dev/null', os.O_RDONLY)
    try:
        os.dup2(in_fd, 0)
    finally:
        os.close(in_fd)

    out_fd = os.open(log_file, os.O_WRONLY | os.O_CREAT)
    try:
        os.dup2(out_fd, 2)
        os.dup2(out_fd, 1)
    finally:
        os.close(out_fd)

    sys.stdin = os.fdopen(0, 'r')
    sys.stdout = os.fdopen(1, 'w')
    sys.stderr = os.fdopen(2, 'w') 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:20,代码来源:parallel.py

示例9: test_get_secret

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def test_get_secret(self):
        fd_mock = mock.mock_open()
        open_mock = mock.Mock()
        secret_id = uuidutils.generate_uuid()
        # Attempt to retrieve the secret
        with mock.patch('os.open', open_mock), mock.patch.object(
                os, 'fdopen', fd_mock):
            local_cert_mgr.LocalCertManager.get_secret(None, secret_id)

        # Verify the correct files were opened
        flags = os.O_RDONLY
        open_mock.assert_called_once_with('/tmp/{0}.crt'.format(secret_id),
                                          flags)

        # Test failure path
        with mock.patch('os.open', open_mock), mock.patch.object(
                os, 'fdopen', fd_mock) as mock_open:
            mock_open.side_effect = IOError
            self.assertRaises(exceptions.CertificateRetrievalException,
                              local_cert_mgr.LocalCertManager.get_secret,
                              None, secret_id) 
开发者ID:openstack,项目名称:octavia,代码行数:23,代码来源:test_local.py

示例10: _readflags

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

示例11: _getTerminalSize_linux

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def _getTerminalSize_linux():
    def ioctl_GWINSZ(fd):
        try:
            import fcntl, termios, struct, os
            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,'1234'))
        except:
            return None
        return cr
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    if not cr:
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = ioctl_GWINSZ(fd)
            os.close(fd)
        except:
            pass
    if not cr:
        try:
            cr = (env['LINES'], env['COLUMNS'])
        except:
            return None
    return int(cr[1]), int(cr[0]) 
开发者ID:euphrat1ca,项目名称:fuzzdb-collect,代码行数:24,代码来源:consle_width.py

示例12: _get_terminal_size_linux

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def _get_terminal_size_linux(self):
        def ioctl_GWINSZ(fd):
            try:
                import fcntl
                import termios

                cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234"))
                return cr
            except:
                pass

        cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
        if not cr:
            try:
                fd = os.open(os.ctermid(), os.O_RDONLY)
                cr = ioctl_GWINSZ(fd)
                os.close(fd)
            except:
                pass

        if not cr:
            try:
                cr = (os.environ["LINES"], os.environ["COLUMNS"])
            except:
                return None

        return int(cr[1]), int(cr[0]) 
开发者ID:sdispater,项目名称:clikit,代码行数:29,代码来源:terminal.py

示例13: wtrf

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def wtrf():
    if sys.platform != "win32":
        wt = int(os.environ['MYHDL_TO_PIPE'])
        rf = int(os.environ['MYHDL_FROM_PIPE'])
    else:
        wt = msvcrt.open_osfhandle(int(os.environ['MYHDL_TO_PIPE']), os.O_APPEND | os.O_TEXT)
        rf = msvcrt.open_osfhandle(int(os.environ['MYHDL_FROM_PIPE']), os.O_RDONLY | os.O_TEXT)

    return wt, rf 
开发者ID:myhdl,项目名称:myhdl,代码行数:11,代码来源:test_Cosimulation.py

示例14: readmsr

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDONLY [as 别名]
def readmsr(msr, cpu = 0):
    try:
        f = os.open('/dev/cpu/%d/msr' % cpu, os.O_RDONLY)
        os.lseek(f, msr, os.SEEK_SET)
        val = struct.unpack('Q', os.read(f, 8))[0]
        os.close(f)
        return val
    except:
        raise OSError("msr module not loaded (run modprobe msr)") 
开发者ID:r4m0n,项目名称:ZenStates-Linux,代码行数:11,代码来源:zenstates.py

示例15: __init__

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


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