def decode(text):
    """ Converts an arbitrary string to byte string in UTF-8. On failure
    returns the given string.

    @param text: string to be converted
    @type text: string
    """
    if type(text) is str:
        return text.encode('utf-8')
    encoding_lst = [('iso-8859-15',), ('utf-8',), ('latin-1',), ('utf-8',
        'replace')]
    for encoding in encoding_lst:
        try:
            return text.decode(*encoding).encode('utf-8')
        except:
            return text
