def get_options(cls, items, options, warnfn):
        "Given a keyword specification, validate and compute options"
        options = cls.update_options(options, items)
        for keyword in cls.defaults:
            if keyword in items:
                value = items[keyword]
                allowed = cls.allowed[keyword]
                if isinstance(allowed, set):  pass
                elif isinstance(allowed, dict):
                    if not isinstance(value, dict):
                        raise ValueError("Value %r not a dict type" % value)
                    disallowed = set(value.keys()) - set(allowed.keys())
                    if disallowed:
                        raise ValueError("Keywords %r for %r option not one of %s"
                                         % (disallowed, keyword, allowed))
                    wrong_type = {k: v for k, v in value.items()
                                  if not isinstance(v, allowed[k])}
                    if wrong_type:
                        errors = []
                        for k,v in wrong_type.items():
                            errors.append("Value %r for %r option's %r attribute not of type %r" %
                                          (v, keyword, k, allowed[k]))
                        raise ValueError('\n'.join(errors))
                elif isinstance(allowed, list) and value not in allowed:
                    if keyword in cls.custom_exceptions:
                        cls.custom_exceptions[keyword](value, keyword, allowed)
                    else:
                        raise ValueError("Value %r for key %r not one of %s"
                                         % (value, keyword, allowed))
                elif isinstance(allowed, tuple):
                    if not (allowed[0] <= value <= allowed[1]):
                        info = (keyword,value)+allowed
                        raise ValueError("Value %r for key %r not between %s and %s" % info)
                options[keyword] = value
        return cls._validate(options, items, warnfn)
def get_options ( cls , items , options , warnfn ) : options = cls . update_options ( options , items ) for keyword in cls . defaults : if keyword in items : value = items [ keyword ] allowed = cls . allowed [ keyword ] if isinstance ( allowed , set ) : pass elif isinstance ( allowed , dict ) : if not isinstance ( value , dict ) : raise ValueError ( "Value %r not a dict type" % value ) disallowed = set ( value . keys ( ) ) - set ( allowed . keys ( ) ) if disallowed : raise ValueError ( "Keywords %r for %r option not one of %s" % ( disallowed , keyword , allowed ) ) wrong_type = { k : v for k , v in value . items ( ) if not isinstance ( v , allowed [ k ] ) } if wrong_type : errors = [ ] for k , v in wrong_type . items ( ) : errors . append ( "Value %r for %r option's %r attribute not of type %r" % ( v , keyword , k , allowed [ k ] ) ) raise ValueError ( '\n' . join ( errors ) ) elif isinstance ( allowed , list ) and value not in allowed : if keyword in cls . custom_exceptions : cls . custom_exceptions [ keyword ] ( value , keyword , allowed ) else : raise ValueError ( "Value %r for key %r not one of %s" % ( value , keyword , allowed ) ) elif isinstance ( allowed , tuple ) : if not ( allowed [ 0 ] <= value <= allowed [ 1 ] ) : info = ( keyword , value ) + allowed raise ValueError ( "Value %r for key %r not between %s and %s" % info ) options [ keyword ] = value return cls . _validate ( options , items , warnfn )
Given a keyword specification, validate and compute options