summaryrefslogtreecommitdiff
path: root/pyasn1/codec/native/decoder.py
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2019-11-16 18:02:12 +0100
committerIlya Etingof <etingof@gmail.com>2019-11-16 18:02:12 +0100
commit317452bd76d711c35a1bbdda54879606dd693268 (patch)
tree2d06cd815b392ca7f075d4c51b76451677a35742 /pyasn1/codec/native/decoder.py
parent8393983359edc25b75cbe07f0d4c13497285aa71 (diff)
downloadpyasn1-git-317452bd76d711c35a1bbdda54879606dd693268.tar.gz
Pass `tagMap` and `typeMap` to decoder instance
This change should simplify decoder specialization by means of parameterization in addition to subclassing.
Diffstat (limited to 'pyasn1/codec/native/decoder.py')
-rw-r--r--pyasn1/codec/native/decoder.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/pyasn1/codec/native/decoder.py b/pyasn1/codec/native/decoder.py
index db30c71..1838b7d 100644
--- a/pyasn1/codec/native/decoder.py
+++ b/pyasn1/codec/native/decoder.py
@@ -135,9 +135,9 @@ class SingleItemDecoder(object):
TAG_MAP = TAG_MAP
TYPE_MAP = TYPE_MAP
- def __init__(self, tagMap=None, typeMap=None):
- self.__tagMap = tagMap or self.TAG_MAP
- self.__typeMap = typeMap or self.TYPE_MAP
+ def __init__(self, **options):
+ self._tagMap = options.get('tagMap', self.TAG_MAP)
+ self._typeMap = options.get('typeMap', self.TYPE_MAP)
def __call__(self, pyObject, asn1Spec, **options):
@@ -152,14 +152,14 @@ class SingleItemDecoder(object):
'Item, not %s)' % asn1Spec.__class__.__name__)
try:
- valueDecoder = self.__typeMap[asn1Spec.typeId]
+ valueDecoder = self._typeMap[asn1Spec.typeId]
except KeyError:
# use base type for codec lookup to recover untagged types
baseTagSet = tag.TagSet(asn1Spec.tagSet.baseTag, asn1Spec.tagSet.baseTag)
try:
- valueDecoder = self.__tagMap[baseTagSet]
+ valueDecoder = self._tagMap[baseTagSet]
except KeyError:
raise error.PyAsn1Error('Unknown ASN.1 tag %s' % asn1Spec.tagSet)
@@ -184,7 +184,7 @@ class Decoder(object):
SINGLE_ITEM_DECODER = SingleItemDecoder
def __init__(self, **options):
- self._singleItemDecoder = self.SINGLE_ITEM_DECODER()
+ self._singleItemDecoder = self.SINGLE_ITEM_DECODER(**options)
def __call__(self, pyObject, asn1Spec=None, **kwargs):
return self._singleItemDecoder(pyObject, asn1Spec=asn1Spec, **kwargs)