Back to index

moin  1.9.0~rc2
Functions
jabberbot.oob Namespace Reference

Functions

def add_urls

Function Documentation

def jabberbot.oob.add_urls (   stanza,
  data 
)
Adds a URL to a message or presence stanza

Adds an <x> element qualified by the jabber:x:oob namespace
to the stanza's payload

@param stanza: message or presence stanza to add the URL info to
@type stanza: pyxmpp.message.Message or pyxmpp.presence.Presence
@param data: a list of dictionaries containing (url, description), as unicode
@type data: list

Definition at line 15 of file oob.py.

00015 
00016 def add_urls(stanza, data):
00017     """Adds a URL to a message or presence stanza
00018 
00019     Adds an <x> element qualified by the jabber:x:oob namespace
00020     to the stanza's payload
00021 
00022     @param stanza: message or presence stanza to add the URL info to
00023     @type stanza: pyxmpp.message.Message or pyxmpp.presence.Presence
00024     @param data: a list of dictionaries containing (url, description), as unicode
00025     @type data: list
00026 
00027     """
00028     if not (isinstance(stanza, Presence) or isinstance(stanza, Message)):
00029         raise TypeError("Stanza must be either of type Presence or Message!")
00030 
00031     for piece in data:
00032         x_elem = stanza.add_new_content(u"jabber:x:oob", u"x")
00033         url = x_elem.newChild(None, u"url", None)
00034         desc = x_elem.newChild(None, u"desc", None)
00035         url.addContent(piece['url'].encode("utf-8"))
00036         desc.addContent(piece['description'].encode("utf-8"))