Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2019-08-29 20:07:24 +0300
committerPhilipp Hörist <philipp@hoerist.com>2019-08-29 20:35:21 +0300
commit0fdbbd1fedc662d3fca62ff81272aff8ca2200bd (patch)
tree7250ae8090f3b83b334c0170e6c3d0d4b46121aa /nbxmpp/structs.py
parent193bbff1e71a38bcc88dbba485589677a86467fd (diff)
Add StanzaMalformedError
Before we raised CommonError even if the stanza was not an error node. Now we raise the dedicated StanzaMalformedError.
Diffstat (limited to 'nbxmpp/structs.py')
-rw-r--r--nbxmpp/structs.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/nbxmpp/structs.py b/nbxmpp/structs.py
index d86d48f..5c7358e 100644
--- a/nbxmpp/structs.py
+++ b/nbxmpp/structs.py
@@ -368,13 +368,11 @@ class CommonError:
self.id = stanza.getID()
self._text = {}
- error = stanza.getTag('error')
- if error is not None:
- text_elements = error.getTags('text', namespace=NS_STANZAS)
- for element in text_elements:
- lang = element.getXmlLang()
- text = element.getData()
- self._text[lang] = text
+ text_elements = self._error_node.getTags('text', namespace=NS_STANZAS)
+ for element in text_elements:
+ lang = element.getXmlLang()
+ text = element.getData()
+ self._text[lang] = text
def get_text(self, pref_lang=None):
if pref_lang is not None:
@@ -406,6 +404,26 @@ class CommonError:
return 'Error from %s: %s%s' % (self.jid, condition, text)
+class StanzaMalformedError(CommonError):
+ def __init__(self, stanza, text):
+ self._error_node = None
+ self.condition = 'stanza-malformed'
+ self.condition_data = None
+ self.app_condition = None
+ self.type = None
+ self.jid = stanza.getFrom()
+ self.id = stanza.getID()
+ self._text = {}
+ if text:
+ self._text['en'] = text
+
+ def __str__(self):
+ text = self.get_text('en')
+ if text:
+ text = ': %s' % text
+ return 'Received malformed stanza from %s%s' % (self.jid, text)
+
+
class TuneData(namedtuple('TuneData', 'artist length rating source title track uri')):
__slots__ = []