Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (2)
Improve setTagAttr/getTagAttr
· 7d4efe25
Philipp Hörist
authored
Jul 28, 2017
Make them except a namespace named argument
7d4efe25
Add setOriginID/getOriginID methods
· 21b06c5d
Philipp Hörist
authored
Jul 28, 2017
21b06c5d
Hide whitespace changes
Inline
Side-by-side
nbxmpp/protocol.py
View file @
21b06c5d
...
...
@@ -1034,6 +1034,12 @@ class Message(Protocol):
"""
return
self
.
getTagData
(
'
thread
'
)
def
getOriginID
(
self
):
"""
Return origin-id of the message
"""
return
self
.
getTagAttr
(
'
origin-id
'
,
namespace
=
NS_SID
,
attr
=
'
id
'
)
def
setBody
(
self
,
val
):
"""
Set the text of the message
"""
...
...
@@ -1071,6 +1077,12 @@ class Message(Protocol):
"""
self
.
setTagData
(
'
thread
'
,
val
)
def
setOriginID
(
self
,
val
):
"""
Sets the origin-id of the message
"""
self
.
setTag
(
'
origin-id
'
,
namespace
=
NS_SID
,
attrs
=
{
'
id
'
:
val
})
def
buildReply
(
self
,
text
=
None
):
"""
Builds and returns another message object with specified text. The to,
...
...
nbxmpp/simplexml.py
View file @
21b06c5d
...
...
@@ -331,13 +331,13 @@ class Node(object):
"""
return
self
.
getTags
(
name
,
attrs
,
namespace
,
one
=
1
)
def
getTagAttr
(
self
,
tag
,
attr
):
def
getTagAttr
(
self
,
tag
,
attr
,
namespace
=
None
):
"""
Return attribute value of the child with specified name (or None if no
such attribute)
"""
try
:
return
self
.
getTag
(
tag
).
attrs
[
attr
]
return
self
.
getTag
(
tag
,
namespace
=
namespace
).
attrs
[
attr
]
except
:
return
None
...
...
@@ -445,15 +445,15 @@ class Node(object):
else
:
return
self
.
addChild
(
name
,
attrs
,
namespace
=
namespace
)
def
setTagAttr
(
self
,
tag
,
attr
,
val
):
def
setTagAttr
(
self
,
tag
,
attr
,
val
,
namespace
=
None
):
"""
Create new node (if not already present) with name
"
tag
"
and set it
'
s
attribute
"
attr
"
to value
"
val
"
"""
try
:
self
.
getTag
(
tag
).
attrs
[
attr
]
=
val
self
.
getTag
(
tag
,
namespace
=
namespace
).
attrs
[
attr
]
=
val
except
Exception
:
self
.
addChild
(
tag
,
attrs
=
{
attr
:
val
})
self
.
addChild
(
tag
,
namespace
=
namespace
,
attrs
=
{
attr
:
val
})
def
setTagData
(
self
,
tag
,
val
,
attrs
=
None
):
"""
...
...