mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-18 06:16:29 +00:00
[Py2to3] Make VersionSplit Python 3 compatible.
The builtin cmp() and the __cmp__() special method is no longer used in Python 3, instead we use functools.total_ordering decorator and the __lt__/__eq__ special methods to get the same effect.
This commit is contained in:
parent
da51e3a3d5
commit
da4b2b4849
@ -10,6 +10,7 @@
|
|||||||
"""Common functions for various parts of Deluge to use."""
|
"""Common functions for various parts of Deluge to use."""
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import functools
|
||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
import numbers
|
import numbers
|
||||||
@ -818,6 +819,7 @@ def utf8_encoded(s, encoding="utf8"):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
@functools.total_ordering
|
||||||
class VersionSplit(object):
|
class VersionSplit(object):
|
||||||
"""
|
"""
|
||||||
Used for comparing version numbers.
|
Used for comparing version numbers.
|
||||||
@ -857,26 +859,32 @@ class VersionSplit(object):
|
|||||||
if vs[-1].startswith('dev'):
|
if vs[-1].startswith('dev'):
|
||||||
self.dev = vs[-1]
|
self.dev = vs[-1]
|
||||||
|
|
||||||
def __cmp__(self, ver):
|
def get_comparable_versions(self, other):
|
||||||
"""
|
"""
|
||||||
The comparison method.
|
Returns a 2-tuple of lists for use in the comparison
|
||||||
|
methods.
|
||||||
:param ver: the version to compare with
|
|
||||||
:type ver: VersionSplit
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# PEP 386 versions with .devN precede release version
|
# PEP 386 versions with .devN precede release version
|
||||||
if bool(self.dev) != bool(ver.dev):
|
if bool(self.dev) != bool(other.dev):
|
||||||
if self.dev != 'dev':
|
if self.dev != 'dev':
|
||||||
self.dev = not self.dev
|
self.dev = not self.dev
|
||||||
if ver.dev != 'dev':
|
if other.dev != 'dev':
|
||||||
ver.dev = not ver.dev
|
other.dev = not other.dev
|
||||||
|
|
||||||
# If there is no suffix we use z because we want final
|
# If there is no suffix we use z because we want final
|
||||||
# to appear after alpha, beta, and rc alphabetically.
|
# to appear after alpha, beta, and rc alphabetically.
|
||||||
v1 = [self.version, self.suffix or 'z', self.dev]
|
v1 = [self.version, self.suffix or 'z', self.dev]
|
||||||
v2 = [ver.version, ver.suffix or 'z', ver.dev]
|
v2 = [other.version, other.suffix or 'z', other.dev]
|
||||||
return cmp(v1, v2)
|
|
||||||
|
return (v1, v2)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
v1, v2 = self.get_comparable_versions(other)
|
||||||
|
return v1 == v2
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
v1, v2 = self.get_comparable_versions(other)
|
||||||
|
return v1 < v2
|
||||||
|
|
||||||
|
|
||||||
# Common AUTH stuff
|
# Common AUTH stuff
|
||||||
|
Loading…
x
Reference in New Issue
Block a user