Beispiel #1
0
    def deserialize(self, content, format='application/json'):
        """
        Given some data and a format, calls the correct method to deserialize
        the data and returns the result.
        """
        desired_format = None

        format = format.split(';')[0]

        for short_format, long_format in self.content_types.items():
            if format == long_format:
                if hasattr(self, "from_%s" % short_format):
                    desired_format = short_format
                    break

        if desired_format is None:
            raise UnsupportedFormat(
                "The format indicated '%s' had no available deserialization method. Please check your ``formats`` and ``content_types`` on your Serializer."
                % format)

        if isinstance(content, six.binary_type):
            content = force_text(content)

        deserialized = getattr(self, "from_%s" % desired_format)(content)
        return deserialized
    def deserialize(self, content, format='application/json', tag=None):
        """
        Given some data and a format, calls the correct method to deserialize
        the data and returns the result.
        """
        desired_format = None

        format = format.split(';')[0]

        for short_format, long_format in self.content_types.items():
            if format == long_format:
                if hasattr(self, "from_%s" % short_format):
                    desired_format = short_format
                    break

        if desired_format is None:
            raise UnsupportedFormat(
                "The format indicated '%s' had no available deserialization method. Please check your ``formats`` "
                "and ``content_types`` on your Serializer." % format)

        if desired_format == 'xml' and tag:
            deserialized = getattr(self, "from_%s" % desired_format)(content,
                                                                     tag)
        else:
            try:
                deserialized = getattr(self,
                                       "from_%s" % desired_format)(content)
            except (JSONDecodeError, ValueError):
                raise BadRequest('%s is not serialised using %s format' %
                                 (content, desired_format))
        return deserialized
    def serialize(self, bundle, format='application/json', options=None):
        """
        Given some data and a format, calls the correct method to serialize
        the data and returns the result.
        """
        method = None
        if options is None:
            options = {}

        method = self._to_methods.get(format)

        if method is None:
            raise UnsupportedFormat("The format indicated '%s' had no available serialization method. Please check your ``formats`` and ``content_types`` on your Serializer." % format)

        return method(bundle, options)
Beispiel #4
0
    def serialize(self, bundle, format='application/json', options={}):
        """
        Given some data and a format, calls the correct method to serialize
        the data and returns the result.
        """
        desired_format = None

        for short_format, long_format in self.content_types.items():
            if format == long_format:
                if hasattr(self, "to_%s" % short_format):
                    desired_format = short_format
                    break

        if desired_format is None:
            raise UnsupportedFormat("The format indicated '%s' had no available serialization method. Please check your ``formats`` and ``content_types`` on your Serializer." % format)

        serialized = getattr(self, "to_%s" % desired_format)(bundle, options)
        return serialized
    def deserialize(self, content, format='application/json'):
        """
        Given some data and a format, calls the correct method to deserialize
        the data and returns the result.
        """
        method = None

        format = format.split(';')[0]

        method = self._from_methods.get(format)

        if method is None:
            raise UnsupportedFormat("The format indicated '%s' had no available deserialization method. Please check your ``formats`` and ``content_types`` on your Serializer." % format)

        if isinstance(content, six.binary_type):
            content = force_text(content)

        return method(content)
    def deserialize(self, content, format='application/json'):
        """
        Given some data and a format, calls the correct method to deserialize
        the data and returns the result.
        """
        method = None

        format = format.split(';')[0]

        method = self._from_methods.get(format)

        if method is None:
            raise UnsupportedFormat(format)

        if isinstance(content, six.binary_type):
            content = force_text(content)

        return method(content)