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.
11 from slixmpp
import Iq
12 from slixmpp
.plugins
import BasePlugin
13 from slixmpp
.xmlstream
.handler
import Callback
14 from slixmpp
.xmlstream
.matcher
import StanzaPath
15 from slixmpp
.xmlstream
import register_stanza_plugin
, JID
16 from slixmpp
.plugins
.xep_0191
import stanza
, Block
, Unblock
, BlockList
19 log
= logging
.getLogger(__name__
)
22 class XEP_0191(BasePlugin
):
25 description
= 'XEP-0191: Blocking Command'
26 dependencies
= set(['xep_0030'])
29 def plugin_init(self
):
30 register_stanza_plugin(Iq
, BlockList
)
31 register_stanza_plugin(Iq
, Block
)
32 register_stanza_plugin(Iq
, Unblock
)
34 self
.xmpp
.register_handler(
35 Callback('Blocked Contact',
36 StanzaPath('iq@type=set/block'),
37 self
._handle
_blocked
))
39 self
.xmpp
.register_handler(
40 Callback('Unblocked Contact',
41 StanzaPath('iq@type=set/unblock'),
42 self
._handle
_unblocked
))
45 self
.xmpp
.remove_handler('Blocked Contact')
46 self
.xmpp
.remove_handler('Unblocked Contact')
48 def get_blocked(self
, ifrom
=None, block
=True, timeout
=None, callback
=None):
52 iq
.enable('blocklist')
53 return iq
.send(block
=block
, timeout
=timeout
, callback
=callback
)
55 def block(self
, jids
, ifrom
=None, block
=True, timeout
=None, callback
=None):
60 if not isinstance(jids
, (set, list)):
63 iq
['block']['items'] = jids
64 return iq
.send(block
=block
, timeout
=timeout
, callback
=callback
)
66 def unblock(self
, jids
=None, ifrom
=None, block
=True, timeout
=None, callback
=None):
73 if not isinstance(jids
, (set, list)):
76 iq
['unblock']['items'] = jids
77 return iq
.send(block
=block
, timeout
=timeout
, callback
=callback
)
79 def _handle_blocked(self
, iq
):
80 self
.xmpp
.event('blocked', iq
)
82 def _handle_unblocked(self
, iq
):
83 self
.xmpp
.event('unblocked', iq
)