Full rich comparison operators
[pyderasn.git] / pyderasn.py
index 5c311e09c11d2c39eed450a0d2f768bd195f1bea..0c2c2ee44d1fff5f4b664427124f8f0d41caaa81 100755 (executable)
@@ -735,6 +735,24 @@ class Obj(object):
     def __str__(self):  # pragma: no cover
         return self.__bytes__() if PY2 else self.__unicode__()
 
+    def __eq__(self, their):  # pragma: no cover
+        raise NotImplementedError()
+
+    def __ne__(self, their):
+        return not(self == their)
+
+    def __lt__(self, their):  # pragma: no cover
+        raise NotImplementedError()
+
+    def __gt__(self, their):  # pragma: no cover
+        return not(self < their)
+
+    def __le__(self, their):  # pragma: no cover
+        return (self == their) or (self < their)
+
+    def __ge__(self, their):  # pragma: no cover
+        return (self == their) or (self > their)
+
     def _encode(self):  # pragma: no cover
         raise NotImplementedError()
 
@@ -1327,10 +1345,7 @@ class Integer(Obj):
         )
 
     def __lt__(self, their):
-        return self._value < their
-
-    def __gt__(self, their):
-        return self._value > their
+        return self._value < their._value
 
     @property
     def named(self):
@@ -1946,6 +1961,9 @@ class OctetString(Obj):
             self._expl == their._expl
         )
 
+    def __lt__(self, their):
+        return self._value < their._value
+
     def __call__(
             self,
             value=None,
@@ -2313,10 +2331,7 @@ class ObjectIdentifier(Obj):
         )
 
     def __lt__(self, their):
-        return self._value < their
-
-    def __gt__(self, their):
-        return self._value > their
+        return self._value < their._value
 
     def __call__(
             self,