Allow for registering a handler and setting it as default in one step.

This commit is contained in:
Lance Stout 2012-04-02 21:55:48 -07:00
parent 3ee3fdca91
commit 898f5f4b51

View file

@ -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.