diff options
author | hut <hut@lavabit.com> | 2010-03-30 19:55:17 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-03-30 19:55:17 +0200 |
commit | da0771094b1a1e10c70e9e359296ae105b7f6ea2 (patch) | |
tree | 4440c1f9fbde9e4fdad29764a6c9117cfbded989 /ranger | |
parent | 9b83f1144024c98cad6ece752b7e625bfec608f2 (diff) | |
download | ranger-da0771094b1a1e10c70e9e359296ae105b7f6ea2.tar.gz |
ext.signal_dispatcher: fixed weak refs to bound methods
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/ext/signal_dispatcher.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/ranger/ext/signal_dispatcher.py b/ranger/ext/signal_dispatcher.py index 2762493b..11e9c955 100644 --- a/ranger/ext/signal_dispatcher.py +++ b/ranger/ext/signal_dispatcher.py @@ -15,6 +15,7 @@ import re import weakref +from types import MethodType class Signal(dict): stopped = False @@ -48,9 +49,17 @@ class SignalDispatcher(object): handlers = self._signals[signal_name] except: handlers = self._signals[signal_name] = [] - nargs = function.__code__.co_argcount - hasattr(function, 'im_func') - if weak: - function = weakref.proxy(function) + nargs = function.__code__.co_argcount + + try: + instance = function.__self__ + except: + if weak: + function = weakref.proxy(function) + else: + nargs -= 1 + if weak: + function = (function.__func__, weakref.proxy(function.__self__)) handler = SignalHandler(signal_name, function, priority, nargs > 0) handlers.append(handler) handlers.sort(key=lambda handler: -handler.priority) @@ -82,10 +91,14 @@ class SignalDispatcher(object): for handler in tuple(handlers): if handler.active: try: + if isinstance(handler.function, tuple): + fnc = MethodType(*handler.function) + else: + fnc = handler.function if handler.pass_signal: - handler.function(signal) + fnc(signal) else: - handler.function() + fnc() if signal.stopped: return except ReferenceError: |