Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #397 from rerobins/xep_0050_updates
Browse files Browse the repository at this point in the history
Xep 0050 updates
  • Loading branch information
bear committed Sep 18, 2015
2 parents d245558 + c2dc44c commit 4305edd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sleekxmpp/plugins/xep_0050/adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def plugin_init(self):
self._handle_command))

register_stanza_plugin(Iq, Command)
register_stanza_plugin(Command, Form)
register_stanza_plugin(Command, Form, iterable=True)

self.xmpp.add_event_handler('command_execute',
self._handle_command_start,
Expand Down Expand Up @@ -425,12 +425,25 @@ def _handle_command_complete(self, iq):

del self.sessions[sessionid]

payload = session['payload']
if payload is None:
payload = []
if not isinstance(payload, list):
payload = [payload]

for item in payload:
register_stanza_plugin(Command, item.__class__, iterable=True)

iq.reply()
iq['command']['node'] = node
iq['command']['sessionid'] = sessionid
iq['command']['actions'] = []
iq['command']['status'] = 'completed'
iq['command']['notes'] = session['notes']

for item in payload:
iq['command'].append(item)

iq.send()
else:
raise XMPPError('item-not-found')
Expand Down
3 changes: 3 additions & 0 deletions tests/test_stream_xep_0050.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def handle_command(iq, session):

def handle_form(form, session):
results.append(form.get_values()['foo'])
session['payload'] = None

form = self.xmpp['xep_0004'].makeForm('form')
form.addField(var='foo', ftype='text-single', label='Foo')
Expand Down Expand Up @@ -192,6 +193,7 @@ def handle_command(iq, session):

def handle_step2(form, session):
results.append(form.get_values()['bar'])
session['payload'] = None

def handle_step1(form, session):
results.append(form.get_values()['foo'])
Expand Down Expand Up @@ -427,6 +429,7 @@ def handle_command(iq, session):
def handle_form(forms, session):
for form in forms:
results.append(form.get_values()['FORM_TYPE'])
session['payload'] = None

form1 = self.xmpp['xep_0004'].makeForm('form')
form1.addField(var='FORM_TYPE', ftype='hidden', value='form_1')
Expand Down

0 comments on commit 4305edd

Please sign in to comment.