Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Replace __cmp__ with __lt__, __gt__, __lte__ and so on for Py3k compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
Jyrki Pulliainen committed Jul 3, 2009
1 parent 8117611 commit e1a7ecd
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions filesystem/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,26 @@ def _incomparable(self, other):
return NotImplemented
return False

def __cmp__(self, other):
def __lt__(self, other):
return (self._incomparable(other) or
cmp(self._pathname, other._pathname))

(self._pathname < other._pathname))

def __eq__(self, other):
return (self._incomparable(other) or
(self._pathname == other._pathname))

def __gt__(self, other):
return not (self < other or self == other)

def __le__(self, other):
return self < other or self == other

def __ge__(self, other):
return not self < other

def __ne__(self, other):
return not self == other

class SimpleComparitionMixin(object):
"""
This class implements the equity/comparition-methods using
Expand All @@ -272,17 +288,37 @@ def _incomparable(self, other):
return NotImplemented
return False

def __cmp__(self, other):
def __lt__(self, other):
if self._incomparable(other):
return NotImplemented

## root object
if self.parent() is self and other.parent() is other:
return cmp(self.name(), other.name())
return self.name() < other.name()

## compare parents ... and if they are equal, compare name
return (cmp(self.parent(), other.parent()) or
cmp(self.name(), other.name()))
return ((self.parent() < other.parent()) or
(self.name() < other.name()))

def __eq__(self, other):
if self._incomparable(other):
return NotImplemented

## root object
if self.parent() is self and other.parent() is other:
return self.name() == other.name()

return ((self.parent() == other.parent()) and
(self.name() == other.name()))

def __gt__(self, other):
return not self <= other

def __le__(self, other):
return self < other or self == other

def __ge__(self, other):
return not self < other

def __unicode__(self):
if self.parent() == self:
Expand Down

0 comments on commit e1a7ecd

Please sign in to comment.