Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
7d4efe25 by Philipp Hörist at 2017-07-28T13:56:43+02:00
Improve setTagAttr/getTagAttr
Make them except a namespace named argument
- - - - -
21b06c5d by Philipp Hörist at 2017-07-28T13:56:53+02:00
Add setOriginID/getOriginID methods
- - - - -
2 changed files:
- nbxmpp/protocol.py
- nbxmpp/simplexml.py
Changes:
=====================================
nbxmpp/protocol.py
=====================================
--- a/nbxmpp/protocol.py
+++ b/nbxmpp/protocol.py
@@ -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
=====================================
--- a/nbxmpp/simplexml.py
+++ b/nbxmpp/simplexml.py
@@ -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):
"""
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/compare/d8e4ed3e7f198a03279f47aa0b0ed19d6999d43e...21b06c5d677f9fe61749fd34bfe199a2a9f08ea6
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits