Resolve most Python3.3 related issues.

Tests now run successfully. Occasionally get single error related to
duplicated payload data in pubsub items when copying stanza values.
This commit is contained in:
Lance Stout 2013-02-14 01:24:09 -08:00
parent ec5e819b16
commit d8c9662302
9 changed files with 63 additions and 89 deletions

View File

@ -41,10 +41,11 @@ class FormField(ElementBase):
self._type = value self._type = value
def add_option(self, label='', value=''): def add_option(self, label='', value=''):
if self._type in self.option_types: if self._type is None or self._type in self.option_types:
opt = FieldOption(parent=self) opt = FieldOption()
opt['label'] = label opt['label'] = label
opt['value'] = value opt['value'] = value
self.append(opt)
else: else:
raise ValueError("Cannot add options to " + \ raise ValueError("Cannot add options to " + \
"a %s field." % self['type']) "a %s field." % self['type'])

View File

@ -65,7 +65,7 @@ class Form(ElementBase):
if kwtype is None: if kwtype is None:
kwtype = ftype kwtype = ftype
field = FormField(parent=self) field = FormField()
field['var'] = var field['var'] = var
field['type'] = kwtype field['type'] = kwtype
field['value'] = value field['value'] = value
@ -77,6 +77,7 @@ class Form(ElementBase):
field['options'] = options field['options'] = options
else: else:
del field['type'] del field['type']
self.append(field)
return field return field
def getXML(self, type='submit'): def getXML(self, type='submit'):
@ -144,10 +145,9 @@ class Form(ElementBase):
def get_fields(self, use_dict=False): def get_fields(self, use_dict=False):
fields = OrderedDict() fields = OrderedDict()
fieldsXML = self.xml.findall('{%s}field' % FormField.namespace) for stanza in self['substanzas']:
for fieldXML in fieldsXML: if isinstance(stanza, FormField):
field = FormField(xml=fieldXML) fields[stanza['var']] = stanza
fields[field['var']] = field
return fields return fields
def get_instructions(self): def get_instructions(self):
@ -221,6 +221,8 @@ class Form(ElementBase):
def set_values(self, values): def set_values(self, values):
fields = self['fields'] fields = self['fields']
for field in values: for field in values:
if field not in fields:
fields[field] = self.add_field(var=field)
fields[field]['value'] = values[field] fields[field]['value'] = values[field]
def merge(self, other): def merge(self, other):

View File

