import six
import base64


def b64_encode(s):
    """Encode s as base64 using :func:`base64.b64encode`.

    Args:
        s (:obj:`str`):
            Text to base64 encode.

    Returns:
        :obj:`str`

    """
    s = format("" if s is None else s) if not isinstance(s, six.string_types) else s
    s = six.ensure_binary(s)
    s = base64.b64encode(s)
    return six.ensure_str(s)