Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (2)
Make CommonError serializeable
· 1c38ab14
Philipp Hörist
authored
Oct 19, 2019
1c38ab14
MUC: Set muc_private_message attribute also for error messages
· 7bbf8194
Philipp Hörist
authored
Oct 20, 2019
7bbf8194
Hide whitespace changes
Inline
Side-by-side
nbxmpp/modules/muc.py
View file @
7bbf8194
...
...
@@ -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
View file @
7bbf8194
...
...
@@ -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
'
)):
...
...