def ensure_unicode(str_or_unicode):
    """
    tests, if the input is ``str`` or ``unicode``. if it is ``str``, it
    will be decoded from ``UTF-8`` to unicode.
    """
    if isinstance(str_or_unicode, str):
        return str_or_unicode.decode('utf-8')
    elif isinstance(str_or_unicode, unicode):
        return str_or_unicode
    else:
        raise ValueError("Input '{0}' should be a string or unicode, "
                         "but its of type {1}".format(str_or_unicode,
                                                      type(str_or_unicode)))
def ensure_unicode ( str_or_unicode ) : if isinstance ( str_or_unicode , str ) : return str_or_unicode . decode ( 'utf-8' ) elif isinstance ( str_or_unicode , unicode ) : return str_or_unicode else : raise ValueError ( "Input '{0}' should be a string or unicode, " "but its of type {1}" . format ( str_or_unicode , type ( str_or_unicode ) ) )
tests, if the input is ``str`` or ``unicode``. if it is ``str``, it
    will be decoded from ``UTF-8`` to unicode.