diff options
author | elie <elie> | 2013-12-02 07:34:52 +0000 |
---|---|---|
committer | elie <elie> | 2013-12-02 07:34:52 +0000 |
commit | 6ab22c92a5833238047749ff7ce20f3f507637c1 (patch) | |
tree | bc2c96dbef3800a95720888262d41121f5d5bcb7 | |
parent | 78ba77094a788190c3403201bf101f22297b9aba (diff) | |
download | pyasn1-6ab22c92a5833238047749ff7ce20f3f507637c1.tar.gz |
when comparing ASN.1 types, by-tag and/or by-constraints matching
can now be performed with the isSuperTypeOf()/isSameTypeWith() optional
flags
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | pyasn1/type/base.py | 17 |
2 files changed, 14 insertions, 6 deletions
@@ -15,6 +15,9 @@ Revision 0.1.8 made public. - The base.NoValue() class instances now support __repr__() what makes possible to perform repr() on uninitialized pyasn1 types objects. +- When comparing ASN.1 types, by-tag and/or by-constraints matching + can now be performed with the isSuperTypeOf()/isSameTypeWith() optional + flags. - 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/base.py b/pyasn1/type/base.py index 7d3445c..2380fb0 100644 --- a/pyasn1/type/base.py +++ b/pyasn1/type/base.py @@ -38,14 +38,19 @@ class Asn1ItemBase(Asn1Item): def getEffectiveTagSet(self): return self._tagSet # used by untagged types def getTagMap(self): return tagmap.TagMap({self._tagSet: self}) - def isSameTypeWith(self, other): + def isSameTypeWith(self, other, ignoreTags=False, ignoreConstraints=False): return self is other or \ - self._tagSet == other.getTagSet() and \ - self._subtypeSpec == other.getSubtypeSpec() - def isSuperTypeOf(self, other): + (ignoreTags or \ + self._tagSet == other.getTagSet()) and \ + (ignoreConstraints or \ + self._subtypeSpec==other.getSubtypeSpec()) + + def isSuperTypeOf(self, other, ignoreTags=False, ignoreConstraints=False): """Returns true if argument is a ASN1 subtype of ourselves""" - return self._tagSet.isSuperTagSetOf(other.getTagSet()) and \ - self._subtypeSpec.isSuperTypeOf(other.getSubtypeSpec()) + return (ignoreTags or \ + self._tagSet.isSuperTagSetOf(other.getTagSet())) and \ + (ignoreConstraints or \ + (self._subtypeSpec.isSuperTypeOf(other.getSubtypeSpec()))) class NoValue: def __getattr__(self, attr): |