<div>There appears to be a bug with lxml.sax&#39;s handling of comments, as the following code causes lxml.sax.saxify to fail:</div><div><br class="khtml-block-placeholder"></div><div>&quot;&quot;&quot;</div><div>import lxml.etree
, lxml.sax, xml.sax.handler</div><div>from cStringIO import StringIO</div><div><br class="khtml-block-placeholder"></div><div>p = lxml.etree.HTMLParser(remove_blank_text=True)</div><div>h = xml.sax.handler.ContentHandler()
</div><div>f = StringIO(&quot;&lt;body&gt;&lt;!-- foo --&gt;&lt;p&gt;bar&lt;/p&gt;&lt;/body&gt;&quot;)</div><div>t = lxml.etree.parse(f, p)</div><div>lxml.sax.saxify(t, h)</div><div>&quot;&quot;&quot;</div><div><br class="khtml-block-placeholder">
</div><div>&quot;&quot;&quot;</div><div>Traceback (most recent call last):</div><div>&nbsp; File &quot;saxBug.py&quot;, line 11, in &lt;module&gt;</div><div>&nbsp; &nbsp; lxml.sax.saxify(t, h)</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/lxml-
1.3beta-py2.5-macosx-10.4-i386.egg/lxml/sax.py&quot;, line 178, in saxify</div><div>&nbsp; &nbsp; return ElementTreeProducer(element_or_tree, content_handler).saxify()</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/lxml-
1.3beta-py2.5-macosx-10.4-i386.egg/lxml/sax.py&quot;, line 130, in saxify</div><div>&nbsp; &nbsp; self._recursive_saxify(self._element, {})</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/lxml-
1.3beta-py2.5-macosx-10.4-i386.egg/lxml/sax.py&quot;, line 160, in _recursive_saxify</div><div>&nbsp; &nbsp; self._recursive_saxify(child, prefixes)</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/lxml-
1.3beta-py2.5-macosx-10.4-i386.egg/lxml/sax.py&quot;, line 160, in _recursive_saxify</div><div>&nbsp; &nbsp; self._recursive_saxify(child, prefixes)</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/lxml-
1.3beta-py2.5-macosx-10.4-i386.egg/lxml/sax.py&quot;, line 149, in _recursive_saxify</div><div>&nbsp; &nbsp; ns_uri, local_name = _getNsTag(element.tag)</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/lxml-
1.3beta-py2.5-macosx-10.4-i386.egg/lxml/sax.py&quot;, line 8, in _getNsTag</div><div>&nbsp; &nbsp; if tag[0] == &#39;{&#39;:</div><div>TypeError: &#39;builtin_function_or_method&#39; object is unsubscriptable</div><div>&quot;&quot;&quot;
</div><div><br class="khtml-block-placeholder"></div><div>I have been able to replicate the above error with both release and svn lxml, as well as with both Apple-supplied libxml2/libxslt and up-to-date libraries.</div><div>
<br class="khtml-block-placeholder"></div><div>Also, and I doubt this is related, but `make test` fails for me on OS X 10.4.9 with MacPython 2.5.1 (<a href="http://python.org">python.org</a> binary):</div><div><br class="khtml-block-placeholder">
</div><div>&quot;&quot;&quot;</div><div>python test.py -p -v&nbsp;</div><div><br class="khtml-block-placeholder"></div><div>TESTED VERSION:</div><div>&nbsp; &nbsp; Python:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (2, 5, 1, &#39;final&#39;, 0)</div><div>&nbsp; &nbsp; lxml.etree
:&nbsp; &nbsp; &nbsp; &nbsp; (1, 3, -1, 42667)</div><div>&nbsp; &nbsp; libxml used: &nbsp; &nbsp; &nbsp; (2, 6, 28)</div><div>&nbsp; &nbsp; libxml compiled: &nbsp; (2, 6, 28)</div><div>&nbsp; &nbsp; libxslt used:&nbsp; &nbsp; &nbsp; (1, 1, 20)</div><div>&nbsp; &nbsp; libxslt compiled:&nbsp; (1, 1, 20)</div><div><br class="khtml-block-placeholder">
</div><div>&nbsp;733/733 (100.0%): Doctest: xpathxslt.txt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>======================================================================</div><div>FAIL: test_module_HTML_unicode (
lxml.tests.test_htmlparser.HtmlParserTestCaseBase)</div><div>----------------------------------------------------------------------</div><div>Traceback (most recent call last):</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/unittest.py&quot;, line 260, in run
</div><div>&nbsp; &nbsp; testMethod()</div><div>&nbsp; File &quot;/Users/erik/Projects/lxml/src/lxml/tests/test_htmlparser.py&quot;, line 33, in test_module_HTML_unicode</div><div>&nbsp; &nbsp; self.uhtml_str)</div><div>&nbsp; File &quot;/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/unittest.py&quot;, line 334, in failUnlessEqual
</div><div>&nbsp; &nbsp; (msg or &#39;%r != %r&#39; % (first, second))</div><div>AssertionError: u&#39;&lt;html&gt;&lt;head&gt;&lt;title&gt;test \xc3\x83\xc2\xa1\xef\xa3\x92&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;page \xc3\x83\xc2\xa1\xef\xa3\x92 title&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;&#39; != u&#39;&lt;html&gt;&lt;head&gt;&lt;title&gt;test \xc3\xa1\uf8d2&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;page \xc3\xa1\uf8d2 title&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;&#39;
</div><div><br class="khtml-block-placeholder"></div><div>----------------------------------------------------------------------</div><div>Ran 733 tests in 1.380s</div><div><br class="khtml-block-placeholder"></div><div>FAILED (failures=1)
</div><div>&quot;&quot;&quot;</div><br>-- <br>Erik Swanson