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/roster.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'sleekxmpp/stanza/roster.py') diff --git a/sleekxmpp/stanza/roster.py b/sleekxmpp/stanza/roster.py index 292c8956..8f154a22 100644 --- a/sleekxmpp/stanza/roster.py +++ b/sleekxmpp/stanza/roster.py @@ -8,8 +8,7 @@ from sleekxmpp.stanza import Iq from sleekxmpp.xmlstream import JID -from sleekxmpp.xmlstream.stanzabase import registerStanzaPlugin -from sleekxmpp.xmlstream.stanzabase import ET, ElementBase +from sleekxmpp.xmlstream import ET, ElementBase, register_stanza_plugin class Roster(ElementBase): @@ -29,9 +28,9 @@ class Roster(ElementBase): in the stanza. Methods: - getItems -- Return a dictionary of roster entries. - setItems -- Add elements. - delItems -- Remove all elements. + get_items -- Return a dictionary of roster entries. + set_items -- Add elements. + del_items -- Remove all elements. """ namespace = 'jabber:iq:roster' @@ -39,7 +38,24 @@ class Roster(ElementBase): plugin_attrib = 'roster' interfaces = set(('items',)) - def setItems(self, items): + def setup(self, xml=None): + """ + Populate the stanza object using an optional XML object. + + Overrides StanzaBase.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.setItems = self.set_items + self.getItems = self.get_items + self.delItems = self.del_items + + return ElementBase.setup(self, xml) + + def set_items(self, items): """ Set the roster entries in the stanza. @@ -54,7 +70,7 @@ class Roster(ElementBase): Arguments: items -- A dictionary of roster entries. """ - self.delItems() + self.del_items() for jid in items: ijid = str(jid) item = ET.Element('{jabber:iq:roster}item', {'jid': ijid}) @@ -72,7 +88,7 @@ class Roster(ElementBase): self.xml.append(item) return self - def getItems(self): + def get_items(self): """ Return a dictionary of roster entries. @@ -98,7 +114,7 @@ class Roster(ElementBase): items[itemxml.get('jid')] = item return items - def delItems(self): + def del_items(self): """ Remove all elements from the roster stanza. """ @@ -106,4 +122,4 @@ class Roster(ElementBase): self.xml.remove(child) -registerStanzaPlugin(Iq, Roster) +register_stanza_plugin(Iq, Roster) -- cgit v1.2.3