• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compatibility.cmp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中snakeoil.compatibility.cmp函数的典型用法代码示例。如果您正苦于以下问题:Python cmp函数的具体用法?Python cmp怎么用?Python cmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __cmp__

 def __cmp__(self, other):
     c = cmp(self.location, other.location)
     if c:
         return c
     if isinstance(other, self.__class__):
         return cmp(self.target, other.target)
     return 0
开发者ID:chutz,项目名称:pkgcore,代码行数:7,代码来源:fs.py


示例2: test_cmp

    def test_cmp(self):
        pkg1 = self.make_fakepkg()
        pkg2 = self.make_fakepkg(ver=2)
        mpkg1 = MutatedPkg(pkg1, {})
        mpkg2 = MutatedPkg(pkg2, {})

        for lpkg in (pkg1, mpkg1):
            self.assertTrue(cmp(lpkg, mpkg2) < 0)
            self.assertTrue(cmp(mpkg2, lpkg) > 0)
        self.assertEqual(mpkg1, mpkg1)
        self.assertEqual(pkg1, mpkg1)
开发者ID:veelai,项目名称:pkgcore,代码行数:11,代码来源:test_mutated.py


示例3: assertEqual2

 def assertEqual2(self, o1, o2):
     # logic bugs hidden behind short circuiting comparisons for metadata
     # is why we test the comparison *both* ways.
     self.assertEqual(o1, o2)
     c = cmp(o1, o2)
     self.assertEqual(c, 0,
         msg="checking cmp for %r, %r, aren't equal: got %i" % (o1, o2, c))
     self.assertEqual(o2, o1)
     c = cmp(o2, o1)
     self.assertEqual(c, 0,
         msg="checking cmp for %r, %r,aren't equal: got %i" % (o2, o1, c))
开发者ID:radhermit,项目名称:pkgcore,代码行数:11,代码来源:test_atom.py


示例4: assertNotEqual2

 def assertNotEqual2(self, o1, o2):
     # is why we test the comparison *both* ways.
     self.assertNotEqual(o1, o2)
     c = cmp(o1, o2)
     self.assertNotEqual(c, 0,
         msg="checking cmp for %r, %r, not supposed to be equal, got %i"
             % (o1, o2, c))
     self.assertNotEqual(o2, o1)
     c = cmp(o2, o1)
     self.assertNotEqual(c, 0,
         msg="checking cmp for %r, %r, not supposed to be equal, got %i"
             % (o2, o1, c))
开发者ID:radhermit,项目名称:pkgcore,代码行数:12,代码来源:test_atom.py


示例5: ver_cmp

 def ver_cmp(ver1, rev1, ver2, rev2):
     if ver1 == ver2:
         return cmp(rev1, rev2)
     if ver1 is None:
         ver1 = ''
     if ver2 is None:
         ver2 = ''
     c = cmp(cpy_CPV("fake", "pkg", ver1, versioned=bool(ver1)),
             cpy_CPV("fake", "pkg", ver2, versioned=bool(ver2)))
     if c != 0:
         return c
     return cmp(rev1, rev2)
开发者ID:radhermit,项目名称:pkgcore,代码行数:12,代码来源:cpv.py


示例6: cpy_ver_cmp

def cpy_ver_cmp(ver1, rev1, ver2, rev2):
    if ver1 == ver2:
        return cmp(rev1, rev2)
    if ver1 is None:
        ver1 = ''
    if ver2 is None:
        ver2 = ''
    c = cmp(cpy_CPV(fake_cat, fake_pkg, ver1, versioned=bool(ver1)),
            cpy_CPV(fake_cat, fake_pkg, ver2, versioned=bool(ver2)))
    if c != 0:
        return c
    return cmp(rev1, rev2)
开发者ID:neko259,项目名称:pkgcore,代码行数:12,代码来源:cpv.py


示例7: sort_func

 def sort_func(x, y):
     if x.is_dir:
         if not y.is_dir:
             return -1
         return cmp(x, y)
     elif y.is_dir:
         return +1
     elif x.is_reg:
         if y.is_reg:
             return cmp(files_ordering[x.data], files_ordering[y.data])
         return +1
     elif y.is_reg:
         return -1
     return cmp(x, y)
开发者ID:neko259,项目名称:pkgcore,代码行数:14,代码来源:tar.py


