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


Python errno.EINVAL属性代码示例

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


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

示例1: truncate

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def truncate(self, size=None):
        """Truncate the file's size.

        If the optional size argument is present, the file is truncated to
        (at most) that size. The size defaults to the current position.
        The current file position is not changed unless the position
        is beyond the new file size.

        If the specified size exceeds the file's current size, the
        file remains unchanged.
        """
        _complain_ifclosed(self.closed)
        if size is None:
            size = self.pos
        elif size < 0:
            raise IOError(EINVAL, "Negative size not allowed")
        elif size < self.pos:
            self.pos = size
        self.buf = self.getvalue()[:size]
        self.len = size 
开发者ID:war-and-code,项目名称:jawfish,代码行数:22,代码来源:io.py

示例2: create_symlinks

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def create_symlinks(venv=VENV, atlas_clients=False):
    print 'Installing binaries symlinks ...'
    bin_dir = os.path.join(ROOT, "bin")
    venv_bin_dir = os.path.join(venv, "bin")
    binaries = os.listdir(bin_dir)
    for binary in binaries:
        source = os.path.join(bin_dir, binary)
        link_name = os.path.join(venv_bin_dir, binary)
        try:
            os.path.exists(link_name) and source != os.readlink(link_name)
        except OSError, e:
            if e.errno == errno.EINVAL:
                print 'Delete broken symlink: %(link_name)s -> %(source)s' % locals()
                os.remove(link_name)
            else:
                raise e
        if not os.path.exists(link_name):
            print 'Create the symlink: %(link_name)s -> %(source)s' % locals()
            os.symlink(source, link_name) 
开发者ID:rucio,项目名称:rucio,代码行数:21,代码来源:install_venv.py

示例3: cmdline

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def cmdline(self):
        if OPENBSD and self.pid == 0:
            return []  # ...else it crashes
        elif NETBSD:
            # XXX - most of the times the underlying sysctl() call on Net
            # and Open BSD returns a truncated string.
            # Also /proc/pid/cmdline behaves the same so it looks
            # like this is a kernel bug.
            try:
                return cext.proc_cmdline(self.pid)
            except OSError as err:
                if err.errno == errno.EINVAL:
                    if not pid_exists(self.pid):
                        raise NoSuchProcess(self.pid, self._name)
                    else:
                        raise ZombieProcess(self.pid, self._name, self._ppid)
                else:
                    raise
        else:
            return cext.proc_cmdline(self.pid) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:_psbsd.py

示例4: cwd

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def cwd(self):
        """Return process current working directory."""
        # sometimes we get an empty string, in which case we turn
        # it into None
        if OPENBSD and self.pid == 0:
            return None  # ...else it would raise EINVAL
        elif NETBSD:
            with wrap_exceptions_procfs(self):
                return os.readlink("/proc/%s/cwd" % self.pid)
        elif hasattr(cext, 'proc_open_files'):
            # FreeBSD < 8 does not support functions based on
            # kinfo_getfile() and kinfo_getvmmap()
            return cext.proc_cwd(self.pid) or None
        else:
            raise NotImplementedError(
                "supported only starting from FreeBSD 8" if
                FREEBSD else "") 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:_psbsd.py

示例5: cpu_affinity_set

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def cpu_affinity_set(self, cpus):
            # Pre-emptively check if CPUs are valid because the C
            # function has a weird behavior in case of invalid CPUs,
            # see: https://github.com/giampaolo/psutil/issues/586
            allcpus = tuple(range(len(per_cpu_times())))
            for cpu in cpus:
                if cpu not in allcpus:
                    raise ValueError("invalid CPU #%i (choose between %s)"
                                     % (cpu, allcpus))
            try:
                cext.proc_cpu_affinity_set(self.pid, cpus)
            except OSError as err:
                # 'man cpuset_setaffinity' about EDEADLK:
                # <<the call would leave a thread without a valid CPU to run
                # on because the set does not overlap with the thread's
                # anonymous mask>>
                if err.errno in (errno.EINVAL, errno.EDEADLK):
                    for cpu in cpus:
                        if cpu not in allcpus:
                            raise ValueError(
                                "invalid CPU #%i (choose between %s)" % (
                                    cpu, allcpus))
                raise 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:_psbsd.py

