(self, value, **options)
| 191 | self._typeMap = typeMap if typeMap is not _MISSING else self.TYPE_MAP |
| 192 | |
| 193 | def __call__(self, value, **options): |
| 194 | if not isinstance(value, base.Asn1Item): |
| 195 | raise error.PyAsn1Error( |
| 196 | 'value is not valid (should be an instance of an ASN.1 Item)') |
| 197 | |
| 198 | if LOG: |
| 199 | debug.scope.push(type(value).__name__) |
| 200 | LOG('encoder called for type %s ' |
| 201 | '<%s>' % (type(value).__name__, value.prettyPrint())) |
| 202 | |
| 203 | tagSet = value.tagSet |
| 204 | |
| 205 | try: |
| 206 | concreteEncoder = self._typeMap[value.typeId] |
| 207 | |
| 208 | except KeyError: |
| 209 | # use base type for codec lookup to recover untagged types |
| 210 | baseTagSet = tag.TagSet( |
| 211 | value.tagSet.baseTag, value.tagSet.baseTag) |
| 212 | |
| 213 | try: |
| 214 | concreteEncoder = self._tagMap[baseTagSet] |
| 215 | |
| 216 | except KeyError: |
| 217 | raise error.PyAsn1Error('No encoder for %s' % (value,)) |
| 218 | |
| 219 | if LOG: |
| 220 | LOG('using value codec %s chosen by ' |
| 221 | '%s' % (concreteEncoder.__class__.__name__, tagSet)) |
| 222 | |
| 223 | pyObject = concreteEncoder.encode(value, self, **options) |
| 224 | |
| 225 | if LOG: |
| 226 | LOG('encoder %s produced: ' |
| 227 | '%s' % (type(concreteEncoder).__name__, repr(pyObject))) |
| 228 | debug.scope.pop() |
| 229 | |
| 230 | return pyObject |
| 231 | |
| 232 | |
| 233 | class Encoder(object): |
nothing calls this directly
no test coverage detected