call_with_argcheck utility function
This commit is contained in:
parent
2c372cd5f0
commit
51ec9b8b50
3 changed files with 19 additions and 34 deletions
15
koji/util.py
15
koji/util.py
|
|
@ -16,13 +16,14 @@
|
|||
|
||||
import calendar
|
||||
from fnmatch import fnmatch
|
||||
import logging
|
||||
import koji
|
||||
import logging
|
||||
import os
|
||||
import os.path
|
||||
import re
|
||||
import resource
|
||||
import stat
|
||||
import sys
|
||||
import time
|
||||
|
||||
try:
|
||||
|
|
@ -131,6 +132,18 @@ def dslice(dict, keys, strict=True):
|
|||
ret[key] = dict[key]
|
||||
return ret
|
||||
|
||||
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
|
||||
raise
|
||||
|
||||
|
||||
class HiddenValue(object):
|
||||
"""A wrapper that prevents a value being accidentally printed"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue