How to use the asn1tools.codecs.EncodeError function in asn1tools

To help you get started, we’ve selected a few asn1tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eerimoq / asn1tools / asn1tools / codecs / per.py View on Github external
def encode_member(self, member, data, encoder, encode_default=False):
        name = member.name

        if name in data:
            try:
                if member.default is None:
                    member.encode(data[name], encoder)
                elif not member.is_default(data[name]) or encode_default:
                    member.encode(data[name], encoder)
            except EncodeError as e:
                e.location.append(member.name)
                raise
        elif member.optional or member.default is not None:
            pass
        else:
            raise EncodeError(
                "{} member '{}' not found in {}.".format(
                    self.__class__.__name__,
                    name,
                    data))
github eerimoq / asn1tools / asn1tools / codecs / jer.py View on Github external
def encode(self, data):
        try:
            member = self.name_to_member[data[0]]
        except KeyError:
            raise EncodeError(
                "Expected choice {}, but got '{}'.".format(
                    self.format_names(),
                    data[0]))

        try:
            return {member.name: member.encode(data[1])}
        except EncodeError as e:
            e.location.append(member.name)
            raise
github eerimoq / asn1tools / asn1tools / codecs / xer.py View on Github external
def encode(self, data):
        try:
            member = self.name_to_member[data[0]]
        except KeyError:
            raise EncodeError(
                "Expected choice {}, but got '{}'.".format(
                    self.format_names(),
                    data[0]))

        element = ElementTree.Element(self.name)

        try:
            element.append(member.encode(data[1]))
        except EncodeError as e:
            e.location.append(member.name)
            raise

        return element
github eerimoq / asn1tools / asn1tools / codecs / oer.py View on Github external
def encode_member(self, member, data, encoder, encode_default=False):
        name = member.name

        if name in data:
            try:
                if member.default is None:
                    member.encode(data[name], encoder)
                elif not member.is_default(data[name]) or encode_default:
                    member.encode(data[name], encoder)
            except EncodeError as e:
                e.location.append(member.name)
                raise
        elif member.optional or member.has_default():
            pass
        else:
            raise EncodeError(
                "{} member '{}' not found in {}.".format(
                    self.__class__.__name__,
                    name,
                    data))
github eerimoq / asn1tools / asn1tools / codecs / type_checker.py View on Github external
def encode(self, data):
        if sys.version_info[0] > 2:
            if not isinstance(data, (int, str)):
                raise EncodeError(
                    'Expected data of type int or str, but got {}.'.format(
                        data))
        else:
            if not isinstance(data, (int, long, str, unicode)):
                raise EncodeError(
                    'Expected data of type int or str, but got {}.'.format(
                        data))
github eerimoq / asn1tools / asn1tools / codecs / ber.py View on Github external
if name in data:
            value = data[name]

            try:
                if isinstance(member, AnyDefinedBy):
                    member.encode(value, encoded_members, data)
                elif not member.is_default(value):
                    member.encode(value, encoded_members)
            except EncodeError as e:
                e.location.append(member.name)
                raise
        elif member.optional:
            pass
        elif not member.has_default():
            raise EncodeError("{} member '{}' not found in {}.".format(
                self.__class__.__name__,
                name,
                data))
github eerimoq / asn1tools / asn1tools / codecs / oer.py View on Github external
def encode_member(self, member, data, encoder):
        try:
            member.encode(data, encoder)
        except EncodeError as e:
            e.location.append(member.name)
            raise
github eerimoq / asn1tools / asn1tools / codecs / per.py View on Github external
def encode_member(self, member, data, encoder):
        try:
            member.encode(data, encoder)
        except EncodeError as e:
            e.location.append(member.name)
            raise