Convert to unicode, raise exception with instructive error
    message if s is not unicode, ascii, or utf-8.

def to_unicode(s):
    """ Convert to unicode, raise exception with instructive error
    message if s is not unicode, ascii, or utf-8. """
    if not isinstance(s, TEXT):
        if not isinstance(s, bytes):
            raise TypeError('You are required to pass either unicode or '
                            'bytes here, not: %r (%s)' % (type(s), s))
        try:
            s = s.decode('utf-8')
        except UnicodeDecodeError as le:
            raise TypeError('You are required to pass either a unicode '
                            'object or a utf-8-encoded bytes string here. '
                            'You passed a bytes object which contained '
                            'non-utf-8: %r. The UnicodeDecodeError that '
                            'resulted from attempting to interpret it as '
                            'utf-8 was: %s'
                            % (s, le,))
    return s