# HG changeset patch
# User souliane <souliane@mailoo.org>
# Date 1394838949 -3600
# Node ID cad8e52bb2e617ea17d556d8a21012b6e858523a
# Parent  95dabdb0c79903e70cc0345f68cfcb307657f6d8
tools: xml_tools.ElementParser do not replace '\n' and '\t' with ' ' by default

diff -r 95dabdb0c799 -r cad8e52bb2e6 src/tools/xml_tools.py
--- a/src/tools/xml_tools.py	Sat Mar 15 01:19:22 2014 +0100
+++ b/src/tools/xml_tools.py	Sat Mar 15 00:15:49 2014 +0100
@@ -792,7 +792,11 @@
     Found at http://stackoverflow.com/questions/2093400/how-to-create-twisted-words-xish-domish-element-entirely-from-raw-xml/2095942#2095942
     (c) Karl Anderson"""
 
-    def __call__(self, string):
+    def __call__(self, string, force_spaces=False):
+        """
+        @param string: the XML string
+        @param force_spaces: if True, replace occurrences of 'n' and '\t' with ' '.
+        """
         self.result = None
 
         def onStart(elem):
@@ -809,6 +813,8 @@
         parser.ElementEvent = onElement
         parser.DocumentEndEvent = onEnd
         tmp = domish.Element((None, "s"))
-        tmp.addRawXml(string.replace('\n', ' ').replace('\t', ' '))
+        if force_spaces:
+            string = string.replace('\n', ' ').replace('\t', ' ')
+        tmp.addRawXml(string)
         parser.parse(tmp.toXml().encode('utf-8'))
         return self.result.firstChildElement()