diff options
| author | qdp-odoo <qdp@odoo.com> | 2017-01-04 16:30:26 +0100 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2017-01-04 16:30:50 +0100 |
| commit | 4a8b088773c3252cbf2ad56f2a70d9837335f931 (patch) | |
| tree | b110f9f419405ce5c8b9cd5ef8890de264714c03 /odoo | |
| parent | 8509db6485888f9b37d6d593350ff4d00c58f3c4 (diff) | |
[ADD] xml_utils: utilitary file for common xml operations
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/tools/__init__.py | 1 | ||||
| -rw-r--r-- | odoo/tools/xml_utils.py | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/odoo/tools/__init__.py b/odoo/tools/__init__.py index 6e657a8ddd3..93ab0477546 100644 --- a/odoo/tools/__init__.py +++ b/odoo/tools/__init__.py @@ -19,3 +19,4 @@ from float_utils import * from mail import * from func import * from debugger import * +from xml_utils import * diff --git a/odoo/tools/xml_utils.py b/odoo/tools/xml_utils.py new file mode 100644 index 00000000000..d179559db75 --- /dev/null +++ b/odoo/tools/xml_utils.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +from lxml import etree +from odoo.tools.misc import file_open + +def check_with_xsd(tree_or_str, xsd_path): + if not isinstance(tree_or_str, etree._Element): + tree_or_str = etree.fromstring(tree_or_str) + xml_schema_doc = etree.parse(file_open(xsd_path)) + xsd_schema = etree.XMLSchema(xml_schema_doc) + try: + xsd_schema.assertValid(tree_or_str) + except etree.DocumentInvalid, xml_errors: + #import UserError only here to avoid circular import statements with tools.func being imported in exceptions.py + from odoo.exceptions import UserError + raise UserError('\n'.join([e.message for e in xml_errors.error_log])) |
