Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
1c38ab14 by Philipp Hörist at 2019-10-19T21:15:35Z
Make CommonError serializeable
- - - - -
7bbf8194 by Philipp Hörist at 2019-10-20T17:22:58Z
MUC: Set muc_private_message attribute also for error messages
- - - - -
2 changed files:
- nbxmpp/modules/muc.py
- nbxmpp/structs.py
Changes:
=====================================
nbxmpp/modules/muc.py
=====================================
@@ -185,7 +185,9 @@ class MUC:
return
# MUC Private message
- if properties.type == MessageType.CHAT and not muc_user.getChildren():
+ if (properties.type.is_chat or
+ properties.type.is_error and
+ not muc_user.getChildren()):
properties.muc_private_message = True
return
=====================================
nbxmpp/structs.py
=====================================
@@ -25,6 +25,8 @@ from nbxmpp.protocol import NS_MAM_1
from nbxmpp.protocol import NS_MAM_2
from nbxmpp.protocol import NS_MUC
from nbxmpp.protocol import NS_MUC_INFO
+from nbxmpp.protocol import NS_CLIENT
+from nbxmpp.protocol import Protocol
from nbxmpp.const import MessageType
from nbxmpp.const import AvatarState
from nbxmpp.const import StatusCode
@@ -385,6 +387,7 @@ class ChatMarker(namedtuple('ChatMarker', 'type id')):
class CommonError:
def __init__(self, stanza):
+ self._stanza_name = stanza.getName()
self._error_node = stanza.getTag('error')
self.condition = stanza.getError()
self.condition_data = self._error_node.getTagData(self.condition)
@@ -400,6 +403,10 @@ class CommonError:
text = element.getData()
self._text[lang] = text
+ @classmethod
+ def from_string(cls, node_string):
+ return cls(Protocol(node=node_string))
+
def get_text(self, pref_lang=None):
if pref_lang is not None:
text = self._text.get(pref_lang)
@@ -429,6 +436,13 @@ class CommonError:
text = ' - %s' % text
return 'Error from %s: %s%s' % (self.jid, condition, text)
+ def serialize(self):
+ return str(Protocol(name=self._stanza_name,
+ frm=self.jid,
+ xmlns=NS_CLIENT,
+ attrs={'id': self.id},
+ payload=self._error_node))
+
class StanzaMalformedError(CommonError):
def __init__(self, stanza, text):
@@ -443,12 +457,19 @@ class StanzaMalformedError(CommonError):
if text:
self._text['en'] = text
+ @classmethod
+ def from_string(cls, node_string):
+ raise NotImplementedError
+
def __str__(self):
text = self.get_text('en')
if text:
text = ': %s' % text
return 'Received malformed stanza from %s%s' % (self.jid, text)
+ def serialize(self):
+ raise NotImplementedError
+
class TuneData(namedtuple('TuneData', 'artist length rating source title track
uri')):
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/compare/8fb372a55962a47e4ddf8bb35a46188f7ce0a5b9...7bbf8194fbe6b54e41987778214c4f1417f07c11
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/compare/8fb372a55962a47e4ddf8bb35a46188f7ce0a5b9...7bbf8194fbe6b54e41987778214c4f1417f07c11
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits