Rename to slixmpp
[slixmpp.git] / slixmpp / plugins / xep_0191 / stanza.py
blob4dac7bfcf12e857dc572ad309e55374e5c3a9a4e
1 """
2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permission.
7 """
9 from slixmpp.xmlstream import ET, ElementBase, JID
12 class BlockList(ElementBase):
13 name = 'blocklist'
14 namespace = 'urn:xmpp:blocking'
15 plugin_attrib = 'blocklist'
16 interfaces = set(['items'])
18 def get_items(self):
19 result = set()
20 items = self.xml.findall('{%s}item' % self.namespace)
21 if items is not None:
22 for item in items:
23 jid = JID(item.attrib.get('jid', ''))
24 if jid:
25 result.add(jid)
26 return result
28 def set_items(self, values):
29 self.del_items()
30 for jid in values:
31 if jid:
32 item = ET.Element('{%s}item' % self.namespace)
33 item.attrib['jid'] = JID(jid).full
34 self.xml.append(item)
36 def del_items(self):
37 items = self.xml.findall('{%s}item' % self.namespace)
38 if items is not None:
39 for item in items:
40 self.xml.remove(item)
43 class Block(BlockList):
44 name = 'block'
45 plugin_attrib = 'block'
48 class Unblock(BlockList):
49 name = 'unblock'
50 plugin_attrib = 'unblock'