From 181aea737d5bce9479795b58c29b5a92da3bd48b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 5 Jun 2012 16:54:26 -0700 Subject: Add initial support for xml:lang for streams and stanza plugins. Remaining items are suitable default actions for language supporting interfaces. --- sleekxmpp/stanza/roster.py | 1 + 1 file changed, 1 insertion(+) (limited to 'sleekxmpp/stanza') diff --git a/sleekxmpp/stanza/roster.py b/sleekxmpp/stanza/roster.py index 253c2aea..3fae42cc 100644 --- a/sleekxmpp/stanza/roster.py +++ b/sleekxmpp/stanza/roster.py @@ -102,6 +102,7 @@ class Roster(ElementBase): # Remove extra JID reference to keep everything # backward compatible del items[item['jid']]['jid'] + del items[item['jid']]['lang'] return items def del_items(self): -- cgit v1.2.3 From 3d2d11f169407d8acd7ab9797398018bd414d974 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 5 Jun 2012 21:57:55 -0700 Subject: Update stream features stanza to work with new plugin keys. --- sleekxmpp/stanza/stream_features.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sleekxmpp/stanza') diff --git a/sleekxmpp/stanza/stream_features.py b/sleekxmpp/stanza/stream_features.py index 9993c84a..e487721e 100644 --- a/sleekxmpp/stanza/stream_features.py +++ b/sleekxmpp/stanza/stream_features.py @@ -6,6 +6,7 @@ See the file LICENSE for copying permission. """ +from sleekxmpp.thirdparty import OrderedDict from sleekxmpp.xmlstream import StanzaBase @@ -28,7 +29,10 @@ class StreamFeatures(StanzaBase): def get_features(self): """ """ - return self.plugins + features = OrderedDict() + for (name, lang), plugin in self.plugins.items(): + features[name] = plugin + return features def set_features(self, value): """ -- cgit v1.2.3 From 8da387a38aa90069cdcb44df2a36ccea303b62c8 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sat, 16 Jun 2012 14:12:13 -0700 Subject: Add support for error conditions that include data. --- sleekxmpp/stanza/error.py | 26 +++++++++++++++++++++++++- sleekxmpp/stanza/stream_error.py | 16 +++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'sleekxmpp/stanza') diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py index 825287ad..35a8913a 100644 --- a/sleekxmpp/stanza/error.py +++ b/sleekxmpp/stanza/error.py @@ -51,7 +51,8 @@ class Error(ElementBase): namespace = 'jabber:client' name = 'error' plugin_attrib = 'error' - interfaces = set(('code', 'condition', 'text', 'type')) + interfaces = set(('code', 'condition', 'text', 'type', + 'gone', 'redirect')) sub_interfaces = set(('text',)) plugin_attrib_map = {} plugin_tag_map = {} @@ -135,6 +136,29 @@ class Error(ElementBase): self._del_sub('{%s}text' % self.condition_ns) return self + def get_gone(self): + return self._get_sub_text('{%s}gone' % self.condition_ns, '') + + def get_redirect(self): + return self._get_sub_text('{%s}redirect' % self.condition_ns, '') + + def set_gone(self, value): + del self['condition'] + if value: + return self._set_sub_text('{%s}gone' % self.condition_ns, value) + + def set_redirect(self, value): + del self['condition'] + if value: + ns = self.condition_ns + return self._set_sub_text('{%s}redirect' % ns, value) + + def del_gone(self): + self._del_sub('{%s}gone' % self.condition_ns) + + def del_redirect(self): + self._del_sub('{%s}redirect' % self.condition_ns) + # To comply with PEP8, method names now use underscores. # Deprecated method names are re-mapped for backwards compatibility. diff --git a/sleekxmpp/stanza/stream_error.py b/sleekxmpp/stanza/stream_error.py index 5a6dac96..bf77d932 100644 --- a/sleekxmpp/stanza/stream_error.py +++ b/sleekxmpp/stanza/stream_error.py @@ -54,7 +54,7 @@ class StreamError(Error, StanzaBase): """ namespace = 'http://etherx.jabber.org/streams' - interfaces = set(('condition', 'text')) + interfaces = set(('condition', 'text', 'see_other_host')) conditions = set(( 'bad-format', 'bad-namespace-prefix', 'conflict', 'connection-timeout', 'host-gone', 'host-unknown', @@ -66,3 +66,17 @@ class StreamError(Error, StanzaBase): 'unsupported-feature', 'unsupported-stanza-type', 'unsupported-version')) condition_ns = 'urn:ietf:params:xml:ns:xmpp-streams' + + def get_see_other_host(self): + ns = self.condition_ns + return self._get_sub_text('{%s}see-other-host' % ns, '') + + def set_see_other_host(self, value): + del self['condition'] + if value: + ns = self.condition_ns + return self._set_sub_text('{%s}see-other-host' % ns, value) + + def del_see_other_host(self): + self._del_sub('{%s}see-other-host' % self.condition_ns) + -- cgit v1.2.3 From d92aa05b5c18806ab5addc947eeedaaf4d51500e Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 19 Jun 2012 01:29:48 -0700 Subject: PEP8 formatting updates. --- sleekxmpp/stanza/error.py | 2 +- sleekxmpp/stanza/rootstanza.py | 3 ++- sleekxmpp/stanza/roster.py | 4 ++-- sleekxmpp/stanza/stream_error.py | 1 - 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'sleekxmpp/stanza') diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py index 35a8913a..809a74b4 100644 --- a/sleekxmpp/stanza/error.py +++ b/sleekxmpp/stanza/error.py @@ -51,7 +51,7 @@ class Error(ElementBase): namespace = 'jabber:client' name = 'error' plugin_attrib = 'error' - interfaces = set(('code', 'condition', 'text', 'type', + interfaces = set(('code', 'condition', 'text', 'type', 'gone', 'redirect')) sub_interfaces = set(('text',)) plugin_attrib_map = {} diff --git a/sleekxmpp/stanza/rootstanza.py b/sleekxmpp/stanza/rootstanza.py index bb756acb..a7c2b218 100644 --- a/sleekxmpp/stanza/rootstanza.py +++ b/sleekxmpp/stanza/rootstanza.py @@ -78,7 +78,8 @@ class RootStanza(StanzaBase): self['error']['type'] = 'cancel' self.send() # log the error - log.exception('Error handling {%s}%s stanza' , self.namespace, self.name) + log.exception('Error handling {%s}%s stanza', + self.namespace, self.name) # Finally raise the exception to a global exception handler self.stream.exception(e) diff --git a/sleekxmpp/stanza/roster.py b/sleekxmpp/stanza/roster.py index 3fae42cc..a415c482 100644 --- a/sleekxmpp/stanza/roster.py +++ b/sleekxmpp/stanza/roster.py @@ -47,7 +47,7 @@ class Roster(ElementBase): roster versioning. """ return self.xml.attrib.get('ver', None) - + def set_ver(self, ver): """ Ensure handling an empty ver attribute propery. @@ -101,7 +101,7 @@ class Roster(ElementBase): items[item['jid']] = item.values # Remove extra JID reference to keep everything # backward compatible - del items[item['jid']]['jid'] + del items[item['jid']]['jid'] del items[item['jid']]['lang'] return items diff --git a/sleekxmpp/stanza/stream_error.py b/sleekxmpp/stanza/stream_error.py index bf77d932..8c541da4 100644 --- a/sleekxmpp/stanza/stream_error.py +++ b/sleekxmpp/stanza/stream_error.py @@ -79,4 +79,3 @@ class StreamError(Error, StanzaBase): def del_see_other_host(self): self._del_sub('{%s}see-other-host' % self.condition_ns) - -- cgit v1.2.3 From 7858d969d82eaaa7124b8d59a68c286f06cbf758 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 19 Jun 2012 09:47:31 -0700 Subject: Remove usage of deprecated getchildren() method. --- sleekxmpp/stanza/error.py | 4 ++-- sleekxmpp/stanza/iq.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'sleekxmpp/stanza') diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py index 809a74b4..8d9266bd 100644 --- a/sleekxmpp/stanza/error.py +++ b/sleekxmpp/stanza/error.py @@ -89,7 +89,7 @@ class Error(ElementBase): def get_condition(self): """Return the condition element's name.""" - for child in self.xml.getchildren(): + for child in self.xml: if "{%s}" % self.condition_ns in child.tag: cond = child.tag.split('}', 1)[-1] if cond in self.conditions: @@ -110,7 +110,7 @@ class Error(ElementBase): def del_condition(self): """Remove the condition element.""" - for child in self.xml.getchildren(): + for child in self.xml: if "{%s}" % self.condition_ns in child.tag: tag = child.tag.split('}', 1)[-1] if tag in self.conditions: diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py index 47d51b04..f45b3c67 100644 --- a/sleekxmpp/stanza/iq.py +++ b/sleekxmpp/stanza/iq.py @@ -122,7 +122,7 @@ class Iq(RootStanza): def get_query(self): """Return the namespace of the element.""" - for child in self.xml.getchildren(): + for child in self.xml: if child.tag.endswith('query'): ns = child.tag.split('}')[0] if '{' in ns: @@ -132,7 +132,7 @@ class Iq(RootStanza): def del_query(self): """Remove the element.""" - for child in self.xml.getchildren(): + for child in self.xml: if child.tag.endswith('query'): self.xml.remove(child) return self -- cgit v1.2.3 From 019a4b20ae5284ec07d4ecc5e5136be5012e88bd Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 19 Jun 2012 16:21:34 -0700 Subject: Fix assigning values to error stanzas. The new data interfaces were deleting the actual error conditions if they were set afterward with falsy data. --- sleekxmpp/stanza/error.py | 8 ++++++-- sleekxmpp/stanza/stream_error.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'sleekxmpp/stanza') diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py index 8d9266bd..60bc65bc 100644 --- a/sleekxmpp/stanza/error.py +++ b/sleekxmpp/stanza/error.py @@ -143,15 +143,19 @@ class Error(ElementBase): return self._get_sub_text('{%s}redirect' % self.condition_ns, '') def set_gone(self, value): - del self['condition'] if value: + del self['condition'] return self._set_sub_text('{%s}gone' % self.condition_ns, value) + elif self['condition'] == 'gone': + del self['condition'] def set_redirect(self, value): - del self['condition'] if value: + del self['condition'] ns = self.condition_ns return self._set_sub_text('{%s}redirect' % ns, value) + elif self['condition'] == 'redirect': + del self['condition'] def del_gone(self): self._del_sub('{%s}gone' % self.condition_ns) diff --git a/sleekxmpp/stanza/stream_error.py b/sleekxmpp/stanza/stream_error.py index 8c541da4..ed0078c9 100644 --- a/sleekxmpp/stanza/stream_error.py +++ b/sleekxmpp/stanza/stream_error.py @@ -72,10 +72,12 @@ class StreamError(Error, StanzaBase): return self._get_sub_text('{%s}see-other-host' % ns, '') def set_see_other_host(self, value): - del self['condition'] if value: + del self['condition'] ns = self.condition_ns return self._set_sub_text('{%s}see-other-host' % ns, value) + elif self['condition'] == 'see-other-host': + del self['condition'] def del_see_other_host(self): self._del_sub('{%s}see-other-host' % self.condition_ns) -- cgit v1.2.3