changeset 798:8f5479f8709a

core: XMLUI now use @property for session_id and submit
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:02:40 +0100
parents 84214df2d837
children 7f2082b192ed
files src/plugins/plugin_xep_0050.py src/tools/xml_tools.py
diffstat 2 files changed, 37 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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