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


Python stat.S_ISCHR属性代码示例

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


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

示例1: get_device_type

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def get_device_type(filename):
    """
    Get the device type of a device file.

    ``filename`` is a string containing the path of a device file.

    Return ``'char'`` if ``filename`` is a character device, or ``'block'`` if
    ``filename`` is a block device.  Raise :exc:`~exceptions.ValueError` if
    ``filename`` is no device file at all.  Raise
    :exc:`~exceptions.EnvironmentError` if ``filename`` does not exist or if
    its metadata was inaccessible.

    .. versionadded:: 0.15
    """
    mode = os.stat(filename).st_mode
    if stat.S_ISCHR(mode):
        return 'char'
    elif stat.S_ISBLK(mode):
        return 'block'
    else:
        raise ValueError('not a device file: {0!r}'.format(filename)) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:23,代码来源:_util.py

示例2: __init__

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def __init__(self, devname=None):
        if devname is None:
            self.name = "/dev/urandom"
        else:
            self.name = devname

        # Test that /dev/urandom is a character special device
        f = open(self.name, "rb", 0)
        fmode = os.fstat(f.fileno())[stat.ST_MODE]
        if not stat.S_ISCHR(fmode):
            f.close()
            raise TypeError("%r is not a character special device" % (self.name,))

        self.__file = f

        BaseRNG.__init__(self) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:18,代码来源:posix.py

示例3: __hashEntry

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def __hashEntry(self, prefix, entry, s):
        if stat.S_ISREG(s.st_mode):
            digest = self.__index.check(prefix, entry, s, hashFile)
        elif stat.S_ISDIR(s.st_mode):
            digest = self.__hashDir(prefix, entry)
        elif stat.S_ISLNK(s.st_mode):
            digest = self.__index.check(prefix, entry, s, DirHasher.__hashLink)
        elif stat.S_ISBLK(s.st_mode) or stat.S_ISCHR(s.st_mode):
            digest = struct.pack("<L", s.st_rdev)
        elif stat.S_ISFIFO(s.st_mode):
            digest = b''
        else:
            digest = b''
            logging.getLogger(__name__).warning("Unknown file: %s", entry)

        return digest 
开发者ID:BobBuildTool,项目名称:bob,代码行数:18,代码来源:utils.py

示例4: test_write_full

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def test_write_full(self):
        devfull = '/dev/full'
        if not (os.path.exists(devfull) and
                stat.S_ISCHR(os.stat(devfull).st_mode)):
            # Issue #21934: OpenBSD does not have a /dev/full character device
            self.skipTest('requires %r' % devfull)
        with open(devfull, 'wb', 1) as f:
            with self.assertRaises(IOError):
                f.write('hello\n')
        with open(devfull, 'wb', 1) as f:
            with self.assertRaises(IOError):
                # Issue #17976
                f.write('hello')
                f.write('\n')
        with open(devfull, 'wb', 0) as f:
            with self.assertRaises(IOError):
                f.write('h') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_file2k.py

示例5: mode_filetype

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def mode_filetype(mode):
    mode = stat.S_IFMT(mode)
    dic = {
            stat.S_ISFIFO: "fifo file",
            stat.S_ISCHR: "character device",
            stat.S_ISDIR: "directory",
            stat.S_ISBLK: "block device",
            stat.S_ISREG: "regular file",
            stat.S_ISLNK: "symbolic link",
            stat.S_ISSOCK: "socket",
            stat.S_ISDOOR: "door",
            }
    for test_func, name in dic.items():
        if test_func(mode):
            return name
    return "???" 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:18,代码来源:plugin.py

示例6: __init__

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
        super().__init__(extra)
        self._extra['pipe'] = pipe
        self._loop = loop
        self._pipe = pipe
        self._fileno = pipe.fileno()
        mode = os.fstat(self._fileno).st_mode
        if not (stat.S_ISFIFO(mode) or
                stat.S_ISSOCK(mode) or
                stat.S_ISCHR(mode)):
            raise ValueError("Pipe transport is for pipes/sockets only.")
        _set_nonblocking(self._fileno)
        self._protocol = protocol
        self._closing = False
        self._loop.call_soon(self._protocol.connection_made, self)
        # only start reading when connection_made() has been called
        self._loop.call_soon(self._loop.add_reader,
                             self._fileno, self._read_ready)
        if waiter is not None:
            # only wake up the waiter when connection_made() has been called
            self._loop.call_soon(futures._set_result_unless_cancelled,
                                 waiter, None) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:unix_events.py

示例7: is_special_file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def is_special_file(path):
    """
    This function checks to see if a special file.  It checks if the
    file is a character special device, block special device, FIFO, or
    socket.
    """
    mode = os.stat(path).st_mode
    # Character special device.
    if stat.S_ISCHR(mode):
        return True
    # Block special device
    if stat.S_ISBLK(mode):
        return True
    # FIFO.
    if stat.S_ISFIFO(mode):
        return True
    # Socket.
    if stat.S_ISSOCK(mode):
        return True
    return False 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:22,代码来源:filegenerator.py

示例8: __init__

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
        super().__init__(extra)
        self._extra['pipe'] = pipe
        self._loop = loop
        self._pipe = pipe
        self._fileno = pipe.fileno()
        mode = os.fstat(self._fileno).st_mode
        if not (stat.S_ISFIFO(mode) or
                stat.S_ISSOCK(mode) or
                stat.S_ISCHR(mode)):
            raise ValueError("Pipe transport is for pipes/sockets only.")
        _set_nonblocking(self._fileno)
        self._protocol = protocol
        self._closing = False
        self._loop.call_soon(self._protocol.connection_made, self)
        # only start reading when connection_made() has been called
        self._loop.call_soon(self._loop.add_reader,
                             self._fileno, self._read_ready)
        if waiter is not None:
            # only wake up the waiter when connection_made() has been called
            self._loop.call_soon(waiter._set_result_unless_cancelled, None) 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:23,代码来源:unix_events.py

示例9: test_stdout

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def test_stdout(self):
        proc, info, buf = run_fd_check(self.func, 1, 'write',
            lambda proc: wait_read(proc.stdout, 4))

        st = os.fstat(proc.stdout.fileno())
        self.assertTrue(stat.S_ISCHR(st.st_mode))
        self.assertTrue(stat.S_ISCHR(info['st_mode']))

        self.assertTrue(isinstance(info['ttyname'],
                        mitogen.core.UnicodeType))
        self.assertTrue(os.isatty(proc.stdout.fileno()))

        flags = fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETFL)
        self.assertTrue(flags & os.O_RDWR)
        self.assertTrue(info['flags'] & os.O_RDWR)

        self.assertTrue(flags & os.O_RDWR)
        self.assertTrue(buf, 'TEST') 
开发者ID:dw,项目名称:mitogen,代码行数:20,代码来源:create_child_test.py

示例10: test_stderr

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def test_stderr(self):
        # proc.stderr is None in the parent since there is no separate stderr
        # stream. In the child, FD 2/stderr is connected to the TTY.
        proc, info, buf = run_fd_check(self.func, 2, 'write',
            lambda proc: wait_read(proc.stdout, 4))

        st = os.fstat(proc.stdout.fileno())
        self.assertTrue(stat.S_ISCHR(st.st_mode))
        self.assertTrue(stat.S_ISCHR(info['st_mode']))

        self.assertTrue(isinstance(info['ttyname'],
                        mitogen.core.UnicodeType))
        self.assertTrue(os.isatty(proc.stdout.fileno()))

        flags = fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETFL)
        self.assertTrue(flags & os.O_RDWR)
        self.assertTrue(info['flags'] & os.O_RDWR)

        self.assertTrue(flags & os.O_RDWR)
        self.assertTrue(buf, 'TEST') 
开发者ID:dw,项目名称:mitogen,代码行数:22,代码来源:create_child_test.py

示例11: isdev

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def isdev(self):
		from stat import S_ISBLK, S_ISCHR
		mode = self.__st_mode()
		return S_ISBLK(mode) or S_ISCHR(mode) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:6,代码来源:__init__.py

示例12: ischardev

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def ischardev(self):
		from stat import S_ISCHR
		return S_ISCHR(self.__st_mode()) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:5,代码来源:__init__.py

示例13: find_sa120_devices

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def find_sa120_devices():
    devices = []
    seen_devices = set()
    for device_glob in devices_to_check:
        for device in glob.glob(device_glob):
            try:
                stats = os.stat(device)
            except OSError:
                continue
            if not stat.S_ISCHR(stats.st_mode):
                print('Enclosure not found on ' + device)
                continue
            device_id = format_device_id(stats)
            if device_id in seen_devices:
                print('Enclosure already seen on ' + device)
                continue
            seen_devices.add(device_id)
            try:
                output = check_output([sg_ses_binary, '--maxlen=32768', device], stderr=STDOUT)
                if b'ThinkServerSA120' in output:
                    print('Enclosure found on ' + device)
                    devices.append(device)
                else:
                    print('Enclosure not found on ' + device)
            except CalledProcessError:
                print('Enclosure not found on ' + device)
    return devices 
开发者ID:AndrewX192,项目名称:lenovo-sa120-fanspeed-utility,代码行数:29,代码来源:fancontrol.py

示例14: is_special_file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def is_special_file(cls, filename):
        """Checks to see if a file is a special UNIX file.

        It checks if the file is a character special device, block special
        device, FIFO, or socket.

        :param filename: Name of the file

        :returns: True if the file is a special file. False, if is not.
        """
        # If it does not exist, it must be a new file so it cannot be
        # a special file.
        if not os.path.exists(filename):
            return False
        mode = os.stat(filename).st_mode
        # Character special device.
        if stat.S_ISCHR(mode):
            return True
        # Block special device
        if stat.S_ISBLK(mode):
            return True
        # Named pipe / FIFO
        if stat.S_ISFIFO(mode):
            return True
        # Socket.
        if stat.S_ISSOCK(mode):
            return True
        return False 
开发者ID:skarlekar,项目名称:faces,代码行数:30,代码来源:utils.py

示例15: is_device

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISCHR [as 别名]
def is_device(mode):
    mode = stat.S_IFMT(mode)
    return stat.S_ISCHR(mode) or stat.S_ISBLK(mode) 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:5,代码来源:plugin.py


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