mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
* added error, htmlim, roster, and nick stanza plugins
This commit is contained in:
parent
ca044a4934
commit
6897a0b57c
4 changed files with 140 additions and 0 deletions
55
sleekxmpp/stanza/error.py
Normal file
55
sleekxmpp/stanza/error.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
from .. xmlstream.stanzabase import ElementBase, ET
|
||||
|
||||
class Error(ElementBase):
|
||||
namespace = 'jabber:client'
|
||||
name = 'error'
|
||||
plugin_attrib = 'error'
|
||||
conditions = set(('bad-request', 'conflict', 'feature-not-implemented', 'forbidden', 'gone', 'item-not-found', 'jid-malformed', 'not-acceptable', 'not-allowed', 'not-authorized', 'payment-required', 'recipient-unavailable', 'redirect', 'registration-required', 'remote-server-not-found', 'remote-server-timeout', 'service-unavailable', 'subscription-required', 'undefined-condition', 'unexpected-request'))
|
||||
interfaces = set(('condition', 'text', 'type'))
|
||||
types = set(('cancel', 'continue', 'modify', 'auth', 'wait'))
|
||||
sub_interfaces = set(('text',))
|
||||
condition_ns = 'urn:ietf:params:xml:ns:xmpp-stanzas'
|
||||
|
||||
def setup(self, xml=None):
|
||||
if ElementBase.setup(self, xml): #if we had to generate xml
|
||||
self['type'] = 'cancel'
|
||||
self['condition'] = 'feature-not-implemented'
|
||||
if self.parent is not None:
|
||||
self.parent['type'] = 'error'
|
||||
|
||||
def getCondition(self):
|
||||
for child in self.xml.getchildren():
|
||||
if "{%s}" % self.condition_ns in child.tag:
|
||||
return child.tag.split('}', 1)[-1]
|
||||
return ''
|
||||
|
||||
def setCondition(self, value):
|
||||
if value in self.conditions:
|
||||
for child in self.xml.getchildren():
|
||||
if "{%s}" % self.condition_ns in child.tag:
|
||||
self.xml.remove(child)
|
||||
condition = ET.Element("{%s}%s" % (self.condition_ns, value))
|
||||
self.xml.append(condition)
|
||||
return self
|
||||
|
||||
def delCondition(self):
|
||||
return self
|
||||
|
||||
def getText(self):
|
||||
text = ''
|
||||
textxml = self.xml.find("{urn:ietf:params:xml:ns:xmpp-stanzas}text")
|
||||
if textxml is not None:
|
||||
text = textxml.text
|
||||
return text
|
||||
|
||||
def setText(self, value):
|
||||
self.delText()
|
||||
textxml = ET.Element('{urn:ietf:params:xml:ns:xmpp-stanzas}text')
|
||||
textxml.text = value
|
||||
self.xml.append(textxml)
|
||||
return self
|
||||
|
||||
def delText(self):
|
||||
textxml = self.xml.find("{urn:ietf:params:xml:ns:xmpp-stanzas}text")
|
||||
if textxml is not None:
|
||||
self.xml.remove(textxml)
|
25
sleekxmpp/stanza/htmlim.py
Normal file
25
sleekxmpp/stanza/htmlim.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from .. xmlstream.stanzabase import ElementBase, ET
|
||||
|
||||
class HTMLIM(ElementBase):
|
||||
namespace = 'http://jabber.org/protocol/xhtml-im'
|
||||
name = 'html'
|
||||
plugin_attrib = 'html'
|
||||
interfaces = set(('html'))
|
||||
|
||||
def setHtml(self, html):
|
||||
if issinstance(html, str):
|
||||
html = ET.XML(html)
|
||||
if html.find('{http://www.w3.org/1999/xhtml}body') is None:
|
||||
body = ET.Element('{http://www.w3.org/1999/xhtml}body')
|
||||
body.append(html)
|
||||
else:
|
||||
body = html
|
||||
self.xml.append(html)
|
||||
|
||||
def getHtml(self):
|
||||
html = self.xml.find('{http://www.w3.org/1999/xhtml}body')
|
||||
if html is None: return ''
|
||||
return __str__(html)
|
||||
|
||||
def delHtml(self):
|
||||
return self.__del__()
|
16
sleekxmpp/stanza/nick.py
Normal file
16
sleekxmpp/stanza/nick.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from .. xmlstream.stanzabase import ElementBase, ET
|
||||
|
||||
class HTMLIM(ElementBase):
|
||||
namespace = 'http://jabber.org/nick/nick'
|
||||
name = 'nick'
|
||||
plugin_attrib = 'nick'
|
||||
interfaces = set(('nick'))
|
||||
|
||||
def setNick(self, nick):
|
||||
self.xml.text = nick
|
||||
|
||||
def getNick(self):
|
||||
return self.xml.text
|
||||
|
||||
def delNick(self):
|
||||
return self.__del__()
|
44
sleekxmpp/stanza/roster.py
Normal file
44
sleekxmpp/stanza/roster.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from .. xmlstream.stanzabase import ElementBase, ET, JID
|
||||
|
||||
class Roster(ElementBase):
|
||||
namespace = 'jabber:iq:roster'
|
||||
name = 'query'
|
||||
plugin_attrib = 'roster'
|
||||
interfaces = set(('items',))
|
||||
|
||||
def setItems(self, items):
|
||||
self.delItems()
|
||||
for jid in items:
|
||||
ijid = str(jid)
|
||||
item = ET.Element('{jabber:iq:roster}item', {'jid': ijid})
|
||||
if 'subscription' in items[jid]:
|
||||
item.attrib['subscription'] = items[jid]['subscription']
|
||||
if 'name' in items[jid]:
|
||||
item.attrib['name'] = items[jid]['name']
|
||||
if 'groups' in items[jid]:
|
||||
for group in items[jid]['groups']:
|
||||
groupxml = ET.Element('{jabber:iq:roster}group')
|
||||
groupxml.text = group
|
||||
item.append(groupxml)
|
||||
self.xml.append(item)
|
||||
return self
|
||||
|
||||
def getItems(self):
|
||||
items = {}
|
||||
itemsxml = self.xml.findall('{jabber:iq:roster}item')
|
||||
if itemsxml is not None:
|
||||
item = {}
|
||||
for itemxml in itemsxml:
|
||||
item['name'] = itemxml.get('name', '')
|
||||
item['subscription'] = itemxml.get('subscription', '')
|
||||
item['groups'] = []
|
||||
groupsxml = itemxml.findall('{jabber:iq:roster}group')
|
||||
if groupsxml is not None:
|
||||
for groupxml in groupsxml:
|
||||
item['groups'].append(groupxml.text)
|
||||
items[JID(itemxml.get('jid'))] = item
|
||||
return items
|
||||
|
||||
def delItems(self):
|
||||
for child in self.xml.getchildren():
|
||||
self.xml.remove(child)
|
Loading…
Reference in a new issue