summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins
diff options
context:
space:
mode:
authorfritzy <fritzy@ip-10-251-242-239.ec2.internal>2010-08-21 22:48:43 +0000
committerfritzy <fritzy@ip-10-251-242-239.ec2.internal>2010-08-21 22:48:43 +0000
commit345656926ea5ee8e8cc359b97fd1d0cbc4b1fab4 (patch)
treeca0c851734641f6c4a0169528eee19bd706191be /sleekxmpp/plugins
parentc05ddcb7f5eaa5bbf7efb4e765d04b62212a3394 (diff)
downloadslixmpp-345656926ea5ee8e8cc359b97fd1d0cbc4b1fab4.tar.gz
slixmpp-345656926ea5ee8e8cc359b97fd1d0cbc4b1fab4.tar.bz2
slixmpp-345656926ea5ee8e8cc359b97fd1d0cbc4b1fab4.tar.xz
slixmpp-345656926ea5ee8e8cc359b97fd1d0cbc4b1fab4.zip
added form compatibility with old api, stanzas now bool() to True on 2.x, jid attributes will return '' if not set
Diffstat (limited to 'sleekxmpp/plugins')
-rw-r--r--sleekxmpp/plugins/stanza_pubsub.py17
-rw-r--r--sleekxmpp/plugins/xep_0004.py24
-rw-r--r--sleekxmpp/plugins/xep_0060.py6
3 files changed, 44 insertions, 3 deletions
diff --git a/sleekxmpp/plugins/stanza_pubsub.py b/sleekxmpp/plugins/stanza_pubsub.py
index 96d02f93..01aac095 100644
--- a/sleekxmpp/plugins/stanza_pubsub.py
+++ b/sleekxmpp/plugins/stanza_pubsub.py
@@ -284,6 +284,14 @@ class DefaultConfig(ElementBase):
t = self._getAttr('type')
if not t: t = 'leaf'
return t
+
+ def getConfig(self):
+ return self['form']
+
+ def setConfig(self, value):
+ self['form'].setStanzaValues(value.getStanzaValues())
+ print self['form']['title']
+ return self
registerStanzaPlugin(PubsubOwner, DefaultConfig)
registerStanzaPlugin(DefaultConfig, xep_0004.Form)
@@ -356,8 +364,17 @@ class OwnerDefault(OwnerConfigure):
interfaces = set(('node', 'config'))
plugin_attrib_map = {}
plugin_tag_map = {}
+
+ def getConfig(self):
+ return self['form']
+
+ def setConfig(self, value):
+ self['form'].setStanzaValues(value.getStanzaValues())
+ print self['from']['title']
+ return self
registerStanzaPlugin(PubsubOwner, OwnerDefault)
+registerStanzaPlugin(OwnerDefault, xep_0004.Form)
class OwnerDelete(ElementBase, OptionalSetting):
namespace = 'http://jabber.org/protocol/pubsub#owner'
diff --git a/sleekxmpp/plugins/xep_0004.py b/sleekxmpp/plugins/xep_0004.py
index 86963632..9e67e656 100644
--- a/sleekxmpp/plugins/xep_0004.py
+++ b/sleekxmpp/plugins/xep_0004.py
@@ -31,6 +31,7 @@ class Form(ElementBase):
ElementBase.__init__(self, *args, **kwargs)
if title is not None:
self['title'] = title
+ self.field = FieldAccessor(self)
def setup(self, xml=None):
if ElementBase.setup(self, xml): #if we had to generate xml
@@ -111,7 +112,7 @@ class Form(ElementBase):
reportedXML = self.xml.find('{%s}reported' % self.namespace)
if reportedXML is not None:
self.xml.remove(reportedXML)
-
+
def getFields(self, use_dict=False):
fields = {} if use_dict else []
fieldsXML = self.xml.findall('{%s}field' % FormField.namespace)
@@ -195,6 +196,27 @@ class Form(ElementBase):
fields = self.getFields(use_dict=True)
for field in values:
fields[field]['value'] = values[field]
+
+ def merge(self, other):
+ new = copy.copy(self)
+ nfields = new.getFields(use_dict=True)
+ ofields = other.getFields(use_dict=True)
+ nfields.update(ofields)
+ new.setFields([(x, nfields[x]) for x in nfields])
+ return new
+
+class FieldAccessor(object):
+ def __init__(self, form):
+ self.form = form
+
+ def __getitem__(self, key):
+ return self.form.getFields(use_dict=True)[key]
+
+ def __contains__(self, key):
+ return key in self.form.getFields(use_dict=True)
+
+ def has_key(self, key):
+ return key in self.form.getFields(use_dict=True)
class FormField(ElementBase):
diff --git a/sleekxmpp/plugins/xep_0060.py b/sleekxmpp/plugins/xep_0060.py
index a92a3844..0b056f0b 100644
--- a/sleekxmpp/plugins/xep_0060.py
+++ b/sleekxmpp/plugins/xep_0060.py
@@ -4,6 +4,7 @@ import logging
#from xml.etree import cElementTree as ET
from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
from . import stanza_pubsub
+from . xep_0004 import Form
class xep_0060(base.base_plugin):
"""
@@ -41,7 +42,8 @@ class xep_0060(base.base_plugin):
submitform.field['pubsub#node_type'].setValue('leaf')
else:
submitform.addField('pubsub#node_type', value='leaf')
- configure.append(submitform.getXML('submit'))
+ submitform['type'] = 'submit'
+ configure.append(submitform.xml)
pubsub.append(configure)
iq = self.xmpp.makeIqSet(pubsub)
iq.attrib['to'] = jid
@@ -117,7 +119,7 @@ class xep_0060(base.base_plugin):
if not form or form is None:
logging.error("No form found.")
return False
- return self.xmpp.plugin['xep_0004'].buildForm(form)
+ return Form(xml=form)
def getNodeSubscriptions(self, jid, node):
pubsub = ET.Element('{http://jabber.org/protocol/pubsub#owner}pubsub')