annotate wokkel/rsm.py @ 21:54f834e40341

tmp (wokkel/rsm): various improvments: - restored original tmp.wokkel.pubsub.PubSubService._toResponse_items - changed arguments order in RSMRequest.__init__ to have most common arguments first - added __str__ methods - better parsing/toElement - better handling of optional elements/attributes (count/index) - _toResponse_items handler RSM set elements without modifying original pubsub _toResponse_items - renamed parse to fromElement for coherency
author Goffi <goffi@goffi.org>
date Tue, 05 Jan 2016 23:20:20 +0100
parents 80f9a1a3d002
children 777b4e63fc8a
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
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
48 class RSMRequest(object):
0
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
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
65 def __init__(self, max_=10, after=None, before=None, index=None):
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
66 self.max = int(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
67
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
68 if index is not None:
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
69 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
70 index = int(index)
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
71 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
72
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
73 if after is not None:
5
4c3e159abf0b plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1
diff changeset
74 assert before is None
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
75 assert isinstance(after, basestring)
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
76 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
77
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
78 if before is not None:
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
79 assert isinstance(before, basestring)
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
80 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
81
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
82 def __str__(self):
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
83 return "RSM Request: max={0.max} after={0.after} before={0.before} index={0.index}".format(self)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
84
0
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
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
86 def fromElement(cls, 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
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
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
100 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
101 before_elt = set_elt.elements(NS_RSM, 'before').next()
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
102 except StopIteration:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
103 before = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
104 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
105 before = unicode(before_elt)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
106
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
107 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
108 after_elt = set_elt.elements(NS_RSM, 'after').next()
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
109 except StopIteration:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
110 after = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
111 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
112 after = unicode(after_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
113
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
114 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
115 max_elt = set_elt.elements(NS_RSM, 'max').next()
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
116 except StopIteration:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
117 # FIXME: even if it doesn't make a lot of sense without it
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
118 # <max/> element is not mandatory in XEP-0059
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
119 raise RSMError("RSM request is missing its 'max' element")
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
120 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
121 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
122 max_ = int(unicode(max_elt))
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
123 except ValueError:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
124 raise RSMError("bad value for '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
125
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
126 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
127 index_elt = set_elt.elements(NS_RSM, 'index').next()
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
128 except StopIteration:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
129 index = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
130 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
131 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
132 index = int(unicode(index_elt))
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
133 except ValueError:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
134 raise RSMError("bad value for 'index' element")
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
135
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
136 return RSMRequest(max_, after, before, 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
137
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
138 def toElement(self):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
139 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
140 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
141
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
142 @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
143 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
144 set_elt = domish.Element((NS_RSM, 'set'))
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
145 set_elt.addElement('max', content=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
146
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
147 if self.index is not None:
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
148 set_elt.addElement('index', content=unicode(self.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
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 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
151 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
152 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
153 else:
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
154 set_elt.addElement('before', content=self.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
155
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
156 if self.after is not None:
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
157 set_elt.addElement('after', content=self.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
158
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
159 return set_elt
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
160
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
161 def render(self, element):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
162 """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
163
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
164 @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
165 @type element: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
166
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
167 @return: RSM request element.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
168 @rtype: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
169 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
170 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
171 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
172
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
173 set_elt = self.toElement()
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
174 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
175
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
176 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
177
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
178
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
179 class RSMResponse(object):
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
180 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
181 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
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 @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
184 @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
185
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
186 @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
187 @itype last: C{unicode}
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
188
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
189 @ivar index: starting index of the returned page.
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
190 @itype index: C{int}
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
191
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
192 @ivar count: total number of items.
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
193 @itype count: C{int}
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
194
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 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
196
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
197 def __init__(self, first=None, last=None, index=None, count=None):
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
198 if first is None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
199 assert last is None and index is None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
200 if last is None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
201 assert first is None
7
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
202 self.first = first
1e21b4e94566 plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 6
diff changeset
203 self.last = last
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
204 if count is not None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
205 self.count = int(count)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
206 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
207 self.count = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
208 if index is not None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
209 self.index = int(index)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
210 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
211 self.index = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
212
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
213 def __str__(self):
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
214 return "RSM Request: first={0.first} last={0.last} index={0.index} count={0.count}".format(self)
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 @classmethod
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
217 def fromElement(cls, 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
218 """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
219
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
220 @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
221 @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
222
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
223 @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
224 @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
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 try:
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
227 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
228 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
229 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
230
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
231 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
232 first_elt = set_elt.elements(NS_RSM, 'first').next()
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
233 except StopIteration:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
234 first = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
235 index = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
236 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
237 first = unicode(first_elt)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
238 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
239 index = int(first_elt['index'])
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
240 except KeyError:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
241 index = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
242 except ValueError:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
243 raise RSMError("bad index in RSM response")
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
244
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
245 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
246 last_elt = set_elt.elements(NS_RSM, 'last').next()
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
247 except StopIteration:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
248 if first is not None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
249 raise RSMError("RSM response is missing its 'last' element")
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
250 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
251 last = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
252 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
253 if first is None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
254 raise RSMError("RSM response is missing its 'first' element")
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
255 last = unicode(last_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
256
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
257 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
258 count_elt = set_elt.elements(NS_RSM, 'count').next()
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
259 except StopIteration:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
260 count = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
261 else:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
262 try:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
263 count = int(unicode(count_elt))
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
264 except ValueError:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
265 raise RSMError("invalid count in RSM response")
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
266
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
267 return RSMResponse(first, last, index, 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
268
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
269 def toElement(self):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
270 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
271 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
272
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
273 @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
274 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
275 set_elt = domish.Element((NS_RSM, 'set'))
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
276 if self.first is not None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
277 first_elt = set_elt.addElement('first', content=self.first)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
278 if self.index is not None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
279 first_elt['index'] = unicode(self.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
280
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
281 set_elt.addElement('last', content=self.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
282
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
283 if self.count is not None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
284 set_elt.addElement('count', content=unicode(self.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
285
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
286 return set_elt
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
287
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
288 def render(self, element):
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
289 """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
290
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
291 @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
292 @type element: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
293
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
294 @return: RSM request element.
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
295 @rtype: L{domish.Element}
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
296 """
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
297 set_elt = self.toElement()
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
298 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
299 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
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 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
302 """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
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 @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
305 @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
306 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
307 result = {}
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
308 for attr in ('first', 'last', 'index', '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
309 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
310 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
311 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
312 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
313
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 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
316 """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
317
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
318 @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
319 @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
320 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
321
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
322 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
323
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
324 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
325 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
326 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
327 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
328
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
329 def _parse_rsm(self, verbElement):
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
330 try:
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
331 self.rsm = RSMRequest.fromElement(verbElement.parent)
1
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
332 except RSMNotFoundError:
9d35f88168a1 tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 0
diff changeset
333 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
334
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
335 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
336 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
337 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
338
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
339
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
340 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
341 """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
342
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
343 _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
344
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
345 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
346 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
347 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
348 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
349
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
350 @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
351 @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
352
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
353 @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
354 @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
355
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
356 @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
357 @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
358
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
359 @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
360 @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
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 @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
363 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
364 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
365 @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
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 @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
368 @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
369
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
370 @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
371 @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
372 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
373 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
374 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
375 request.nodeIdentifier = nodeIdentifier
16
4629645a368d tmp (wokkel): fixes RSM when maxItems is 0
souliane <souliane@mailoo.org>
parents: 15
diff changeset
376 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
377 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
378 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
379 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
380 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
381 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
382 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
383
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
384 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
385 items = []
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
386 if iq.pubsub.items:
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
387 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
388 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
389
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
390 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
391 try:
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
392 response = RSMResponse.fromElement(iq.pubsub)
11
bcdae28d2b1f tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 9
diff changeset
393 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
394 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
395 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
396 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
397 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
398
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
399 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
400 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
401 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
402
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
403 def getRSMResponse(self, id_):
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
404 """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
405
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
406 @param id_: extension data ID
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
407 @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
408
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
409 @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
410 @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
411 """
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
412 # 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
413 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
414 return {}
9
9a4c367b22bb tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 8
diff changeset
415 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
416 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
417 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
418
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
419
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
420 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
421 """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
422
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
423 _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
424
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
425 def _toResponse_items(self, elts, resource, request):
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
426 # default method only manage <item/> elements
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
427 # but we need to add RSM set element
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
428 rsm_elt = None
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
429 for idx, elt in enumerate(reversed(elts)):
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
430 if elt.name == "set" and elt.uri == NS_RSM:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
431 rsm_elt = elts.pop(-1-idx)
14
1de25b1f609f tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 12
diff changeset
432 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
433
21
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
434 response = pubsub.PubSubService._toResponse_items(self, elts,
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
435 resource, request)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
436 if rsm_elt is not None:
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
437 response.addChild(rsm_elt)
54f834e40341 tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 19
diff changeset
438
0
09e7c32a6a00 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
439 return response