comparison sat/plugins/plugin_xep_0059.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT plugin for Result Set Management (XEP-0059) 4 # SAT plugin for Result Set Management (XEP-0059)
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) 6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
27 from wokkel import disco 27 from wokkel import disco
28 from wokkel import iwokkel 28 from wokkel import iwokkel
29 from wokkel import rsm 29 from wokkel import rsm
30 30
31 from twisted.words.protocols.jabber import xmlstream 31 from twisted.words.protocols.jabber import xmlstream
32 from zope.interface import implements 32 from zope.interface import implementer
33 33
34 34
35 PLUGIN_INFO = { 35 PLUGIN_INFO = {
36 C.PI_NAME: u"Result Set Management", 36 C.PI_NAME: "Result Set Management",
37 C.PI_IMPORT_NAME: u"XEP-0059", 37 C.PI_IMPORT_NAME: "XEP-0059",
38 C.PI_TYPE: u"XEP", 38 C.PI_TYPE: "XEP",
39 C.PI_PROTOCOLS: [u"XEP-0059"], 39 C.PI_PROTOCOLS: ["XEP-0059"],
40 C.PI_MAIN: u"XEP_0059", 40 C.PI_MAIN: "XEP_0059",
41 C.PI_HANDLER: u"yes", 41 C.PI_HANDLER: "yes",
42 C.PI_DESCRIPTION: _(u"""Implementation of Result Set Management"""), 42 C.PI_DESCRIPTION: _("""Implementation of Result Set Management"""),
43 } 43 }
44 44
45 RSM_PREFIX = u"rsm_" 45 RSM_PREFIX = "rsm_"
46 46
47 47
48 class XEP_0059(object): 48 class XEP_0059(object):
49 # XXX: RSM management is done directly in Wokkel. 49 # XXX: RSM management is done directly in Wokkel.
50 50
51 def __init__(self, host): 51 def __init__(self, host):
52 log.info(_(u"Result Set Management plugin initialization")) 52 log.info(_("Result Set Management plugin initialization"))
53 53
54 def getHandler(self, client): 54 def getHandler(self, client):
55 return XEP_0059_handler() 55 return XEP_0059_handler()
56 56
57 def parseExtra(self, extra): 57 def parseExtra(self, extra):
59 59
60 @param extra(dict): data for parse 60 @param extra(dict): data for parse
61 @return (rsm.RSMRequest, None): request with parsed arguments 61 @return (rsm.RSMRequest, None): request with parsed arguments
62 or None if no RSM arguments have been found 62 or None if no RSM arguments have been found
63 """ 63 """
64 if int(extra.get(RSM_PREFIX + u'max', 0)) < 0: 64 if int(extra.get(RSM_PREFIX + 'max', 0)) < 0:
65 raise ValueError(_(u"rsm_max can't be negative")) 65 raise ValueError(_("rsm_max can't be negative"))
66 66
67 rsm_args = {} 67 rsm_args = {}
68 for arg in (u"max", u"after", u"before", u"index"): 68 for arg in ("max", "after", "before", "index"):
69 try: 69 try:
70 argname = "max_" if arg == u"max" else arg 70 argname = "max_" if arg == "max" else arg
71 rsm_args[argname] = extra.pop(RSM_PREFIX + arg) 71 rsm_args[argname] = extra.pop(RSM_PREFIX + arg)
72 except KeyError: 72 except KeyError:
73 continue 73 continue
74 74
75 if rsm_args: 75 if rsm_args:
93 @return (dict): data dict 93 @return (dict): data dict
94 """ 94 """
95 if data is None: 95 if data is None:
96 data = {} 96 data = {}
97 if rsm_response.first is not None: 97 if rsm_response.first is not None:
98 data[u"rsm_first"] = rsm_response.first 98 data["rsm_first"] = rsm_response.first
99 if rsm_response.last is not None: 99 if rsm_response.last is not None:
100 data[u"rsm_last"] = rsm_response.last 100 data["rsm_last"] = rsm_response.last
101 if rsm_response.index is not None: 101 if rsm_response.index is not None:
102 data[u"rsm_index"] = unicode(rsm_response.index) 102 data["rsm_index"] = str(rsm_response.index)
103 if rsm_response.index is not None: 103 if rsm_response.index is not None:
104 data[u"rsm_index"] = unicode(rsm_response.index) 104 data["rsm_index"] = str(rsm_response.index)
105 return data 105 return data
106 106
107 107
108 @implementer(iwokkel.IDisco)
108 class XEP_0059_handler(xmlstream.XMPPHandler): 109 class XEP_0059_handler(xmlstream.XMPPHandler):
109 implements(iwokkel.IDisco)
110 110
111 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): 111 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
112 return [disco.DiscoFeature(rsm.NS_RSM)] 112 return [disco.DiscoFeature(rsm.NS_RSM)]
113 113
114 def getDiscoItems(self, requestor, target, nodeIdentifier=""): 114 def getDiscoItems(self, requestor, target, nodeIdentifier=""):