faster argcheck
This commit is contained in:
parent
51ec9b8b50
commit
6296043fe4
1 changed files with 6 additions and 6 deletions
12
koji/util.py
12
koji/util.py
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue