[Erp5-report] r39077 kazuhiko - /erp5/trunk/products/PortalTransforms/transforms/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Oct 12 22:43:41 CEST 2010


Author: kazuhiko
Date: Tue Oct 12 22:43:40 2010
New Revision: 39077

URL: http://svn.erp5.org?rev=39077&view=rev
Log:
rewrite xml_to_text transform using lxml, so as to support other encoding than utf-8.

Modified:
    erp5/trunk/products/PortalTransforms/transforms/xml_to_text.py

Modified: erp5/trunk/products/PortalTransforms/transforms/xml_to_text.py
URL: http://svn.erp5.org/erp5/trunk/products/PortalTransforms/transforms/xml_to_text.py?rev=39077&r1=39076&r2=39077&view=diff
==============================================================================
--- erp5/trunk/products/PortalTransforms/transforms/xml_to_text.py [utf8] (original)
+++ erp5/trunk/products/PortalTransforms/transforms/xml_to_text.py [utf8] Tue Oct 12 22:43:40 2010
@@ -1,10 +1,21 @@
-from Products.PortalTransforms.libtransforms.retransform import retransform
+from Products.PortalTransforms.interfaces import itransform
+from zope.interface import implements
+from lxml import etree
 
-class xml_to_text(retransform):
+class xml_to_text:
+    implements(itransform)
+
+    __name__ = 'xml_to_text'
     inputs  = ('text/xml', 'application/xml')
     output = 'text/plain'
 
+    def name(self):
+        return self.__name__
+
+    def convert(self, data, cache, **kw):
+        out = ''.join(etree.fromstring(data).itertext()).encode('utf-8')
+        cache.setData(out)
+        return cache
+
 def register():
-    return xml_to_text("xml_to_text",
-                       ('<[^>]*>', ' '),
-                       )
+    return xml_to_text()




More information about the Erp5-report mailing list