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