From 898f5f4b51473a60cfd4b3c699ee3d1b47b7529b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 2 Apr 2012 21:55:48 -0700 Subject: [PATCH] Allow for registering a handler and setting it as default in one step. --- sleekxmpp/api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sleekxmpp/api.py b/sleekxmpp/api.py index 9d8ec201..82ff8ae7 100644 --- a/sleekxmpp/api.py +++ b/sleekxmpp/api.py @@ -14,9 +14,9 @@ class APIWrapper(object): elif attr == 'settings': return self.api.settings[self.name] elif attr == 'register': - def curried_handler(handler, op, jid=None, node=None): + def curried_handler(handler, op, jid=None, node=None, default=False): register = getattr(self.api, attr) - return register(handler, self.name, op, jid, node) + return register(handler, self.name, op, jid, node, default) return curried_handler elif attr == 'register_default': def curried_handler(handler, op, jid=None, node=None): @@ -153,6 +153,9 @@ class APIRegistry(object): else: self._handlers[ctype][op]['node'][(jid, node)] = handler + if default: + self.register_default(handler, ctype, op) + def register_default(self, handler, ctype, op): """Register a default, global handler for an operation.