Back to index

moin  1.9.0~rc2
oob.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Out Of Band Data (XEP-066) implementation
00004 
00005     This is used by the xmpp thread to send URIs to clients
00006     in a structured manner.
00007 
00008     @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
00009     @license: GNU GPL, see COPYING for details.
00010 """
00011 
00012 from pyxmpp.message import Message
00013 from pyxmpp.presence import Presence
00014 
00015 def add_urls(stanza, data):
00016     """Adds a URL to a message or presence stanza
00017 
00018     Adds an <x> element qualified by the jabber:x:oob namespace
00019     to the stanza's payload
00020 
00021     @param stanza: message or presence stanza to add the URL info to
00022     @type stanza: pyxmpp.message.Message or pyxmpp.presence.Presence
00023     @param data: a list of dictionaries containing (url, description), as unicode
00024     @type data: list
00025 
00026     """
00027     if not (isinstance(stanza, Presence) or isinstance(stanza, Message)):
00028         raise TypeError("Stanza must be either of type Presence or Message!")
00029 
00030     for piece in data:
00031         x_elem = stanza.add_new_content(u"jabber:x:oob", u"x")
00032         url = x_elem.newChild(None, u"url", None)
00033         desc = x_elem.newChild(None, u"desc", None)
00034         url.addContent(piece['url'].encode("utf-8"))
00035         desc.addContent(piece['description'].encode("utf-8"))