本文整理汇总了Python中errno.ENODEV属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ENODEV属性的具体用法?Python errno.ENODEV怎么用?Python errno.ENODEV使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.ENODEV属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: net_if_stats
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def net_if_stats():
"""Get NIC stats (isup, duplex, speed, mtu)."""
names = net_io_counters().keys()
ret = {}
for name in names:
try:
mtu = cext_posix.net_if_mtu(name)
isup = cext_posix.net_if_flags(name)
duplex, speed = cext_posix.net_if_duplex_speed(name)
except OSError as err:
# https://github.com/giampaolo/psutil/issues/1279
if err.errno != errno.ENODEV:
raise
else:
if hasattr(_common, 'NicDuplex'):
duplex = _common.NicDuplex(duplex)
ret[name] = _common.snicstats(isup, duplex, speed, mtu)
return ret
示例2: read
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def read(self, timeout=0):
if self.usb_inp is not None:
try:
ep_addr = self.usb_inp.getAddress()
frame = self.usb_dev.bulkRead(ep_addr, 300, timeout)
except libusb.USBErrorTimeout:
raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
except libusb.USBErrorNoDevice:
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
except libusb.USBError as error:
log.error("%r", error)
raise IOError(errno.EIO, os.strerror(errno.EIO))
if len(frame) == 0:
log.error("bulk read returned zero data")
raise IOError(errno.EIO, os.strerror(errno.EIO))
frame = bytearray(frame)
log.log(logging.DEBUG-1, "<<< %s", hexlify(frame).decode())
return frame
示例3: test_init_sam_cfg_ack_err
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def test_init_sam_cfg_ack_err(self, mocker, transport): # noqa: F811
mocker.patch('nfc.clf.pn532.Device.__init__').return_value = None
sys.platform = ""
transport.write.return_value = None
transport.read.side_effect = [
ACK(), RSP('03 32010607'), # GetFirmwareVersion
ERR(), # SAMConfiguration
]
with pytest.raises(IOError) as excinfo:
nfc.clf.pn532.init(transport)
assert excinfo.value.errno == errno.ENODEV
assert transport.write.mock_calls == [call(_) for _ in [
HEX(10 * '00') + CMD('02'), # GetFirmwareVersion
HEX(10 * '00') + CMD('14 010000'), # SAMConfiguration
]]
示例4: test_init_sam_cfg_rsp_err
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def test_init_sam_cfg_rsp_err(self, mocker, transport): # noqa: F811
mocker.patch('nfc.clf.pn532.Device.__init__').return_value = None
sys.platform = ""
transport.write.return_value = None
transport.read.side_effect = [
ACK(), RSP('03 32010607'), # GetFirmwareVersion
ACK(), ERR(), # SAMConfiguration
]
with pytest.raises(IOError) as excinfo:
nfc.clf.pn532.init(transport)
assert excinfo.value.errno == errno.ENODEV
assert transport.write.mock_calls == [call(_) for _ in [
HEX(10 * '00') + CMD('02'), # GetFirmwareVersion
HEX(10 * '00') + CMD('14 010000'), # SAMConfiguration
]]
示例5: net_if_stats
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def net_if_stats():
"""Get NIC stats (isup, duplex, speed, mtu)."""
duplex_map = {cext.DUPLEX_FULL: NIC_DUPLEX_FULL,
cext.DUPLEX_HALF: NIC_DUPLEX_HALF,
cext.DUPLEX_UNKNOWN: NIC_DUPLEX_UNKNOWN}
names = net_io_counters().keys()
ret = {}
for name in names:
try:
mtu = cext_posix.net_if_mtu(name)
isup = cext_posix.net_if_flags(name)
duplex, speed = cext.net_if_duplex_speed(name)
except OSError as err:
# https://github.com/giampaolo/psutil/issues/1279
if err.errno != errno.ENODEV:
raise
else:
ret[name] = _common.snicstats(isup, duplex_map[duplex], speed, mtu)
return ret
# =====================================================================
# --- disks
# =====================================================================
示例6: net_if_stats
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def net_if_stats():
"""Get NIC stats (isup, duplex, speed, mtu)."""
names = net_io_counters().keys()
ret = {}
for name in names:
try:
mtu = cext_posix.net_if_mtu(name)
isup = cext_posix.net_if_flags(name)
duplex, speed = cext_posix.net_if_duplex_speed(name)
except OSError as err:
# https://github.com/giampaolo/psutil/issues/1279
if err.errno != errno.ENODEV:
raise
else:
if hasattr(_common, 'NicDuplex'):
duplex = _common.NicDuplex(duplex)
ret[name] = _common.snicstats(isup, duplex, speed, mtu)
return ret
# =====================================================================
# --- other system functions
# =====================================================================
示例7: play_sound_file
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def play_sound_file(path):
fp = open(path, 'r')
size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
data = fp.read()
fp.close()
if enc != SND_FORMAT_MULAW_8:
print "Expect .au file with 8-bit mu-law samples"
return
try:
a = linuxaudiodev.open('w')
except linuxaudiodev.error, msg:
if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
raise TestSkipped, msg
raise TestFailed, msg
# convert the data to 16-bit signed
示例8: get_interface_mac
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def get_interface_mac(sock: socket.socket, ifname: str) -> str:
"""Obtain a network interface's MAC address, as a string."""
ifreq = struct.pack(b"256s", ifname.encode("utf-8")[:15])
try:
info = fcntl.ioctl(sock.fileno(), SIOCGIFHWADDR, ifreq)
except OSError as e:
if e.errno is not None and e.errno == errno.ENODEV:
raise InterfaceNotFound("Interface not found: '%s'." % ifname)
else:
raise MACAddressNotAvailable(
"Failed to get MAC address for '%s': %s."
% (ifname, strerror(e.errno))
)
else:
# Of course we're sure these are the correct indexes into the `ifreq`.
# Also, your lack of faith is disturbing.
mac = "".join("%02x:" % char for char in info[18:24])[:-1]
return mac
示例9: play_sound_file
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def play_sound_file(self, data, rate, ssize, nchannels):
try:
dsp = ossaudiodev.open('w')
except IOError, msg:
if msg.args[0] in (errno.EACCES, errno.ENOENT,
errno.ENODEV, errno.EBUSY):
raise unittest.SkipTest(msg)
raise
# at least check that these methods can be invoked
示例10: test_main
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def test_main():
try:
dsp = ossaudiodev.open('w')
except (ossaudiodev.error, IOError), msg:
if msg.args[0] in (errno.EACCES, errno.ENOENT,
errno.ENODEV, errno.EBUSY):
raise unittest.SkipTest(msg)
raise
示例11: test_main
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def test_main():
try:
dsp = linuxaudiodev.open('w')
except linuxaudiodev.error, msg:
if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
raise unittest.SkipTest(msg)
raise
示例12: __init__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def __init__(self, path=None):
self.device = None
self.target = None
self.lock = threading.Lock()
if path and not self.open(path):
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
示例13: exchange
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def exchange(self, send_data, timeout):
"""Exchange data with an activated target (*send_data* is a command
frame) or as an activated target (*send_data* is a response
frame). Returns a target response frame (if data is send to an
activated target) or a next command frame (if data is send
from an activated target). Returns None if the communication
link broke during exchange (if data is sent as a target). The
timeout is the number of seconds to wait for data to return,
if the timeout expires an nfc.clf.TimeoutException is
raised. Other nfc.clf.CommunicationError exceptions may be raised if
an error is detected during communication.
"""
with self.lock:
if self.device is None:
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
log.debug(">>> %s timeout=%s", print_data(send_data), str(timeout))
if isinstance(self.target, RemoteTarget):
exchange = self.device.send_cmd_recv_rsp
elif isinstance(self.target, LocalTarget):
exchange = self.device.send_rsp_recv_cmd
else:
log.error("no target for data exchange")
return None
send_time = time.time()
rcvd_data = exchange(self.target, send_data, timeout)
recv_time = time.time() - send_time
log.debug("<<< %s %.3fs", print_data(rcvd_data), recv_time)
return rcvd_data
示例14: max_send_data_size
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def max_send_data_size(self):
"""The maximum number of octets that can be send with the
:meth:`exchange` method in the established operating mode.
"""
with self.lock:
if self.device is None:
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
else:
return self.device.get_max_send_data_size(self.target)
示例15: max_recv_data_size
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODEV [as 别名]
def max_recv_data_size(self):
"""The maximum number of octets that can be received with the
:meth:`exchange` method in the established operating mode.
"""
with self.lock:
if self.device is None:
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
else:
return self.device.get_max_recv_data_size(self.target)