import six
import base64


def nice64(src):
    """
    Returns src base64-encoded and formatted nicely for our XML,
    as Unicode.
    """
    # If src is a Unicode string, we encode it as UTF8.
    if isinstance(src, six.text_type):
        src = src.encode('utf8')
    return base64.b64encode(src).decode('utf8').replace('\n', '')