diff sat/tools/xml_tools.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents bb211f80c3e6
children 2594e1951cf7
line wrap: on
line diff
--- a/sat/tools/xml_tools.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/tools/xml_tools.py	Sat Apr 08 13:54:42 2023 +0200
@@ -47,7 +47,7 @@
 
 # method to clean XHTML, receive raw unsecure XML or HTML, must return cleaned raw XHTML
 # this method must be set during runtime
-cleanXHTML = None
+clean_xhtml = None
 
 # TODO: move XMLUI stuff in a separate module
 # TODO: rewrite this with lxml or ElementTree or domish.Element: it's complicated and difficult to maintain with current minidom implementation
@@ -55,7 +55,7 @@
 # Helper functions
 
 
-def _dataFormField2XMLUIData(field, read_only=False):
+def _data_form_field_2_xmlui_data(field, read_only=False):
     """Get data needed to create an XMLUI's Widget from Wokkel's data_form's Field.
 
     The attribute field can be modified (if it's fixed and it has no value).
@@ -144,14 +144,14 @@
 
     return widget_type, widget_args, widget_kwargs
 
-def dataForm2Widgets(form_ui, form, read_only=False, prepend=None, filters=None):
+def data_form_2_widgets(form_ui, form, read_only=False, prepend=None, filters=None):
     """Complete an existing XMLUI with widget converted from XEP-0004 data forms.
 
     @param form_ui (XMLUI): XMLUI instance
     @param form (data_form.Form): Wokkel's implementation of data form
     @param read_only (bool): if True and it makes sense, create a read only input widget
     @param prepend(iterable, None): widgets to prepend to main LabelContainer
-        if not None, must be an iterable of *args for addWidget. Those widgets will
+        if not None, must be an iterable of *args for add_widget. Those widgets will
         be added first to the container.
     @param filters(dict, None): if not None, a dictionary of callable:
         key is the name of the widget to filter
@@ -165,14 +165,14 @@
     if form.instructions:
         form_ui.addText("\n".join(form.instructions), "instructions")
 
-    form_ui.changeContainer("label")
+    form_ui.change_container("label")
 
     if prepend is not None:
         for widget_args in prepend:
-            form_ui.addWidget(*widget_args)
+            form_ui.add_widget(*widget_args)
 
     for field in form.fieldList:
