annotate wokkel/rsm.py @ 19:80f9a1a3d002

tmp (rsm): removed useless cast
author Goffi <goffi@goffi.org>
date Sun, 03 Jan 2016 18:36:41 +0100
parents 4629645a368d
children 54f834e40341
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
a07bf3fb4b54 core (tests): test fixes
Goffi <goffi@goffi.org>
parents: 7
diff changeset
1 # -*- coding: utf-8 -*-
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- test-case-name: wokkel.test.test_rsm -*-
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
3 #
6
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
4 # SàT Wokkel extension for Result Set Management (XEP-0059)
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
5 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org)
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
6
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
7 # This program is free software: you can redistribute it and/or modify
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
10 # (at your option) any later version.
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
11
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
12 # This program is distributed in the hope that it will be useful,
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
15 # GNU Affero General Public License for more details.
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
16
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
dc3a3f454f39 tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 5
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
19
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
20 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
21 XMPP Result Set Management protocol.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
22
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
23 This protocol is specified in
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
24 U{XEP-0059<http://xmpp.org/extensions/xep-0059.html>}.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
25 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
26
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from twisted.words.xish import domish
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
28
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
29 import pubsub
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
30 import copy
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
31
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
32
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
33 NS_RSM = 'http://jabber.org/protocol/rsm'
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
34
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
35
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
36 class RSMError(Exception):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
37 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
38 RSM error.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
39 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
40
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
41
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
42 class RSMNotFoundError(Exception):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
43 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
44 An expected RSM element has not been found.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
45 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
46
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
47
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
48 class RSMRequest():
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
49 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
50 A Result Set Management request.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
51
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
52 @ivar max_: limit on the number of retrieved items.
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
53 @itype max_: C{int} or C{unicode}
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
54
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
55 @ivar index: starting index of the requested page.
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
56 @itype index: C{int} or C{unicode} or C{None}
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
57
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
58 @ivar after: ID of the element immediately preceding the page.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
59 @itype after: C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
60
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
61 @ivar before: ID of the element immediately following the page.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
62 @itype before: C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
63 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
64
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
65 def __init__(self, max_=10, index=None, after=None, before=None):
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
66 max_ = int(max_)
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
67 assert max_ >= 0
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
68 self.max = max_
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
69
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
70 if index is not None:
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
71 assert after is None and before is None
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
72 index = int(index)
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
73 assert index >= 0
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
74 self.index = index
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
75
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
76 if after is not None:
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
77 assert before is None
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
78 assert isinstance(after, unicode)
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
79 self.after = after
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
80
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
81 if before is not None:
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
82 assert isinstance(before, unicode)
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
83 self.before = before
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
84
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
85 @classmethod
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
86 def parse(cls, element):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
87 """Parse the given request element.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
88
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
89 @param element: request containing a set element.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
90 @type element: L{domish.Element}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
91
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
92 @return: RSMRequest instance.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
93 @rtype: L{RSMRequest}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
94 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
95 try:
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
96 set_elt = element.elements(NS_RSM, 'set').next()
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
97 except StopIteration:
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
98 raise RSMNotFoundError()
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
99
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
100 request = RSMRequest()
19
80f9a1a3d002 tmp (rsm): removed useless cast
Goffi <goffi@goffi.org>
parents: 16
diff changeset
101 for elt in set_elt.elements():
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
102 if elt.name in ('before', 'after'):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
103 setattr(request, elt.name, ''.join(elt.children))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
104 elif elt.name in ('max', 'index'):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
105 setattr(request, elt.name, int(''.join(elt.children)))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
106
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
107 if request.max is None:
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
108 raise RSMError("RSM request is missing its 'max' element")
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
109
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
110 return request
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
111
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
112 def toElement(self):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
113 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
114 Return the DOM representation of this RSM request.
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
115
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
116 @rtype: L{domish.Element}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
117 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
118 set_elt = domish.Element((NS_RSM, 'set'))
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
119 set_elt.addElement('max').addContent(unicode(self.max))
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
120
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
121 if self.index is not None:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
122 set_elt.addElement('index').addContent(unicode(self.index))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
123
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
124 if self.before is not None:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
125 if self.before == '': # request the last page
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
126 set_elt.addElement('before')
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
127 else:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
128 set_elt.addElement('before').addContent(self.before)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
129
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
130 if self.after is not None:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
131 set_elt.addElement('after').addContent(self.after)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
132
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
133 return set_elt
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
134
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
135 def render(self, element):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
136 """Embed the DOM representation of this RSM request in the given element.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
137
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
138 @param element: Element to contain the RSM request.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
139 @type element: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
140
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
141 @return: RSM request element.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
142 @rtype: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
143 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
144 if element.name == 'pubsub' and hasattr(element, 'items'):
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
145 element.items.attributes['max_items'] = unicode(self.max)
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
146
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
147 set_elt = self.toElement()
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
148 element.addChild(set_elt)
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
149
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
150 return set_elt
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
151
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
152
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
153 class RSMResponse():
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
154 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
155 A Result Set Management response.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
156
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
157 @ivar count: total number of items.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
158 @itype count: C{int}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
159
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
160 @ivar index: starting index of the returned page.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
161 @itype index: C{int}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
162
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
163 @ivar first: ID of the first element of the returned page.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
164 @itype first: C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
165
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
166 @ivar last: ID of the last element of the returned page.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
167 @itype last: C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
168 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
169
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
170 def __init__(self, count=0, index=None, first=None, last=None):
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
171 assert isinstance(count, int) and count >= 0
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
172 self.count = count
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
173 if index is not None:
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
174 assert isinstance(index, int) and index >= 0
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
175 assert isinstance(first, unicode)
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
176 assert isinstance(last, unicode)
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
177 else:
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
178 assert first is None and last is None
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
179 self.index = index
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
180 self.first = first
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
181 self.last = last
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
182
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
183 @classmethod
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
184 def parse(cls, element):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
185 """Parse the given response element.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
186
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
187 @param element: response element.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
188 @type element: L{domish.Element}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
189
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
190 @return: RSMResponse instance.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
191 @rtype: L{RSMResponse}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
192 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
193 try:
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
194 set_elt = element.elements(NS_RSM, 'set').next()
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
195 except StopIteration:
11
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
196 raise RSMNotFoundError()
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
197
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
198 response = RSMResponse()
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
199 for elt in list(set_elt.elements()):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
200 if elt.name in ('first', 'last'):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
201 setattr(response, elt.name, ''.join(elt.children))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
202 if elt.name == 'first':
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
203 response.index = int(elt.getAttribute("index"))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
204 elif elt.name == 'count':
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
205 response.count = int(''.join(elt.children))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
206
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
207 if response.count is None:
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
208 raise RSMError("RSM response is missing its 'count' element")
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
209
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
210 return response
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
211
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
212 def toElement(self):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
213 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
214 Return the DOM representation of this RSM request.
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
215
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
216 @rtype: L{domish.Element}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
217 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
218 set_elt = domish.Element((NS_RSM, 'set'))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
219 set_elt.addElement('count').addContent(unicode(self.count))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
220
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
221 if self.index is not None:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
222 first_elt = set_elt.addElement('first')
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
223 first_elt.addContent(self.first)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
224 first_elt['index'] = unicode(self.index)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
225
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
226 set_elt.addElement('last').addContent(self.last)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
227
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
228 return set_elt
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
229
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
230 def render(self, element):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
231 """Embed the DOM representation of this RSM response in the given element.
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
232
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
233 @param element: Element to contain the RSM response.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
234 @type element: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
235
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
236 @return: RSM request element.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
237 @rtype: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
238 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
239 set_elt = self.toElement()
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
240 element.addChild(set_elt)
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
241 return set_elt
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
242
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
243 def toDict(self):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
244 """Return a dict representation of the object.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
245
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
246 @return: a dict of strings.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
247 @rtype: C{dict} binding C{unicode} to C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
248 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
249 result = {}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
250 for attr in ('count', 'index', 'first', 'last'):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
251 value = getattr(self, attr)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
252 if value is not None:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
253 result[attr] = unicode(value)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
254 return result
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
255
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
256
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
257 class PubSubRequest(pubsub.PubSubRequest):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
258 """PubSubRequest extension to handle RSM.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
259
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
260 @ivar rsm: RSM request instance.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
261 @type rsm: L{RSMRequest}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
262 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
263
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
264 rsm = None
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
265
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
266 def __init__(self, verb=None):
12
1564566e4c1f tmp (wokkel.rsm): use of super instead of direct call in PubSubRequest
Goffi <goffi@goffi.org>
parents: 11
diff changeset
267 super(PubSubRequest, self).__init__(verb)
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
268 self._parameters = copy.deepcopy(pubsub.PubSubRequest._parameters)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
269 self._parameters['items'].append('rsm')
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
270
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
271 def _parse_rsm(self, verbElement):
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
272 try:
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
273 self.rsm = RSMRequest.parse(verbElement.parent)
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
274 except RSMNotFoundError:
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
275 self.rsm = None
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
276
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
277 def _render_rsm(self, verbElement):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
278 if self.rsm:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
279 self.rsm.render(verbElement.parent)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
280
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
281
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
282 class PubSubClient(pubsub.PubSubClient):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
283 """PubSubClient extension to handle RSM."""
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
284
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
285 _rsm_responses = {}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
286
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
287 def items(self, service, nodeIdentifier, maxItems=None, itemIdentifiers=None,
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
288 subscriptionIdentifier=None, sender=None, ext_data=None):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
289 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
290 Retrieve previously published items from a publish subscribe node.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
291
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
292 @param service: The publish subscribe service that keeps the node.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
293 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
294
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
295 @param nodeIdentifier: The identifier of the node.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
296 @type nodeIdentifier: C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
297
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
298 @param maxItems: Optional limit on the number of retrieved items.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
299 @type maxItems: C{int}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
300
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
301 @param itemIdentifiers: Identifiers of the items to be retrieved.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
302 @type itemIdentifiers: C{set}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
303
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
304 @param subscriptionIdentifier: Optional subscription identifier. In
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
305 case the node has been subscribed to multiple times, this narrows
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
306 the results to the specific subscription.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
307 @type subscriptionIdentifier: C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
308
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
309 @param ext_data: extension data.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
310 @type ext_data: L{dict}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
311
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
312 @return: a Deferred that fires a C{list} of L{domish.Element}.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
313 @rtype: L{defer.Deferred}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
314 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
315 request = PubSubRequest('items') # that's a rsm.PubSubRequest instance
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
316 request.recipient = service
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
317 request.nodeIdentifier = nodeIdentifier
16
4629645a368d tmp (wokkel): fixes RSM when maxItems is 0
souliane <souliane@mailoo.org>
parents: 15
diff changeset
318 if maxItems is not None:
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
319 request.maxItems = str(int(maxItems))
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
320 request.subscriptionIdentifier = subscriptionIdentifier
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
321 request.sender = sender
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
322 request.itemIdentifiers = itemIdentifiers
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
323 if ext_data and 'rsm' in ext_data:
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
324 request.rsm = ext_data['rsm']
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
325
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
326 def cb(iq):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
327 items = []
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
328 if iq.pubsub.items:
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
329 for element in iq.pubsub.items.elements(pubsub.NS_PUBSUB, 'item'):
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
330 items.append(element)
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
331
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
332 if request.rsm:
11
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
333 try:
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
334 response = RSMResponse.parse(iq.pubsub)
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
335 if response is not None:
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
336 self._rsm_responses[ext_data['id']] = response
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
337 except RSMNotFoundError: # target pubsub server doesn't support RSM
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
338 pass
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
339 return items
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
340
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
341 d = request.send(self.xmlstream)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
342 d.addCallback(cb)
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
343 return d
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
344
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
345 def getRSMResponse(self, id_):
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
346 """Post-retrieve the RSM response data after items retrieval is done.
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
347
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
348 @param id_: extension data ID
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
349 @type id_: C{unicode}
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
350
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
351 @return: dict representation of the RSM response.
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
352 @rtype: C{dict} of C{unicode}
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
353 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
354 # This method exists to not modify the return value of self.items.
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
355 if id_ not in self._rsm_responses:
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
356 return {}
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
357 result = self._rsm_responses[id_].toDict()
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
358 del self._rsm_responses[id_]
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
359 return result
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
360
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
361
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
362 class PubSubService(pubsub.PubSubService):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
363 """PubSubService extension to handle RSM."""
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
364
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
365 _request_class = PubSubRequest
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
366
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
367 def _toResponse_items(self, result, resource, request):
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
368 response = pubsub.PubSubService._toResponse_items(self, result,
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
369 resource, request)
14
1de25b1f609f tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 12
diff changeset
370 for item in result:
1de25b1f609f tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 12
diff changeset
371 if isinstance(item, tuple):
1de25b1f609f tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 12
diff changeset
372 # XXX: see sat_pubsub.pgsql_storage.LeafNode.getItemsById return value
1de25b1f609f tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 12
diff changeset
373 item = item[0]
15
9019d6cbaf0e tmp (wokkel): fixes changeset 1de25b1f609f (rev 1510)
souliane <souliane@mailoo.org>
parents: 14
diff changeset
374 if item.name == "set":
14
1de25b1f609f tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 12
diff changeset
375 response.addChild(item)
1de25b1f609f tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 12
diff changeset
376 break
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
377
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
378 return response