當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。