Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0059.py @ 2700:035901dc946d
plugin XEP-0059: added "parseExtra" method to easily handle RSM argument coming from bridge.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Dec 2018 10:10:25 +0100 |
parents | 56f94936df1e |
children | e3f6de6ce320 |
comparison
equal
deleted
inserted
replaced
2699:310e41bd6666 | 2700:035901dc946d |
---|---|
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 implements |
33 | 33 |
34 | 34 |
35 PLUGIN_INFO = { | 35 PLUGIN_INFO = { |
36 C.PI_NAME: "Result Set Management", | 36 C.PI_NAME: u"Result Set Management", |
37 C.PI_IMPORT_NAME: "XEP-0059", | 37 C.PI_IMPORT_NAME: u"XEP-0059", |
38 C.PI_TYPE: "XEP", | 38 C.PI_TYPE: u"XEP", |
39 C.PI_PROTOCOLS: ["XEP-0059"], | 39 C.PI_PROTOCOLS: [u"XEP-0059"], |
40 C.PI_MAIN: "XEP_0059", | 40 C.PI_MAIN: u"XEP_0059", |
41 C.PI_HANDLER: "yes", | 41 C.PI_HANDLER: u"yes", |
42 C.PI_DESCRIPTION: _("""Implementation of Result Set Management"""), | 42 C.PI_DESCRIPTION: _(u"""Implementation of Result Set Management"""), |
43 } | 43 } |
44 | |
45 RSM_PREFIX = u"rsm_" | |
44 | 46 |
45 | 47 |
46 class XEP_0059(object): | 48 class XEP_0059(object): |
47 # XXX: RSM management is done directly in Wokkel. | 49 # XXX: RSM management is done directly in Wokkel. |
48 | 50 |
49 def __init__(self, host): | 51 def __init__(self, host): |
50 log.info(_("Result Set Management plugin initialization")) | 52 log.info(_(u"Result Set Management plugin initialization")) |
51 | 53 |
52 def getHandler(self, client): | 54 def getHandler(self, client): |
53 return XEP_0059_handler() | 55 return XEP_0059_handler() |
56 | |
57 def parseExtra(self, extra): | |
58 """Parse extra dictionnary to retrieve RSM arguments | |
59 | |
60 @param extra(dict): data for parse | |
61 @return (rsm.RSMRequest, None): request with parsed arguments | |
62 or None if no RSM arguments have been found | |
63 """ | |
64 rsm_args = {} | |
65 for arg in (u"max", u"after", u"before", u"index"): | |
66 try: | |
67 argname = "max_" if arg == u"max" else arg | |
68 rsm_args[argname] = extra.pop(RSM_PREFIX + arg) | |
69 except KeyError: | |
70 continue | |
71 | |
72 if rsm_args: | |
73 return rsm.RSMRequest(**rsm_args) | |
74 else: | |
75 return None | |
54 | 76 |
55 | 77 |
56 class XEP_0059_handler(xmlstream.XMPPHandler): | 78 class XEP_0059_handler(xmlstream.XMPPHandler): |
57 implements(iwokkel.IDisco) | 79 implements(iwokkel.IDisco) |
58 | 80 |