aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-12-01 15:24:06 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-12-01 15:24:06 +0800
commit4e9b6fad6b65f6ca107726e8819f0db73721aa3b (patch)
tree47ed59ac82f3ce7fcc61bad8240f70c0418abe9a /examples
parentf8a063cb02c647f849f7e31189f3503e8d9d0fc8 (diff)
Use builtin and default library functions over custom functions.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/data/uzbl/scripts/uzbl-event-manager31
1 files changed, 4 insertions, 27 deletions
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