faster argcheck

This commit is contained in:
Mike McLean 2012-05-17 09:44:03 -04:00
parent 51ec9b8b50
commit 6296043fe4

View file

@ -132,16 +132,16 @@ def dslice(dict, keys, strict=True):
ret[key] = dict[key]
return ret
def call_with_argcheck(func, args, kwargs):
def call_with_argcheck(func, args, kwargs={}):
"""Call function, raising ParameterError if args do not match"""
try:
return func(*args, **kwargs)
except TypeError, e:
tb = sys.exc_info()[2]
while tb.tb_next:
tb = tb.tb_next
if tb.tb_frame.f_code == call_with_argcheck.func_code:
raise koji.ParameterError, e.message
if sys.exc_info()[2].tb_next is None:
# The stack is only one high, so the error occurred in this function.
# Therefore, we assume the TypeError is due to a parameter mismatch
# in the above function call.
raise koji.ParameterError, str(e)
raise