示例8: __cmp__

    def __cmp__(self, other):
        if not isinstance(other, self.__class__):
            raise TypeError("other isn't of %s type, is %s" %
                            (self.__class__, other.__class__))

        c = cmp(self.category, other.category)
        if c:
            return c

        c = cmp(self.package, other.package)
        if c:
            return c

        c = cmp(self.op, other.op)
        if c:
            return c

        c = cpv.ver_cmp(self.version, self.revision,
                        other.version, other.revision)
        if c:
            return c

        c = cmp(self.blocks, other.blocks)
        if c:
            # invert it; cmp(True, False) == 1
            # want non blockers then blockers.
            return -c

        c = cmp(self.blocks_strongly, other.blocks_strongly)
        if c:
            # want !! prior to !
            return c

        c = cmp(self.negate_vers, other.negate_vers)
        if c:
            return c

        def f(v):
            return '' if v is None else v
        c = cmp(f(self.slot), f(other.slot))
        if c:
            return c

        c = cmp(self.use, other.use)
        if c:
            return c

        return cmp(self.repo_id, other.repo_id)
开发者ID:chutz,项目名称:pkgcore,代码行数:48,代码来源:atom.py


示例9: __cmp__

    def __cmp__(self, other):
        try:
            if self.cpvstr == other.cpvstr:
                return 0

            if (self.category and other.category and self.category != other.category):
                return cmp(self.category, other.category)

            if self.package and other.package and self.package != other.package:
                return cmp(self.package, other.package)

            # note I chucked out valueerror, none checks on versions
            # passed in. I suck, I know.
            # ~harring
            # fails in doing comparison of unversioned atoms against
            # versioned atoms
            return native_ver_cmp(self.version, self.revision, other.version,
                              other.revision)
        except AttributeError:
            return 1
开发者ID:neko259,项目名称:pkgcore,代码行数:20,代码来源:cpv.py


示例10: f

 def f(x, y):
     c = cmp(x, y)
     if c:
         return c
     elif x.repo.livefs:
         if y.repo.livefs:
             return 0
         return -1
     elif y.repo.livefs:
         return 1
     return 0
开发者ID:veelai,项目名称:pkgcore,代码行数:11,代码来源:plan.py


示例11: test_simple

 def test_simple(self):
     t = tuple([1, 2, 3])
     o = make_DI(tuple, lambda: t)
     objs = [o, t]
     self.assertEqual(*map(str, objs))
     self.assertEqual(*map(repr, objs))
     self.assertEqual(*map(hash, objs))
     self.assertEqual(*objs)
     self.assertTrue(cmp(t, o) == 0)
     self.assertFalse(t < o)
     self.assertTrue(t <= o)
     self.assertTrue(t == o)
     self.assertTrue(t >= o)
     self.assertFalse(t > o)
     self.assertFalse(t != o)
开发者ID:rhn,项目名称:snakeoil,代码行数:15,代码来源:test_obj.py


示例12: __eq__

 def __eq__(self, other):
     if isinstance(other, wrapper):
         return cmp(self._raw_pkg, other._raw_pkg) == 0
     return cmp(self._raw_pkg, other) == 0
开发者ID:chutz,项目名称:pkgcore,代码行数:4,代码来源:base.py


