Bump to 1.3.1
[slixmpp.git] / sleekxmpp / plugins / xep_0128 / static.py
blob427011c0454356b25147cea81fc01c1644ee1836
1 """
2 SleekXMPP: The Sleek XMPP Library
3 Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of SleekXMPP.
6 See the file LICENSE for copying permission.
7 """
9 import logging
11 import sleekxmpp
12 from sleekxmpp.plugins.xep_0030 import StaticDisco
15 log = logging.getLogger(__name__)
18 class StaticExtendedDisco(object):
20 """
21 Extend the default StaticDisco implementation to provide
22 support for extended identity information.
23 """
25 def __init__(self, static):
26 """
27 Augment the default XEP-0030 static handler object.
29 Arguments:
30 static -- The default static XEP-0030 handler object.
31 """
32 self.static = static
34 def set_extended_info(self, jid, node, ifrom, data):
35 """
36 Replace the extended identity data for a JID/node combination.
38 The data parameter may provide:
39 data -- Either a single data form, or a list of data forms.
40 """
41 with self.static.lock:
42 self.del_extended_info(jid, node, ifrom, data)
43 self.add_extended_info(jid, node, ifrom, data)
45 def add_extended_info(self, jid, node, ifrom, data):
46 """
47 Add additional extended identity data for a JID/node combination.
49 The data parameter may provide:
50 data -- Either a single data form, or a list of data forms.
51 """
52 with self.static.lock:
53 self.static.add_node(jid, node)
55 forms = data.get('data', [])
56 if not isinstance(forms, list):
57 forms = [forms]
59 info = self.static.get_node(jid, node)['info']
60 for form in forms:
61 info.append(form)
63 def del_extended_info(self, jid, node, ifrom, data):
64 """
65 Replace the extended identity data for a JID/node combination.
67 The data parameter is not used.
68 """
69 with self.static.lock:
70 if self.static.node_exists(jid, node):
71 info = self.static.get_node(jid, node)['info']
72 for form in info['substanza']:
73 info.xml.remove(form.xml)