[Zope3-checkins] SVN: Zope3/trunk/src/zope/tal/ Added position
(line, column) information to TALParser.
Marius Gedminas
marius at pov.lt
Fri Jun 11 11:14:27 EDT 2004
Log message for revision 25352:
Added position (line, column) information to TALParser.
-=-
Modified: Zope3/trunk/src/zope/tal/talparser.py
===================================================================
--- Zope3/trunk/src/zope/tal/talparser.py 2004-06-11 15:11:07 UTC (rev 25351)
+++ Zope3/trunk/src/zope/tal/talparser.py 2004-06-11 15:14:27 UTC (rev 25352)
@@ -62,7 +62,8 @@
name, attrlist, taldict, metaldict, i18ndict \
= self.process_ns(name, attrlist)
attrlist = self.xmlnsattrs() + attrlist
- self.gen.emitStartElement(name, attrlist, taldict, metaldict, i18ndict)
+ self.gen.emitStartElement(name, attrlist, taldict, metaldict, i18ndict,
+ self.getpos())
def process_ns(self, name, attrlist):
taldict = {}
@@ -122,7 +123,7 @@
def EndElementHandler(self, name):
name = self.fixname(name)[0]
- self.gen.emitEndElement(name)
+ self.gen.emitEndElement(name, position=self.getpos())
def DefaultHandler(self, text):
self.gen.emitRawText(text)
Added: Zope3/trunk/src/zope/tal/tests/input/test_sa3.xml
===================================================================
--- Zope3/trunk/src/zope/tal/tests/input/test_sa3.xml 2004-06-11 15:11:07 UTC (rev 25351)
+++ Zope3/trunk/src/zope/tal/tests/input/test_sa3.xml 2004-06-11 15:14:27 UTC (rev 25352)
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<html>
+<body xmlns:metal="http://xml.zope.org/namespaces/metal">
+ <div metal:define-macro="macro1">This is macro1 on sa3 line 4.
+ <span metal:define-slot="slot1">This is slot1 on sa3 line 5.</span>
+ This is the end of macro1 on sa3 line 6.
+ </div>
+ <p>Some text on sa3 line 8.</p>
+ <p metal:use-macro="macro1">
+ This text on sa3 line 10 will disappear.
+ <b metal:fill-slot="slot1">Text from sa3 line 11 is filled into slot1.</b>
+ This text on sa3 line 12 will disappear.
+ </p>
+ <p>This is some text on sa3 line 14.</p>
+</body>
+</html>
Property changes on: Zope3/trunk/src/zope/tal/tests/input/test_sa3.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/trunk/src/zope/tal/tests/output/test_sa3.xml
===================================================================
--- Zope3/trunk/src/zope/tal/tests/output/test_sa3.xml 2004-06-11 15:11:07 UTC (rev 25351)
+++ Zope3/trunk/src/zope/tal/tests/output/test_sa3.xml 2004-06-11 15:14:27 UTC (rev 25352)
@@ -0,0 +1,43 @@
+<?xml version="1.0" ?><!--
+==============================================================================
+tests/input/test_sa3.xml
+==============================================================================
+-->
+<html>
+<body>
+ <!--
+==============================================================================
+tests/input/test_sa3.xml (line 4)
+==============================================================================
+--><div>This is macro1 on sa3 line 4.
+ <span>This is slot1 on sa3 line 5.</span><!--
+==============================================================================
+tests/input/test_sa3.xml (line 5)
+==============================================================================
+-->
+ This is the end of macro1 on sa3 line 6.
+ </div>
+ <p>Some text on sa3 line 8.</p>
+ <!--
+==============================================================================
+tests/input/test_sa3.xml (line 4)
+==============================================================================
+--><div>This is macro1 on sa3 line 4.
+ <!--
+==============================================================================
+tests/input/test_sa3.xml (line 11)
+==============================================================================
+--><b>Text from sa3 line 11 is filled into slot1.</b><!--
+==============================================================================
+tests/input/test_sa3.xml (line 5)
+==============================================================================
+-->
+ This is the end of macro1 on sa3 line 6.
+ </div><!--
+==============================================================================
+tests/input/test_sa3.xml (line 13)
+==============================================================================
+-->
+ <p>This is some text on sa3 line 14.</p>
+</body>
+</html>
Property changes on: Zope3/trunk/src/zope/tal/tests/output/test_sa3.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/tal/xmlparser.py
===================================================================
--- Zope3/trunk/src/zope/tal/xmlparser.py 2004-06-11 15:11:07 UTC (rev 25351)
+++ Zope3/trunk/src/zope/tal/xmlparser.py 2004-06-11 15:14:27 UTC (rev 25352)
@@ -84,3 +84,16 @@
def parseFragment(self, s, end=0):
self.parser.Parse(s, end)
+
+ def getpos(self):
+ # Apparently ErrorLineNumber and ErrorLineNumber contain the current
+ # position even when there was no error. This contradicts the official
+ # documentation[1], but expat.h[2] contains the following definition:
+ #
+ # /* For backwards compatibility with previous versions. */
+ # #define XML_GetErrorLineNumber XML_GetCurrentLineNumber
+ #
+ # [1] http://python.org/doc/current/lib/xmlparser-objects.html
+ # [2] http://cvs.sourceforge.net/viewcvs.py/expat/expat/lib/expat.h
+ return (self.parser.ErrorLineNumber, self.parser.ErrorColumnNumber)
+
More information about the Zope3-Checkins
mailing list