Mercurial > libervia-backend
changeset 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 | 310e41bd6666 |
children | 2ea2369ae7de |
files | sat/plugins/plugin_xep_0059.py |
diffstat | 1 files changed, 30 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0059.py Sat Dec 01 10:08:17 2018 +0100 +++ b/sat/plugins/plugin_xep_0059.py Sat Dec 01 10:10:25 2018 +0100 @@ -33,25 +33,47 @@ PLUGIN_INFO = { - C.PI_NAME: "Result Set Management", - C.PI_IMPORT_NAME: "XEP-0059", - C.PI_TYPE: "XEP", - C.PI_PROTOCOLS: ["XEP-0059"], - C.PI_MAIN: "XEP_0059", - C.PI_HANDLER: "yes", - C.PI_DESCRIPTION: _("""Implementation of Result Set Management"""), + C.PI_NAME: u"Result Set Management", + C.PI_IMPORT_NAME: u"XEP-0059", + C.PI_TYPE: u"XEP", + C.PI_PROTOCOLS: [u"XEP-0059"], + C.PI_MAIN: u"XEP_0059", + C.PI_HANDLER: u"yes", + C.PI_DESCRIPTION: _(u"""Implementation of Result Set Management"""), } +RSM_PREFIX = u"rsm_" + class XEP_0059(object): # XXX: RSM management is done directly in Wokkel. def __init__(self, host): - log.info(_("Result Set Management plugin initialization")) + log.info(_(u"Result Set Management plugin initialization")) def getHandler(self, client): return XEP_0059_handler() + def parseExtra(self, extra): + """Parse extra dictionnary to retrieve RSM arguments + + @param extra(dict): data for parse + @return (rsm.RSMRequest, None): request with parsed arguments + or None if no RSM arguments have been found + """ + rsm_args = {} + for arg in (u"max", u"after", u"before", u"index"): + try: + argname = "max_" if arg == u"max" else arg + rsm_args[argname] = extra.pop(RSM_PREFIX + arg) + except KeyError: + continue + + if rsm_args: + return rsm.RSMRequest(**rsm_args) + else: + return None + class XEP_0059_handler(xmlstream.XMPPHandler): implements(iwokkel.IDisco)