示例13: test_cmp

    def test_cmp(self):
        ukls, vkls = self.ukls, self.vkls
        assert cmp(vkls("dev-util/diffball-0.1"), vkls("dev-util/diffball-0.2")) < 0
        base = "dev-util/diffball-0.7.1"
        assert not cmp(vkls(base), vkls(base))
        for rev in ("", "-r1"):
            last = None
            for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
                if suf == "":
                    sufs = [suf]
                else:
                    sufs = [suf, suf+"4"]
                for x in sufs:
                    cur = vkls(base+x+rev)
                    assert cur == vkls(base+x+rev)
                    if last is not None:
                        assert cur > last

        assert vkls("da/ba-6a") > vkls("da/ba-6")
        assert vkls("da/ba-6a-r1") > vkls("da/ba-6a")
        assert vkls("da/ba-6.0") > vkls("da/ba-6")
        assert vkls("da/ba-6.0.0") > vkls("da/ba-6.0b")
        assert vkls("da/ba-6.02") > vkls("da/ba-6.0.0")
        # float comparison rules.
        assert vkls("da/ba-6.2") > vkls("da/ba-6.054")
        assert vkls("da/ba-6") == vkls("da/ba-6")
        assert ukls("db/ba") > ukls("da/ba")
        assert ukls("da/bb") > ukls("da/ba")
        assert vkls("da/ba-6.0_alpha0_p1") > vkls("da/ba-6.0_alpha")
        assert vkls("da/ba-6.0_alpha") == vkls("da/ba-6.0_alpha0")
        assert vkls("da/ba-6.1") > vkls("da/ba-6.09")
        assert vkls("da/ba-6.0.1") > vkls("da/ba-6.0")
        assert vkls("da/ba-12.2.5") > vkls("da/ba-12.2b")

        # test for gentoo bug 287848
        assert vkls("dev-lang/erlang-12.2.5") > vkls("dev-lang/erlang-12.2b")
        assert vkls("dev-lang/erlang-12.2.5-r1") > vkls("dev-lang/erlang-12.2b")

        assert vkls("da/ba-6.01.0") == vkls("da/ba-6.010.0")

        for v1, v2 in (("1.001000000000000000001", "1.001000000000000000002"),
            ("1.00100000000", "1.0010000000000000001"),
            ("1.01", "1.1")):
            assert vkls(f"da/ba-{v2}") > vkls(f"da/ba-{v1}")

        for x in (18, 36, 100):
            s = "0" * x
            assert vkls(f"da/ba-10{s}1") > vkls(f"da/ba-1{s}1")

        for x in (18, 36, 100):
            s = "0" * x
            assert vkls(f"da/ba-1-r10{s}1") > vkls(f"da/ba-1-r1{s}1")

        assert vkls('sys-apps/net-tools-1.60_p2010081516093') > \
            vkls('sys-apps/net-tools-1.60_p2009072801401')

        assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
            vkls('sys-apps/net-tools-1.60_p20090728014017')

        assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
            vkls('sys-apps/net-tools-1.60_p20090728014017-r1')

        # Regression test: python does comparison slightly differently
        # if the classes do not match exactly (it prefers rich
        # comparison over __cmp__).
        class DummySubclass(self.kls):
            pass

        assert DummySubclass("da/ba-6.0_alpha0_p1", versioned=True) != vkls("da/ba-6.0_alpha")
        assert DummySubclass("da/ba-6.0_alpha0", versioned=True) == vkls("da/ba-6.0_alpha")

        assert DummySubclass("da/ba-6.0", versioned=True) != "foon"
        assert DummySubclass("da/ba-6.0", versioned=True) == \
            DummySubclass("da/ba-6.0-r0", versioned=True)
开发者ID:radhermit,项目名称:pkgcore,代码行数:74,代码来源:test_cpv.py


示例14: __cmp__

 def __cmp__(self, other):
     return cmp(self.value, other.value)
开发者ID:rafaelmartins,项目名称:snakeoil,代码行数:2,代码来源:test_klass.py


