From 29938397ee17835645e89ee0dadb26e14ef45927 Mon Sep 17 00:00:00 2001 From: william <wan@odoo.com> Date: Thu, 9 Jul 2020 08:36:21 +0000 Subject: [PATCH] [REF] base: clean dosctring and remove deprecated function The function check_with_xsd has been deprecated for more than 3 years. Docstring is now compliant with PEP 257 closes odoo/odoo#54130 Signed-off-by: Josse Colpaert <jco@openerp.com> --- odoo/tools/xml_utils.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/odoo/tools/xml_utils.py b/odoo/tools/xml_utils.py index 513aa2076635..8780dd54d25e 100644 --- a/odoo/tools/xml_utils.py +++ b/odoo/tools/xml_utils.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +"""Utilities for generating, parsing and checking XML/XSD files on top of the lxml.etree module.""" + import base64 from io import BytesIO from lxml import etree @@ -23,9 +25,6 @@ class odoo_resolver(etree.Resolver): return self.resolve_string(base64.b64decode(attachment.datas), context) -def check_with_xsd(tree_or_str, stream): - raise UserError("Method 'check_with_xsd' deprecated ") - def _check_with_xsd(tree_or_str, stream, env=None): """Check an XML against an XSD schema. @@ -55,11 +54,14 @@ def _check_with_xsd(tree_or_str, stream, env=None): def create_xml_node_chain(first_parent_node, nodes_list, last_node_value=None): - """ Utility function for generating XML files nodes. Generates as a hierarchical - chain of nodes (each new node being the son of the previous one) based on the tags - contained in `nodes_list`, under the given node `first_parent_node`. - It will also set the value of the last of these nodes to `last_node_value` if it is - specified. This function returns the list of created nodes. + """Generate a hierarchical chain of nodes. + + Each new node being the child of the previous one based on the tags contained + in `nodes_list`, under the given node `first_parent_node`. + :param first_parent_node (etree._Element): parent of the created tree/chain + :param nodes_list (iterable<str>): tag names to be created + :param last_node_value (str): if specified, set the last node's text to this value + :returns (list<etree._Element>): the list of created nodes """ res = [] current_node = first_parent_node @@ -71,11 +73,13 @@ def create_xml_node_chain(first_parent_node, nodes_list, last_node_value=None): current_node.text = last_node_value return res + def create_xml_node(parent_node, node_name, node_value=None): - """ Utility function for managing XML. It creates a new node with the specified - `node_name` as a child of given `parent_node` and assigns it `node_value` as value. - :param parent_node: valid etree Element - :param node_name: string - :param node_value: string + """Create a new node. + + :param parent_node (etree._Element): parent of the created node + :param node_name (str): name of the created node + :param node_value (str): value of the created node (optional) + :returns (etree._Element): """ return create_xml_node_chain(parent_node, [node_name], node_value)[0] -- GitLab