code: def ensure_keyword_args(kwargs, mandatory=(), optional=()):
      
      from taipan.strings import ensure_string
  
      ensure_mapping(kwargs)
      mandatory = list(map(ensure_string, ensure_iterable(mandatory)))
      optional = list(map(ensure_string, ensure_iterable(optional)))
      if not (mandatory or optional):
          raise ValueError(
              "mandatory and/or optional argument names must be provided")
  
      names = set(kwargs)
      for name in mandatory:
          try:
              names.remove(name)
          except KeyError:
              raise TypeError(
                  "no value for mandatory keyword argument '%s'" % name)
  
      excess = names - set(optional)
      if excess:
          if len(excess) == 1:
              raise TypeError("unexpected keyword argument '%s'" % excess.pop())
          else:
              raise TypeError(
                  "unexpected keyword arguments: %s" % (tuple(excess),))
  
      return kwargs
docs: Checks whether dictionary of keyword arguments satisfies conditions.
  
      :param kwargs: Dictionary of keyword arguments, received via ``*kwargs``
      :param mandatory: Iterable of mandatory argument names
      :param optional: Iterable of optional argument names
  
      :return: ``kwargs`` if the conditions are met:
               all ``mandatory`` arguments are present, and besides that
               no arguments outside of ``optional`` ones are.
  
      :raise TypeError: When conditions are not met