2010-03-26 14:32:16 -07:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2010 Nathanael C. Fritz
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
2010-07-20 08:19:49 -07:00
|
|
|
See the file LICENSE for copying permission.
|
2010-03-26 14:32:16 -07:00
|
|
|
"""
|
2010-07-19 21:04:34 -07:00
|
|
|
|
2009-12-10 17:29:46 -08:00
|
|
|
from . error import Error
|
2010-01-05 13:56:48 -08:00
|
|
|
from . rootstanza import RootStanza
|
2010-07-19 21:04:34 -07:00
|
|
|
from .. xmlstream.stanzabase import StanzaBase, ET
|
|
|
|
|
2009-06-03 15:56:51 -07:00
|
|
|
|
2010-01-05 13:56:48 -08:00
|
|
|
class Presence(RootStanza):
|
2010-07-19 21:04:34 -07:00
|
|
|
interfaces = set(('type', 'to', 'from', 'id', 'show', 'status', 'priority'))
|
2009-12-10 17:29:46 -08:00
|
|
|
types = set(('available', 'unavailable', 'error', 'probe', 'subscribe', 'subscribed', 'unsubscribe', 'unsubscribed'))
|
2010-02-26 18:02:08 -08:00
|
|
|
showtypes = set(('dnd', 'chat', 'xa', 'away'))
|
2010-07-19 21:04:34 -07:00
|
|
|
sub_interfaces = set(('show', 'status', 'priority'))
|
2009-12-10 17:29:46 -08:00
|
|
|
name = 'presence'
|
2010-04-14 01:23:17 -07:00
|
|
|
plugin_attrib = name
|
2009-12-10 17:29:46 -08:00
|
|
|
namespace = 'jabber:client'
|
2009-06-03 15:56:51 -07:00
|
|
|
|
2010-07-19 21:04:34 -07:00
|
|
|
def setShow(self, show):
|
|
|
|
if show in self.showtypes:
|
|
|
|
self._setSubText('show', text=show)
|
|
|
|
return self
|
2009-12-10 17:29:46 -08:00
|
|
|
|
|
|
|
def setType(self, value):
|
|
|
|
if value in self.types:
|
2010-07-19 21:04:34 -07:00
|
|
|
self['show'] = None
|
2010-01-23 01:08:21 -08:00
|
|
|
if value == 'available':
|
|
|
|
value = ''
|
|
|
|
self._setAttr('type', value)
|
|
|
|
elif value in self.showtypes:
|
2010-07-19 21:04:34 -07:00
|
|
|
self['show'] = value
|
2009-12-10 17:29:46 -08:00
|
|
|
return self
|
2009-06-03 15:56:51 -07:00
|
|
|
|
2009-12-10 17:29:46 -08:00
|
|
|
def setPriority(self, value):
|
2010-02-13 08:06:25 -08:00
|
|
|
self._setSubText('priority', text = str(value))
|
2009-12-10 17:29:46 -08:00
|
|
|
|
|
|
|
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:
|
2010-07-19 21:04:34 -07:00
|
|
|
out = self['show']
|
2009-12-10 17:29:46 -08:00
|
|
|
if not out or out is None:
|
|
|
|
out = 'available'
|
|
|
|
return out
|
|
|
|
|
2009-12-16 17:54:22 -08:00
|
|
|
def reply(self):
|
|
|
|
if self['type'] == 'unsubscribe':
|
|
|
|
self['type'] = 'unsubscribed'
|
|
|
|
elif self['type'] == 'subscribe':
|
|
|
|
self['type'] = 'subscribed'
|
|
|
|
return StanzaBase.reply(self)
|