Mercurial > sat_tmp
annotate sat_tmp/wokkel/rsm.py @ 69:0721b6254c9e
python 3 port:
- applied 2to3
- replaced zope's implements by @implementer decorator
- replaced references to python2 by python3
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 18:58:11 +0200 |
parents | 938c740d31fe |
children | 76b7ae23dc66 |
rev | line source |
---|---|
8 | 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 | 4 # SàT Wokkel extension for Result Set Management (XEP-0059) |
60 | 5 # Copyright (C) 2015-2019 Jérôme Poisson (goffi@goffi.org) |
6 | 6 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org) |
7 | |
8 # This program is free software: you can redistribute it and/or modify | |
9 # it under the terms of the GNU Affero General Public License as published by | |
10 # the Free Software Foundation, either version 3 of the License, or | |
11 # (at your option) any later version. | |
12 | |
13 # This program is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 # GNU Affero General Public License for more details. | |
17 | |
18 # You should have received a copy of the GNU Affero General Public License | |
19 # 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
|
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 """ |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 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
|
23 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 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
|
25 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
|
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 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from twisted.words.xish import domish |
27
a24c2476f7e0
tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents:
26
diff
changeset
|
29 from twisted.words.protocols.jabber import error |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 |
69 | 31 from . import pubsub |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 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
|
33 |
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 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
|
36 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 |
27
a24c2476f7e0
tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents:
26
diff
changeset
|
38 class RSMError(error.StanzaError): |
1
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 RSM error. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
41 """ |
27
a24c2476f7e0
tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents:
26
diff
changeset
|
42 def __init__(self, text=None): |
a24c2476f7e0
tmp (wokkel.rsm): RSMError now inherit from StanzaError, so they are correctly handled by services
Goffi <goffi@goffi.org>
parents:
26
diff
changeset
|
43 error.StanzaError.__init__(self, 'bad-request', text=text) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
44 |
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 class RSMNotFoundError(Exception): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
47 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
48 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
|
49 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
50 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
51 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
52 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
|
53 """ |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 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
|
55 |
5
4c3e159abf0b
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
56 @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
|
57 @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
|
58 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 @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
|
60 @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
|
61 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 @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
|
63 @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
|
64 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 @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
|
66 @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
|
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 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
69 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
|
70 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
|
71 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 if index is not None: |
5
4c3e159abf0b
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
73 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
|
74 index = int(index) |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
75 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
|
76 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 if after is not None: |
5
4c3e159abf0b
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
78 assert before is None |
69 | 79 assert isinstance(after, str) |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
80 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
|
81 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 if before is not None: |
69 | 83 assert isinstance(before, str) |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
84 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
|
85 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
86 def __str__(self): |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
87 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
|
88 |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 @classmethod |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
90 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
|
91 """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
|
92 |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
93 @param element: request containing a set element, or set element itself. |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 @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
|
95 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 @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
|
97 @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
|
98 """ |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
99 |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
100 if element.name == 'set' and element.uri == NS_RSM: |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
101 set_elt = element |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
102 else: |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
103 try: |
69 | 104 set_elt = next(element.elements(NS_RSM, 'set')) |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
105 except StopIteration: |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
106 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
|
107 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
108 try: |
69 | 109 before_elt = next(set_elt.elements(NS_RSM, 'before')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
110 except StopIteration: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
111 before = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
112 else: |
69 | 113 before = str(before_elt) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
114 |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
115 try: |
69 | 116 after_elt = next(set_elt.elements(NS_RSM, 'after')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
117 except StopIteration: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
118 after = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
119 else: |
69 | 120 after = str(after_elt) |
28
c782fb5237f8
tmp (wokkel.rsm): raise RSMError when <after/> element is empty
Goffi <goffi@goffi.org>
parents:
27
diff
changeset
|
121 if not after: |
c782fb5237f8
tmp (wokkel.rsm): raise RSMError when <after/> element is empty
Goffi <goffi@goffi.org>
parents:
27
diff
changeset
|
122 raise RSMError("<after/> element can't be empty in 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
|
123 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
124 try: |
69 | 125 max_elt = next(set_elt.elements(NS_RSM, 'max')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
126 except StopIteration: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
127 # 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
|
128 # <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
|
129 raise RSMError("RSM request is missing its 'max' element") |
21
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: |
69 | 132 max_ = int(str(max_elt)) |
21
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 '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
|
135 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
136 try: |
69 | 137 index_elt = next(set_elt.elements(NS_RSM, 'index')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
138 except StopIteration: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
139 index = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
140 else: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
141 try: |
69 | 142 index = int(str(index_elt)) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
143 except ValueError: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
144 raise RSMError("bad value for 'index' element") |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
145 |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
146 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
|
147 |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
148 def toElement(self): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
149 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
150 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
|
151 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 @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
|
153 """ |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 set_elt = domish.Element((NS_RSM, 'set')) |
69 | 155 set_elt.addElement('max', content=str(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
|
156 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 if self.index is not None: |
69 | 158 set_elt.addElement('index', content=str(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
|
159 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 else: |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
164 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
|
165 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 if self.after is not None: |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
167 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
|
168 |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
169 return set_elt |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
170 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
171 def render(self, element): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
172 """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
|
173 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
174 @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
|
175 @type element: L{domish.Element} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
176 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
177 @return: RSM request element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
178 @rtype: L{domish.Element} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
179 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
180 set_elt = self.toElement() |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
181 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
|
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 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
|
184 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
186 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
|
187 """ |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 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
|
189 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 @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
|
191 @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
|
192 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 @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
|
194 @itype last: C{unicode} |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
195 |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
196 @ivar index: starting index of the returned page. |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
197 @itype index: C{int} |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
198 |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
199 @ivar count: total number of items. |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
200 @itype count: C{int} |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
201 |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 """ |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
204 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
|
205 if first is None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
206 assert last is None and index is None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
207 if last is None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
208 assert first is None |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
209 self.first = first |
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
210 self.last = last |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
211 if count is not None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
212 self.count = int(count) |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
213 else: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
214 self.count = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
215 if index is not None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
216 self.index = int(index) |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
217 else: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
218 self.index = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
219 |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
220 def __str__(self): |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
221 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
|
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 @classmethod |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
224 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
|
225 """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
|
226 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 @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
|
228 @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
|
229 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 @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
|
231 @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
|
232 """ |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 try: |
69 | 234 set_elt = next(element.elements(NS_RSM, 'set')) |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 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
|
236 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
|
237 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
238 try: |
69 | 239 first_elt = next(set_elt.elements(NS_RSM, 'first')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
240 except StopIteration: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
241 first = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
242 index = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
243 else: |
69 | 244 first = str(first_elt) |
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 index = int(first_elt['index']) |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
247 except KeyError: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
248 index = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
249 except ValueError: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
250 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
|
251 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
252 try: |
69 | 253 last_elt = next(set_elt.elements(NS_RSM, 'last')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
254 except StopIteration: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
255 if first is not None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
256 raise RSMError("RSM response is missing its 'last' element") |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
257 else: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
258 last = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
259 else: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
260 if first is None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
261 raise RSMError("RSM response is missing its 'first' element") |
69 | 262 last = str(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
|
263 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
264 try: |
69 | 265 count_elt = next(set_elt.elements(NS_RSM, 'count')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
266 except StopIteration: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
267 count = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
268 else: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
269 try: |
69 | 270 count = int(str(count_elt)) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
271 except ValueError: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
272 raise RSMError("invalid count in RSM response") |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
273 |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
274 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
|
275 |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
276 def toElement(self): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
277 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
278 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
|
279 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 @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
|
281 """ |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 set_elt = domish.Element((NS_RSM, 'set')) |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
283 if self.first is not None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
284 first_elt = set_elt.addElement('first', content=self.first) |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
285 if self.index is not None: |
69 | 286 first_elt['index'] = str(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
|
287 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
288 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
|
289 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
290 if self.count is not None: |
69 | 291 set_elt.addElement('count', content=str(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
|
292 |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
293 return set_elt |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
294 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
295 def render(self, element): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
296 """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
|
297 |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
298 @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
|
299 @type element: L{domish.Element} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
300 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
301 @return: RSM request element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
302 @rtype: L{domish.Element} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
303 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
304 set_elt = self.toElement() |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
305 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
|
306 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
|
307 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 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
|
309 """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
|
310 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 @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
|
312 @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
|
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 result = {} |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
315 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
|
316 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
|
317 if value is not None: |
69 | 318 result[attr] = str(value) |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 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
|
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 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
|
323 """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
|
324 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 @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
|
326 @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
|
327 """ |
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 rsm = None |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
330 _parameters = copy.deepcopy(pubsub.PubSubRequest._parameters) |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
331 _parameters['items'].append('rsm') |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 def _parse_rsm(self, verbElement): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
334 try: |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
335 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
|
336 except RSMNotFoundError: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
0
diff
changeset
|
337 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
|
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 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
|
340 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
|
341 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
|
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 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 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
|
345 """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
|
346 |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
347 _request_class = PubSubRequest |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 |
58
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
349 def items(self, service, nodeIdentifier, maxItems=None, |
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
350 subscriptionIdentifier=None, sender=None, itemIdentifiers=None, |
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
351 orderBy=None, rsm_request=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
|
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 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
|
354 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 @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
|
356 @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
|
357 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 @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
|
359 @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
|
360 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 @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
|
362 @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
|
363 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
364 @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
|
365 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
|
366 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
|
367 @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
|
368 |
58
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
369 @param itemIdentifiers: Identifiers of the items to be retrieved. |
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
370 @type itemIdentifiers: C{set} |
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
371 |
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
372 @param orderBy: Keys to order by |
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
373 @type orderBy: L{list} of L{unicode} |
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
374 |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 @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
|
376 @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
|
377 |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
378 @return: a Deferred that fires a C{list} of C{tuple} of L{domish.Element}, L{RSMResponse}. |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 @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
|
380 """ |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
381 # XXX: we have to copy initial method instead of calling it, |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
382 # as original cb remove all non item elements |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
383 request = self._request_class('items') |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 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
|
385 request.nodeIdentifier = nodeIdentifier |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
386 if maxItems: |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
387 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
|
388 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
|
389 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
|
390 request.itemIdentifiers = itemIdentifiers |
58
f4d569dc8e6b
wokkel/mam, wokkel/pubsub, wokkel/rsm: implemented "order-by" protoXEP (for Pubsub and MAM)
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
391 request.orderBy = orderBy |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
392 request.rsm = 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
|
393 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
394 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
|
395 items = [] |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
396 pubsub_elt = iq.pubsub |
34
213122b92b08
tmp/wokkel (rsm): fixes elements count (items retrieval with RSM max = 0)
souliane <souliane@mailoo.org>
parents:
28
diff
changeset
|
397 if pubsub_elt.items: |
213122b92b08
tmp/wokkel (rsm): fixes elements count (items retrieval with RSM max = 0)
souliane <souliane@mailoo.org>
parents:
28
diff
changeset
|
398 for element in pubsub_elt.items.elements(pubsub.NS_PUBSUB, 'item'): |
213122b92b08
tmp/wokkel (rsm): fixes elements count (items retrieval with RSM max = 0)
souliane <souliane@mailoo.org>
parents:
28
diff
changeset
|
399 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
|
400 |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
401 try: |
25
4816f7d55367
tmp (wokkel.rsm): fixed forgotten method renaming
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
402 rsm_response = RSMResponse.fromElement(pubsub_elt) |
23
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
403 except RSMNotFoundError: |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
404 rsm_response = None |
777b4e63fc8a
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
405 return (items, 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
|
406 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 |
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 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
|
413 """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
|
414 |
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
415 _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
|
416 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
417 def _toResponse_items(self, elts, resource, request): |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
418 # default method only manage <item/> elements |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
419 # but we need to add RSM set element |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
420 rsm_elt = None |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
421 for idx, elt in enumerate(reversed(elts)): |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
422 if elt.name == "set" and elt.uri == NS_RSM: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
423 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
|
424 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
|
425 |
21
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
426 response = pubsub.PubSubService._toResponse_items(self, elts, |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
427 resource, request) |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
428 if rsm_elt is not None: |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
429 response.addChild(rsm_elt) |
54f834e40341
tmp (wokkel/rsm): various improvments:
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
430 |
0
09e7c32a6a00
use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
431 return response |