-        widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(
+        widget_type, widget_args, widget_kwargs = _data_form_field_2_xmlui_data(
             field, read_only
         )
         try:
@@ -190,12 +190,12 @@
             else:
                 form_ui.addEmpty()
 
-        form_ui.addWidget(widget_type, *widget_args, **widget_kwargs)
+        form_ui.add_widget(widget_type, *widget_args, **widget_kwargs)
 
     return form_ui
 
 
-def dataForm2XMLUI(form, submit_id, session_id=None, read_only=False):
+def data_form_2_xmlui(form, submit_id, session_id=None, read_only=False):
     """Take a data form (Wokkel's XEP-0004 implementation) and convert it to a SàT XMLUI.
 
     @param form (data_form.Form): a Form instance
@@ -205,13 +205,13 @@
     @return: XMLUI instance
     """
     form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
-    return dataForm2Widgets(form_ui, form, read_only=read_only)
+    return data_form_2_widgets(form_ui, form, read_only=read_only)
 
 
-def dataForm2dataDict(form: data_form.Form) -> dict:
+def data_form_2_data_dict(form: data_form.Form) -> dict:
     """Convert data form to a simple dict, easily serialisable
 
-    see dataDict2dataForm for a description of the format
+    see data_dict_2_data_form for a description of the format
     """
     fields = []
     data_dict = {
@@ -253,7 +253,7 @@
     return data_dict
 
 
-def dataDict2dataForm(data_dict):
+def data_dict_2_data_form(data_dict):
     """Convert serialisable dict of data to a data form
 
     The format of the dict is as follow:
@@ -299,7 +299,7 @@
     )
 
 
-def dataFormEltResult2XMLUIData(form_xml):
+def data_form_elt_result_2_xmlui_data(form_xml):
     """Parse a data form result (not parsed by Wokkel's XEP-0004 implementation).
 
     The raw data form is used because Wokkel doesn't manage result items parsing yet.
@@ -337,12 +337,12 @@
                 continue
             field = data_form.Field.fromElement(elt)
 
-            xmlui_data.append(_dataFormField2XMLUIData(field))
+            xmlui_data.append(_data_form_field_2_xmlui_data(field))
 
     return headers, xmlui_data
 
 
-def XMLUIData2AdvancedList(xmlui, headers, xmlui_data):
+def xmlui_data_2_advanced_list(xmlui, headers, xmlui_data):
     """Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
 
     The raw data form is used because Wokkel doesn't manage result items parsing yet.
@@ -354,15 +354,15 @@
     adv_list = AdvancedListContainer(
         xmlui, headers=headers, columns=len(headers), parent=xmlui.current_container
     )
-    xmlui.changeContainer(adv_list)
+    xmlui.change_container(adv_list)
 
     for widget_type, widget_args, widget_kwargs in xmlui_data:
-        xmlui.addWidget(widget_type, *widget_args, **widget_kwargs)
+        xmlui.add_widget(widget_type, *widget_args, **widget_kwargs)
 
     return xmlui
 
 
-def dataFormResult2AdvancedList(xmlui, form_xml):
+def data_form_result_2_advanced_list(xmlui, form_xml):
     """Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
 
     The raw data form is used because Wokkel doesn't manage result items parsing yet.
@@ -370,11 +370,11 @@
     @param form_xml (domish.Element): element of the data form
     @return: the completed XMLUI instance
     """
-    headers, xmlui_data = dataFormEltResult2XMLUIData(form_xml)
-    XMLUIData2AdvancedList(xmlui, headers, xmlui_data)
+    headers, xmlui_data = data_form_elt_result_2_xmlui_data(form_xml)
+    xmlui_data_2_advanced_list(xmlui, headers, xmlui_data)
 
 
-def dataFormEltResult2XMLUI(form_elt, session_id=None):
+def data_form_elt_result_2_xmlui(form_elt, session_id=None):
     """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI.
 
     The raw data form is used because Wokkel doesn't manage result items parsing yet.
@@ -384,14 +384,14 @@
     """
     xml_ui = XMLUI("window", "vertical", session_id=session_id)
     try:
-        dataFormResult2AdvancedList(xml_ui, form_elt)
+        data_form_result_2_advanced_list(xml_ui, form_elt)
     except exceptions.DataError:
         parsed_form = data_form.Form.fromElement(form_elt)
-        dataForm2Widgets(xml_ui, parsed_form, read_only=True)
+        data_form_2_widgets(xml_ui, parsed_form, read_only=True)
     return xml_ui
 
 
-def dataFormResult2XMLUI(result_form, base_form, session_id=None, prepend=None,
+def data_form_result_2_xmlui(result_form, base_form, session_id=None, prepend=None,
                          filters=None, read_only=True):
     """Convert data form result to SàT XMLUI.
 
@@ -399,12 +399,12 @@
     @param base_form (data_form.Form): initial form (i.e. of form type "form")
         this one is necessary to reconstruct options when needed (e.g. list elements)
     @param session_id (unicode): session id to return with the data
-    @param prepend: same as for [dataForm2Widgets]
-    @param filters: same as for [dataForm2Widgets]
-    @param read_only: same as for [dataForm2Widgets]
+    @param prepend: same as for [data_form_2_widgets]
+    @param filters: same as for [data_form_2_widgets]
+    @param read_only: same as for [data_form_2_widgets]
     @return: XMLUI instance
     """
-    # we deepcopy the form because _dataFormField2XMLUIData can modify the value
+    # we deepcopy the form because _data_form_field_2_xmlui_data can modify the value
     # FIXME: check if it's really important, the only modified value seems to be
     #        the replacement of None by "" on fixed fields
     # form = deepcopy(result_form)
@@ -416,11 +416,11 @@
             continue
         field.options = base_field.options[:]
     xml_ui = XMLUI("window", "vertical", session_id=session_id)
-    dataForm2Widgets(xml_ui, form, read_only=read_only, prepend=prepend, filters=filters)
+    data_form_2_widgets(xml_ui, form, read_only=read_only, prepend=prepend, filters=filters)
     return xml_ui
 
 
-def _cleanValue(value):
+def _clean_value(value):
     """Workaround method to avoid DBus types with D-Bus bridge.
 
     @param value: value to clean
@@ -433,7 +433,7 @@
     return value
 
 
-def XMLUIResult2DataFormResult(xmlui_data):
+def xmlui_result_2_data_form_result(xmlui_data):
     """ Extract form data from a XMLUI return.
 
     @param xmlui_data (dict): data returned by frontends for XMLUI form
@@ -451,11 +451,11 @@
                 # FIXME: workaround to handle multiple values. Proper serialisation must
                 #   be done in XMLUI
                 value = value.split("\t")
-        ret[key[len(SAT_FORM_PREFIX) :]] = _cleanValue(value)
+        ret[key[len(SAT_FORM_PREFIX) :]] = _clean_value(value)
     return ret
 
 
-def formEscape(name):
+def form_escape(name):
     """Return escaped name for forms.
 
     @param name (unicode): form name
@@ -464,23 +464,23 @@
     return "%s%s" % (SAT_FORM_PREFIX, name)
 
 
-def isXMLUICancelled(raw_xmlui):
+def is_xmlui_cancelled(raw_xmlui):
     """Tell if an XMLUI has been cancelled by checking raw XML"""
     return C.bool(raw_xmlui.get('cancelled', C.BOOL_FALSE))
 
 
-def XMLUIResultToElt(xmlui_data):
+def xmlui_result_to_elt(xmlui_data):
     """Construct result domish.Element from XMLUI result.
 
     @param xmlui_data (dict): data returned by frontends for XMLUI form
     @return: domish.Element
     """
     form = data_form.Form("submit")
-    form.makeFields(XMLUIResult2DataFormResult(xmlui_data))
+    form.makeFields(xmlui_result_2_data_form_result(xmlui_data))
     return form.toElement()
 
 
-def tupleList2dataForm(values):
+def tuple_list_2_data_form(values):
     """Convert a list of tuples (name, value) to a wokkel submit data form.
 
     @param values (list): list of tuples
@@ -494,7 +494,7 @@
     return form
 
 
-def paramsXML2XMLUI(xml):
+def params_xml_2_xmlui(xml):
     """Convert the XML for parameter to a SàT XML User Interface.
 
     @param xml (unicode)
@@ -516,7 +516,7 @@
             raise exceptions.DataError(
                 _("INTERNAL ERROR: params categories must have a name")
             )
-        tabs_cont.addTab(category_name, label=label, container=LabelContainer)
+        tabs_cont.add_tab(category_name, label=label, container=LabelContainer)
         for param in category.getElementsByTagName("param"):
             widget_kwargs = {}
 
@@ -530,12 +530,12 @@
             callback_id = param.getAttribute("callback_id") or None
 
             if type_ == "list":
-                options, selected = _paramsGetListOptions(param)
+                options, selected = _params_get_list_options(param)
                 widget_kwargs["options"] = options
                 widget_kwargs["selected"] = selected
                 widget_kwargs["styles"] = ["extensible"]
             elif type_ == "jids_list":
-                widget_kwargs["jids"] = _paramsGetListJids(param)
+                widget_kwargs["jids"] = _params_get_list_jids(param)
 
             if type_ in ("button", "text"):
                 param_ui.addEmpty()
@@ -562,12 +562,12 @@
                 param_name,
             )
 
-            param_ui.addWidget(type_, **widget_kwargs)
+            param_ui.add_widget(type_, **widget_kwargs)
 
     return param_ui.toXml()
 
 
-def _paramsGetListOptions(param):
+def _params_get_list_options(param):
     """Retrieve the options for list element.
 
     The <option/> tags must be direct children of <param/>.
@@ -599,7 +599,7 @@
     return (options, selected)
 
 
-def _paramsGetListJids(param):
+def _params_get_list_jids(param):
     """Retrive jids from a jids_list element.
 
     the <jid/> tags must be direct children of <param/>
@@ -679,9 +679,9 @@
         self.elem.setAttribute("name", name)
         self.elem.setAttribute("label", label)
         if selected:
-            self.setSelected(selected)
+            self.set_selected(selected)
 
-    def setSelected(self, selected=False):
+    def set_selected(self, selected=False):
         """Set the tab selected.
 
         @param selected (bool): set to True to select this tab
@@ -824,7 +824,7 @@
         super(Container, self).__init__(xmlui, parent)
         self.elem.setAttribute("type", self.type)
 
-    def getParentContainer(self):
+    def get_parent_container(self):
         """ Return first parent container
 
         @return: parent container or None
@@ -856,7 +856,7 @@
 class TabsContainer(Container):
     type = "tabs"
 
-    def addTab(self, name, label=None, selected=None, container=VerticalContainer):
+    def add_tab(self, name, label=None, selected=None, container=VerticalContainer):
         """Add a tab.
 
         @param name (unicode): tab name
@@ -869,15 +869,15 @@
             label = name
         tab_elt = TabElement(self, name, label, selected)
         new_container = container(self.xmlui, tab_elt)
-        return self.xmlui.changeContainer(new_container)
+        return self.xmlui.change_container(new_container)
 
     def end(self):
         """ Called when we have finished tabs
 
         change current container to first container parent
         """
-        parent_container = self.getParentContainer()
-        self.xmlui.changeContainer(parent_container)
+        parent_container = self.get_parent_container()
+        self.xmlui.change_container(parent_container)
 
 
 class AdvancedListContainer(Container):
@@ -928,9 +928,9 @@
                 raise exceptions.DataError(
                     _("Headers lenght doesn't correspond to columns")
                 )
-            self.addHeaders(headers)
+            self.add_headers(headers)
         if items:
-            self.addItems(items)
+            self.add_items(items)
         self.elem.setAttribute("columns", str(self._columns))
         if callback_id is not None:
             self.elem.setAttribute("callback", callback_id)
@@ -940,18 +940,18 @@
             self.elem.setAttribute("auto_index", "true")
         self.next_row_idx = None
 
-    def addHeaders(self, headers):
+    def add_headers(self, headers):
         for header in headers:
             self.addHeader(header)
 
     def addHeader(self, header):
         pass  # TODO
 
-    def addItems(self, items):
+    def add_items(self, items):
         for item in items:
             self.append(item)
 
-    def setRowIndex(self, idx):
+    def set_row_index(self, idx):
         """ Set index for next row
 
         index are returned when a row is selected, in data's "index" key
@@ -974,8 +974,8 @@
         """
         if self._item_idx % self._columns != 0:
             raise exceptions.DataError(_("Incorrect number of items in list"))
-        parent_container = self.getParentContainer()
-        self.xmlui.changeContainer(parent_container)
+        parent_container = self.get_parent_container()
+        self.xmlui.change_container(parent_container)
 
 
 ## Widgets ##
@@ -1004,7 +1004,7 @@
             xmlui.named_widgets[name] = self
         self.elem.setAttribute("type", self.type)
 
-    def setInternalCallback(self, callback, fields, data_elts=None):
+    def set_internal_callback(self, callback, fields, data_elts=None):
         """Set an internal UI callback when the widget value is changed.
 
         The internal callbacks are NO callback ids, they are strings from
@@ -1169,10 +1169,10 @@
             word, set to False only if you made the XHTML yourself)
         """
         if clean:
-            if cleanXHTML is None:
+            if clean_xhtml is None:
                 raise exceptions.NotFound(
                     "No cleaning method set, can't clean the XHTML")
-            value = cleanXHTML(value)
+            value = clean_xhtml(value)
 
         super(XHTMLBoxWidget, self).__init__(
             xmlui, value=value, name=name, parent=parent, read_only=read_only)
@@ -1279,10 +1279,10 @@
             # because we would not have the labels
             log.warning(_('empty "options" list'))
         super(ListWidget, self).__init__(xmlui, name, parent)
-        self.addOptions(options, selected)
-        self.setStyles(styles)
+        self.add_options(options, selected)
+        self.set_styles(styles)
 
-    def addOptions(self, options, selected=None):
+    def add_options(self, options, selected=None):
         """Add options to a multi-values element (e.g. list) """
         if selected:
             if isinstance(selected, str):
@@ -1294,7 +1294,7 @@
             value = option if isinstance(option, str) else option[0]
             OptionElement(self, option, value in selected)
 
-    def setStyles(self, styles):
+    def set_styles(self, styles):
         if not styles.issubset(self.STYLES):
             raise exceptions.DataError(_("invalid styles"))
         for style in styles:
@@ -1302,7 +1302,7 @@
         # TODO: check flags incompatibily (noselect and multi) like in __init__
 
     def setStyle(self, style):
-        self.setStyles([style])
+        self.set_styles([style])
 
     @property
     def value(self):
@@ -1336,9 +1336,9 @@
         if not jids:
             log.debug("empty jids list")
         else:
-            self.addJids(jids)
+            self.add_jids(jids)
 
-    def addJids(self, jids):
+    def add_jids(self, jids):
         for jid_ in jids:
             JidElement(self, jid_)
 
@@ -1499,20 +1499,20 @@
         if panel_type == C.XMLUI_DIALOG:
             if dialog_opt is None:
                 dialog_opt = {}
-            self._createDialog(dialog_opt)
+            self._create_dialog(dialog_opt)
             return
-        self.main_container = self._createContainer(container, TopElement(self))
+        self.main_container = self._create_container(container, TopElement(self))
         self.current_container = self.main_container
         self.named_widgets = {}
 
     @staticmethod
-    def creatorWrapper(widget_cls, is_input):
+    def creator_wrapper(widget_cls, is_input):
         # TODO: once moved to Python 3, use functools.partialmethod and
-        #       remove the creatorWrapper
-        def createWidget(self, *args, **kwargs):
+        #       remove the creator_wrapper
+        def create_widget(self, *args, **kwargs):
             if self.type == C.XMLUI_DIALOG:
                 raise exceptions.InternalError(_(
-                    "createWidget can't be used with dialogs"))
+                    "create_widget can't be used with dialogs"))
             if "parent" not in kwargs:
                 kwargs["parent"] = self.current_container
             if "name" not in kwargs and is_input:
@@ -1521,7 +1521,7 @@
                 args = list(args)
                 kwargs["name"] = args.pop(0)
             return widget_cls(self, *args, **kwargs)
-        return createWidget
+        return create_widget
 
     @classmethod
     def _introspect(cls):
@@ -1547,10 +1547,10 @@
                     #     .format(creator_name=creator_name, is_input=is_input))
 
                     assert not hasattr(cls, creator_name)
-                    # XXX: we need to use creatorWrapper because we are in a loop
+                    # XXX: we need to use creator_wrapper because we are in a loop
                     #      and Python 2 doesn't support default values in kwargs
                     #      when using *args, **kwargs
-                    setattr(cls, creator_name, cls.creatorWrapper(obj, is_input))
+                    setattr(cls, creator_name, cls.creator_wrapper(obj, is_input))
 
                 elif issubclass(obj, Container):
                     if obj.__name__ == "Container":
@@ -1602,7 +1602,7 @@
         else:
             raise exceptions.DataError("session_id can't be empty")
 
-    def _createDialog(self, dialog_opt):
+    def _create_dialog(self, dialog_opt):
         dialog_type = dialog_opt.setdefault(C.XMLUI_DATA_TYPE, C.XMLUI_DIALOG_MESSAGE)
         if (
             dialog_type in [C.XMLUI_DIALOG_CONFIRM, C.XMLUI_DIALOG_FILE]
@@ -1630,7 +1630,7 @@
         except KeyError:
             pass
 
-    def _createContainer(self, container, parent=None, **kwargs):
+    def _create_container(self, container, parent=None, **kwargs):
         """Create a container element
 
         @param type: container type (cf init doc)
@@ -1642,15 +1642,15 @@
         new_container = cls(self, parent=parent, **kwargs)
         return new_container
 
-    def changeContainer(self, container, **kwargs):
+    def change_container(self, container, **kwargs):
         """Change the current container
 
         @param container: either container type (container it then created),
                           or an Container instance"""
         if isinstance(container, str):
-            self.current_container = self._createContainer(
+            self.current_container = self._create_container(
                 container,
-                self.current_container.getParentContainer() or self.main_container,
+                self.current_container.get_parent_container() or self.main_container,
                 **kwargs
             )
         else:
@@ -1660,7 +1660,7 @@
         assert isinstance(self.current_container, Container)
         return self.current_container
 
-    def addWidget(self, type_, *args, **kwargs):
+    def add_widget(self, type_, *args, **kwargs):
         """Convenience method to add an element"""
         if "parent" not in kwargs:
             kwargs["parent"] = self.current_container
@@ -1702,13 +1702,13 @@
     return note_xmlui
 
 
-def quickNote(host, client, message, title="", level=C.XMLUI_DATA_LVL_INFO):
+def quick_note(host, client, message, title="", level=C.XMLUI_DATA_LVL_INFO):
     """more sugar to do the whole note process"""
     note_ui = note(message, title, level)
-    host.actionNew({"xmlui": note_ui.toXml()}, profile=client.profile)
+    host.action_new({"xmlui": note_ui.toXml()}, profile=client.profile)
 
 
-def deferredUI(host, xmlui, chained=False):
+def deferred_ui(host, xmlui, chained=False):
     """create a deferred linked to XMLUI
 
     @param xmlui(XMLUI): instance of the XMLUI
@@ -1720,15 +1720,15 @@
     assert xmlui.submit_id == ""
     xmlui_d = defer.Deferred()
 
-    def onSubmit(data, profile):
+    def on_submit(data, profile):
         xmlui_d.callback(data)
         return xmlui_d if chained else {}
 
-    xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True)
+    xmlui.submit_id = host.register_callback(on_submit, with_data=True, one_shot=True)
     return xmlui_d
 
 
-def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT,
+def defer_xmlui(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT,
     chained=False, profile=C.PROF_KEY_NONE):
     """Create a deferred linked to XMLUI
 
@@ -1736,17 +1736,17 @@
         Must be an XMLUI that you can submit, with submit_id set to ''
     @param profile: %(doc_profile)s
     @param action_extra(None, dict): extra action to merge with xmlui
-        mainly used to add meta informations (see actionNew doc)
+        mainly used to add meta informations (see action_new doc)
     @param security_limit: %(doc_security_limit)s
     @param chained(bool): True if the Deferred result must be returned to the frontend
         useful when backend is in a series of dialogs with an ui
     @return (data): a deferred which fire the data
     """
-    xmlui_d = deferredUI(host, xmlui, chained)
+    xmlui_d = deferred_ui(host, xmlui, chained)
     action_data = {"xmlui": xmlui.toXml()}
     if action_extra is not None:
         action_data.update(action_extra)
-    host.actionNew(
+    host.action_new(
         action_data,
         security_limit=security_limit,
         keep_id=xmlui.submit_id,
@@ -1755,7 +1755,7 @@
     return xmlui_d
 
 
-def deferDialog(host, message, title="Please confirm", type_=C.XMLUI_DIALOG_CONFIRM,
+def defer_dialog(host, message, title="Please confirm", type_=C.XMLUI_DIALOG_CONFIRM,
     options=None, action_extra=None, security_limit=C.NO_SECURITY_LIMIT, chained=False,
     profile=C.PROF_KEY_NONE):
     """Create a submitable dialog and manage it with a deferred
@@ -1766,7 +1766,7 @@
     @param options(None, dict): if not None, will be used to update (extend) dialog_opt
                                 arguments of XMLUI
     @param action_extra(None, dict): extra action to merge with xmlui
-        mainly used to add meta informations (see actionNew doc)
+        mainly used to add meta informations (see action_new doc)
     @param security_limit: %(doc_security_limit)s
     @param chained(bool): True if the Deferred result must be returned to the frontend
         useful when backend is in a series of dialogs with an ui
@@ -1778,19 +1778,19 @@
     if options is not None:
         dialog_opt.update(options)
     dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id="")
-    return deferXMLUI(host, dialog, action_extra, security_limit, chained, profile)
+    return defer_xmlui(host, dialog, action_extra, security_limit, chained, profile)
 
 
-def deferConfirm(*args, **kwargs):
-    """call deferDialog and return a boolean instead of the whole data dict"""
-    d = deferDialog(*args, **kwargs)
+def defer_confirm(*args, **kwargs):
+    """call defer_dialog and return a boolean instead of the whole data dict"""
+    d = defer_dialog(*args, **kwargs)
     d.addCallback(lambda data: C.bool(data["answer"]))
     return d
 
 
 # Misc other funtions
 
-def elementCopy(
+def element_copy(
     element: domish.Element,
     with_parent: bool = True,
     with_children: bool = True
@@ -1815,7 +1815,7 @@
     return new_elt
 
 
-def isXHTMLField(field):
+def is_xhtml_field(field):
     """Check if a data_form.Field is an XHTML one"""
     return (field.fieldType is None and field.ext_type == "xml" and
             field.value.uri == C.NS_XHTML)
@@ -1826,7 +1826,7 @@
 
     # XXX: Found at http://stackoverflow.com/questions/2093400/how-to-create-twisted-words-xish-domish-element-entirely-from-raw-xml/2095942#2095942
 
-    def _escapeHTML(self, matchobj):
+    def _escape_html(self, matchobj):
         entity = matchobj.group(1)
         if entity in XML_ENTITIES:
             # we don't escape XML entities
@@ -1854,23 +1854,23 @@
             raw_xml = "<div>{}</div>".format(raw_xml)
 
         # avoid ParserError on HTML escaped chars
-        raw_xml = html_entity_re.sub(self._escapeHTML, raw_xml)
+        raw_xml = html_entity_re.sub(self._escape_html, raw_xml)
 
         self.result = None
 
-        def onStart(elem):
+        def on_start(elem):
             self.result = elem
 
-        def onEnd():
+        def on_end():
             pass
 
         def onElement(elem):
             self.result.addChild(elem)
 
         parser = domish.elementStream()
-        parser.DocumentStartEvent = onStart
+        parser.DocumentStartEvent = on_start
         parser.ElementEvent = onElement
-        parser.DocumentEndEvent = onEnd
+        parser.DocumentEndEvent = on_end
         tmp = domish.Element((None, "s"))
         if force_spaces:
             raw_xml = raw_xml.replace("\n", " ").replace("\t", " ")
@@ -1888,8 +1888,8 @@
 parse = ElementParser()
 
 
-# FIXME: this method is duplicated from frontends.tools.xmlui.getText
-def getText(node):
+# FIXME: this method is duplicated from frontends.tools.xmlui.get_text
+def get_text(node):
     """Get child text nodes of a domish.Element.
 
     @param node (domish.Element)
@@ -1902,7 +1902,7 @@
     return "".join(data)
 
 
-def findAll(elt, namespaces=None, names=None):
+def find_all(elt, namespaces=None, names=None):
     """Find child element at any depth matching criteria
 
     @param elt(domish.Element): top parent of the elements to find
@@ -1924,11 +1924,11 @@
             and (not namespaces or child.uri in namespaces)
         ):
             yield child
-        for found in findAll(child, namespaces, names):
+        for found in find_all(child, namespaces, names):
             yield found
 
 
-def findAncestor(
+def find_ancestor(
     elt,
     name: str,
     namespace: Optional[Union[str, Iterable[str]]] = None
@@ -1958,12 +1958,12 @@
         current = current.parent
 
 
-def pFmtElt(elt, indent=0, defaultUri=""):
+def p_fmt_elt(elt, indent=0, defaultUri=""):
     """Pretty format a domish.Element"""
     strings = []
     for child in elt.children:
         if domish.IElement.providedBy(child):
-            strings.append(pFmtElt(child, indent+2, defaultUri=elt.defaultUri))
+            strings.append(p_fmt_elt(child, indent+2, defaultUri=elt.defaultUri))
         else:
             strings.append(f"{(indent+2)*' '}{child!s}")
     if elt.children:
@@ -1977,9 +1977,9 @@
     return '\n'.join(strings)
 
 
-def ppElt(elt):
+def pp_elt(elt):
     """Pretty print a domish.Element"""
-    print(pFmtElt(elt))
+    print(p_fmt_elt(elt))
 
 
 # ElementTree