diff options
Diffstat (limited to 'sleekxmpp/stanza')
-rw-r--r-- | sleekxmpp/stanza/error.py | 19 | ||||
-rw-r--r-- | sleekxmpp/stanza/htmlim.py | 23 | ||||
-rw-r--r-- | sleekxmpp/stanza/iq.py | 28 | ||||
-rw-r--r-- | sleekxmpp/stanza/message.py | 38 | ||||
-rw-r--r-- | sleekxmpp/stanza/nick.py | 23 | ||||
-rw-r--r-- | sleekxmpp/stanza/presence.py | 38 | ||||
-rw-r--r-- | sleekxmpp/stanza/rootstanza.py | 3 | ||||
-rw-r--r-- | sleekxmpp/stanza/roster.py | 23 |
8 files changed, 78 insertions, 117 deletions
diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py index 09229bc6..5d1ce50d 100644 --- a/sleekxmpp/stanza/error.py +++ b/sleekxmpp/stanza/error.py @@ -77,15 +77,6 @@ class Error(ElementBase): 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.getCondition = self.get_condition - self.setCondition = self.set_condition - self.delCondition = self.del_condition - self.getText = self.get_text - self.setText = self.set_text - self.delText = self.del_text - if ElementBase.setup(self, xml): #If we had to generate XML then set default values. self['type'] = 'cancel' @@ -139,3 +130,13 @@ class Error(ElementBase): """Remove the <text> element.""" self._del_sub('{%s}text' % self.condition_ns) return self + + +# To comply with PEP8, method names now use underscores. +# Deprecated method names are re-mapped for backwards compatibility. +Error.getCondition = Error.get_condition +Error.setCondition = Error.set_condition +Error.delCondition = Error.del_condition +Error.getText = Error.get_text +Error.setText = Error.set_text +Error.delText = Error.del_text diff --git a/sleekxmpp/stanza/htmlim.py b/sleekxmpp/stanza/htmlim.py index 45868287..d21a74e1 100644 --- a/sleekxmpp/stanza/htmlim.py +++ b/sleekxmpp/stanza/htmlim.py @@ -46,23 +46,6 @@ class HTMLIM(ElementBase): interfaces = set(('body',)) plugin_attrib = name - 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.setBody = self.set_body - self.getBody = self.get_body - self.delBody = self.del_body - - return ElementBase.setup(self, xml) - def set_body(self, html): """ Set the contents of the HTML body. @@ -95,3 +78,9 @@ class HTMLIM(ElementBase): register_stanza_plugin(Message, HTMLIM) + +# To comply with PEP8, method names now use underscores. +# Deprecated method names are re-mapped for backwards compatibility. +HTMLIM.setBody = HTMLIM.set_body +HTMLIM.getBody = HTMLIM.get_body +HTMLIM.delBody = HTMLIM.del_body diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py index c6aa64d0..2bfbc7b1 100644 --- a/sleekxmpp/stanza/iq.py +++ b/sleekxmpp/stanza/iq.py @@ -75,13 +75,6 @@ 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() @@ -144,7 +137,7 @@ class Iq(RootStanza): self.xml.remove(child) return self - def reply(self): + def reply(self, clear=True): """ Send a reply <iq> stanza. @@ -152,9 +145,13 @@ class Iq(RootStanza): Sets the 'type' to 'result' in addition to the default StanzaBase.reply behavior. + + Arguments: + clear -- Indicates if existing content should be + removed before replying. Defaults to True. """ self['type'] = 'result' - StanzaBase.reply(self) + StanzaBase.reply(self, clear) return self def send(self, block=True, timeout=None, callback=None): @@ -185,13 +182,14 @@ class Iq(RootStanza): if timeout is None: timeout = self.stream.response_timeout if callback is not None and self['type'] in ('get', 'set'): - handler = Callback('IqCallback_%s' % self['id'], + handler_name = 'IqCallback_%s' % self['id'] + handler = Callback(handler_name, MatcherId(self['id']), callback, once=True) self.stream.register_handler(handler) StanzaBase.send(self) - return None + return handler_name elif block and self['type'] in ('get', 'set'): waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id'])) self.stream.register_handler(waitfor) @@ -224,3 +222,11 @@ class Iq(RootStanza): else: StanzaBase._set_stanza_values(self, values) return self + + +# To comply with PEP8, method names now use underscores. +# Deprecated method names are re-mapped for backwards compatibility. +Iq.setPayload = Iq.set_payload +Iq.getQuery = Iq.get_query +Iq.setQuery = Iq.set_query +Iq.delQuery = Iq.del_query diff --git a/sleekxmpp/stanza/message.py b/sleekxmpp/stanza/message.py index 66c74d8a..cb3d344c 100644 --- a/sleekxmpp/stanza/message.py +++ b/sleekxmpp/stanza/message.py @@ -63,27 +63,6 @@ class Message(RootStanza): plugin_attrib = name types = set((None, 'normal', 'chat', 'headline', 'error', 'groupchat')) - 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.getType = self.get_type - self.getMucroom = self.get_mucroom - self.setMucroom = self.set_mucroom - self.delMucroom = self.del_mucroom - self.getMucnick = self.get_mucnick - self.setMucnick = self.set_mucnick - self.delMucnick = self.del_mucnick - - return StanzaBase.setup(self, xml) - def get_type(self): """ Return the message type. @@ -104,7 +83,7 @@ class Message(RootStanza): self['type'] = 'normal' return self - def reply(self, body=None): + def reply(self, body=None, clear=True): """ Create a message reply. @@ -114,7 +93,9 @@ class Message(RootStanza): adds a message body if one is given. Arguments: - body -- Optional text content for the message. + body -- Optional text content for the message. + clear -- Indicates if existing content should be removed + before replying. Defaults to True. """ StanzaBase.reply(self) if self['type'] == 'groupchat': @@ -163,3 +144,14 @@ class Message(RootStanza): def del_mucnick(self): """Dummy method to prevent deletion.""" pass + + +# To comply with PEP8, method names now use underscores. +# Deprecated method names are re-mapped for backwards compatibility. +Message.getType = Message.get_type +Message.getMucroom = Message.get_mucroom +Message.setMucroom = Message.set_mucroom +Message.delMucroom = Message.del_mucroom +Message.getMucnick = Message.get_mucnick +Message.setMucnick = Message.set_mucnick +Message.delMucnick = Message.del_mucnick diff --git a/sleekxmpp/stanza/nick.py b/sleekxmpp/stanza/nick.py index dce41d14..1e23d34f 100644 --- a/sleekxmpp/stanza/nick.py +++ b/sleekxmpp/stanza/nick.py @@ -49,23 +49,6 @@ class Nick(ElementBase): plugin_attrib = name interfaces = set(('nick',)) - 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.setNick = self.set_nick - self.getNick = self.get_nick - self.delNick = self.del_nick - - return ElementBase.setup(self, xml) - def set_nick(self, nick): """ Add a <nick> element with the given nickname. @@ -87,3 +70,9 @@ class Nick(ElementBase): register_stanza_plugin(Message, Nick) register_stanza_plugin(Presence, Nick) + +# To comply with PEP8, method names now use underscores. +# Deprecated method names are re-mapped for backwards compatibility. +Nick.setNick = Nick.set_nick +Nick.getNick = Nick.get_nick +Nick.delNick = Nick.del_nick diff --git a/sleekxmpp/stanza/presence.py b/sleekxmpp/stanza/presence.py index 7dcd8f90..c8706233 100644 --- a/sleekxmpp/stanza/presence.py +++ b/sleekxmpp/stanza/presence.py @@ -72,26 +72,6 @@ class Presence(RootStanza): 'subscribed', 'unsubscribe', 'unsubscribed')) showtypes = set(('dnd', 'chat', 'xa', 'away')) - 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 exception(self, e): """ Override exception passback for presence. @@ -173,14 +153,28 @@ class Presence(RootStanza): # The priority is not a number: we consider it 0 as a default return 0 - def reply(self): + def reply(self, clear=True): """ Set the appropriate presence reply type. Overrides StanzaBase.reply. + + Arguments: + clear -- Indicates if the stanza contents should be removed + before replying. Defaults to True. """ if self['type'] == 'unsubscribe': self['type'] = 'unsubscribed' elif self['type'] == 'subscribe': self['type'] = 'subscribed' - return StanzaBase.reply(self) + return StanzaBase.reply(self, clear) + + +# To comply with PEP8, method names now use underscores. +# Deprecated method names are re-mapped for backwards compatibility. +Presence.setShow = Presence.set_show +Presence.getType = Presence.get_type +Presence.setType = Presence.set_type +Presence.delType = Presence.get_type +Presence.getPriority = Presence.get_priority +Presence.setPriority = Presence.set_priority diff --git a/sleekxmpp/stanza/rootstanza.py b/sleekxmpp/stanza/rootstanza.py index 8123c5f8..bc11476e 100644 --- a/sleekxmpp/stanza/rootstanza.py +++ b/sleekxmpp/stanza/rootstanza.py @@ -43,8 +43,8 @@ class RootStanza(StanzaBase): Arguments: e -- Exception object """ - self.reply() if isinstance(e, XMPPError): + self.reply(clear=e.clear) # We raised this deliberately self['error']['condition'] = e.condition self['error']['text'] = e.text @@ -56,6 +56,7 @@ class RootStanza(StanzaBase): self['error']['type'] = e.etype self.send() else: + self.reply() # We probably didn't raise this on purpose, so send an error stanza self['error']['condition'] = 'undefined-condition' self['error']['text'] = "SleekXMPP got into trouble." diff --git a/sleekxmpp/stanza/roster.py b/sleekxmpp/stanza/roster.py index 57ea62ba..3fcdbebc 100644 --- a/sleekxmpp/stanza/roster.py +++ b/sleekxmpp/stanza/roster.py @@ -38,23 +38,6 @@ class Roster(ElementBase): plugin_attrib = 'roster' interfaces = set(('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. @@ -125,3 +108,9 @@ class Roster(ElementBase): register_stanza_plugin(Iq, Roster) + +# To comply with PEP8, method names now use underscores. +# Deprecated method names are re-mapped for backwards compatibility. +Roster.setItems = Roster.set_items +Roster.getItems = Roster.get_items +Roster.delItems = Roster.del_items |