Skip to content
Snippets Groups Projects
Commit 35412535 authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

[sgala] add some xmpp functions for xhtml-im support. see #316

parent ee508248
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ Protocol module contains tools that is needed for processing of ...@@ -19,7 +19,7 @@ Protocol module contains tools that is needed for processing of
xmpp-related data structures. xmpp-related data structures.
""" """
from simplexml import Node,ustr from simplexml import Node,NodeBuilder,ustr
import time import time
NS_ACTIVITY ='http://jabber.org/protocol/activity' # JEP-0108 NS_ACTIVITY ='http://jabber.org/protocol/activity' # JEP-0108
NS_ADDRESS ='http://jabber.org/protocol/address' # JEP-0033 NS_ADDRESS ='http://jabber.org/protocol/address' # JEP-0033
...@@ -94,6 +94,7 @@ NS_VCARD_UPDATE =NS_VCARD+':x:update' ...@@ -94,6 +94,7 @@ NS_VCARD_UPDATE =NS_VCARD+':x:update'
NS_VERSION ='jabber:iq:version' NS_VERSION ='jabber:iq:version'
NS_WAITINGLIST ='http://jabber.org/protocol/waitinglist' # JEP-0130 NS_WAITINGLIST ='http://jabber.org/protocol/waitinglist' # JEP-0130
NS_XHTML_IM ='http://jabber.org/protocol/xhtml-im' # JEP-0071 NS_XHTML_IM ='http://jabber.org/protocol/xhtml-im' # JEP-0071
NS_XHTML = 'http://www.w3.org/1999/xhtml' # "
NS_DATA_LAYOUT ='http://jabber.org/protocol/xdata-layout' # JEP-0141 NS_DATA_LAYOUT ='http://jabber.org/protocol/xdata-layout' # JEP-0141
NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate' # JEP-0122 NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate' # JEP-0122
NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams' NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams'
...@@ -385,16 +386,21 @@ class Protocol(Node): ...@@ -385,16 +386,21 @@ class Protocol(Node):
class Message(Protocol): class Message(Protocol):
""" XMPP Message stanza - "push" mechanism.""" """ XMPP Message stanza - "push" mechanism."""
def __init__(self, to=None, body=None, typ=None, subject=None, attrs={}, frm=None, payload=[], timestamp=None, xmlns=NS_CLIENT, node=None): def __init__(self, to=None, body=None, xhtml=None, typ=None, subject=None, attrs={}, frm=None, payload=[], timestamp=None, xmlns=NS_CLIENT, node=None):
""" Create message object. You can specify recipient, text of message, type of message """ Create message object. You can specify recipient, text of message, type of message
any additional attributes, sender of the message, any additional payload (f.e. jabber:x:delay element) and namespace in one go. any additional attributes, sender of the message, any additional payload (f.e. jabber:x:delay element) and namespace in one go.
Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as message. """ Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as message. """
Protocol.__init__(self, 'message', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node) Protocol.__init__(self, 'message', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
if body: self.setBody(body) if body: self.setBody(body)
if xhtml: self.setXHTML(xhtml)
if subject: self.setSubject(subject) if subject: self.setSubject(subject)
def getBody(self): def getBody(self):
""" Returns text of the message. """ """ Returns text of the message. """
return self.getTagData('body') return self.getTagData('body')
def getXHTML(self):
""" Returns serialized xhtml-im body text of the message. """
xhtml = self.getTag('xhtml')
return str(xhtml.getTag('body'))
def getSubject(self): def getSubject(self):
""" Returns subject of the message. """ """ Returns subject of the message. """
return self.getTagData('subject') return self.getTagData('subject')
...@@ -404,6 +410,11 @@ class Message(Protocol): ...@@ -404,6 +410,11 @@ class Message(Protocol):
def setBody(self,val): def setBody(self,val):
""" Sets the text of the message. """ """ Sets the text of the message. """
self.setTagData('body',val) self.setTagData('body',val)
def setXHTML(self,val):
""" Sets the xhtml text of the message (JEP-0071).
The parameter is the "inner html" to the body."""
dom = NodeBuilder(val)
self.setTag('html',namespace=NS_XHTML_IM).setTag('body',namespace=NS_XHTML).addChild(node=dom.getDom())
def setSubject(self,val): def setSubject(self,val):
""" Sets the subject of the message. """ """ Sets the subject of the message. """
self.setTagData('subject',val) self.setTagData('subject',val)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment