annotate jabberbot/oob.py @ 6097:815981fad7fd

upgrade pygments from 1.6 to 2.1.3
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Sep 2016 23:55:33 +0200
parents 8ec6cc1a909f
children
rev   line source
2631
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - Out Of Band Data (XEP-066) implementation
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2634
diff changeset
4
2631
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 This is used by the xmpp thread to send URIs to clients
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 in a structured manner.
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
9 @license: GNU GPL, see COPYING for details.
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10 """
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
12 from pyxmpp.message import Message
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
13 from pyxmpp.presence import Presence
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
14
2634
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
15 def add_urls(stanza, data):
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
16 """Adds a URL to a message or presence stanza
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2634
diff changeset
17
2631
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
18 Adds an <x> element qualified by the jabber:x:oob namespace
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19 to the stanza's payload
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2634
diff changeset
20
2634
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
21 @param stanza: message or presence stanza to add the URL info to
2631
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
22 @type stanza: pyxmpp.message.Message or pyxmpp.presence.Presence
2634
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
23 @param data: a list of dictionaries containing (url, description), as unicode
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
24 @type data: list
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2634
diff changeset
25
2631
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
26 """
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
27 if not (isinstance(stanza, Presence) or isinstance(stanza, Message)):
80ec0bb44cb2 Add a partial implementation Out Of Band Data (XEP-066)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
28 raise TypeError("Stanza must be either of type Presence or Message!")
2634
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
29
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
30 for piece in data:
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
31 x_elem = stanza.add_new_content(u"jabber:x:oob", u"x")
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
32 url = x_elem.newChild(None, u"url", None)
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
33 desc = x_elem.newChild(None, u"desc", None)
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
34 url.addContent(piece['url'].encode("utf-8"))
53a79ea2ad93 Make url description mandatory, pass args in a dictionary.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2631
diff changeset
35 desc.addContent(piece['description'].encode("utf-8"))