From 4375ac7d8b9e62f34a4d3754a90b3538d5e978a3 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sun, 17 Oct 2010 21:38:22 -0400 Subject: Underscore names by default. Stanza objects now accept the use of underscored names. The CamelCase versions are still available for backwards compatibility, but are discouraged. The property stanza.values now maps to the old getStanzaValues and setStanzaValues, in addition to _set_stanza_values and _get_stanza_values. --- sleekxmpp/stanza/presence.py | 83 +++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 31 deletions(-) (limited to 'sleekxmpp/stanza/presence.py') diff --git a/sleekxmpp/stanza/presence.py b/sleekxmpp/stanza/presence.py index cb957221..964ef11a 100644 --- a/sleekxmpp/stanza/presence.py +++ b/sleekxmpp/stanza/presence.py @@ -8,7 +8,7 @@ from sleekxmpp.stanza import Error from sleekxmpp.stanza.rootstanza import RootStanza -from sleekxmpp.xmlstream.stanzabase import StanzaBase, ET +from sleekxmpp.xmlstream import StanzaBase, ET class Presence(RootStanza): @@ -52,12 +52,13 @@ class Presence(RootStanza): showtypes -- One of: away, chat, dnd, and xa. Methods: - reply -- Overrides StanzaBase.reply - setShow -- Set the value of the element. - getType -- Get the value of the type attribute or element. - setType -- Set the value of the type attribute or element. - getPriority -- Get the value of the element. - setPriority -- Set the value of the element. + setup -- Overrides StanzaBase.setup + reply -- Overrides StanzaBase.reply + set_show -- Set the value of the element. + get_type -- Get the value of the type attribute or element. + set_type -- Set the value of the type attribute or element. + get_priority -- Get the value of the element. + set_priority -- Set the value of the element. """ namespace = 'jabber:client' @@ -71,7 +72,27 @@ class Presence(RootStanza): 'subscribed', 'unsubscribe', 'unsubscribed')) showtypes = set(('dnd', 'chat', 'xa', 'away')) - def setShow(self, show): + def setup(self, xml=None): + """ + Populate the stanza object using an optional XML object. + + Overrides ElementBase.setup. + + Arguments: + xml -- Use an existing XML object for the stanza's values. + """ + # To comply with PEP8, method names now use underscores. + # Deprecated method names are re-mapped for backwards compatibility. + self.setShow = self.set_show + self.getType = self.get_type + self.setType = self.set_type + self.delType = self.get_type + self.getPriority = self.get_priority + self.setPriority = self.set_priority + + return StanzaBase.setup(self, xml) + + def set_show(self, show): """ Set the value of the element. @@ -79,12 +100,24 @@ class Presence(RootStanza): show -- Must be one of: away, chat, dnd, or xa. """ if show is None: - self._delSub('show') + self._del_sub('show') elif show in self.showtypes: - self._setSubText('show', text=show) + self._set_sub_text('show', text=show) return self - def setType(self, value): + def get_type(self): + """ + Return the value of the stanza's type attribute, or + the value of the element. + """ + out = self._get_attr('type') + if not out: + out = self['show'] + if not out or out is None: + out = 'available' + return out + + def set_type(self, value): """ Set the type attribute's value, and the element if applicable. @@ -96,19 +129,19 @@ class Presence(RootStanza): self['show'] = None if value == 'available': value = '' - self._setAttr('type', value) + self._set_attr('type', value) elif value in self.showtypes: self['show'] = value return self - def delType(self): + def del_type(self): """ Remove both the type attribute and the element. """ - self._delAttr('type') - self._delSub('show') + self._del_attr('type') + self._del_sub('show') - def setPriority(self, value): + def set_priority(self, value): """ Set the entity's priority value. Some server use priority to determine message routing behavior. @@ -119,13 +152,13 @@ class Presence(RootStanza): Arguments: value -- An integer value greater than or equal to 0. """ - self._setSubText('priority', text=str(value)) + self._set_sub_text('priority', text=str(value)) - def getPriority(self): + def get_priority(self): """ Return the value of the element as an integer. """ - p = self._getSubText('priority') + p = self._get_sub_text('priority') if not p: p = 0 try: @@ -134,18 +167,6 @@ class Presence(RootStanza): # The priority is not a number: we consider it 0 as a default return 0 - def getType(self): - """ - Return the value of the stanza's type attribute, or - the value of the element. - """ - out = self._getAttr('type') - if not out: - out = self['show'] - if not out or out is None: - out = 'available' - return out - def reply(self): """ Set the appropriate presence reply type. -- cgit v1.2.3