From 4e9b6fad6b65f6ca107726e8819f0db73721aa3b Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Tue, 1 Dec 2009 15:24:06 +0800 Subject: Use builtin and default library functions over custom functions. --- examples/data/uzbl/scripts/uzbl-event-manager | 31 ++++----------------------- 1 file changed, 4 insertions(+), 27 deletions(-) (limited to 'examples') diff --git a/examples/data/uzbl/scripts/uzbl-event-manager b/examples/data/uzbl/scripts/uzbl-event-manager index 0054ff6..e926643 100755 --- a/examples/data/uzbl/scripts/uzbl-event-manager +++ b/examples/data/uzbl/scripts/uzbl-event-manager @@ -39,6 +39,7 @@ from select import select from signal import signal, SIGTERM from optparse import OptionParser from traceback import print_exc +from functools import partial # ============================================================================ @@ -111,18 +112,6 @@ def counter(): yield i -def iscallable(obj): - '''Return true if the object is callable.''' - - return hasattr(obj, "__call__") - - -def isiterable(obj): - '''Return true if you can iterate over the item.''' - - return hasattr(obj, "__iter__") - - def find_plugins(plugin_dirs): '''Find all event manager plugins in the plugin dirs and return a dictionary of {'plugin-name.py': '/full/path/to/plugin-name.py', ...}''' @@ -289,24 +278,12 @@ def term_process(pid): time.sleep(0.25) -def prepender(function, *pre_args): - '''Creates a wrapper around a callable object injecting a list of - arguments before the called arguments.''' - - locals = (function, pre_args) - def _prepender(*args, **kargs): - (function, pre_args) = locals - return function(*(pre_args + args), **kargs) - - return _prepender - - class EventHandler(object): nexthid = counter().next def __init__(self, event, handler, *args, **kargs): - if not iscallable(handler): + if not callable(handler): raise ArgumentError("EventHandler object requires a callable " "object function for the handler argument not: %r" % handler) @@ -378,8 +355,8 @@ class UzblInstance(object): raise KeyError("conflicting export: %r" % export) obj = getattr(plugin, export) - if iscallable(obj): - obj = prepender(obj, self) + if callable(obj): + obj = partial(obj, self) self._exports[export] = obj -- cgit v1.2.3