docs: def check_arguments_compatibility(the_callable, argd):
      """
      Check if calling the_callable with the given arguments would be correct
      or not.
  
      >>> def foo(arg1, arg2, arg3='val1', arg4='val2', *args, **argd):
      ...     pass
      >>> try: check_arguments_compatibility(foo, {'arg1': 'bla', 'arg2': 'blo'})
      ... except ValueError as err: print 'failed'
      ... else: print 'ok'
      ok
      >>> try: check_arguments_compatibility(foo, {'arg1': 'bla'})
      ... except ValueError as err: print 'failed'
      ... else: print 'ok'
      failed
  
      Basically this function is simulating the call:
  
      >>> the_callable(**argd)
  
      but it only checks for the correctness of the arguments, without
      actually calling the_callable.
  
      :param the_callable: the callable to be analyzed.
      :type the_callable: function/callable
      :param argd: the arguments to be passed.
      :type argd: dict
      :raise ValueError: in case of uncompatibility
      """
      if not argd:
          argd = {}
      args, dummy, varkw, defaults = inspect.getargspec(the_callable)
      tmp_args = list(args)
      optional_args = []
      args_dict = {}
      if defaults:
          defaults = list(defaults)
      else:
          defaults = []
      while defaults:
          arg = tmp_args.pop()
          optional_args.append(arg)
          args_dict[arg] = defaults.pop()
  
      while tmp_args:
          args_dict[tmp_args.pop()] = None
  
      for arg, dummy_value in iteritems(argd):
          if arg in args_dict:
              del args_dict[arg]
          elif not varkw:
              raise ValueError(
                  'Argument %s not expected when calling callable '
                  '"%s" with arguments %s' % (
                      arg, get_callable_signature_as_string(the_callable), argd))
  
      for arg in args_dict.keys():
          if arg in optional_args:
              del args_dict[arg]
  
      if args_dict:
          raise ValueError(
              'Arguments %s not specified when calling callable '
              '"%s" with arguments %s' % (
                  ', '.join(args_dict.keys()),
                  get_callable_signature_as_string(the_callable),
                  argd))