| 145 | self._typeMap = typeMap if typeMap is not _MISSING else self.TYPE_MAP |
| 146 | |
| 147 | def __call__(self, pyObject, asn1Spec, **options): |
| 148 | |
| 149 | if LOG: |
| 150 | debug.scope.push(type(pyObject).__name__) |
| 151 | LOG('decoder called at scope %s, working with ' |
| 152 | 'type %s' % (debug.scope, type(pyObject).__name__)) |
| 153 | |
| 154 | if asn1Spec is None or not isinstance(asn1Spec, base.Asn1Item): |
| 155 | raise error.PyAsn1Error( |
| 156 | 'asn1Spec is not valid (should be an instance of an ASN.1 ' |
| 157 | 'Item, not %s)' % asn1Spec.__class__.__name__) |
| 158 | |
| 159 | try: |
| 160 | valueDecoder = self._typeMap[asn1Spec.typeId] |
| 161 | |
| 162 | except KeyError: |
| 163 | # use base type for codec lookup to recover untagged types |
| 164 | baseTagSet = tag.TagSet(asn1Spec.tagSet.baseTag, asn1Spec.tagSet.baseTag) |
| 165 | |
| 166 | try: |
| 167 | valueDecoder = self._tagMap[baseTagSet] |
| 168 | |
| 169 | except KeyError: |
| 170 | raise error.PyAsn1Error('Unknown ASN.1 tag %s' % asn1Spec.tagSet) |
| 171 | |
| 172 | if LOG: |
| 173 | LOG('calling decoder %s on Python type %s ' |
| 174 | '<%s>' % (type(valueDecoder).__name__, |
| 175 | type(pyObject).__name__, repr(pyObject))) |
| 176 | |
| 177 | value = valueDecoder(pyObject, asn1Spec, self, **options) |
| 178 | |
| 179 | if LOG: |
| 180 | LOG('decoder %s produced ASN.1 type %s ' |
| 181 | '<%s>' % (type(valueDecoder).__name__, |
| 182 | type(value).__name__, repr(value))) |
| 183 | debug.scope.pop() |
| 184 | |
| 185 | return value |
| 186 | |
| 187 | |
| 188 | class Decoder(object): |