Add hooke.compat.minidom to fix Python's XML generation issue5752.
[hooke.git] / hooke / playlist.py
index 8efac4770568a3a6923c83a138317349494ad7d8..b58e9b6fa7f49be199780279bb8dc358f4ff2fe7 100644 (file)
@@ -27,6 +27,7 @@ import os.path
 import xml.dom.minidom
 
 from . import curve as curve
+from .compat import minidom as minidom  # dynamically patch xml.sax.minidom
 
 
 class NoteIndexList (list):
@@ -185,20 +186,20 @@ class FilePlaylist (Playlist):
         >>> c.info['note'] = 'The first curve'
         >>> p.append(c)
         >>> c = curve.Curve(os.path.join(root_path, 'to', 'curve', 'two'))
-        >>> c.info['note'] = 'The second curve'
+        >>> c.info['note'] = 'The second curve\\nwith endlines'
         >>> p.append(c)
         >>> print p.flatten() # doctest: +NORMALIZE_WHITESPACE +REPORT_UDIFF
         <?xml version="1.0" encoding="utf-8"?>
         <playlist index="0" note="An example playlist" version="0.1">
-            <curve note="The first curve" path="curve/one"/>
-            <curve note="The second curve" path="curve/two"/>
+           <curve note="The first curve" path="curve/one"/>
+           <curve note="The second curve&#xA;with endlines" path="curve/two"/>
         </playlist>
         <BLANKLINE>
         >>> print p.flatten(absolute_paths=True) # doctest: +NORMALIZE_WHITESPACE +REPORT_UDIFF
         <?xml version="1.0" encoding="utf-8"?>
         <playlist index="0" note="An example playlist" version="0.1">
-            <curve note="The first curve" path="/path/to/curve/one"/>
-            <curve note="The second curve" path="/path/to/curve/two"/>
+           <curve note="The first curve" path="/path/to/curve/one"/>
+           <curve note="The second curve&#xA;with endlines" path="/path/to/curve/two"/>
         </playlist>
         <BLANKLINE>
         """
@@ -224,7 +225,7 @@ class FilePlaylist (Playlist):
             for key,value in curve.info.items():
                 if key in self._ignored_keys:
                     continue
-                curve_element.setAttribute(key, str(value))
+                curve_element.setAttribute(key,str(value))
         string = doc.toprettyxml(encoding='utf-8')
         root.unlink() # break circular references for garbage collection
         return string
@@ -259,7 +260,7 @@ class FilePlaylist (Playlist):
         >>> string = '''<?xml version="1.0" encoding="utf-8"?>
         ... <playlist index="1" note="An example playlist" version="0.1">
         ...     <curve note="The first curve" path="../curve/one"/>
-        ...     <curve note="The second curve" path="../curve/two"/>
+        ...     <curve note="The second curve&#xA;with endlines" path="../curve/two"/>
         ... </playlist>
         ... '''
         >>> p = FilePlaylist(drivers=[],
@@ -273,6 +274,8 @@ class FilePlaylist (Playlist):
         ...     print curve.path
         path/to/curve/one
         path/to/curve/two
+        >>> p[-1].info['note']
+        u'The second curve\\nwith endlines'
         """
         doc = xml.dom.minidom.parseString(string)
         self._from_xml_doc(doc, identify=identify)