# HG changeset patch # User Goffi # Date 1543655425 -3600 # Node ID 035901dc946dd9943d91b727787b66943eaaa169 # Parent 310e41bd6666d6f41a14f539ad27c894d3b0bc08 plugin XEP-0059: added "parseExtra" method to easily handle RSM argument coming from bridge. diff -r 310e41bd6666 -r 035901dc946d sat/plugins/plugin_xep_0059.py --- 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)