Python errno.ENODEV Examples

The following are 30 code examples of errno.ENODEV(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module errno , or try the search function .
Example #1
Source File: test_linuxaudiodev.py    From medicare-demo with Apache License 2.0 6 votes vote down vote up
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 
Example #2
Source File: _psosx.py    From psutil with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
# ===================================================================== 
Example #3
Source File: _pslinux.py    From Galaxy_Plugin_Bethesda with MIT License 6 votes vote down vote up
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
# ===================================================================== 
Example #4
Source File: _pslinux.py    From psutil with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
# ===================================================================== 
Example #5
Source File: _psbsd.py    From psutil with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #6
Source File: _psbsd.py    From Galaxy_Plugin_Bethesda with MIT License 6 votes vote down vote up
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 
Example #7
Source File: _psosx.py    From Galaxy_Plugin_Bethesda with MIT License 6 votes vote down vote up
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
# ===================================================================== 
Example #8
Source File: test_clf_pn532.py    From nfcpy with European Union Public License 1.1 6 votes vote down vote up
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
        ]] 
Example #9
Source File: test_clf_pn532.py    From nfcpy with European Union Public License 1.1 6 votes vote down vote up
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
        ]] 
Example #10
Source File: _psbsd.py    From teleport with Apache License 2.0 6 votes vote down vote up
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 
Example #11
Source File: _pslinux.py    From teleport with Apache License 2.0 6 votes vote down vote up
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
# ===================================================================== 
Example #12
Source File: transport.py    From nfcpy with European Union Public License 1.1 6 votes vote down vote up
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 
Example #13
Source File: _psosx.py    From teleport with Apache License 2.0 6 votes vote down vote up
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
# ===================================================================== 
Example #14
Source File: _psbsd.py    From teleport with Apache License 2.0 6 votes vote down vote up
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 
Example #15
Source File: detect.py    From maas with GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example #16
Source File: _pslinux.py    From teleport with Apache License 2.0 6 votes vote down vote up
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
# ===================================================================== 
Example #17
Source File: _psbsd.py    From teleport with Apache License 2.0 6 votes vote down vote up
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 
Example #18
Source File: _pslinux.py    From teleport with Apache License 2.0 6 votes vote down vote up
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
# ===================================================================== 
Example #19
Source File: _psosx.py    From teleport with Apache License 2.0 6 votes vote down vote up
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
# ===================================================================== 
Example #20
Source File: test_linuxaudiodev.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #21
Source File: detect.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_interface_ip(sock: socket.socket, ifname: str) -> str:
    """Obtain an IP address for a network interface, as a string."""
    ifreq_tuple = (ifname.encode("utf-8")[:15], socket.AF_INET, b"\x00" * 14)
    ifreq = struct.pack(b"16sH14s", *ifreq_tuple)
    try:
        info = fcntl.ioctl(sock, SIOCGIFADDR, ifreq)
    except OSError as e:
        if e.errno == errno.ENODEV:
            raise InterfaceNotFound("Interface not found: '%s'." % ifname)
        elif e.errno == errno.EADDRNOTAVAIL:
            raise IPAddressNotAvailable(
                "No IP address found on interface '%s'." % ifname
            )
        else:
            raise IPAddressNotAvailable(
                "Failed to get IP address for '%s': %s."
                % (ifname, strerror(e.errno))
            )
    else:
        (  # Parse the `struct ifreq` that comes back from the ioctl() call.
            #     16x --> char ifr_name[IFNAMSIZ];
            # ... next is a union of structures; we're interested in the
            # `sockaddr_in` that is returned from this particular ioctl().
            #     2x  --> short sin_family;
            #     2x  --> unsigned short sin_port;
            #     4s  --> struct in_addr sin_addr;
            #     8x  --> char sin_zero[8];
            addr,
        ) = struct.unpack(b"16x2x2x4s8x", info)
        ip = socket.inet_ntoa(addr)
    return ip 
Example #22
Source File: test_tuntap.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def open(self, filename, *args, **kwargs):
        """
        Attempt an open, but if the file is /dev/net/tun and it does not exist,
        translate the error into L{SkipTest} so that tests that require
        platform support for tuntap devices are skipped instead of failed.
        """
        try:
            return super(TestRealSystem, self).open(filename, *args, **kwargs)
        except OSError as e:
            # The device file may simply be missing.  The device file may also
            # exist but be unsupported by the kernel.
            if e.errno in (ENOENT, ENODEV) and filename == b"/dev/net/tun":
                raise SkipTest("Platform lacks /dev/net/tun")
            raise 
Example #23
Source File: test_ossaudiodev.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #24
Source File: test_ossaudiodev.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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 
Example #25
Source File: test_ossaudiodev.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #26
Source File: test_ossaudiodev.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #27
Source File: test_ossaudiodev.py    From android_universal with MIT License 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, OSError) as msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise
    dsp.close()
    support.run_unittest(__name__) 
Example #28
Source File: test_ossaudiodev.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, OSError) as msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise
    dsp.close()
    support.run_unittest(__name__) 
Example #29
Source File: test_ossaudiodev.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, OSError) as msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise
    dsp.close()
    support.run_unittest(__name__) 
Example #30
Source File: test_linuxaudiodev.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
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