Beispiel #1
0
    def __init__(self, default=None, serializers=None):
        if default is None:
            default = "json" if _SERIALIZERS["json"] else "yaml"

        if serializers is None:
            serializers = [x() for x in [JsonSerializer, YamlSerializer] if _SERIALIZERS[x.key]]

        if not serializers:
            raise exceptions.SerializerNoAvailable("There are no Available Serializers.")

        self.serializers = {}

        for serializer in serializers:
            self.serializers[serializer.key] = serializer

        self.default = default
Beispiel #2
0
try:
    import simplejson as json
except ImportError:
    try:
        import json
    except ImportError:
        SERIALIZERS["json"] = False

try:
    import yaml
except ImportError:
    SERIALIZERS["yaml"] = False

if not len([x for x in SERIALIZERS.values() if x]):
    raise exceptions.SerializerNoAvailable("There are no Available Serializers.")


class BaseSerializer(object):

    content_type = None

    def get_content_type(self):
        if self.content_type is None:
            raise NotImplementedError()
        return self.content_type

    def loads(self, data):
        raise NotImplementedError()

    def dumps(self, data):