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/iq.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'sleekxmpp/stanza/iq.py') diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py index c5ef8bb4..614d14f5 100644 --- a/sleekxmpp/stanza/iq.py +++ b/sleekxmpp/stanza/iq.py @@ -8,8 +8,7 @@ from sleekxmpp.stanza import Error from sleekxmpp.stanza.rootstanza import RootStanza -from sleekxmpp.xmlstream import RESPONSE_TIMEOUT -from sleekxmpp.xmlstream.stanzabase import StanzaBase, ET +from sleekxmpp.xmlstream import RESPONSE_TIMEOUT, StanzaBase, ET from sleekxmpp.xmlstream.handler import Waiter from sleekxmpp.xmlstream.matcher import MatcherId @@ -53,14 +52,14 @@ class Iq(RootStanza): types -- May be one of: get, set, result, or error. Methods: - __init__ -- Overrides StanzaBase.__init__. - unhandled -- Send error if there are no handlers. - setPayload -- Overrides StanzaBase.setPayload. - setQuery -- Add or modify a element. - getQuery -- Return the namespace of the element. - delQuery -- Remove the element. - reply -- Overrides StanzaBase.reply - send -- Overrides StanzaBase.send + __init__ -- Overrides StanzaBase.__init__. + unhandled -- Send error if there are no handlers. + set_payload -- Overrides StanzaBase.set_payload. + set_query -- Add or modify a element. + get_query -- Return the namespace of the element. + del_query -- Remove the element. + reply -- Overrides StanzaBase.reply + send -- Overrides StanzaBase.send """ namespace = 'jabber:client' @@ -76,6 +75,13 @@ class Iq(RootStanza): Overrides StanzaBase.__init__. """ StanzaBase.__init__(self, *args, **kwargs) + # To comply with PEP8, method names now use underscores. + # Deprecated method names are re-mapped for backwards compatibility. + self.setPayload = self.set_payload + self.getQuery = self.get_query + self.setQuery = self.set_query + self.delQuery = self.del_query + if self['id'] == '': if self.stream is not None: self['id'] = self.stream.getNewId() @@ -94,7 +100,7 @@ class Iq(RootStanza): self['error']['text'] = 'No handlers registered for this request.' self.send() - def setPayload(self, value): + def set_payload(self, value): """ Set the XML contents of the stanza. @@ -102,10 +108,10 @@ class Iq(RootStanza): value -- An XML object to use as the stanza's contents """ self.clear() - StanzaBase.setPayload(self, value) + StanzaBase.set_payload(self, value) return self - def setQuery(self, value): + def set_query(self, value): """ Add or modify a element. @@ -121,7 +127,7 @@ class Iq(RootStanza): self.xml.append(query) return self - def getQuery(self): + def get_query(self): """Return the namespace of the element.""" for child in self.xml.getchildren(): if child.tag.endswith('query'): @@ -131,7 +137,7 @@ class Iq(RootStanza): return ns return '' - def delQuery(self): + def del_query(self): """Remove the element.""" for child in self.xml.getchildren(): if child.tag.endswith('query'): -- cgit v1.2.3