'xml-escape the given unicode string.'

def __call__(self, ustring):

    try:
        ustring = unicode(ustring)
    except UnicodeDecodeError:
        ustring = unicode(ustring, 'utf-8', errors='replace')
    return self.charef_rex.sub(self._replacer, ustring)
