def validate_signature_against_kwargs(function, keyword_arguments):
 arg_spec = getargspec(function)
 accepted_arguments = frozenset(arg_spec.args)
 optional_arguments = frozenset()
 if (arg_spec.defaults is not None):
  optional_arguments = frozenset(arg_spec.args[(- len(arg_spec.defaults)):])
 if (arg_spec.keywords is None):
  unexpected_arguments = frozenset((keyword_arguments - accepted_arguments))
 else:
  unexpected_arguments = frozenset()
 missing_arguments = frozenset(((accepted_arguments - keyword_arguments) - optional_arguments))
 if ((missing_arguments != frozenset()) or (unexpected_arguments != frozenset())):
  raise InvalidSignature(unexpected_arguments=unexpected_arguments, missing_arguments=missing_arguments, missing_optional_arguments=frozenset((optional_arguments - keyword_arguments)))

def validate_signature_against_kwargs ( function , keyword_arguments ) : arg_spec = getargspec ( function ) accepted_arguments = frozenset ( arg_spec . args ) optional_arguments = frozenset ( ) if ( arg_spec . defaults is not None ) : optional_arguments = frozenset ( arg_spec . args [ ( - len ( arg_spec . defaults ) ) : ] ) if ( arg_spec . keywords is None ) : unexpected_arguments = frozenset ( ( keyword_arguments - accepted_arguments ) ) else : unexpected_arguments = frozenset ( ) missing_arguments = frozenset ( ( ( accepted_arguments - keyword_arguments ) - optional_arguments ) ) if ( ( missing_arguments != frozenset ( ) ) or ( unexpected_arguments != frozenset ( ) ) ) : raise InvalidSignature ( unexpected_arguments = unexpected_arguments , missing_arguments = missing_arguments , missing_optional_arguments = frozenset ( ( optional_arguments - keyword_arguments ) ) )
validates that function can be called with keyword arguments with exactly the specified keyword_arguments_keys and no positional arguments .