示例15: test_cmp

    def test_cmp(self):
        ukls, vkls = self.ukls, self.vkls
        self.assertTrue(cmp(vkls("dev-util/diffball-0.1"), vkls("dev-util/diffball-0.2")) < 0)
        base = "dev-util/diffball-0.7.1"
        self.assertFalse(cmp(vkls(base), vkls(base)))
        for rev in ("", "-r1"):
            last = None
            for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
                if suf == "":
                    sufs = [suf]
                else:
                    sufs = [suf, suf + "4"]
                for x in sufs:
                    cur = vkls(base + x + rev)
                    self.assertEqual(cur, vkls(base + x + rev))
                    if last is not None:
                        self.assertGT(cur, last)

        self.assertGT(vkls("da/ba-6a"), vkls("da/ba-6"))
        self.assertGT(vkls("da/ba-6a-r1"), vkls("da/ba-6a"))
        self.assertGT(vkls("da/ba-6.0"), vkls("da/ba-6"))
        self.assertGT(vkls("da/ba-6.0.0"), vkls("da/ba-6.0b"))
        self.assertGT(vkls("da/ba-6.02"), vkls("da/ba-6.0.0"))
        # float comparison rules.
        self.assertGT(vkls("da/ba-6.2"), vkls("da/ba-6.054"))
        self.assertEqual(vkls("da/ba-6"), vkls("da/ba-6"))
        self.assertGT(ukls("db/ba"), ukls("da/ba"))
        self.assertGT(ukls("da/bb"), ukls("da/ba"))
        self.assertGT(vkls("da/ba-6.0_alpha0_p1"), vkls("da/ba-6.0_alpha"))
        self.assertEqual(vkls("da/ba-6.0_alpha"), vkls("da/ba-6.0_alpha0"))
        self.assertGT(vkls("da/ba-6.1"), vkls("da/ba-6.09"))
        self.assertGT(vkls("da/ba-6.0.1"), vkls("da/ba-6.0"))
        self.assertGT(vkls("da/ba-12.2.5"), vkls("da/ba-12.2b"))

        # test for gentoo bug 287848
        self.assertGT(vkls("dev-lang/erlang-12.2.5"), vkls("dev-lang/erlang-12.2b"))
        self.assertGT(vkls("dev-lang/erlang-12.2.5-r1"), vkls("dev-lang/erlang-12.2b"))

        self.assertEqual(vkls("da/ba-6.01.0"), vkls("da/ba-6.010.0"))

        for v1, v2 in (
            ("1.001000000000000000001", "1.001000000000000000002"),
            ("1.00100000000", "1.0010000000000000001"),
            ("1.01", "1.1"),
        ):
            self.assertGT(vkls("da/ba-%s" % v2), vkls("da/ba-%s" % v1))

        for x in (18, 36, 100):
            s = "0" * x
            self.assertGT(vkls("da/ba-10%s1" % s), vkls("da/ba-1%s1" % s))

        for x in (18, 36, 100):
            s = "0" * x
            self.assertGT(vkls("da/ba-1-r10%s1" % s), vkls("da/ba-1-r1%s1" % s))

        self.assertGT(vkls("sys-apps/net-tools-1.60_p2010081516093"), vkls("sys-apps/net-tools-1.60_p2009072801401"))

        self.assertGT(vkls("sys-apps/net-tools-1.60_p20100815160931"), vkls("sys-apps/net-tools-1.60_p20090728014017"))

        self.assertGT(
            vkls("sys-apps/net-tools-1.60_p20100815160931"), vkls("sys-apps/net-tools-1.60_p20090728014017-r1")
        )

        # Regression test: python does comparison slightly differently
        # if the classes do not match exactly (it prefers rich
        # comparison over __cmp__).
        class DummySubclass(self.kls):
            pass

        self.assertNotEqual(DummySubclass("da/ba-6.0_alpha0_p1", versioned=True), vkls("da/ba-6.0_alpha"))
        self.assertEqual(DummySubclass("da/ba-6.0_alpha0", versioned=True), vkls("da/ba-6.0_alpha"))

        self.assertNotEqual(DummySubclass("da/ba-6.0", versioned=True), "foon")
        self.assertEqual(DummySubclass("da/ba-6.0", versioned=True), DummySubclass("da/ba-6.0-r0", versioned=True))
开发者ID:neko259,项目名称:pkgcore,代码行数:74,代码来源:test_cpv.py


示例16: native_ver_cmp

def native_ver_cmp(ver1, rev1, ver2, rev2):

    # If the versions are the same, comparing revisions will suffice.
    if ver1 == ver2:
        return cmp(rev1, rev2)

    # Split up the versions into dotted strings and lists of suffixes.
    parts1 = ver1.split("_")
    parts2 = ver2.split("_")

    # If the dotted strings are equal, we can skip doing a detailed comparison.
    if parts1[0] != parts2[0]:

        # First split up the dotted strings into their components.
        ver_parts1 = parts1[0].split(".")
        ver_parts2 = parts2[0].split(".")

        # Pull out any letter suffix on the final components and keep
        # them for later.
        letters = []
        for ver_parts in (ver_parts1, ver_parts2):
            if ver_parts[-1][-1].isalpha():
                letters.append(ord(ver_parts[-1][-1]))
                ver_parts[-1] = ver_parts[-1][:-1]
            else:
                # Using -1 simplifies comparisons later
                letters.append(-1)

        # OPT: Pull length calculation out of the loop
        ver_parts1_len = len(ver_parts1)
        ver_parts2_len = len(ver_parts2)

        # Iterate through the components
        for v1, v2 in izip(ver_parts1, ver_parts2):

            # If the string components are equal, the numerical
            # components will be equal too.
            if v1 == v2:
                continue

            # If one of the components begins with a "0" then they
            # are compared as floats so that 1.1 > 1.02; else ints.
            if v1[0] != "0" and v2[0] != "0":
                v1 = int(v1)
                v2 = int(v2)
            else:
                # handle the 0.060 == 0.060 case.
                v1 = v1.rstrip("0")
                v2 = v2.rstrip("0")

            # If they are not equal, the higher value wins.
            c = cmp(v1, v2)
            if c:
                return c

        if ver_parts1_len > ver_parts2_len:
            return 1
        elif ver_parts2_len > ver_parts1_len:
            return -1

        # The dotted components were equal. Let's compare any single
        # letter suffixes.
        if letters[0] != letters[1]:
            return cmp(letters[0], letters[1])

    # The dotted components were equal, so remove them from our lists
    # leaving only suffixes.
    del parts1[0]
    del parts2[0]

    # OPT: Pull length calculation out of the loop
    parts1_len = len(parts1)
    parts2_len = len(parts2)

    # Iterate through the suffixes
    for x in xrange(max(parts1_len, parts2_len)):

        # If we're at the end of one of our lists, we need to use
        # the next suffix from the other list to decide who wins.
        if x == parts1_len:
            match = suffix_regexp.match(parts2[x])
            val = suffix_value[match.group(1)]
            if val:
                return cmp(0, val)
            return cmp(0, int("0"+match.group(2)))
        if x == parts2_len:
            match = suffix_regexp.match(parts1[x])
            val = suffix_value[match.group(1)]
            if val:
                return cmp(val, 0)
            return cmp(int("0"+match.group(2)), 0)

        # If the string values are equal, no need to parse them.
        # Continue on to the next.
        if parts1[x] == parts2[x]:
            continue

        # Match against our regular expression to make a split between
        # "beta" and "1" in "beta1"
        match1 = suffix_regexp.match(parts1[x])
