def decode(s, format, **kwargs):
    serializer = get_serializer_by_format(format)
    if not serializer:
        raise ValueError('Invalid format: {}.'.format(format))
    decode_opts = kwargs.copy()
    data = serializer.decode(s.strip(), **decode_opts)
    return data
Пример #2
0
    def _pop_options(self, options):
        encoding = options.pop('encoding', 'utf-8')
        subformat = options.pop('subformat', None)
        from benedict.serializers import get_serializer_by_format

        serializer = get_serializer_by_format(subformat)
        return (serializer, encoding)
def encode(d, format, **kwargs):
    serializer = get_serializer_by_format(format)
    if not serializer:
        raise ValueError('Invalid format: {}.'.format(format))
    s = serializer.encode(d, **kwargs)
    return s