call_with_argcheck utility function

This commit is contained in:
Mike McLean 2012-05-16 23:27:09 -04:00
parent 2c372cd5f0
commit 51ec9b8b50
3 changed files with 19 additions and 34 deletions

View file

@ -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"""