#.........这里部分代码省略.........
开发者ID:neko259,项目名称:pkgcore,代码行数:101,代码来源:cpv.py


示例17: _verify

    def _verify(self, file_location, target, all_chksums=True, handlers=None):
        """
        Internal function for derivatives.

        Digs through chksums, and either returns None, or throws an
        errors.FetchFailed exception.
          - -2: file doesn't exist.
          - -1: if (size chksum is available, and
                file is smaller than stated chksum)
          - 0:  if all chksums match
          - 1:  if file is too large (if size chksums are available)
                or else size is right but a chksum didn't match.

        if all_chksums is True, all chksums must be verified; if false, all
        a handler can be found for are used.
        """

        nondefault_handlers = handlers
        if handlers is None:
            try:
                handlers = get_handlers(target.chksums)
            except KeyError:
                compatibility.raise_from(errors.FetchFailed(
                    file_location, "Couldn't find a required checksum handler"))
        if all_chksums:
            missing = set(target.chksums).difference(handlers)
            if missing:
                raise errors.RequiredChksumDataMissing(target, *sorted(missing))

        if "size" in handlers:
            val = handlers["size"](file_location)
            if val == -1:
                raise errors.MissingDistfile(file_location)
            c = cmp(val, target.chksums["size"])
            if c:
                resumable = (c < 0)
                if resumable:
                    msg = "File is too small."
                else:
                    msg = "File is too big."
                raise errors.FetchFailed(
                    file_location, msg, resumable=resumable)
        elif not os.path.exists(file_location):
            raise errors.MissingDistfile(file_location)
        elif not os.stat(file_location).st_size:
            raise errors.FetchFailed(
                file_location, 'file is empty', resumable=False)

        chfs = set(target.chksums).intersection(handlers)
        chfs.discard("size")
        chfs = list(chfs)
        if nondefault_handlers:
            for x in chfs:
                val = handlers[x](file_location)
                if val != target.chksums[x]:
                    raise errors.FetchFailed(
                        file_location,
                        "Validation handler %s: expected %s, got %s" %
                        (x, target.chksums[x], val))
        else:
            desired_vals = [target.chksums[x] for x in chfs]
            calced = get_chksums(file_location, *chfs)
            for desired, got, chf in zip(desired_vals, calced, chfs):
                if desired != got:
                    raise errors.FetchFailed(
                        file_location,
                        "Validation handler %s: expected %s, got %s" %
                        (chf, desired, got))
开发者ID:den4ix,项目名称:pkgcore,代码行数:68,代码来源:base.py


示例18: __cmp__

 def __cmp__(self, other):
     return cmp(self.ver, other.ver)
开发者ID:veelai,项目名称:pkgcore,代码行数:2,代码来源:test_mutated.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compatibility.raise_from函数代码示例发布时间:2022-05-27
下一篇:
Python formatter.format_bytes函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap