def build_dict_conforming_to_schema(schema, **kwargs):
  """
  Given a schema object (for example, TIMESTAMP_SCHEMA from this module) and
  a set of keyword arguments, create a dictionary that conforms to the given
  schema, using the keyword arguments to define the elements of the new dict.

  Checks the result to make sure that it conforms to the given schema, raising
  an error if not.

  Returns the new dict conforming to the schema if there are no problems.
  """

  # Check that schema supports a check_match call.
  # Duck typing version of this check:
  if not hasattr(schema, 'check_match'):
    raise ValueError(
        'The given "schema" does not seem to be a schema.  It has no '
        '"check_match" method.  Given schema: ' + repr(schema))

  # # Strict typing version of this check:
  # # Check that schema_name is a SCHEMA.Object.
  # if not isinstance(schema, schema.Schema):
  #   raise ValueError(
  #       'The first argument must be a schema.Schema object, but is not. '
  #       'Given schema: ' + repr(schema))

  # The return value.
  d = {}

  for key, value in kwargs.items():
    d[key] = value

  schema.check_match(d)

  return d