with self.assertRaises(LookupError):
parser.Parse(data, True)
+ @support.subTests('sample,exception', [
+ (b'<x> \xa1</x>', UnicodeDecodeError), # crashed
+ (b'<x> \xa1</x', UnicodeDecodeError), # crashed
+ (b'<x> \xa1', expat.ExpatError),
+ ])
+ def test_multibyte_encoding_errors(self, sample, exception):
+ parser = expat.ParserCreate()
+ data = b'<?xml version="1.0" encoding="EUC-JP"?>\n' + sample
+ with self.assertRaises(exception):
+ parser.Parse(data, True)
class NamespaceSeparatorTest(unittest.TestCase):
def test_legal(self):
self.assertRaises(ValueError, ET.XML, xml('undefined').encode('ascii'))
self.assertRaises(LookupError, ET.XML, xml('xxx').encode('ascii'))
+ @support.subTests('sample,exception', [
+ (b'<x> \xa1</x>', UnicodeDecodeError), # crashed
+ (b'<x> \xa1</x', UnicodeDecodeError), # crashed
+ (b'<x> \xa1', None), # ET.ParseError
+ ])
+ def test_multibyte_encoding_errors(self, sample, exception):
+ exception = exception or ET.ParseError
+ data = b'<?xml version="1.0" encoding="EUC-JP"?>\n' + sample
+ with self.assertRaises(exception):
+ ET.XML(data)
+
def test_methods(self):
# Test serialization methods.
static int
pyexpat_encoding_convert(void *data, const char *s)
{
+ if (PyErr_Occurred()) {
+ return -1;
+ }
pyexpat_encoding_info *info = (pyexpat_encoding_info *)data;
int i = (unsigned char)s[0];
assert(info->map[i] < -1);