Mercurial > libervia-pubsub
comparison sat_pubsub/mam.py @ 414:ccb2a22ea0fc
Python 3 port:
/!\ Python 3.6+ is now needed to use SàT Pubsub
/!\ instability may occur and features may not be working anymore, this will improve with time
The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs
for details).
Python minimal version has been updated in setup.py
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 16 Aug 2019 12:53:33 +0200 |
parents | c56a728412f1 |
children | 5e8b8ef5c862 |
comparison
equal
deleted
inserted
replaced
413:a5edf5e1dd74 | 414:ccb2a22ea0fc |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/env python3 |
2 #-*- coding: utf-8 -*- | 2 #-*- coding: utf-8 -*- |
3 | 3 |
4 # Copyright (c) 2016 Jérôme Poisson | 4 # Copyright (c) 2016 Jérôme Poisson |
5 # Copyright (c) 2015-2016 Adrien Cossa | 5 # Copyright (c) 2015-2016 Adrien Cossa |
6 # | 6 # |
23 This protocol is specified in | 23 This protocol is specified in |
24 U{XEP-0313<http://xmpp.org/extensions/xep-0313.html>}. | 24 U{XEP-0313<http://xmpp.org/extensions/xep-0313.html>}. |
25 """ | 25 """ |
26 | 26 |
27 | 27 |
28 from zope.interface import implements | 28 from zope.interface import implementer |
29 | 29 |
30 from twisted.words.xish import domish | 30 from twisted.words.xish import domish |
31 from twisted.python import log | 31 from twisted.python import log |
32 from twisted.words.protocols.jabber import error | 32 from twisted.words.protocols.jabber import error |
33 | 33 |
38 from wokkel import rsm | 38 from wokkel import rsm |
39 from wokkel import mam | 39 from wokkel import mam |
40 from wokkel import delay | 40 from wokkel import delay |
41 | 41 |
42 | 42 |
43 @implementer(mam.IMAMResource) | |
43 class MAMResource(object): | 44 class MAMResource(object): |
44 implements(mam.IMAMResource) | |
45 _errorMap = backend.PubSubResourceFromBackend._errorMap | 45 _errorMap = backend.PubSubResourceFromBackend._errorMap |
46 | 46 |
47 def __init__(self, backend_): | 47 def __init__(self, backend_): |
48 self.backend = backend_ | 48 self.backend = backend_ |
49 | 49 |
50 def _mapErrors(self, failure): | 50 def _mapErrors(self, failure): |
51 # XXX: come from backend.PubsubResourceFromBackend | 51 # XXX: come from backend.PubsubResourceFromBackend |
52 e = failure.trap(*self._errorMap.keys()) | 52 e = failure.trap(*list(self._errorMap.keys())) |
53 | 53 |
54 condition, pubsubCondition, feature = self._errorMap[e] | 54 condition, pubsubCondition, feature = self._errorMap[e] |
55 msg = failure.value.msg | 55 msg = failure.value.msg |
56 | 56 |
57 if pubsubCondition: | 57 if pubsubCondition: |
75 pep = mam_request.delegated | 75 pep = mam_request.delegated |
76 except AttributeError: | 76 except AttributeError: |
77 pep = False | 77 pep = False |
78 ext_data = {'pep': pep} | 78 ext_data = {'pep': pep} |
79 if mam_request.form: | 79 if mam_request.form: |
80 ext_data['filters'] = mam_request.form.fields.values() | 80 ext_data['filters'] = list(mam_request.form.fields.values()) |
81 if mam_request.rsm is None: | 81 if mam_request.rsm is None: |
82 if const.VAL_RSM_MAX_DEFAULT != None: | 82 if const.VAL_RSM_MAX_DEFAULT != None: |
83 log.msg("MAM request without RSM limited to {}".format(const.VAL_RSM_MAX_DEFAULT)) | 83 log.msg("MAM request without RSM limited to {}".format(const.VAL_RSM_MAX_DEFAULT)) |
84 ext_data['rsm'] = rsm.RSMRequest(const.VAL_RSM_MAX_DEFAULT) | 84 ext_data['rsm'] = rsm.RSMRequest(const.VAL_RSM_MAX_DEFAULT) |
85 else: | 85 else: |
112 # XXX: we check if it is the last page using initial request data | 112 # XXX: we check if it is the last page using initial request data |
113 # and RSM element data. In this case, we must have the | 113 # and RSM element data. In this case, we must have the |
114 # "complete" | 114 # "complete" |
115 # attribute set to "true". | 115 # attribute set to "true". |
116 page_max = (int(rsm_elt.first['index']) + 1) * mam_request.rsm.max | 116 page_max = (int(rsm_elt.first['index']) + 1) * mam_request.rsm.max |
117 count = int(unicode(rsm_elt.count)) | 117 count = int(str(rsm_elt.count)) |
118 if page_max >= count: | 118 if page_max >= count: |
119 # the maximum items which can be displayed is equal to or | 119 # the maximum items which can be displayed is equal to or |
120 # above the total number of items, which means we are complete | 120 # above the total number of items, which means we are complete |
121 attributes['complete'] = "true" | 121 attributes['complete'] = "true" |
122 else: | 122 else: |