mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
added form compatibility with old api, stanzas now bool() to True on 2.x, jid attributes will return '' if not set
This commit is contained in:
parent
c05ddcb7f5
commit
345656926e
5 changed files with 53 additions and 9 deletions
|
@ -285,6 +285,14 @@ class DefaultConfig(ElementBase):
|
||||||
if not t: t = 'leaf'
|
if not t: t = 'leaf'
|
||||||
return t
|
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(PubsubOwner, DefaultConfig)
|
||||||
registerStanzaPlugin(DefaultConfig, xep_0004.Form)
|
registerStanzaPlugin(DefaultConfig, xep_0004.Form)
|
||||||
|
|
||||||
|
@ -357,7 +365,16 @@ class OwnerDefault(OwnerConfigure):
|
||||||
plugin_attrib_map = {}
|
plugin_attrib_map = {}
|
||||||
plugin_tag_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(PubsubOwner, OwnerDefault)
|
||||||
|
registerStanzaPlugin(OwnerDefault, xep_0004.Form)
|
||||||
|
|
||||||
class OwnerDelete(ElementBase, OptionalSetting):
|
class OwnerDelete(ElementBase, OptionalSetting):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub#owner'
|
namespace = 'http://jabber.org/protocol/pubsub#owner'
|
||||||
|
|
|
@ -31,6 +31,7 @@ class Form(ElementBase):
|
||||||
ElementBase.__init__(self, *args, **kwargs)
|
ElementBase.__init__(self, *args, **kwargs)
|
||||||
if title is not None:
|
if title is not None:
|
||||||
self['title'] = title
|
self['title'] = title
|
||||||
|
self.field = FieldAccessor(self)
|
||||||
|
|
||||||
def setup(self, xml=None):
|
def setup(self, xml=None):
|
||||||
if ElementBase.setup(self, xml): #if we had to generate xml
|
if ElementBase.setup(self, xml): #if we had to generate xml
|
||||||
|
@ -196,6 +197,27 @@ class Form(ElementBase):
|
||||||
for field in values:
|
for field in values:
|
||||||
fields[field]['value'] = values[field]
|
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):
|
class FormField(ElementBase):
|
||||||
namespace = 'jabber:x:data'
|
namespace = 'jabber:x:data'
|
||||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
||||||
#from xml.etree import cElementTree as ET
|
#from xml.etree import cElementTree as ET
|
||||||
from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
|
from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
|
||||||
from . import stanza_pubsub
|
from . import stanza_pubsub
|
||||||
|
from . xep_0004 import Form
|
||||||
|
|
||||||
class xep_0060(base.base_plugin):
|
class xep_0060(base.base_plugin):
|
||||||
"""
|
"""
|
||||||
|
@ -41,7 +42,8 @@ class xep_0060(base.base_plugin):
|
||||||
submitform.field['pubsub#node_type'].setValue('leaf')
|
submitform.field['pubsub#node_type'].setValue('leaf')
|
||||||
else:
|
else:
|
||||||
submitform.addField('pubsub#node_type', value='leaf')
|
submitform.addField('pubsub#node_type', value='leaf')
|
||||||
configure.append(submitform.getXML('submit'))
|
submitform['type'] = 'submit'
|
||||||
|
configure.append(submitform.xml)
|
||||||
pubsub.append(configure)
|
pubsub.append(configure)
|
||||||
iq = self.xmpp.makeIqSet(pubsub)
|
iq = self.xmpp.makeIqSet(pubsub)
|
||||||
iq.attrib['to'] = jid
|
iq.attrib['to'] = jid
|
||||||
|
@ -117,7 +119,7 @@ class xep_0060(base.base_plugin):
|
||||||
if not form or form is None:
|
if not form or form is None:
|
||||||
logging.error("No form found.")
|
logging.error("No form found.")
|
||||||
return False
|
return False
|
||||||
return self.xmpp.plugin['xep_0004'].buildForm(form)
|
return Form(xml=form)
|
||||||
|
|
||||||
def getNodeSubscriptions(self, jid, node):
|
def getNodeSubscriptions(self, jid, node):
|
||||||
pubsub = ET.Element('{http://jabber.org/protocol/pubsub#owner}pubsub')
|
pubsub = ET.Element('{http://jabber.org/protocol/pubsub#owner}pubsub')
|
||||||
|
|
|
@ -59,24 +59,24 @@ class JID(object):
|
||||||
if name == 'resource':
|
if name == 'resource':
|
||||||
if self._resource is None:
|
if self._resource is None:
|
||||||
self._resource = self._jid.split('/', 1)[-1]
|
self._resource = self._jid.split('/', 1)[-1]
|
||||||
return self._resource
|
return self._resource or ""
|
||||||
elif name == 'user':
|
elif name == 'user':
|
||||||
if self._user is None:
|
if self._user is None:
|
||||||
if '@' in self._jid:
|
if '@' in self._jid:
|
||||||
self._user = self._jid.split('@', 1)[0]
|
self._user = self._jid.split('@', 1)[0]
|
||||||
else:
|
else:
|
||||||
self._user = self._user
|
self._user = self._user
|
||||||
return self._user
|
return self._user or ""
|
||||||
elif name in ('server', 'domain'):
|
elif name in ('server', 'domain'):
|
||||||
if self._domain is None:
|
if self._domain is None:
|
||||||
self._domain = self._jid.split('@', 1)[-1].split('/', 1)[0]
|
self._domain = self._jid.split('@', 1)[-1].split('/', 1)[0]
|
||||||
return self._domain
|
return self._domain or ""
|
||||||
elif name == 'full':
|
elif name == 'full':
|
||||||
return self._jid
|
return self._jid or ""
|
||||||
elif name == 'bare':
|
elif name == 'bare':
|
||||||
if self._bare is None:
|
if self._bare is None:
|
||||||
self._bare = self._jid.split('/', 1)[0]
|
self._bare = self._jid.split('/', 1)[0]
|
||||||
return self._bare
|
return self._bare or ""
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -362,7 +362,10 @@ class ElementBase(object):
|
||||||
self.idx = 0
|
self.idx = 0
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self): #python 3.x
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __nonzero__(self): #python 2.x
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
|
|
Loading…
Reference in a new issue