summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2013-12-02 07:34:52 +0000
committerelie <elie>2013-12-02 07:34:52 +0000
commit6ab22c92a5833238047749ff7ce20f3f507637c1 (patch)
treebc2c96dbef3800a95720888262d41121f5d5bcb7
parent78ba77094a788190c3403201bf101f22297b9aba (diff)
downloadpyasn1-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--CHANGES3
-rw-r--r--pyasn1/type/base.py17
2 files changed, 14 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index a5f8267..083d729 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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):