forked from ScoDoc/ScoDoc
Rich Comparisons for py3
This commit is contained in:
parent
427eb169aa
commit
aea498fa86
@ -188,11 +188,29 @@ class ddmmyyyy:
|
|||||||
else:
|
else:
|
||||||
return self.prev(self.weekday)
|
return self.prev(self.weekday)
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other): # #py3 TODO à supprimer
|
||||||
"""return a negative integer if self < other,
|
"""return a negative integer if self < other,
|
||||||
zero if self == other, a positive integer if self > other"""
|
zero if self == other, a positive integer if self > other"""
|
||||||
return int(self.time - other.time)
|
return int(self.time - other.time)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.time == other.time
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return self.time != other.time
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.time < other.time
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return self.time <= other.time
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.time > other.time
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return self.time >= other.time
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
"we are immutable !"
|
"we are immutable !"
|
||||||
return hash(self.time) ^ hash(str(self))
|
return hash(self.time) ^ hash(str(self))
|
||||||
|
@ -411,10 +411,14 @@ class ApoEtapeVDI:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.etape_vdi
|
return self.etape_vdi
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def _cmp(self, other):
|
||||||
"""Test égalité de deux codes étapes.
|
"""Test égalité de deux codes étapes.
|
||||||
Si le VDI des deux est spécifié, on l'utilise. Sinon, seul le code étape est pris en compte.
|
Si le VDI des deux est spécifié, on l'utilise. Sinon, seul le code étape est pris en compte.
|
||||||
Donc V1RT == V1RT!111, V1RT!110 == V1RT, V1RT!77 != V1RT!78, ...
|
Donc V1RT == V1RT!111, V1RT!110 == V1RT, V1RT!77 != V1RT!78, ...
|
||||||
|
|
||||||
|
Compare the two objects x (=self) and y and return an integer according to
|
||||||
|
the outcome. The return value is negative if x < y, zero if x == y
|
||||||
|
and strictly positive if x > y.
|
||||||
"""
|
"""
|
||||||
if other is None:
|
if other is None:
|
||||||
return -1
|
return -1
|
||||||
@ -422,9 +426,31 @@ class ApoEtapeVDI:
|
|||||||
other = ApoEtapeVDI(other)
|
other = ApoEtapeVDI(other)
|
||||||
|
|
||||||
if self.vdi and other.vdi:
|
if self.vdi and other.vdi:
|
||||||
return cmp((self.etape, self.vdi), (other.etape, other.vdi))
|
x = (self.etape, self.vdi)
|
||||||
|
y = (other.etape, other.vdi)
|
||||||
else:
|
else:
|
||||||
return cmp(self.etape, other.etape)
|
x = self.etape
|
||||||
|
y = other.etape
|
||||||
|
|
||||||
|
return (x > y) - (x < y)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self._cmp(other) == 0
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return self._cmp(other) != 0
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self._cmp(other) < 0
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return self._cmp(other) <= 0
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self._cmp(other) > 0
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return self._cmp(other) >= 0
|
||||||
|
|
||||||
def split_etape_vdi(self, etape_vdi):
|
def split_etape_vdi(self, etape_vdi):
|
||||||
"""Etape Apogee can be stored as 'V1RT' or, including the VDI version,
|
"""Etape Apogee can be stored as 'V1RT' or, including the VDI version,
|
||||||
|
Loading…
Reference in New Issue
Block a user