def validate(argspec, dict):
    exclusive = None
    for arg_name, arg_type in argspec.items():
        if arg_type == 'exclusive':
            exclusive = arg_name
    # check if we have unknown arguments
    for key, value in dict.items():
        if not argspec.has_key(key):
            msg = "Unknown argument: %s" % key
            raise BadArgumentError, msg
        if not isinstance(value, basestring):
            raise BadArgumentError, "Argument must be string or unicode"
    # first investigate if we have exclusive argument
    if dict.has_key(exclusive):
        if len(dict) > 1:
            msg = ("Exclusive argument %s is used but other "
                   "arguments found." % exclusive)
            raise BadArgumentError, msg
        return
    # if not exclusive, check for required
    for arg_name, arg_type in argspec.items():
        if arg_type == 'required':
            msg = "Argument required but not found: %s" % arg_name
            if not dict.has_key(arg_name):
                raise BadArgumentError, msg
    return
dataset/ETHPy150Open xarg/pyoai/src/oaipmh/validation.py/validate/original