This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Patch cElementTree to export CurrentLineNumber
Type: enhancement Stage: resolved
Components: XML Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder: Update ElementTree with upstream changes
View: 6472
Assigned To: effbot Nosy List: effbot, flox, georg.brandl, nnorwitz, robinbryce, robinbryce2
Priority: normal Keywords: patch

Created on 2006-08-11 13:27 by robinbryce2, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch_against_51208.diff robinbryce2, 2006-08-11 13:27 [PATCH] pyexpat.c, _elementtree.c & test_xml_etree_c.py
Messages (6)
msg50868 - (view) Author: Robin Bryce (robinbryce2) Date: 2006-08-11 13:27
This patch provides to the 'current' position expat api
via cElementTree.XMLTreeBuilder.

pyexpat already exposes this via the attributes
CurrentLineNumber, CurrentColumnNumber and
CurrentByteIndex. In order for cElementTree to do the
same, the following expat functions are added to those
exported via the pyexpat capi:
 * XML_CurrentLineNumber
 * XML_CurrentColumnNumber
 * XML_CurrentByteIndex

Then, in _elementtree.c, the xmlparser_getattr is made
to mirror the provisions made in pyexpat. A trivial
test is added to test_etree_c.py to cover the three new
attributes.

This patch was motivated by a discussion[1] on the
turbogears list that referenced two xml templating
libraries Kid & Markup. One of the benefits of the
latter is the ability to report line numbers for
template source errors.

If this patch is applied it should be possible for Kid,
and anything else that uses cElementTree for
xmlparsing, to do the same.

[1]
http://groups.google.com/group/turbogears/browse_frm/thread/1ed59ed984fc8bbe/1f06eb00e83f93d9#1f06eb00e83f93d9
msg50869 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-08-11 23:56
Logged In: YES 
user_id=33168

Fredrik, do you want etree patches here?
msg85282 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2009-04-03 00:00
In the upstream 1.0.6, the ParseError exception has a position attribute
that contains a (line, column) tuple.
msg85482 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-05 11:18
Which will be synced into core at some point, I guess?
msg86120 - (view) Author: Robin Bryce (robinbryce) Date: 2009-04-18 15:10
> In the upstream 1.0.6, the ParseError exception has a position attribute
> that contains a (line, column) tuple.

That's fine for errors in the xml domain. Its not enough if I'm
reporting errors in the application domain - where I wont have a handy
exception to interrogate. What's the problem with just exposing the api
and requiring users who need it to use the streaming parser ?

Personally, I would have cached these details as a properties of the
_ElementInterface implementation for precisely this use case.
msg100859 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-03-11 14:49
ElementTree fixed in 2.7. See #6472.
History
Date User Action Args
2022-04-11 14:56:19adminsetgithub: 43808
2010-03-11 14:49:26floxsetstatus: open -> closed
superseder: Update ElementTree with upstream changes
messages: + msg100859

dependencies: - Update ElementTree with upstream changes
resolution: postponed -> fixed
stage: patch review -> resolved
2010-02-13 16:05:16floxsetnosy: + flox
2010-02-13 16:01:18floxsetdependencies: + Update ElementTree with upstream changes
versions: + Python 3.2, - Python 3.1
2009-04-18 15:10:55robinbrycesetstatus: pending -> open
nosy: + robinbryce
messages: + msg86120

2009-04-05 11:18:31georg.brandlsetstatus: open -> pending

nosy: + georg.brandl
messages: + msg85482

resolution: postponed
2009-04-03 00:00:51effbotsetmessages: + msg85282
2009-03-30 03:51:52ajaksu2setstage: patch review
type: enhancement
components: + XML, - None
versions: + Python 3.1, Python 2.7
2006-08-11 13:27:12robinbryce2create