diff options
author | Lance Stout <lancestout@gmail.com> | 2010-10-17 21:38:22 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-10-17 22:04:42 -0400 |
commit | 4375ac7d8b9e62f34a4d3754a90b3538d5e978a3 (patch) | |
tree | c7da6dddc72ecd299f16d5dd82a4d81f8b0146fa /sleekxmpp/stanza/roster.py | |
parent | faec86b3be38756510fb3534c7615db75ecd53b7 (diff) | |
download | slixmpp-4375ac7d8b9e62f34a4d3754a90b3538d5e978a3.tar.gz slixmpp-4375ac7d8b9e62f34a4d3754a90b3538d5e978a3.tar.bz2 slixmpp-4375ac7d8b9e62f34a4d3754a90b3538d5e978a3.tar.xz slixmpp-4375ac7d8b9e62f34a4d3754a90b3538d5e978a3.zip |
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.
Diffstat (limited to 'sleekxmpp/stanza/roster.py')
-rw-r--r-- | sleekxmpp/stanza/roster.py | 36 |
1 files changed, 26 insertions, 10 deletions
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 <item> elements. - delItems -- Remove all <item> elements. + get_items -- Return a dictionary of roster entries. + set_items -- Add <item> elements. + del_items -- Remove all <item> 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 <roster> 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 <item> elements from the roster stanza. """ @@ -106,4 +122,4 @@ class Roster(ElementBase): self.xml.remove(child) -registerStanzaPlugin(Iq, Roster) +register_stanza_plugin(Iq, Roster) |