def METHOD_NAME(s):
    # output for xml without a declared encoding
    # As the output is xml, we have to encode chars (< and > are ok as they're not accepted in the filesystem name --
    # if it was allowed, we'd have to do things more selectively so that < and > don't get wrongly replaced).
    s = s.replace("&", "&amp;")
    try:
        ret = s.encode('ascii', 'xmlcharrefreplace')
    except:
        # use workaround
        ret = ''
        for c in s:
            try:
                ret += c.encode('ascii')
            except:
                try:
                    # Python 2: unicode is a valid identifier
                    ret += unicode("&#%d;") % ord(c)
                except:
                    # Python 3: a string is already unicode, so, just doing it directly should work.
                    ret += "&#%d;" % ord(c)
    return ret