Index: Lib/test/test_pyexpat.py =================================================================== --- Lib/test/test_pyexpat.py (revision 75281) +++ Lib/test/test_pyexpat.py (working copy) @@ -218,6 +218,17 @@ self.assertEquals(op[15], "External entity ref: (None, u'entity.file', None)") self.assertEquals(op[16], "End element: u'root'") + # Issue 6676 + try: + parser.ParseFile(file) + except: + exc, err = sys.exc_info()[:2] + self.assertTrue(lambda: issubclass(exc, expat.error)) + # It would be natural that errors.XML_ERROR_FINISHED is integer not string, but + # now it's string. Use pyexpat.ErrorString() to compare with error code. + self.assertEquals(pyexpat.ErrorString(err.code), pyexpat.errors.XML_ERROR_FINISHED) + else: + self.fail("expected exception") class NamespaceSeparatorTest(unittest.TestCase): def test_legal(self): Index: Modules/pyexpat.c =================================================================== --- Modules/pyexpat.c (revision 75281) +++ Modules/pyexpat.c (working copy) @@ -980,7 +980,7 @@ void *buf = XML_GetBuffer(self->itself, BUF_SIZE); if (buf == NULL) { Py_XDECREF(readmethod); - return PyErr_NoMemory(); + return get_parse_result(self, 0); } if (fp) {