import six


def ensure_binary(s):
    """
    >>> ensure_binary(b"test")
    b'test'
    >>> ensure_binary(u"test")
    b'test'
    """
    if not isinstance(s, six.binary_type):
        s = s.encode('utf-8')
    return s