# HG changeset patch # User Goffi # Date 1391533360 -3600 # Node ID 8f5479f8709a7ce4341531f838e18ee8eb6a5ac5 # Parent 84214df2d83782899a878f021710774ebc8a2caf core: XMLUI now use @property for session_id and submit diff -r 84214df2d837 -r 8f5479f8709a src/plugins/plugin_xep_0050.py --- a/src/plugins/plugin_xep_0050.py Tue Feb 04 18:02:37 2014 +0100 +++ b/src/plugins/plugin_xep_0050.py Tue Feb 04 18:02:40 2014 +0100 @@ -277,7 +277,7 @@ d = self.requestCommandsList(entity, profile) def sendItems(xmlui): - xmlui.setSessionId(session_id) # we need to keep track of the session + xmlui.session_id = session_id # we need to keep track of the session return {'xmlui': xmlui.toXml()} d.addCallback(sendItems) diff -r 84214df2d837 -r 8f5479f8709a src/tools/xml_tools.py --- a/src/tools/xml_tools.py Tue Feb 04 18:02:37 2014 +0100 +++ b/src/tools/xml_tools.py Tue Feb 04 18:02:40 2014 +0100 @@ -19,7 +19,7 @@ from sat.core.i18n import _ from logging import debug, info, error, warning -from xml.dom import minidom +from xml.dom import minidom, NotFoundErr from wokkel import data_form from twisted.words.xish import domish from sat.core import exceptions @@ -264,10 +264,8 @@ top_element.setAttribute("type", panel_type) if title: top_element.setAttribute("title", title) - if submit_id: - top_element.setAttribute("submit", submit_id) - if session_id is not None: - top_element.setAttribute("session_id", session_id) + self.submit_id = submit_id + self.session_id = session_id self.parentTabsLayout = None # used only we have 'tabs' layout self.currentCategory = None # used only we have 'tabs' layout self.currentLayout = None @@ -276,11 +274,41 @@ def __del__(self): self.doc.unlink() - def setSessionId(self, session_id): - assert(session_id) + @property + def submit_id(self): + top_element = self.doc.documentElement + value = top_element.getAttribute("submit") + return value or None + + @submit_id.setter + def submit_id(self, value): top_element = self.doc.documentElement - top_element.setAttribute("session_id", session_id) + if value is None: + try: + top_element.removeAttribute("submit") + except NotFoundErr: + pass + elif value: # submit_id can be the empty string to bypass form restriction + top_element.setAttribute("submit", value) + @property + def session_id(self): + top_element = self.doc.documentElement + value = top_element.getAttribute("session_id") + return value or None + + @session_id.setter + def session_id(self, value): + top_element = self.doc.documentElement + if value is None: + try: + top_element.removeAttribute("session_id") + except NotFoundErr: + pass + elif value: + top_element.setAttribute("session_id", value) + else: + raise exceptions.DataError("session_id can't be empty") def _createLayout(self, layout, parent=None): """Create a layout element