Fix usage of the 0004 plugin interface
form['fields'] is an ordered list of fields while most plugins expect a dict there. Fixes, among other things, a caps bug.
This commit is contained in:
parent
20e88fda50
commit
e177726387
@ -23,7 +23,7 @@ class Form(ElementBase):
|
|||||||
namespace = 'jabber:x:data'
|
namespace = 'jabber:x:data'
|
||||||
name = 'x'
|
name = 'x'
|
||||||
plugin_attrib = 'form'
|
plugin_attrib = 'form'
|
||||||
interfaces = OrderedSet(('instructions', 'reported', 'title', 'type', 'items', ))
|
interfaces = OrderedSet(('instructions', 'reported', 'title', 'type', 'items', 'values'))
|
||||||
sub_interfaces = {'title'}
|
sub_interfaces = {'title'}
|
||||||
form_types = {'cancel', 'form', 'result', 'submit'}
|
form_types = {'cancel', 'form', 'result', 'submit'}
|
||||||
|
|
||||||
|
@ -185,14 +185,14 @@ class XEP_0060(BasePlugin):
|
|||||||
|
|
||||||
if config is not None:
|
if config is not None:
|
||||||
form_type = 'http://jabber.org/protocol/pubsub#node_config'
|
form_type = 'http://jabber.org/protocol/pubsub#node_config'
|
||||||
if 'FORM_TYPE' in config['fields']:
|
if 'FORM_TYPE' in config.get_fields():
|
||||||
config.field['FORM_TYPE']['value'] = form_type
|
config.field['FORM_TYPE']['value'] = form_type
|
||||||
else:
|
else:
|
||||||
config.add_field(var='FORM_TYPE',
|
config.add_field(var='FORM_TYPE',
|
||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
value=form_type)
|
value=form_type)
|
||||||
if ntype:
|
if ntype:
|
||||||
if 'pubsub#node_type' in config['fields']:
|
if 'pubsub#node_type' in config.get_fields():
|
||||||
config.field['pubsub#node_type']['value'] = ntype
|
config.field['pubsub#node_type']['value'] = ntype
|
||||||
else:
|
else:
|
||||||
config.add_field(var='pubsub#node_type', value=ntype)
|
config.add_field(var='pubsub#node_type', value=ntype)
|
||||||
|
@ -97,7 +97,7 @@ class XEP_0095(BasePlugin):
|
|||||||
extension='bad-profile',
|
extension='bad-profile',
|
||||||
extension_ns=SI.namespace)
|
extension_ns=SI.namespace)
|
||||||
|
|
||||||
neg = iq['si']['feature_neg']['form']['fields']
|
neg = iq['si']['feature_neg']['form'].get_fields()
|
||||||
options = neg['stream-method']['options'] or []
|
options = neg['stream-method']['options'] or []
|
||||||
methods = []
|
methods = []
|
||||||
for opt in options:
|
for opt in options:
|
||||||
|
@ -199,8 +199,8 @@ class XEP_0115(BasePlugin):
|
|||||||
log.debug("Non form extension found, ignoring for caps")
|
log.debug("Non form extension found, ignoring for caps")
|
||||||
caps.xml.remove(stanza.xml)
|
caps.xml.remove(stanza.xml)
|
||||||
continue
|
continue
|
||||||
if 'FORM_TYPE' in stanza['fields']:
|
if 'FORM_TYPE' in stanza.get_fields():
|
||||||
f_type = tuple(stanza['fields']['FORM_TYPE']['value'])
|
f_type = tuple(stanza.get_fields()['FORM_TYPE']['value'])
|
||||||
form_types.append(f_type)
|
form_types.append(f_type)
|
||||||
deduped_form_types.add(f_type)
|
deduped_form_types.add(f_type)
|
||||||
if len(form_types) != len(deduped_form_types):
|
if len(form_types) != len(deduped_form_types):
|
||||||
@ -214,7 +214,7 @@ class XEP_0115(BasePlugin):
|
|||||||
log.debug("Extra FORM_TYPE data, invalid for caps")
|
log.debug("Extra FORM_TYPE data, invalid for caps")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if stanza['fields']['FORM_TYPE']['type'] != 'hidden':
|
if stanza.get_fields()['FORM_TYPE']['type'] != 'hidden':
|
||||||
log.debug("Field FORM_TYPE type not 'hidden', " + \
|
log.debug("Field FORM_TYPE type not 'hidden', " + \
|
||||||
"ignoring form for caps")
|
"ignoring form for caps")
|
||||||
caps.xml.remove(stanza.xml)
|
caps.xml.remove(stanza.xml)
|
||||||
@ -253,7 +253,7 @@ class XEP_0115(BasePlugin):
|
|||||||
|
|
||||||
for stanza in info['substanzas']:
|
for stanza in info['substanzas']:
|
||||||
if isinstance(stanza, self.xmpp['xep_0004'].stanza.Form):
|
if isinstance(stanza, self.xmpp['xep_0004'].stanza.Form):
|
||||||
if 'FORM_TYPE' in stanza['fields']:
|
if 'FORM_TYPE' in stanza.get_fields():
|
||||||
f_type = stanza['values']['FORM_TYPE']
|
f_type = stanza['values']['FORM_TYPE']
|
||||||
if len(f_type):
|
if len(f_type):
|
||||||
f_type = f_type[0]
|
f_type = f_type[0]
|
||||||
@ -265,11 +265,11 @@ class XEP_0115(BasePlugin):
|
|||||||
for f_type in sorted_forms:
|
for f_type in sorted_forms:
|
||||||
for form in form_types[f_type]:
|
for form in form_types[f_type]:
|
||||||
S += '%s<' % f_type
|
S += '%s<' % f_type
|
||||||
fields = sorted(form['fields'].keys())
|
fields = sorted(form.get_fields().keys())
|
||||||
fields.remove('FORM_TYPE')
|
fields.remove('FORM_TYPE')
|
||||||
for field in fields:
|
for field in fields:
|
||||||
S += '%s<' % field
|
S += '%s<' % field
|
||||||
vals = form['fields'][field].get_value(convert=False)
|
vals = form.get_fields()[field].get_value(convert=False)
|
||||||
if vals is None:
|
if vals is None:
|
||||||
S += '<'
|
S += '<'
|
||||||
else:
|
else:
|
||||||
|
@ -73,11 +73,11 @@ class XEP_0222(BasePlugin):
|
|||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
value='http://jabber.org/protocol/pubsub#publish-options')
|
value='http://jabber.org/protocol/pubsub#publish-options')
|
||||||
|
|
||||||
fields = options['fields']
|
fields = options.get_fields()
|
||||||
for field, value in self.profile.items():
|
for field, value in self.profile.items():
|
||||||
if field not in fields:
|
if field not in fields:
|
||||||
options.add_field(var=field)
|
options.add_field(var=field)
|
||||||
options['fields'][field]['value'] = value
|
options.get_fields()[field]['value'] = value
|
||||||
|
|
||||||
return self.xmpp['xep_0163'].publish(stanza, node,
|
return self.xmpp['xep_0163'].publish(stanza, node,
|
||||||
options=options,
|
options=options,
|
||||||
|
@ -78,7 +78,7 @@ class XEP_0223(BasePlugin):
|
|||||||
for field, value in self.profile.items():
|
for field, value in self.profile.items():
|
||||||
if field not in fields:
|
if field not in fields:
|
||||||
options.add_field(var=field)
|
options.add_field(var=field)
|
||||||
options['fields'][field]['value'] = value
|
options.get_fields()[field]['value'] = value
|
||||||
|
|
||||||
return self.xmpp['xep_0163'].publish(stanza, node, options=options,
|
return self.xmpp['xep_0163'].publish(stanza, node, options=options,
|
||||||
ifrom=ifrom, callback=callback,
|
ifrom=ifrom, callback=callback,
|
||||||
|
Loading…
Reference in New Issue
Block a user