def safe_args(fn, args):
fn_args = inspect.getargspec(fn)<EOL>if fn_args.defaults:<EOL><INDENT>required_params(args, fn_args.args[:-len(fn_args.defaults)])<EOL><DEDENT>else:<EOL><INDENT>required_params(args, fn_args)<EOL><DEDENT>if not fn_args.keywords:<EOL><INDENT>return {key: value for key, value in viewitems(args) if key in fn_args.args}<EOL><DEDENT>else:<EOL><INDENT>return args<EOL><DEDENT>
Check if ``args`` as a dictionary has the required parameters of ``fn``
    function and filter any waste parameters so ``fn`` can be safely called
    with them.

    :param fn: function object
    :type fn: Callable
    :param args: dictionary of parameters
    :type args: dict
    :return: dictionary to be used as named params for the ``fn``
    :rtype: dict