def dumps()

in elastic_transport/_serializer.py [0:0]


    def dumps(self, data: Any) -> bytes:
        # The body is already encoded to bytes
        # so we forward the request body along.
        if isinstance(data, str):
            return data.encode("utf-8", "surrogatepass")
        elif isinstance(data, bytes):
            return data

        try:
            return self.json_dumps(data)
        # This should be captured by the .default()
        # call but just in case we also wrap these.
        except (ValueError, UnicodeError, TypeError) as e:  # pragma: nocover
            raise SerializationError(
                message=f"Unable to serialize to JSON: {data!r} (type: {type(data).__name__})",
                errors=(e,),
            )