summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0198/stanza.py
blob: 6461d766d2efb88157e3bd41628aee21a25cc18a (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.stanza import Error
from sleekxmpp.xmlstream import ElementBase, StanzaBase


class Enable(StanzaBase):
    name = 'enable'
    namespace = 'urn:xmpp:sm:3'
    interfaces = set(['max', 'resume'])

    def setup(self, xml):
        StanzaBase.setup(self, xml)
        self.xml.tag = self.tag_name()

    def get_resume(self):
        return self._get_attr('resume', 'false').lower() in ('true', '1')

    def set_resume(self, val):
        self._del_attr('resume')
        self._set_attr('resume', 'true' if val else 'false')


class Enabled(StanzaBase):
    name = 'enabled'
    namespace = 'urn:xmpp:sm:3'
    interfaces = set(['id', 'location', 'max', 'resume'])

    def setup(self, xml):
        StanzaBase.setup(self, xml)
        self.xml.tag = self.tag_name()

    def get_resume(self):
        return self._get_attr('resume', 'false').lower() in ('true', '1')

    def set_resume(self, val):
        self._del_attr('resume')
        self._set_attr('resume', 'true' if val else 'false')


class Resume(StanzaBase):
    name = 'resume'
    namespace = 'urn:xmpp:sm:3'
    interfaces = set(['h', 'previd'])

    def setup(self, xml):
        StanzaBase.setup(self, xml)
        self.xml.tag = self.tag_name()

    def get_h(self):
        h = self._get_attr('h', None)
        if h:
            return int(h)
        return None

    def set_h(self, val):
        self._set_attr('h', str(val))


class Resumed(StanzaBase):
    name = 'resumed'
    namespace = 'urn:xmpp:sm:3'
    interfaces = set(['h', 'previd'])

    def setup(self, xml):
        StanzaBase.setup(self, xml)
        self.xml.tag = self.tag_name()

    def get_h(self):
        h = self._get_attr('h', None)
        if h:
            return int(h)
        return None

    def set_h(self, val):
        self._set_attr('h', str(val))


class Failed(StanzaBase, Error):
    name = 'failed'
    namespace = 'urn:xmpp:sm:3'
    interfaces = set()

    def setup(self, xml):
        StanzaBase.setup(self, xml)
        self.xml.tag = self.tag_name()


class StreamManagement(ElementBase):
    name = 'sm'
    namespace = 'urn:xmpp:sm:3'
    plugin_attrib = name
    interfaces = set(['required', 'optional'])

    def get_required(self):
        return self.find('{%s}required' % self.namespace) is not None

    def set_required(self, val):
        self.del_required()
        if val:
            self._set_sub_text('required', '', keep=True)

    def del_required(self):
        self._del_sub('required')

    def get_optional(self):
        return self.find('{%s}optional' % self.namespace) is not None

    def set_optional(self, val):
        self.del_optional()
        if val:
            self._set_sub_text('optional', '', keep=True)

    def del_optional(self):
        self._del_sub('optional')


class RequestAck(StanzaBase):
    name = 'r'
    namespace = 'urn:xmpp:sm:3'
    interfaces = set()

    def setup(self, xml):
        StanzaBase.setup(self, xml)
        self.xml.tag = self.tag_name()


class Ack(StanzaBase):
    name = 'a'
    namespace = 'urn:xmpp:sm:3'
    interfaces = set(['h'])

    def setup(self, xml):
        StanzaBase.setup(self, xml)
        self.xml.tag = self.tag_name()

    def get_h(self):
        h = self._get_attr('h', None)
        if h:
            return int(h)
        return None

    def set_h(self, val):
        self._set_attr('h', str(val))