[Python-checkins] cpython (merge 3.4 -> default): Issue #6676: merge from 3.4
ned.deily
python-checkins at python.org
Fri Mar 28 00:44:40 CET 2014
http://hg.python.org/cpython/rev/ee0034434e65
changeset: 90004:ee0034434e65
parent: 90000:35302cc4fc93
parent: 90003:9e3fc66ee0b8
user: Ned Deily <nad at acm.org>
date: Thu Mar 27 16:44:06 2014 -0700
summary:
Issue #6676: merge from 3.4
files:
Doc/library/pyexpat.rst | 9 ++++++++-
Lib/test/test_pyexpat.py | 12 ++++++++++++
Misc/NEWS | 5 +++++
Modules/pyexpat.c | 2 +-
4 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/Doc/library/pyexpat.rst b/Doc/library/pyexpat.rst
--- a/Doc/library/pyexpat.rst
+++ b/Doc/library/pyexpat.rst
@@ -100,6 +100,11 @@
http://www.python.org/ns/ elem1
elem2
+ Due to limitations in the ``Expat`` library used by :mod:`pyexpat`,
+ the :class:`xmlparser` instance returned can only be used to parse a single
+ XML document. Call ``ParserCreate`` for each document to provide unique
+ parser instances.
+
.. seealso::
@@ -119,7 +124,9 @@
Parses the contents of the string *data*, calling the appropriate handler
functions to process the parsed data. *isfinal* must be true on the final call
- to this method. *data* can be the empty string at any time.
+ to this method; it allows the parsing of a single file in fragments,
+ not the submission of multiple files.
+ *data* can be the empty string at any time.
.. method:: xmlparser.ParseFile(file)
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py
--- a/Lib/test/test_pyexpat.py
+++ b/Lib/test/test_pyexpat.py
@@ -236,6 +236,18 @@
operations = out.out
self._verify_parse_output(operations)
+ def test_parse_again(self):
+ parser = expat.ParserCreate()
+ file = BytesIO(data)
+ parser.ParseFile(file)
+ # Issue 6676: ensure a meaningful exception is raised when attempting
+ # to parse more than one XML document per xmlparser instance,
+ # a limitation of the Expat library.
+ with self.assertRaises(expat.error) as cm:
+ parser.ParseFile(file)
+ self.assertEqual(expat.ErrorString(cm.exception.code),
+ expat.errors.XML_ERROR_FINISHED)
+
class NamespaceSeparatorTest(unittest.TestCase):
def test_legal(self):
# Tests that make sure we get errors when the namespace_separator value
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -119,6 +119,11 @@
- Issue #20817: Fix inspect.getcallargs() to fail correctly if more
than 3 arguments are missing. Patch by Jeremiah Lowin.
+- Issue #6676: Ensure a meaningful exception is raised when attempting
+ to parse more than one XML document per pyexpat xmlparser instance.
+ (Original patches by Hirokazu Yamamoto and Amaury Forgeot d'Arc, with
+ suggested wording by David Gutteridge)
+
Documentation
-------------
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -908,7 +908,7 @@
void *buf = XML_GetBuffer(self->itself, BUF_SIZE);
if (buf == NULL) {
Py_XDECREF(readmethod);
- return PyErr_NoMemory();
+ return get_parse_result(self, 0);
}
bytes_read = readinst(buf, BUF_SIZE, readmethod);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list