From 44aa52663579bcd1a56d2f13cdc91b1ca2c2b542 Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Thu, 29 Oct 2009 02:34:23 +0000 Subject: * fixed bugs with XEP 50 for components * configuration-less nodes --- sleekxmpp/plugins/xep_0004.py | 7 ++++++- sleekxmpp/plugins/xep_0050.py | 15 ++++++++------- sleekxmpp/plugins/xep_0060.py | 33 +++++++++++++++++---------------- sleekxmpp/xmlstream/handler/callback.py | 1 - sleekxmpp/xmlstream/handler/waiter.py | 2 -- sleekxmpp/xmlstream/xmlstream.py | 1 - 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/sleekxmpp/plugins/xep_0004.py b/sleekxmpp/plugins/xep_0004.py index faee631c..abd5ceef 100644 --- a/sleekxmpp/plugins/xep_0004.py +++ b/sleekxmpp/plugins/xep_0004.py @@ -108,6 +108,11 @@ class Form(FieldContainer): form1.fields[field.var].addOption(option, label) return form1 + def copy(self): + newform = Form(ftype=self.type) + newform.fromXML(self.getXML(self.type)) + return newform + def update(self, form): values = form.getValues() for var in values: @@ -126,7 +131,7 @@ class Form(FieldContainer): def setValues(self, values={}): for field in values: if field in self.field: - if isintance(values[field], list) or isinstance(values[field], tuple): + if isinstance(values[field], list) or isinstance(values[field], tuple): for value in values[field]: self.field[field].setValue(value) else: diff --git a/sleekxmpp/plugins/xep_0050.py b/sleekxmpp/plugins/xep_0050.py index 8c7e10d9..b75a675c 100644 --- a/sleekxmpp/plugins/xep_0050.py +++ b/sleekxmpp/plugins/xep_0050.py @@ -39,15 +39,16 @@ class xep_0050(base.base_plugin): self.xmpp.add_handler("" % self.xmpp.default_ns, self.handler_command_complete) self.commands = {} self.sessions = {} + self.sd = self.xmpp.plugin['xep_0030'] def post_init(self): - self.xmpp['xep_0030'].add_feature('http://jabber.org/protocol/commands') + self.sd.add_feature('http://jabber.org/protocol/commands') def addCommand(self, node, name, form, pointer=None, multi=False): - self.xmpp['xep_0030'].add_item(None, name, 'http://jabber.org/protocol/commands', node) - self.xmpp['xep_0030'].add_identity('automation', 'command-node', name, node) - self.xmpp['xep_0030'].add_feature('http://jabber.org/protocol/commands', node) - self.xmpp['xep_0030'].add_feature('jabber:x:data', node) + self.sd.add_item(None, name, 'http://jabber.org/protocol/commands', node) + self.sd.add_identity('automation', 'command-node', name, node) + self.sd.add_feature('http://jabber.org/protocol/commands', node) + self.sd.add_feature('jabber:x:data', node) self.commands[node] = (name, form, pointer, multi) def getNewSession(self): @@ -80,7 +81,7 @@ class xep_0050(base.base_plugin): in_command = xml.find('{http://jabber.org/protocol/commands}command') sessionid = in_command.get('sessionid', None) pointer = self.sessions[sessionid]['next'] - results = self.xmpp['xep_0004'].makeForm('result') + results = self.xmpp.plugin['xep_0004'].makeForm('result') results.fromXML(in_command.find('{jabber:x:data}x')) pointer(results,sessionid) self.xmpp.send(self.makeCommand(xml.attrib['from'], in_command.attrib['node'], form=None, id=xml.attrib['id'], sessionid=sessionid, status='completed', actions=[])) @@ -91,7 +92,7 @@ class xep_0050(base.base_plugin): in_command = xml.find('{http://jabber.org/protocol/commands}command') sessionid = in_command.get('sessionid', None) pointer = self.sessions[sessionid]['next'] - results = self.xmpp['xep_0004'].makeForm('result') + results = self.xmpp.plugin['xep_0004'].makeForm('result') results.fromXML(in_command.find('{jabber:x:data}x')) form, npointer, next = pointer(results,sessionid) self.sessions[sessionid]['next'] = npointer diff --git a/sleekxmpp/plugins/xep_0060.py b/sleekxmpp/plugins/xep_0060.py index 68c391f6..734dd3da 100644 --- a/sleekxmpp/plugins/xep_0060.py +++ b/sleekxmpp/plugins/xep_0060.py @@ -18,25 +18,26 @@ class xep_0060(base.base_plugin): create.set('node', node) pubsub.append(create) configure = ET.Element('configure') - if config is None: - submitform = self.xmpp.plugin['xep_0004'].makeForm('submit') - else: + #if config is None: + # submitform = self.xmpp.plugin['xep_0004'].makeForm('submit') + #else: + if config is not None: submitform = config - if 'FORM_TYPE' in submitform.field: - submitform.field['FORM_TYPE'].setValue('http://jabber.org/protocol/pubsub#node_config') - else: - submitform.addField('FORM_TYPE', 'hidden', value='http://jabber.org/protocol/pubsub#node_config') - if collection: - if 'pubsub#node_type' in submitform.field: - submitform.field['pubsub#node_type'].setValue('collection') + if 'FORM_TYPE' in submitform.field: + submitform.field['FORM_TYPE'].setValue('http://jabber.org/protocol/pubsub#node_config') else: - submitform.addField('pubsub#node_type', value='collection') - else: - if 'pubsub#node_type' in submitform.field: - submitform.field['pubsub#node_type'].setValue('leaf') + submitform.addField('FORM_TYPE', 'hidden', value='http://jabber.org/protocol/pubsub#node_config') + if collection: + if 'pubsub#node_type' in submitform.field: + submitform.field['pubsub#node_type'].setValue('collection') + else: + submitform.addField('pubsub#node_type', value='collection') else: - submitform.addField('pubsub#node_type', value='leaf') - configure.append(submitform.getXML('submit')) + if 'pubsub#node_type' in submitform.field: + submitform.field['pubsub#node_type'].setValue('leaf') + else: + submitform.addField('pubsub#node_type', value='leaf') + configure.append(submitform.getXML('submit')) pubsub.append(configure) iq = self.xmpp.makeIqSet(pubsub) iq.attrib['to'] = jid diff --git a/sleekxmpp/xmlstream/handler/callback.py b/sleekxmpp/xmlstream/handler/callback.py index dd507262..20e731f9 100644 --- a/sleekxmpp/xmlstream/handler/callback.py +++ b/sleekxmpp/xmlstream/handler/callback.py @@ -16,7 +16,6 @@ class Callback(base.BaseHandler): self.run(payload, True) def run(self, payload, instream=False): - logging.debug("Running %s in %s" % (self.name, self._pointer)) if not self._instream or instream: base.BaseHandler.run(self, payload) #if self._thread: diff --git a/sleekxmpp/xmlstream/handler/waiter.py b/sleekxmpp/xmlstream/handler/waiter.py index 2c91052d..57d96f9d 100644 --- a/sleekxmpp/xmlstream/handler/waiter.py +++ b/sleekxmpp/xmlstream/handler/waiter.py @@ -9,14 +9,12 @@ class Waiter(base.BaseHandler): self._payload = queue.Queue() def prerun(self, payload): - logging.debug("Putting into Waiter %s" % self.name) self._payload.put(payload) def run(self, payload): pass def wait(self, timeout=60): - logging.debug("Waiting on %s." % self.name) try: return self._payload.get(True, timeout) except queue.Empty: diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index bfad7cd9..8ffb7841 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -94,7 +94,6 @@ class XMLStream(object): self.socket = ssl.wrap_socket(self.socket) try: self.socket.connect(self.address) - logging.info("creating filesocket") self.filesocket = self.socket.makefile('rb', 0) self.state.set('connected', True) return True -- cgit v1.2.3