Make sure handle_error(im) is failproof
This commit is contained in:
parent
06cea36c97
commit
a5c9541543
@ -1,6 +1,7 @@
|
|||||||
import traceback
|
import traceback
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import socket
|
import socket
|
||||||
|
import types
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from oyoyo.client import IRCClient
|
from oyoyo.client import IRCClient
|
||||||
@ -22,9 +23,6 @@ HOOKS = defaultdict(list)
|
|||||||
|
|
||||||
class handle_error:
|
class handle_error:
|
||||||
|
|
||||||
instance = None
|
|
||||||
owner = object
|
|
||||||
|
|
||||||
def __new__(cls, func):
|
def __new__(cls, func):
|
||||||
if isinstance(func, cls): # already decorated
|
if isinstance(func, cls): # already decorated
|
||||||
return func
|
return func
|
||||||
@ -34,13 +32,13 @@ class handle_error:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def __get__(self, instance, owner):
|
def __get__(self, instance, owner):
|
||||||
self.instance = instance
|
if instance is not None:
|
||||||
self.owner = owner
|
return types.MethodType(self, instance)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return self.func.__get__(self.instance, self.owner)(*args, **kwargs)
|
return self.func(*args, **kwargs)
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc() # no matter what, we want it to print
|
traceback.print_exc() # no matter what, we want it to print
|
||||||
if kwargs.get("cli"): # client
|
if kwargs.get("cli"): # client
|
||||||
|
Loading…
x
Reference in New Issue
Block a user