diff --git a/yaltik_dsl/__manifest__.py b/yaltik_dsl/__manifest__.py index e388fa8..e059173 100644 --- a/yaltik_dsl/__manifest__.py +++ b/yaltik_dsl/__manifest__.py @@ -19,7 +19,7 @@ 'name': 'Yaltik Odoo DSL base module and fns', 'summary': 'Yaltik Odoo Domain Specific Language base module and functions', 'description': """ Yaltik Odoo Domain Specific Language base module and functions """, - 'version': '10.0.0.3.1', + 'version': '10.0.0.3.2', 'category': 'Yaltik', 'author': 'Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/yaltik_dsl/test_xml_base.coco b/yaltik_dsl/test_xml_base.coco index 648edcb..6442bed 100644 --- a/yaltik_dsl/test_xml_base.coco +++ b/yaltik_dsl/test_xml_base.coco @@ -108,7 +108,7 @@ class TestXMLBase(unittest.TestCase): ('/badpath' |> xmlw) `self.assertEquals` None ('/bad.ext' |> xmlw) `self.assertEquals` None - xmlw(__file__) + xmlw(__file__) # Default to pretty filepath = __file__.replace('.py', '_views.xml') with open(filepath, 'r') as output_file: output_xml = output_file.read() @@ -116,7 +116,17 @@ class TestXMLBase(unittest.TestCase): '' `self.assertIn` output_xml '' `self.assertIn` output_xml 'Some text' `self.assertIn` output_xml - unlink(filepath) + unlink(filepath) + + xmlw(__file__, pretty=False) + filepath = __file__.replace('.py', '_views.xml') + with open(filepath, 'r') as output_file: + output_xml = output_file.read() + '' `self.assertIn` output_xml + '' `self.assertIn` output_xml + 'Some text' `self.assertIn` output_xml + unlink(filepath) if __name__ == '__main__': unittest.main() diff --git a/yaltik_dsl/test_xml_base.py b/yaltik_dsl/test_xml_base.py index 572379d..c977586 100644 --- a/yaltik_dsl/test_xml_base.py +++ b/yaltik_dsl/test_xml_base.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- -# __coconut_hash__ = 0x84c101a5 +# __coconut_hash__ = 0x470897d2 # Compiled with Coconut version 1.4.3 [Ernest Scribbler] @@ -132,7 +132,7 @@ class TestXMLBase(unittest.TestCase): (self.assertEquals)(((xmlw)('/badpath')), None) (self.assertEquals)(((xmlw)('/bad.ext')), None) - xmlw(__file__) + xmlw(__file__) # Default to pretty filepath = __file__.replace('.py', '_views.xml') with open(filepath, 'r') as output_file: output_xml = output_file.read() @@ -140,7 +140,17 @@ class TestXMLBase(unittest.TestCase): (self.assertIn)('', output_xml) (self.assertIn)('', output_xml) (self.assertIn)('Some text', output_xml) - unlink(filepath) + unlink(filepath) + + xmlw(__file__, pretty=False) + filepath = __file__.replace('.py', '_views.xml') + with open(filepath, 'r') as output_file: + output_xml = output_file.read() + (self.assertNotIn)('', output_xml) + (self.assertIn)('', output_xml) + (self.assertIn)('Some text', output_xml) + unlink(filepath) if __name__ == '__main__': unittest.main() diff --git a/yaltik_dsl/xml_base.coco b/yaltik_dsl/xml_base.coco index 801309b..0ba5652 100644 --- a/yaltik_dsl/xml_base.coco +++ b/yaltik_dsl/xml_base.coco @@ -73,11 +73,13 @@ def xmln(tag: Text = '', raise TypeError('Invalid arguments for xmln') -def xml_write(filepath, tree): +def xml_write(filepath: Text, tree: ET.Element, pretty: bool = True) -> None: """ Write XML file according to filename and given tree """ if '.py' |> filepath.endswith: # if .pyc, no need to generate XML - output_xml = tree |> ET.tostring |> minidom.parseString |> .toprettyxml(indent=' ') + output_xml = tree |> ET.tostring + if pretty: + output_xml = output_xml |> minidom.parseString |> .toprettyxml(indent=' ') output_path = filepath |> path.abspath |> path.dirname - fpath = [output_path, filepath |> path.basename] |> '/'.join |> .replace('.py', '_views.xml') - with open(fpath, 'w') as output_file: - output_file.write(output_xml) + output_path = [output_path, filepath |> path.basename] |> '/'.join |> .replace('.py', '_views.xml') + with open(output_path, 'w') as output_file: + output_file.write(unicode(output_xml)) diff --git a/yaltik_dsl/xml_base.py b/yaltik_dsl/xml_base.py index d950a7f..4d7aa28 100644 --- a/yaltik_dsl/xml_base.py +++ b/yaltik_dsl/xml_base.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- -# __coconut_hash__ = 0x178765c5 +# __coconut_hash__ = 0x4c21227d # Compiled with Coconut version 1.4.3 [Ernest Scribbler] @@ -134,11 +134,17 @@ def xmln(tag='', # type: Text raise TypeError('Invalid arguments for xmln') -def xml_write(filepath, tree): +def xml_write(filepath, # type: Text + tree, # type: ET.Element + pretty=True # type: bool + ): +# type: (...) -> None """ Write XML file according to filename and given tree """ if (filepath.endswith)('.py'): # if .pyc, no need to generate XML - output_xml = ((minidom.parseString)((ET.tostring)(tree))).toprettyxml(indent=' ') + output_xml = (ET.tostring)(tree) + if pretty: + output_xml = ((minidom.parseString)(output_xml)).toprettyxml(indent=' ') output_path = (path.dirname)((path.abspath)(filepath)) - fpath = (('/'.join)([output_path, (path.basename)(filepath)])).replace('.py', '_views.xml') - with open(fpath, 'w') as output_file: - output_file.write(output_xml) + output_path = (('/'.join)([output_path, (path.basename)(filepath)])).replace('.py', '_views.xml') + with open(output_path, 'w') as output_file: + output_file.write(unicode(output_xml))