示例6: get_proc_inodes

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def get_proc_inodes(self, pid):
        inodes = defaultdict(list)
        for fd in os.listdir("%s/%s/fd" % (self._procfs_path, pid)):
            try:
                inode = readlink("%s/%s/fd/%s" % (self._procfs_path, pid, fd))
            except OSError as err:
                # ENOENT == file which is gone in the meantime;
                # os.stat('/proc/%s' % self.pid) will be done later
                # to force NSP (if it's the case)
                if err.errno in (errno.ENOENT, errno.ESRCH):
                    continue
                elif err.errno == errno.EINVAL:
                    # not a link
                    continue
                else:
                    raise
            else:
                if inode.startswith('socket:['):
                    # the process is using a socket
                    inode = inode[8:][:-1]
                    inodes[inode].append((pid, int(fd)))
        return inodes 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:_pslinux.py

示例7: cpu_affinity_set

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def cpu_affinity_set(self, cpus):
        try:
            cext.proc_cpu_affinity_set(self.pid, cpus)
        except (OSError, ValueError) as err:
            if isinstance(err, ValueError) or err.errno == errno.EINVAL:
                eligible_cpus = self._get_eligible_cpus()
                all_cpus = tuple(range(len(per_cpu_times())))
                for cpu in cpus:
                    if cpu not in all_cpus:
                        raise ValueError(
                            "invalid CPU number %r; choose between %s" % (
                                cpu, eligible_cpus))
                    if cpu not in eligible_cpus:
                        raise ValueError(
                            "CPU number %r is not eligible; choose "
                            "between %s" % (cpu, eligible_cpus))
            raise

    # only starting from kernel 2.6.13 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:_pslinux.py

示例8: test_isfile_strict

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def test_isfile_strict(self):
        from psutil._common import isfile_strict
        this_file = os.path.abspath(__file__)
        assert isfile_strict(this_file)
        assert not isfile_strict(os.path.dirname(this_file))
        with mock.patch('psutil._common.os.stat',
                        side_effect=OSError(errno.EPERM, "foo")):
            self.assertRaises(OSError, isfile_strict, this_file)
        with mock.patch('psutil._common.os.stat',
                        side_effect=OSError(errno.EACCES, "foo")):
            self.assertRaises(OSError, isfile_strict, this_file)
        with mock.patch('psutil._common.os.stat',
                        side_effect=OSError(errno.EINVAL, "foo")):
            assert not isfile_strict(this_file)
        with mock.patch('psutil._common.stat.S_ISREG', return_value=False):
            assert not isfile_strict(this_file) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_misc.py

示例9: test_safe_rmpath

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def test_safe_rmpath(self):
        # test file is removed
        open(TESTFN, 'w').close()
        safe_rmpath(TESTFN)
        assert not os.path.exists(TESTFN)
        # test no exception if path does not exist
        safe_rmpath(TESTFN)
        # test dir is removed
        os.mkdir(TESTFN)
        safe_rmpath(TESTFN)
        assert not os.path.exists(TESTFN)
        # test other exceptions are raised
        with mock.patch('psutil.tests.os.stat',
                        side_effect=OSError(errno.EINVAL, "")) as m:
            with self.assertRaises(OSError):
                safe_rmpath(TESTFN)
            assert m.called 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_misc.py

示例10: test_open_files_file_gone

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def test_open_files_file_gone(self):
        # simulates a file which gets deleted during open_files()
        # execution
        p = psutil.Process()
        files = p.open_files()
        with tempfile.NamedTemporaryFile():
            # give the kernel some time to see the new file
            call_until(p.open_files, "len(ret) != %i" % len(files))
            with mock.patch('psutil._pslinux.os.readlink',
                            side_effect=OSError(errno.ENOENT, "")) as m:
                files = p.open_files()
                assert not files
                assert m.called
            # also simulate the case where os.readlink() returns EINVAL
            # in which case psutil is supposed to 'continue'
            with mock.patch('psutil._pslinux.os.readlink',
                            side_effect=OSError(errno.EINVAL, "")) as m:
                self.assertEqual(p.open_files(), [])
                assert m.called 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:test_linux.py

示例11: extract

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def extract(self, fwad, output_path):
        """Read data, convert it if needed, and write it to a file

        On error, partially retrieved files are removed.
        File redirections are skipped.
        """

        data = self.read_data(fwad)
        if data is None:
            return

        try:
            with write_file_or_remove(output_path) as fout:
                fout.write(data)
        except OSError as e:
            # Windows does not support path components longer than 255
            # ignore such files
            # TODO: Find a better way of handling these files
            if e.errno in (errno.EINVAL, errno.ENAMETOOLONG):
                logger.warning(f"ignore file with invalid path: {self.path}")
            else:
                raise 
开发者ID:CommunityDragon,项目名称:CDTB,代码行数:24,代码来源:wad.py

示例12: poll

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def poll(self, event, timeout):
        if self.state.SHUTDOWN:
            raise err.Error(errno.ESHUTDOWN)

        if event == "recv":
            if self.state.ESTABLISHED or self.state.CLOSE_WAIT:
                rcvd_pdu = super(DataLinkConnection, self).poll(event, timeout)
                if self.state.ESTABLISHED or self.state.CLOSE_WAIT:
                    return isinstance(rcvd_pdu, pdu.Information)
        elif event == "send":
            if self.state.ESTABLISHED:
                if super(DataLinkConnection, self).poll(event, timeout):
                    return self.state.ESTABLISHED
                return False
        elif event == "acks":
            with self.acks_ready:
                if not self.acks_recvd > 0:
                    self.acks_ready.wait(timeout)
                if self.acks_recvd > 0:
                    self.acks_recvd = self.acks_recvd - 1
                    return True
                return False
        else:
            raise err.Error(errno.EINVAL) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:26,代码来源:tco.py

示例13: test_accept

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def test_accept(self, tco):
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.accept()
        assert excinfo.value.errno == errno.EINVAL
        tco.setsockopt(nfc.llcp.SO_RCVMIU, 1000)
        tco.setsockopt(nfc.llcp.SO_RCVBUF, 2)
        tco.listen(backlog=1)
        assert tco.state.LISTEN is True
        tco.enqueue(nfc.llcp.pdu.Connect(tco.addr, 17, 500, 15))
        dlc = tco.accept()
        assert isinstance(dlc, nfc.llcp.tco.DataLinkConnection)
        assert dlc.state.ESTABLISHED is True
        assert dlc.getsockopt(nfc.llcp.SO_RCVMIU) == 1000
        assert dlc.getsockopt(nfc.llcp.SO_SNDMIU) == 500
        assert dlc.getsockopt(nfc.llcp.SO_RCVBUF) == 2
        assert tco.dequeue(128, 4) == \
            nfc.llcp.pdu.ConnectionComplete(17, tco.addr, 1000, 2)
        threading.Timer(0.01, tco.close).start()
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.accept()
        assert excinfo.value.errno == errno.EPIPE
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.accept()
        assert excinfo.value.errno == errno.ESHUTDOWN 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:26,代码来源:test_llcp_tco.py

示例14: test_accept_connect

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def test_accept_connect(self, llc, ldl, dlc, peer_miu, send_miu):
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.accept(object())
            assert excinfo.value.errno == errno.ENOTSOCK
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.accept(ldl)
            assert excinfo.value.errno == errno.EOPNOTSUPP
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.accept(dlc)
            assert excinfo.value.errno == errno.EINVAL
            connect_pdu = nfc.llcp.pdu.Connect(4, 32, peer_miu)
            threading.Timer(0.01, llc.dispatch, (connect_pdu,)).start()
            llc.bind(dlc, b'urn:nfc:sn:snep')
            llc.listen(dlc, 0)
            sock = llc.accept(dlc)
            assert isinstance(sock, nfc.llcp.tco.DataLinkConnection)
            assert llc.getsockopt(sock, nfc.llcp.SO_SNDMIU) == send_miu
            assert llc.getpeername(sock) == 32
            assert llc.getsockname(sock) == 4 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:21,代码来源:test_llcp_llc.py

示例15: cmdline

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINVAL [as 别名]
def cmdline(self):
        if OPENBSD and self.pid == 0:
            return []  # ...else it crashes
        elif NETBSD:
            # XXX - most of the times the underlying sysctl() call on Net
            # and Open BSD returns a truncated string.
            # Also /proc/pid/cmdline behaves the same so it looks
            # like this is a kernel bug.
            try:
                return cext.proc_cmdline(self.pid)
            except OSError as err:
                if err.errno == errno.EINVAL:
                    if is_zombie(self.pid):
                        raise ZombieProcess(self.pid, self._name, self._ppid)
                    elif not pid_exists(self.pid):
                        raise NoSuchProcess(self.pid, self._name, self._ppid)
                    else:
                        # XXX: this happens with unicode tests. It means the C
                        # routine is unable to decode invalid unicode chars.
                        return []
                else:
                    raise
        else:
            return cext.proc_cmdline(self.pid) 
开发者ID:giampaolo,项目名称:psutil,代码行数:26,代码来源:_psbsd.py


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