def testRemoveInvalidControlCharactersWorksOnNonUnicodeStrings( self ): handler = xml.sax.handler.ContentHandler() for char in xml_tools.INVALID_CONTROL_CHARACTERS: xmlStr = "<test>%s</test>" % chr( char ) xmlStr = xml_tools.remove_invalid_control_chars( xmlStr ) self.assertEquals( xmlStr, "<test></test>" ) xml.sax.parseString( xmlStr, handler )
def testRemoveInvalidControlCharactersWorksOnUnicodeStrings( self ): handler = xml.sax.handler.ContentHandler() for char in xml_tools.INVALID_CONTROL_CHARACTERS: xmlStr = u"<test>%s\u2026</test>" % chr( char ) xmlStr = xml_tools.remove_invalid_control_chars( xmlStr ) self.assertEquals( xmlStr, u"<test>\u2026</test>" ) xmlStr = xmlStr.encode( "ascii", "xmlcharrefreplace" ) xml.sax.parseString( xmlStr, handler )