* started converstion to stanza objects
This commit is contained in:
@@ -1,21 +1,51 @@
|
||||
from .. xmlstream.stanzabase import StanzaBase
|
||||
from .. xmlstream import xmlstream as xmlstreammod
|
||||
from .. xmlstream.matcher.xpath import MatchXPath
|
||||
from xml.etree import cElementTree as ET
|
||||
from . error import Error
|
||||
|
||||
#_bases = [StanzaBase] + xmlstreammod.stanza_extensions.get('PresenceStanza', [])
|
||||
class Presence(StanzaBase):
|
||||
interfaces = set(('type', 'to', 'from', 'id', 'status', 'priority'))
|
||||
types = set(('available', 'unavailable', 'error', 'probe', 'subscribe', 'subscribed', 'unsubscribe', 'unsubscribed'))
|
||||
showtypes = set(('dnd', 'ffc', 'xa', 'away'))
|
||||
sub_interfaces = set(('status', 'priority'))
|
||||
name = 'presence'
|
||||
namespace = 'jabber:client'
|
||||
|
||||
#class PresenceStanza(*_bases):
|
||||
class PresenceStanza(StanzaBase):
|
||||
def getShowElement(self):
|
||||
return self.xml.find("{%s}show" % self.namespace)
|
||||
|
||||
def setType(self, value):
|
||||
if value in self.types:
|
||||
show = self.getShowElement()
|
||||
if value in self.types:
|
||||
if show is not None:
|
||||
self.xml.remove(show)
|
||||
self._setAttr('type', value)
|
||||
elif value in self.showtypes:
|
||||
if show is None:
|
||||
show = ET.Element("{%s}show" % self.namespace)
|
||||
show.text = value
|
||||
return self
|
||||
|
||||
def setPriority(self, value):
|
||||
self._setSubText('priority', str(value))
|
||||
|
||||
def __init__(self, stream, xml=None):
|
||||
self.pfrom = ''
|
||||
self.pto = ''
|
||||
StanzaBase.__init__(self, stream, xml, xmlstreammod.stanza_extensions.get('PresenceStanza', []))
|
||||
def getPriority(self):
|
||||
p = self._getSubText('priority')
|
||||
if not p: p = 0
|
||||
return int(p)
|
||||
|
||||
def getType(self):
|
||||
out = self._getAttr('type')
|
||||
if not out:
|
||||
show = self.getShowElement()
|
||||
if show is not None:
|
||||
out = show.text
|
||||
if not out or out is None:
|
||||
out = 'available'
|
||||
return out
|
||||
|
||||
def delType(self):
|
||||
self.setType('available')
|
||||
|
||||
def fromXML(self, xml):
|
||||
StanzaBase.fromXML(self, xml)
|
||||
self.pfrom = xml.get('from')
|
||||
self.pto = xml.get('to')
|
||||
self.ptype = xml.get('type')
|
||||
|
||||
stanzas = ({'stanza_class': PresenceStanza, 'matcher': MatchXPath('{jabber:client}presence'), 'root': True},)
|
||||
Presence.plugin_attrib_map['error'] = Error
|
||||
Presence.plugin_tag_map["{%s}%s" % (Error.namespace, Error.name)] = Error
|
||||
|
||||
Reference in New Issue
Block a user