'Encode data.
Serialize a data structure into a string suitable for sending
as an AMQP message body.
Arguments:
data (List, Dict, str): The message data to send.
serializer (str): An optional string representing
the serialization method you want the data marshalled
into. (For example, `json`, `raw`, or `pickle`).
If :const:`None` (default), then json will be used, unless
`data` is a :class:`str` or :class:`unicode` object. In this
latter case, no serialization occurs as it would be
unnecessary.
Note that if `serializer` is specified, then that
serialization method will be used even if a :class:`str`
or :class:`unicode` object is passed in.
Returns:
Tuple[str, str, str]: A three-item tuple containing the
content type (e.g., `application/json`), content encoding, (e.g.,
`utf-8`) and a string containing the serialized data.
Raises:
SerializerNotInstalled: If the serialization method
requested is not available.'

def dumps(self, data, serializer=None):

    if (serializer == u'raw'):
        return raw_encode(data)
    if (serializer and (not self._encoders.get(serializer))):
        raise SerializerNotInstalled(u'No    encoder    installed    for    {0}'.format(serializer))
    if ((not serializer) and isinstance(data, bytes_t)):
        return (u'application/data', u'binary', data)
    if ((not serializer) and isinstance(data, text_t)):
        with _reraise_errors(EncodeError, exclude=()):
            payload = data.encode(u'utf-8')
        return (u'text/plain', u'utf-8', payload)
    if serializer:
        (content_type, content_encoding, encoder) = self._encoders[serializer]
    else:
        encoder = self._default_encode
        content_type = self._default_content_type
        content_encoding = self._default_content_encoding
    with _reraise_errors(EncodeError):
        payload = encoder(data)
    return (content_type, content_encoding, payload)
