Index: Lib/test/test_pyexpat.py =================================================================== --- Lib/test/test_pyexpat.py (revision 75293) +++ Lib/test/test_pyexpat.py (working copy) @@ -218,7 +218,21 @@ self.assertEquals(op[15], "External entity ref: (None, u'entity.file', None)") self.assertEquals(op[16], "End element: u'root'") + def test_parse_again(self): + parser = expat.ParserCreate() + file = StringIO.StringIO(data) + parser.ParseFile(file) + ctx = self.assertRaises(expat.error) + with ctx: + parser.ParseFile(file) + # It would be natural for XML_ERROR_FINISHED to be an integer, + # but now it's a string. + # Use pyexpat.ErrorString() to compare with error code. + self.assertEquals(pyexpat.ErrorString(ctx.exc_value.code), + pyexpat.errors.XML_ERROR_FINISHED) + + class NamespaceSeparatorTest(unittest.TestCase): def test_legal(self): # Tests that make sure we get errors when the namespace_separator value Index: Modules/pyexpat.c =================================================================== --- Modules/pyexpat.c (revision 75293) +++ 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) {