import six


def ensure_unicode(val):
    """Ensure that a a given value is a unicode string.

    If ``val`` is a :py:data:`six.binary_type <binary type>`, assume it's UTF-8
    and decode it.
    :param val: A :py:data:`six.binary_type <binary>` or
        :py:data:`six.text_type <text>` type.
    :rtype: :py:class:`unicode` on Python 2, :py:class:`str` on Python 3
    """
    if isinstance(val, six.binary_type):
        return val.decode('utf-8')
    return val