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

Class SequenceEncoder

pager_lib/pyasn1/codec/ber/encoder.py:554–674  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552
553
554class SequenceEncoder(AbstractItemEncoder):
555 omitEmptyOptionals = False
556
557 # TODO: handling three flavors of input is too much -- split over codecs
558
559 def encodeValue(self, value, asn1Spec, encodeFun, **options):
560
561 substrate = b''
562
563 omitEmptyOptionals = options.get(
564 'omitEmptyOptionals', self.omitEmptyOptionals)
565
566 if LOG:
567 LOG('%sencoding empty OPTIONAL components' % (
568 omitEmptyOptionals and 'not ' or ''))
569
570 if asn1Spec is None:
571 # instance of ASN.1 schema
572 inconsistency = value.isInconsistent
573 if inconsistency:
574 raise error.PyAsn1Error(
575 f"ASN.1 object {value.__class__.__name__} is inconsistent")
576
577 namedTypes = value.componentType
578
579 for idx, component in enumerate(value.values()):
580 if namedTypes:
581 namedType = namedTypes[idx]
582
583 if namedType.isOptional and not component.isValue:
584 if LOG:
585 LOG('not encoding OPTIONAL component %r' % (namedType,))
586 continue
587
588 if namedType.isDefaulted and component == namedType.asn1Object:
589 if LOG:
590 LOG('not encoding DEFAULT component %r' % (namedType,))
591 continue
592
593 if omitEmptyOptionals:
594 options.update(ifNotEmpty=namedType.isOptional)
595
596 # wrap open type blob if needed
597 if namedTypes and namedType.openType:
598
599 wrapType = namedType.asn1Object
600
601 if wrapType.typeId in (
602 univ.SetOf.typeId, univ.SequenceOf.typeId):
603
604 substrate += encodeFun(
605 component, asn1Spec,
606 **dict(options, wrapType=wrapType.componentType))
607
608 else:
609 chunk = encodeFun(component, asn1Spec, **options)
610
611 if wrapType.isSameTypeWith(component):

Callers 1

encoder.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected