本文整理匯總了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))
示例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)
示例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
示例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')
示例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 "???"
示例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)
示例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
示例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)
示例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')
示例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')
示例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)
示例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())
示例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
示例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
示例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)