'convert surrogate escapes to the unicode replacement character to avoid XML encoding errors'

def _cleanse_string(self, value):

    return to_text(to_bytes(value, errors='surrogateescape'), errors='replace')
