MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / __call__

Method __call__

pager_lib/pyasn1/codec/ber/encoder.py:824–881  ·  view source on GitHub ↗
(self, value, asn1Spec=None, **options)

Source from the content-addressed store, hash-verified

822 self._typeMap = typeMap if typeMap is not _MISSING else self.TYPE_MAP
823
824 def __call__(self, value, asn1Spec=None, **options):
825 try:
826 if asn1Spec is None:
827 typeId = value.typeId
828 else:
829 typeId = asn1Spec.typeId
830
831 except AttributeError:
832 raise error.PyAsn1Error('Value %r is not ASN.1 type instance '
833 'and "asn1Spec" not given' % (value,))
834
835 if LOG:
836 LOG('encoder called in %sdef mode, chunk size %s for type %s, '
837 'value:\n%s' % (not options.get('defMode', True) and 'in' or '',
838 options.get('maxChunkSize', 0),
839 asn1Spec is None and value.prettyPrintType() or
840 asn1Spec.prettyPrintType(), value))
841
842 if self.fixedDefLengthMode is not None:
843 options.update(defMode=self.fixedDefLengthMode)
844
845 if self.fixedChunkSize is not None:
846 options.update(maxChunkSize=self.fixedChunkSize)
847
848 try:
849 concreteEncoder = self._typeMap[typeId]
850
851 if LOG:
852 LOG('using value codec %s chosen by type ID '
853 '%s' % (concreteEncoder.__class__.__name__, typeId))
854
855 except KeyError:
856 if asn1Spec is None:
857 tagSet = value.tagSet
858 else:
859 tagSet = asn1Spec.tagSet
860
861 # use base type for codec lookup to recover untagged types
862 baseTagSet = tag.TagSet(tagSet.baseTag, tagSet.baseTag)
863
864 try:
865 concreteEncoder = self._tagMap[baseTagSet]
866
867 except KeyError:
868 raise error.PyAsn1Error('No encoder for %r (%s)' % (value, tagSet))
869
870 if LOG:
871 LOG('using value codec %s chosen by tagSet '
872 '%s' % (concreteEncoder.__class__.__name__, tagSet))
873
874 substrate = concreteEncoder.encode(value, asn1Spec, self, **options)
875
876 if LOG:
877 LOG('codec %s built %s octets of substrate: %s\nencoder '
878 'completed' % (concreteEncoder, len(substrate),
879 debug.hexdump(substrate)))
880
881 return substrate

Callers

nothing calls this directly

Calls 4

getMethod · 0.45
prettyPrintTypeMethod · 0.45
updateMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected