Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits: 0264a744 by Philipp Hörist at 2017-07-25T02:25:24+02:00 Make better use of Protocol classes
Return always a xmpp aware Protocol instance on getTag(). Otherwise we would fall back to a xmpp unaware Node instance.
Return a Message instance in case the tag name is 'message'
- - - - - 0f51792d by Philipp Hörist at 2017-07-25T02:25:42+02:00 add getJid() attribute method
- - - - -
1 changed file:
- nbxmpp/protocol.py
Changes:
===================================== nbxmpp/protocol.py ===================================== --- a/nbxmpp/protocol.py +++ b/nbxmpp/protocol.py @@ -834,6 +834,15 @@ class Protocol(Node): return self.timestamp return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
+ def getJid(self): + """ + Return the value of the 'jid' attribute + """ + attr = self.getAttr('jid') + if attr: + return JID(attr) + return attr + def getID(self): """ Return the value of the 'id' attribute @@ -946,6 +955,16 @@ class Protocol(Node): props.append(prop) return props
+ def getTag(self, name, attrs=None, namespace=None): + """ + Return at least a Protocol instance, so we dont fall back to simplexml level + """ + tag = super().getTag(name, attrs, namespace) + if not tag: + return None + + return Protocol(node=tag) + def __setitem__(self, item, val): """ Set the item 'item' to the value 'val' @@ -1073,6 +1092,18 @@ class Message(Protocol): attrs.append(child.getAttr('code')) return attrs
+ def getTag(self, name, attrs=None, namespace=None): + """ + Return Message instance, fallback to Protocol + """ + tag = super().getTag(name, attrs, namespace) + if not tag: + return tag + + if name == 'message': + return Message(node=tag) + return tag + class Presence(Protocol):
def __init__(self, to=None, typ=None, priority=None, show=None, status=None,
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/4ce3016001112f7cc2c579bc2f...