import xml.dom.minidom
from . import curve as curve
+from .compat import minidom as minidom # dynamically patch xml.sax.minidom
class NoteIndexList (list):
>>> 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
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
with endlines" path="/path/to/curve/two"/>
</playlist>
<BLANKLINE>
"""
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
>>> 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
with endlines" path="../curve/two"/>
... </playlist>
... '''
>>> p = FilePlaylist(drivers=[],
... 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)