
Burak Arslan schrieb am 16.09.2014 um 10:29:
you were not supposed to merge this patch so soon :)
It looked ok, though. :)
On 09/15/14 15:21, Stefan Behnel wrote:
I also noticed that html.tostring doesn't suppress namespaces, but my
patch does. Should I alter that behaviour?
I was referring to the xf.element() calls (sorry). If people write out subtrees as HTML that use namespaces somewhere, I think they're pretty much on their own.
However, I think it should be an error if you try that directly with xf.element() in HTML mode.
with etree.htmlfile(self._file) as xf: xf.write(etree.Element('{some_ns}some_tag'))
doesnt suppress namespaces
with etree.htmlfile(self._file) as xf: with xf.element("{some_ns}some_tag"): pass
does suppress namespaces. this is inconsistent
True.
and needs to be fixed.
Hmm, does it? What about this case:
plain_p = etree.Element('p') etree.SubElement(plain_p, '{some_ns}some_tag')
with etree.htmlfile(self._file) as xf: xf.write(plain_p)
Namespaces can be used at any place when writing out subtrees. I wouldn't want to validate the entire tree before writing it out.
see: https://github.com/plq/lxml/commit/378408d2b6e94a4c91410fc7bde5bba055f54785
You have three options:
- silently filter namespaces out
- throwing an exception when using html serialization with namespaced
elements 3) let namespaces pass
I'd choose 1 to make the lives of people who generate xhtml and html with the same code easier.
ISTM that 3) is the simpler and more obvious option, i.e. let libxml2 handle it.
1) would require running through the entire subtree, and if we find (XHTML) namespaces, make a copy of the subtree, remove the namespaces from the copy, and serialise it. That sounds like more than we should impose on users behind their back.
Stefan