Re: [lxml-dev] redundant namespace declarations
Hi, On Mon, Dec 04, 2006 at 06:44:28PM +0100, Stefan Behnel wrote:
Well, maybe that won't be that soon. It's currently undecided if this will be in the next release, so it will stay out of the trunk for now.
No problem. I've adapted the code responsible for building the element tree to use SubElement instead of append, so that "pretty_print = True" does what I want. A minor problem remains, but I have a workaround for this. If you try to write the document to a file without write access, "write_c14n" raises a C14NError:
from lxml.etree import * et = ElementTree(Element("abc")) et.write_c14n("nonwritable.xml") et.write_c14n("notwritable.xml") Traceback (most recent call last): File "<stdin>", line 1, in ? File "etree.pyx", line 657, in etree._ElementTree.write_c14n File "serializer.pxi", line 224, in etree._tofilelikeC14N etree.C14NError: C14N failed
But if you use "write" instead, lxml silently ignores the fact that the file can't be written:
et.write("notwritable.xml")
For now, I'm just writing to a StringIO buffer and open the file manually, so this is no serious problem for me. But others might well be bitten by this bug, even more so since lxml does not give any feedback about what just happened. Best regards, Albert Brandl
Hi Albert, Albert Brandl wrote:
If you try to write the document to a file without write access, lxml silently ignores the fact that the file can't be written:
.>>> et.write("notwritable.xml") .>>>
True, thanks for the report. Opening the file is done by libxml2 in this case and we did not handle the case where it failed to do so. Fixed on the trunk. Stefan
participants (2)
-
Albert Brandl
-
Stefan Behnel