summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0060/stanza/pubsub_owner.py
blob: bcb96149b4f8d49bc7e1b56265614d7d5f010976 (plain)
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
125
126
127
128
129
130
131
132
133
134
"""
    Slixmpp: The Slick XMPP Library
    Copyright (C) 2011  Nathanael C. Fritz
    This file is part of Slixmpp.

    See the file LICENSE for copying permission.
"""

from slixmpp import Iq
from slixmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
from slixmpp.plugins.xep_0004 import Form
from slixmpp.plugins.xep_0060.stanza.base import OptionalSetting
from slixmpp.plugins.xep_0060.stanza.pubsub import Affiliations, Affiliation
from slixmpp.plugins.xep_0060.stanza.pubsub import Configure, Subscriptions


class PubsubOwner(ElementBase):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    name = 'pubsub'
    plugin_attrib = 'pubsub_owner'
    interfaces = set(tuple())


class DefaultConfig(ElementBase):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    name = 'default'
    plugin_attrib = name
    interfaces = set(('node', 'config'))

    def __init__(self, *args, **kwargs):
        ElementBase.__init__(self, *args, **kwargs)

    def get_config(self):
        return self['form']

    def set_config(self, value):
        del self['from']
        self.append(value)
        return self


class OwnerAffiliations(Affiliations):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    interfaces = {'node'}

    def append(self, affiliation):
        if not isinstance(affiliation, OwnerAffiliation):
            raise TypeError
        self.xml.append(affiliation.xml)


class OwnerAffiliation(Affiliation):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    interfaces = set(('affiliation', 'jid'))


class OwnerConfigure(Configure):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    name = 'configure'
    plugin_attrib = name
    interfaces = {'node'}


class OwnerDefault(OwnerConfigure):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    interfaces = {'node'}


class OwnerDelete(ElementBase, OptionalSetting):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    name = 'delete'
    plugin_attrib = name
    interfaces = {'node'}


class OwnerPurge(ElementBase, OptionalSetting):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    name = 'purge'
    plugin_attrib = name
    interfaces = {'node'}


class OwnerRedirect(ElementBase):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    name = 'redirect'
    plugin_attrib = name
    interfaces = set(('node', 'jid'))

    def set_jid(self, value):
        self._set_attr('jid', str(value))

    def get_jid(self):
        return JID(self._get_attr('jid'))


class OwnerSubscriptions(Subscriptions):
    name = 'subscriptions'
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    plugin_attrib = name
    interfaces = {'node'}

    def append(self, subscription):
        if not isinstance(subscription, OwnerSubscription):
            raise TypeError
        self.xml.append(subscription.xml)


class OwnerSubscription(ElementBase):
    namespace = 'http://jabber.org/protocol/pubsub#owner'
    name = 'subscription'
    plugin_attrib = name
    interfaces = set(('jid', 'subscription'))

    def set_jid(self, value):
        self._set_attr('jid', str(value))

    def get_jid(self):
        return JID(self._get_attr('jid'))


register_stanza_plugin(Iq, PubsubOwner)
register_stanza_plugin(PubsubOwner, DefaultConfig)
register_stanza_plugin(PubsubOwner, OwnerAffiliations)
register_stanza_plugin(PubsubOwner, OwnerConfigure)
register_stanza_plugin(PubsubOwner, OwnerDefault)
register_stanza_plugin(PubsubOwner, OwnerDelete)
register_stanza_plugin(PubsubOwner, OwnerPurge)
register_stanza_plugin(PubsubOwner, OwnerSubscriptions)
register_stanza_plugin(DefaultConfig, Form)
register_stanza_plugin(OwnerAffiliations, OwnerAffiliation, iterable=True)
register_stanza_plugin(OwnerConfigure, Form)
register_stanza_plugin(OwnerDefault, Form)
register_stanza_plugin(OwnerDelete, OwnerRedirect)
register_stanza_plugin(OwnerSubscriptions, OwnerSubscription, iterable=True)