Exemple #1
0
 def _deserialize(stream_or_string, **options):
     options.setdefault('use_list', True)
     try:
         obj = msgpack.loads(stream_or_string)
         return _decoder(obj)
     except Exception as error:
         raise DeserializationError(error)
def deserialize(stream_or_string, **options):
    """
    Deserialize any string of stream like object into a Python data structure.

    :param stream_or_string: stream or string to deserialize.
    :param options: options given to lower yaml module.
    """

    options.setdefault('Loader', BaseLoader)
    try:
        return yaml.load(stream_or_string, **options)
    except ScannerError as error:
        err_type = ERROR_MAP.get(error.problem, 'Unknown yaml render error')
        line_num = error.problem_mark.line + 1
        raise DeserializationError(err_type, line_num,
                                   error.problem_mark.buffer)
    except ConstructorError as error:
        raise DeserializationError(error)
    except Exception as error:
        raise DeserializationError(error)
Exemple #3
0
def deserialize(stream_or_string, **options):
    """
    Deserialize any string of stream like object into a Python data structure.

    :param stream_or_string: stream or string to deserialize.
    :param options: options given to lower json/simplejson module.
    """

    try:
        if not isinstance(stream_or_string, (bytes, string_types)):
            return json.load(stream_or_string, **options)

        if isinstance(stream_or_string, bytes):
            stream_or_string = stream_or_string.decode('utf-8')

        return json.loads(stream_or_string)
    except Exception as error:
        raise DeserializationError(error)