summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2014-02-22 21:51:28 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2014-02-22 21:51:28 +0000
commit4545d1636ca40d9aef05504a271cff862f0ed03b (patch)
treefa76dd64f6341a1f6a674ee629adf0e0b15b8609 /lib
parent6cd0647da96fdc009b4f30e520bb67778c2a8738 (diff)
downloadpsycopg2-4545d1636ca40d9aef05504a271cff862f0ed03b.tar.gz
Added implementation for Range gt and ge operators
Using a common implementation for all the operators. Note that lt is the one used by sort so it's nice it's the fastest.
Diffstat (limited to 'lib')
-rw-r--r--lib/_range.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/_range.py b/lib/_range.py
index 47a3e0e..29e1836 100644
--- a/lib/_range.py
+++ b/lib/_range.py
@@ -154,20 +154,22 @@ class Range(object):
return False
def __le__(self, other):
- if not isinstance(other, Range):
+ if self == other:
+ return True
+ else:
+ return self.__lt__(other)
+
+ def __gt__(self, other):
+ if isinstance(other, Range):
+ return other.__lt__(self)
+ else:
return NotImplemented
- for attr in self.__slots__:
- self_value = getattr(self, attr)
- other_value = getattr(other, attr)
- if self_value == other_value:
- pass
- elif self_value is None:
- return True
- elif other_value is None:
- return False
- else:
- return self_value <= other_value
- return True
+
+ def __ge__(self, other):
+ if self == other:
+ return True
+ else:
+ return self.__gt__(other)
def register_range(pgrange, pyrange, conn_or_curs, globally=False):