コード例 #1
0
ファイル: yaml_codec.py プロジェクト: ktp-forked-repos/odin
def dump(resource, fp, dumper=OdinDumper, **kwargs):
    """
    Dump to a JSON encoded file.

    :param resource: The root resource to dump to a JSON encoded file.
    :param dumper: Dumper to use serializing to a string; default is the :py:class:`OdinDumper`.
    :param fp: The file pointer that represents the output file.

    """
    try:
        yaml.dump(resource, fp, Dumper=dumper, **kwargs)
    except ValueError as ex:
        raise CodecEncodeError(str(ex))
コード例 #2
0
ファイル: json_codec.py プロジェクト: ktp-forked-repos/odin
def dumps(resource, cls=OdinEncoder, **kwargs):
    """
    Dump to a JSON encoded string.

    :param resource: The root resource to dump to a JSON encoded file.
    :param cls: Encoder to use serializing to a string; default is the :py:class:`OdinEncoder`.
    :returns: JSON encoded string.

    """
    try:
        return json.dumps(resource, cls=cls, **kwargs)
    except ValueError as ex:
        raise CodecEncodeError(str(ex))