diff options
author | elie <elie> | 2013-12-08 15:17:43 +0000 |
---|---|---|
committer | elie <elie> | 2013-12-08 15:17:43 +0000 |
commit | 36bd6c436907c2a78ef8fe9255192e05506b9927 (patch) | |
tree | a8767224426ff270035eddcfd3d075d454151998 | |
parent | 2eba151010dfbbdb561ab09bd927e2fc92c51f04 (diff) | |
download | pyasn1-36bd6c436907c2a78ef8fe9255192e05506b9927.tar.gz |
NamedTypes() and NamedValues() made comparable
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | pyasn1/type/namedtype.py | 17 | ||||
-rw-r--r-- | pyasn1/type/namedval.py | 8 |
3 files changed, 25 insertions, 1 deletions
@@ -23,6 +23,7 @@ Revision 0.1.8 - Constructed types can now be initialized with new .setComponents() method which accepts both var-args and keyword-args. Default repr() modified to reflect this change. +- NamedTypes() and NamedValues() made comparable. - Fix to NamedType.__repr__() to work properly. - Fixes to __repr__() implementation of many built-in ASN.1 types to take into account all of their initializers such as tagSet, subtypeSpec etc. diff --git a/pyasn1/type/namedtype.py b/pyasn1/type/namedtype.py index 5ddcbd3..aca4282 100644 --- a/pyasn1/type/namedtype.py +++ b/pyasn1/type/namedtype.py @@ -11,6 +11,14 @@ class NamedType: def __repr__(self): return '%s(%r, %r)' % ( self.__class__.__name__, self.__name, self.__type ) + def __eq__(self, other): return tuple(self) == tuple(other) + def __ne__(self, other): return tuple(self) != tuple(other) + def __lt__(self, other): return tuple(self) < tuple(other) + def __le__(self, other): return tuple(self) <= tuple(other) + def __gt__(self, other): return tuple(self) > tuple(other) + def __ge__(self, other): return tuple(self) >= tuple(other) + def __hash__(self): return hash(tuple(self)) + def getType(self): return self.__type def getName(self): return self.__name def __getitem__(self, idx): @@ -37,7 +45,14 @@ class NamedTypes: self.__class__.__name__, ', '.join([ repr(x) for x in self.__namedTypes ]) ) - + def __eq__(self, other): return tuple(self) == tuple(other) + def __ne__(self, other): return tuple(self) != tuple(other) + def __lt__(self, other): return tuple(self) < tuple(other) + def __le__(self, other): return tuple(self) <= tuple(other) + def __gt__(self, other): return tuple(self) > tuple(other) + def __ge__(self, other): return tuple(self) >= tuple(other) + def __hash__(self): return hash(tuple(self)) + def __getitem__(self, idx): return self.__namedTypes[idx] if sys.version_info[0] <= 2: diff --git a/pyasn1/type/namedval.py b/pyasn1/type/namedval.py index 20e948e..676cb93 100644 --- a/pyasn1/type/namedval.py +++ b/pyasn1/type/namedval.py @@ -27,6 +27,14 @@ class NamedValues: return '%s(%s)' % (self.__class__.__name__, ', '.join([repr(x) for x in self.namedValues])) def __str__(self): return str(self.namedValues) + + def __eq__(self, other): return tuple(self) == tuple(other) + def __ne__(self, other): return tuple(self) != tuple(other) + def __lt__(self, other): return tuple(self) < tuple(other) + def __le__(self, other): return tuple(self) <= tuple(other) + def __gt__(self, other): return tuple(self) > tuple(other) + def __ge__(self, other): return tuple(self) >= tuple(other) + def __hash__(self): return hash(tuple(self)) def getName(self, value): if value in self.valToNameIdx: |