1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# Slixmpp: The Slick XMPP Library
# Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
# This file is part of Slixmpp.
# See the file LICENSE for copying permission.
from slixmpp import Iq
from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.plugins import BasePlugin
from slixmpp.plugins.xep_0016 import stanza
from slixmpp.plugins.xep_0016.stanza import Privacy, Item
class XEP_0016(BasePlugin):
name = 'xep_0016'
description = 'XEP-0016: Privacy Lists'
dependencies = {'xep_0030'}
stanza = stanza
def plugin_init(self):
register_stanza_plugin(Iq, Privacy)
def plugin_end(self):
self.xmpp['xep_0030'].del_feature(feature=Privacy.namespace)
def session_bind(self, jid):
self.xmpp['xep_0030'].add_feature(Privacy.namespace)
def get_privacy_lists(self, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq.enable('privacy')
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def get_list(self, name, timeout=None, callback=None, timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq['privacy']['list']['name'] = name
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def get_active(self, timeout=None, callback=None, timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq['privacy'].enable('active')
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def get_default(self, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq['privacy'].enable('default')
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def activate(self, name, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['privacy']['active']['name'] = name
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def deactivate(self, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['privacy'].enable('active')
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def make_default(self, name, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['privacy']['default']['name'] = name
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def remove_default(self, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['privacy'].enable('default')
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def edit_list(self, name, rules, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['privacy']['list']['name'] = name
priv_list = iq['privacy']['list']
if not rules:
rules = []
for rule in rules:
if isinstance(rule, Item):
priv_list.append(rule)
continue
priv_list.add_item(
rule['value'],
rule['action'],
rule['order'],
itype=rule.get('type', None),
iq=rule.get('iq', None),
message=rule.get('message', None),
presence_in=rule.get('presence_in',
rule.get('presence-in', None)),
presence_out=rule.get('presence_out',
rule.get('presence-out', None)))
def remove_list(self, name, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['privacy']['list']['name'] = name
iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
|