annotate src/tmp/wokkel/rsm.py @ 2062:e22ab34c68f6

quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
author Goffi <goffi@goffi.org>
date Fri, 09 Sep 2016 23:54:33 +0200
parents 37db78010752
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1424
2d8fccec84e8 core (tests): test fixes
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
1 # -*- coding: utf-8 -*-
1266
9141bde7ff31 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 -*-
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
3 #
1422
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
4 # SàT Wokkel extension for Result Set Management (XEP-0059)
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
5 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org)
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
6
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
7 # This program is free software: you can redistribute it and/or modify
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
10 # (at your option) any later version.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
11
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
12 # This program is distributed in the hope that it will be useful,
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
15 # GNU Affero General Public License for more details.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
16
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
19
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
20 """
9141bde7ff31 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.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
22
9141bde7ff31 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
9141bde7ff31 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>}.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
25 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
26
9141bde7ff31 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
1782
514ade866261 tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents: 1781
diff changeset
28 from twisted.words.protocols.jabber import error
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
29
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
30 import pubsub
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
31 import copy
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
32
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
33
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
34 NS_RSM = 'http://jabber.org/protocol/rsm'
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
35
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
36
1782
514ade866261 tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents: 1781
diff changeset
37 class RSMError(error.StanzaError):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
38 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
39 RSM error.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
40 """
1782
514ade866261 tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents: 1781
diff changeset
41 def __init__(self, text=None):
514ade866261 tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents: 1781
diff changeset
42 error.StanzaError.__init__(self, 'bad-request', text=text)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
43
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
44
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
45 class RSMNotFoundError(Exception):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
46 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
47 An expected RSM element has not been found.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
48 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
49
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
50
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
51 class RSMRequest(object):
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
52 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
53 A Result Set Management request.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
54
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1283
diff changeset
55 @ivar max_: limit on the number of retrieved items.
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1283
diff changeset
56 @itype max_: C{int} or C{unicode}
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
57
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
58 @ivar index: starting index of the requested page.
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
59 @itype index: C{int} or C{unicode} or C{None}
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
60
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
61 @ivar after: ID of the element immediately preceding the page.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
62 @itype after: C{unicode}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
63
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
64 @ivar before: ID of the element immediately following the page.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
65 @itype before: C{unicode}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
66 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
67
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
68 def __init__(self, max_=10, after=None, before=None, index=None):
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
69 self.max = int(max_)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
70
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
71 if index is not None:
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1283
diff changeset
72 assert after is None and before is None
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
73 index = int(index)
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
74 self.index = index
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
75
9141bde7ff31 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:
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1283
diff changeset
77 assert before is None
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
78 assert isinstance(after, basestring)
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
79 self.after = after
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
80
9141bde7ff31 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:
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
82 assert isinstance(before, basestring)
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
83 self.before = before
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
84
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
85 def __str__(self):
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
86 return "RSM Request: max={0.max} after={0.after} before={0.before} index={0.index}".format(self)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
87
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
88 @classmethod
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
89 def fromElement(cls, element):
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
90 """Parse the given request element.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
91
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
92 @param element: request containing a set element, or set element itself.
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
93 @type element: L{domish.Element}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
94
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
95 @return: RSMRequest instance.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
96 @rtype: L{RSMRequest}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
97 """
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
98
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
99 if element.name == 'set' and element.uri == NS_RSM:
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
100 set_elt = element
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
101 else:
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
102 try:
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
103 set_elt = element.elements(NS_RSM, 'set').next()
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
104 except StopIteration:
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
105 raise RSMNotFoundError()
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
106
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
107 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
108 before_elt = set_elt.elements(NS_RSM, 'before').next()
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
109 except StopIteration:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
110 before = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
111 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
112 before = unicode(before_elt)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
113
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
114 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
115 after_elt = set_elt.elements(NS_RSM, 'after').next()
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
116 except StopIteration:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
117 after = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
118 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
119 after = unicode(after_elt)
1783
e393b96dc553 tmp (wokkel.rsm): raise RSMError when <after/> element is empty
Goffi <goffi@goffi.org>
parents: 1782
diff changeset
120 if not after:
e393b96dc553 tmp (wokkel.rsm): raise RSMError when <after/> element is empty
Goffi <goffi@goffi.org>
parents: 1782
diff changeset
121 raise RSMError("<after/> element can't be empty in RSM request")
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
122
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
123 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
124 max_elt = set_elt.elements(NS_RSM, 'max').next()
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
125 except StopIteration:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
126 # FIXME: even if it doesn't make a lot of sense without it
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
127 # <max/> element is not mandatory in XEP-0059
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
128 raise RSMError("RSM request is missing its 'max' element")
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
129 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
130 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
131 max_ = int(unicode(max_elt))
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
132 except ValueError:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
133 raise RSMError("bad value for 'max' element")
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
134
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
135 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
136 index_elt = set_elt.elements(NS_RSM, 'index').next()
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
137 except StopIteration:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
138 index = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
139 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
140 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
141 index = int(unicode(index_elt))
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
142 except ValueError:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
143 raise RSMError("bad value for 'index' element")
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
144
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
145 return RSMRequest(max_, after, before, index)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
146
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
147 def toElement(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
148 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
149 Return the DOM representation of this RSM request.
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
150
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
151 @rtype: L{domish.Element}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
152 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
153 set_elt = domish.Element((NS_RSM, 'set'))
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
154 set_elt.addElement('max', content=unicode(self.max))
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
155
9141bde7ff31 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.index is not None:
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
157 set_elt.addElement('index', content=unicode(self.index))
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
158
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
159 if self.before is not None:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
160 if self.before == '': # request the last page
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
161 set_elt.addElement('before')
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
162 else:
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
163 set_elt.addElement('before', content=self.before)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
164
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
165 if self.after is not None:
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
166 set_elt.addElement('after', content=self.after)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
167
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
168 return set_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
169
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
170 def render(self, element):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
171 """Embed the DOM representation of this RSM request in the given element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
172
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
173 @param element: Element to contain the RSM request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
174 @type element: L{domish.Element}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
175
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
176 @return: RSM request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
177 @rtype: L{domish.Element}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
178 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
179 set_elt = self.toElement()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
180 element.addChild(set_elt)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
181
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
182 return set_elt
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
183
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
184
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
185 class RSMResponse(object):
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
186 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
187 A Result Set Management response.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
188
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
189 @ivar first: ID of the first element of the returned page.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
190 @itype first: C{unicode}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
191
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
192 @ivar last: ID of the last element of the returned page.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
193 @itype last: C{unicode}
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
194
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
195 @ivar index: starting index of the returned page.
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
196 @itype index: C{int}
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
197
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
198 @ivar count: total number of items.
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
199 @itype count: C{int}
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
200
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
201 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
202
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
203 def __init__(self, first=None, last=None, index=None, count=None):
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
204 if first is None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
205 assert last is None and index is None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
206 if last is None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
207 assert first is None
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
208 self.first = first
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
209 self.last = last
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
210 if count is not None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
211 self.count = int(count)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
212 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
213 self.count = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
214 if index is not None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
215 self.index = int(index)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
216 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
217 self.index = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
218
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
219 def __str__(self):
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
220 return "RSM Request: first={0.first} last={0.last} index={0.index} count={0.count}".format(self)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
221
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
222 @classmethod
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
223 def fromElement(cls, element):
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
224 """Parse the given response element.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
225
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
226 @param element: response element.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
227 @type element: L{domish.Element}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
228
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
229 @return: RSMResponse instance.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
230 @rtype: L{RSMResponse}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
231 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
232 try:
1432
60c41422ee48 tmp (rsm): better use of domish.Element.elements() + minor fixes
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
233 set_elt = element.elements(NS_RSM, 'set').next()
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
234 except StopIteration:
1439
ea48663b2605 tmp (wokkel): pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 1432
diff changeset
235 raise RSMNotFoundError()
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
236
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
237 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
238 first_elt = set_elt.elements(NS_RSM, 'first').next()
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
239 except StopIteration:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
240 first = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
241 index = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
242 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
243 first = unicode(first_elt)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
244 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
245 index = int(first_elt['index'])
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
246 except KeyError:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
247 index = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
248 except ValueError:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
249 raise RSMError("bad index in RSM response")
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
250
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
251 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
252 last_elt = set_elt.elements(NS_RSM, 'last').next()
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
253 except StopIteration:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
254 if first is not None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
255 raise RSMError("RSM response is missing its 'last' element")
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
256 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
257 last = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
258 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
259 if first is None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
260 raise RSMError("RSM response is missing its 'first' element")
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
261 last = unicode(last_elt)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
262
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
263 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
264 count_elt = set_elt.elements(NS_RSM, 'count').next()
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
265 except StopIteration:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
266 count = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
267 else:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
268 try:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
269 count = int(unicode(count_elt))
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
270 except ValueError:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
271 raise RSMError("invalid count in RSM response")
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
272
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
273 return RSMResponse(first, last, index, count)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
274
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
275 def toElement(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
276 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
277 Return the DOM representation of this RSM request.
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
278
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
279 @rtype: L{domish.Element}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
280 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
281 set_elt = domish.Element((NS_RSM, 'set'))
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
282 if self.first is not None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
283 first_elt = set_elt.addElement('first', content=self.first)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
284 if self.index is not None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
285 first_elt['index'] = unicode(self.index)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
286
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
287 set_elt.addElement('last', content=self.last)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
288
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
289 if self.count is not None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
290 set_elt.addElement('count', content=unicode(self.count))
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
291
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
292 return set_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
293
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
294 def render(self, element):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
295 """Embed the DOM representation of this RSM response in the given element.
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
296
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
297 @param element: Element to contain the RSM response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
298 @type element: L{domish.Element}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
299
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
300 @return: RSM request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
301 @rtype: L{domish.Element}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
302 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
303 set_elt = self.toElement()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
304 element.addChild(set_elt)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
305 return set_elt
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
306
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
307 def toDict(self):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
308 """Return a dict representation of the object.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
309
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
310 @return: a dict of strings.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
311 @rtype: C{dict} binding C{unicode} to C{unicode}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
312 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
313 result = {}
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
314 for attr in ('first', 'last', 'index', 'count'):
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
315 value = getattr(self, attr)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
316 if value is not None:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
317 result[attr] = unicode(value)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
318 return result
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
319
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
320
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
321 class PubSubRequest(pubsub.PubSubRequest):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
322 """PubSubRequest extension to handle RSM.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
323
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
324 @ivar rsm: RSM request instance.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
325 @type rsm: L{RSMRequest}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
326 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
327
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
328 rsm = None
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
329 _parameters = copy.deepcopy(pubsub.PubSubRequest._parameters)
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
330 _parameters['items'].append('rsm')
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
331
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
332 def _parse_rsm(self, verbElement):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
333 try:
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
334 self.rsm = RSMRequest.fromElement(verbElement.parent)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
335 except RSMNotFoundError:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents: 1266
diff changeset
336 self.rsm = None
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
337
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
338 def _render_rsm(self, verbElement):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
339 if self.rsm:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
340 self.rsm.render(verbElement.parent)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
341
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
342
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
343 class PubSubClient(pubsub.PubSubClient):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
344 """PubSubClient extension to handle RSM."""
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
345
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
346 _request_class = PubSubRequest
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
347
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
348 def items(self, service, nodeIdentifier, maxItems=None, itemIdentifiers=None,
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
349 subscriptionIdentifier=None, sender=None, rsm_request=None):
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
350 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
351 Retrieve previously published items from a publish subscribe node.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
352
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
353 @param service: The publish subscribe service that keeps the node.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
354 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
355
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
356 @param nodeIdentifier: The identifier of the node.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
357 @type nodeIdentifier: C{unicode}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
358
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
359 @param maxItems: Optional limit on the number of retrieved items.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
360 @type maxItems: C{int}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
361
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
362 @param itemIdentifiers: Identifiers of the items to be retrieved.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
363 @type itemIdentifiers: C{set}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
364
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
365 @param subscriptionIdentifier: Optional subscription identifier. In
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
366 case the node has been subscribed to multiple times, this narrows
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
367 the results to the specific subscription.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
368 @type subscriptionIdentifier: C{unicode}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
369
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
370 @param ext_data: extension data.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
371 @type ext_data: L{dict}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
372
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
373 @return: a Deferred that fires a C{list} of C{tuple} of L{domish.Element}, L{RSMResponse}.
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
374 @rtype: L{defer.Deferred}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
375 """
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
376 # XXX: we have to copy initial method instead of calling it,
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
377 # as original cb remove all non item elements
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
378 request = self._request_class('items')
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
379 request.recipient = service
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
380 request.nodeIdentifier = nodeIdentifier
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
381 if maxItems:
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
382 request.maxItems = str(int(maxItems))
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
383 request.subscriptionIdentifier = subscriptionIdentifier
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
384 request.sender = sender
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
385 request.itemIdentifiers = itemIdentifiers
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
386 request.rsm = rsm_request
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
387
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
388 def cb(iq):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
389 items = []
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
390 pubsub_elt = iq.pubsub
1914
37db78010752 tmp/wokkel (rsm): fixes elements count (items retrieval with RSM max = 0)
souliane <souliane@mailoo.org>
parents: 1783
diff changeset
391 if pubsub_elt.items:
37db78010752 tmp/wokkel (rsm): fixes elements count (items retrieval with RSM max = 0)
souliane <souliane@mailoo.org>
parents: 1783
diff changeset
392 for element in pubsub_elt.items.elements(pubsub.NS_PUBSUB, 'item'):
37db78010752 tmp/wokkel (rsm): fixes elements count (items retrieval with RSM max = 0)
souliane <souliane@mailoo.org>
parents: 1783
diff changeset
393 items.append(element)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
394
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
395 try:
1780
4beb613d277c tmp (wokkel.rsm): fixed forgotten method renaming
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
396 rsm_response = RSMResponse.fromElement(pubsub_elt)
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
397 except RSMNotFoundError:
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
398 rsm_response = None
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1771
diff changeset
399 return (items, rsm_response)
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
400
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
401 d = request.send(self.xmlstream)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
402 d.addCallback(cb)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
403 return d
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
404
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
405
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
406 class PubSubService(pubsub.PubSubService):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
407 """PubSubService extension to handle RSM."""
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
408
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
409 _request_class = PubSubRequest
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
410
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
411 def _toResponse_items(self, elts, resource, request):
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
412 # default method only manage <item/> elements
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
413 # but we need to add RSM set element
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
414 rsm_elt = None
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
415 for idx, elt in enumerate(reversed(elts)):
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
416 if elt.name == "set" and elt.uri == NS_RSM:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
417 rsm_elt = elts.pop(-1-idx)
1510
91631837ce5c tmp (wokkel): fixes RSM implementation to fit sat_pubsub answer when in "unrestricted" mode
souliane <souliane@mailoo.org>
parents: 1455
diff changeset
418 break
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
419
1771
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
420 response = pubsub.PubSubService._toResponse_items(self, elts,
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
421 resource, request)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
422 if rsm_elt is not None:
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
423 response.addChild(rsm_elt)
b77dc676a4df tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents: 1768
diff changeset
424
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
425 return response