More options for XML canonicalization in write_c14n
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Wishlist
|
Unassigned |
Bug Description
XML Canonicalization (C14N) is useful in some cases such as digital signature. lxml provides a very easy way to do it in Python. However, the current version lxml 2.1 does not give access to all C14N parameters. This is a simple patch to improve its C14N support.
Here is an example showing how to perform C14N using lxml 2.1:
import lxml.etree as ET
et = ET.parse(
output = StringIO.StringIO()
et.write_
print output.getvalue()
XML C14N version 1.0 provides two options which make four possibilities (see http://
- Inclusive or Exclusive C14N
- With or without comments
libxml2 gives access to these options in its C14N API: http://
However, the options are not exposed in the lxml write_c14n method. Current versions of lxml provide only inclusive C14N with comments, which may not always be the right solution.
It is possible to fix that limitation by changing a few lines in lxml source code, and recompiling it.
Attached are patched versions of lxml.etree.pyx and serializer.pxi, based on the latest SVN version.
Here is how to use this patched version:
import lxml.etree as ET
et = ET.parse(
output = StringIO.StringIO()
et.write_
print output.getvalue()
As the default values are the same as in lxml 2.1, this patch should not have any impact on current code using lxml.
For more info, see http://
Changed in lxml: | |
importance: | Undecided → Wishlist |
status: | New → Fix Committed |
Changed in lxml: | |
status: | Fix Committed → Fix Released |
Changed in lxml: | |
milestone: | none → 2.2 |
Thanks for the changes, they will be in lxml 2.2.
It's common to send patches, though. If you are using SVN anyway, "svn diff"
will do the right thing.