@ -423,7 +423,7 @@ class XEP_0060(BasePlugin):
callback=None, timeout=None): callback=None, timeout=None):
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set') iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
iq['pubsub_owner']['configure']['node'] = node iq['pubsub_owner']['configure']['node'] = node
iq['pubsub_owner']['configure']['form'].values = config.values iq['pubsub_owner']['configure'].append(config)
return iq.send(block=block, callback=callback, timeout=timeout) return iq.send(block=block, callback=callback, timeout=timeout)
def publish(self, jid, node, id=None, payload=None, options=None, def publish(self, jid, node, id=None, payload=None, options=None,

View File

@ -74,7 +74,12 @@ class Item(ElementBase):
def set_payload(self, value): def set_payload(self, value):
del self['payload'] del self['payload']
self.append(value) if isinstance(value, ElementBase):
if value.tag_name() in self.plugin_tag_map:
self.init_plugin(value.plugin_attrib, existing_xml=value.xml)
self.xml.append(value.xml)
else:
self.xml.append(value)
def get_payload(self): def get_payload(self):
childs = list(self.xml) childs = list(self.xml)
@ -243,39 +248,6 @@ class PublishOptions(ElementBase):
self.parent().xml.remove(self.xml) self.parent().xml.remove(self.xml)
class PubsubState(ElementBase):
"""This is an experimental pubsub extension."""
namespace = 'http://jabber.org/protocol/psstate'
name = 'state'
plugin_attrib = 'psstate'
interfaces = set(('node', 'item', 'payload'))
def set_payload(self, value):
self.xml.append(value)
def get_payload(self):
childs = list(self.xml)
if len(childs) > 0:
return childs[0]
def del_payload(self):
for child in self.xml:
self.xml.remove(child)
class PubsubStateEvent(ElementBase):
"""This is an experimental pubsub extension."""
namespace = 'http://jabber.org/protocol/psstate#event'
name = 'event'
plugin_attrib = 'psstate_event'
intefaces = set(tuple())
register_stanza_plugin(Iq, PubsubState)
register_stanza_plugin(Message, PubsubStateEvent)
register_stanza_plugin(PubsubStateEvent, PubsubState)
register_stanza_plugin(Iq, Pubsub) register_stanza_plugin(Iq, Pubsub)
register_stanza_plugin(Pubsub, Affiliations) register_stanza_plugin(Pubsub, Affiliations)
register_stanza_plugin(Pubsub, Configure) register_stanza_plugin(Pubsub, Configure)

View File

@ -34,7 +34,8 @@ class DefaultConfig(ElementBase):
return self['form'] return self['form']
def set_config(self, value): def set_config(self, value):
self['form'].values = value.values del self['from']
self.append(value)
return self return self

View File

@ -115,6 +115,10 @@ class Iq(RootStanza):
""" """
query = self.xml.find("{%s}query" % value) query = self.xml.find("{%s}query" % value)
if query is None and value: if query is None and value:
plugin = self.plugin_tag_map.get('{%s}query' % value, None)
if plugin:
self.enable(plugin.plugin_attrib)
else:
self.clear() self.clear()
query = ET.Element("{%s}query" % value) query = ET.Element("{%s}query" % value)
self.xml.append(query) self.xml.append(query)

View File

@ -3,7 +3,7 @@
sleekxmpp.xmlstream.stanzabase sleekxmpp.xmlstream.stanzabase
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This module implements a wrapper layer for XML objects module implements a wrapper layer for XML objects
that allows them to be treated like dictionaries. that allows them to be treated like dictionaries.
Part of SleekXMPP: The Sleek XMPP Library Part of SleekXMPP: The Sleek XMPP Library
@ -141,7 +141,7 @@ def multifactory(stanza, plugin_attrib):
parent.loaded_plugins.remove(plugin_attrib) parent.loaded_plugins.remove(plugin_attrib)
try: try:
parent.xml.remove(self.xml) parent.xml.remove(self.xml)
except: except ValueError:
pass pass
else: else:
for stanza in list(res): for stanza in list(res):
@ -596,20 +596,20 @@ class ElementBase(object):
iterable_interfaces = [p.plugin_attrib for \ iterable_interfaces = [p.plugin_attrib for \
p in self.plugin_iterables] p in self.plugin_iterables]
for interface, value in values.items(): if 'lang' in values:
full_interface = interface self['lang'] = values['lang']
interface_lang = ('%s|' % interface).split('|')
interface = interface_lang[0]
lang = interface_lang[1] or self.get_lang()
if interface == 'substanzas': if 'substanzas' in values:
# Remove existing substanzas # Remove existing substanzas
for stanza in self.iterables: for stanza in self.iterables:
try:
self.xml.remove(stanza.xml) self.xml.remove(stanza.xml)
except ValueError:
pass
self.iterables = [] self.iterables = []
# Add new substanzas # Add new substanzas
for subdict in value: for subdict in values['substanzas']:
if '__childtag__' in subdict: if '__childtag__' in subdict:
for subclass in self.plugin_iterables: for subclass in self.plugin_iterables:
child_tag = "{%s}%s" % (subclass.namespace, child_tag = "{%s}%s" % (subclass.namespace,
@ -618,9 +618,17 @@ class ElementBase(object):
sub = subclass(parent=self) sub = subclass(parent=self)
sub.values = subdict sub.values = subdict
self.iterables.append(sub) self.iterables.append(sub)
break
elif interface == 'lang': for interface, value in values.items():
self[interface] = value full_interface = interface
interface_lang = ('%s|' % interface).split('|')
interface = interface_lang[0]
lang = interface_lang[1] or self.get_lang()
if interface == 'lang':
continue
elif interface == 'substanzas':
continue
elif interface in self.interfaces: elif interface in self.interfaces:
self[full_interface] = value self[full_interface] = value
elif interface in self.plugin_attrib_map: elif interface in self.plugin_attrib_map:
@ -866,7 +874,7 @@ class ElementBase(object):
self.loaded_plugins.remove(attrib) self.loaded_plugins.remove(attrib)
try: try:
self.xml.remove(plugin.xml) self.xml.remove(plugin.xml)
except: except ValueError:
pass pass
return self return self

View File

@ -129,20 +129,6 @@ class TestPubsubStanzas(SleekTest):
</pubsub> </pubsub>
</iq>""") </iq>""")
def testState(self):
"Testing iq/psstate stanzas"
iq = self.Iq()
iq['psstate']['node']= 'mynode'
iq['psstate']['item']= 'myitem'
pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed')
iq['psstate']['payload'] = pl
self.check(iq, """
<iq id="0">
<state xmlns="http://jabber.org/protocol/psstate" node="mynode" item="myitem">
<claimed xmlns="http://andyet.net/protocol/pubsubqueue" />
</state>
</iq>""")
def testDefault(self): def testDefault(self):
"Testing iq/pubsub_owner/default stanzas" "Testing iq/pubsub_owner/default stanzas"
iq = self.Iq() iq = self.Iq()

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py26,py27,py31,py32 envlist = py26,py27,py31,py32,py33
[testenv] [testenv]
deps = nose deps = nose
commands = nosetests --where=tests --exclude=live -i sleektest.py commands = nosetests --where=tests --exclude=live -i sleektest.py