[Erp5-report] r25066 - /erp5/trunk/products/ERP5OOo/OOoUtils.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Jan 8 18:50:59 CET 2009
Author: nicolas
Date: Thu Jan 8 18:50:55 2009
New Revision: 25066
URL: http://svn.erp5.org?rev=25066&view=rev
Log:
replace libxml2 by etree
Modified:
erp5/trunk/products/ERP5OOo/OOoUtils.py
Modified: erp5/trunk/products/ERP5OOo/OOoUtils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/OOoUtils.py?rev=25066&r1=25065&r2=25066&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/OOoUtils.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/OOoUtils.py [utf8] Thu Jan 8 18:50:55 2009
@@ -151,24 +151,28 @@
content_xml = self.extract(ooo_xml_file_id)
output = StringIO()
try:
- import libxml2
- import libxslt
+ from lxml import etree
+ from lxml.etree import Element, SubElement
+ from copy import deepcopy
if xsl_content is None:
raise ImportError
- stylesheet_doc = libxml2.parseDoc(xsl_content)
- stylesheet = libxslt.parseStylesheetDoc(stylesheet_doc)
- content_doc = libxml2.parseDoc(content_xml)
- result_doc = stylesheet.applyStylesheet(content_doc, None)
+ stylesheet_doc = etree.XML(xsl_content)
+ stylesheet = etree.XSLT(stylesheet_doc)
+ content_doc = etree.XML(content_xml)
+ result_doc = stylesheet(content_doc)
+ root = result_doc.getroot()
#Declare zope namespaces
- root = result_doc.getRootElement()
- tal = root.newNs('http://xml.zope.org/namespaces/tal', 'tal')
- i18n = root.newNs('http://xml.zope.org/namespaces/i18n', 'i18n')
- metal = root.newNs('http://xml.zope.org/namespaces/metal', 'metal')
- root.setNsProp(tal, 'attributes', 'dummy python:request.RESPONSE.setHeader(\'Content-Type\', \'text/html;; charset=utf-8\')')
- buff = libxml2.createOutputBuffer(output, 'utf-8')
- result_doc.saveFormatFileTo(buff, 'utf-8', 1)
- stylesheet_doc.freeDoc(); content_doc.freeDoc(); result_doc.freeDoc()
- return output.getvalue()
+ NSMAP = {'tal': 'http://xml.zope.org/namespaces/tal',
+ 'i18n': 'http://xml.zope.org/namespaces/i18n',
+ 'metal': 'http://xml.zope.org/namespaces/metal'}
+ NSMAP.update(root.nsmap)
+ new_root = Element(root.tag, nsmap=NSMAP)
+ new_root.attrib.update(dict(root.attrib))
+ new_root.attrib.update({'{%s}attributes' % NSMAP.get('tal'): 'dummy python:request.RESPONSE.setHeader(\'Content-Type\', \'text/html;; charset=utf-8\')'})
+ for child in root.getchildren():
+ new_root.append(deepcopy(child))
+ return etree.tostring(new_root, encoding='utf-8', xml_declaration=True,
+ pretty_print=True)
except ImportError:
document = Parse(content_xml)
document_element = document.documentElement
More information about the Erp5-report
mailing list