def ExpectDict(obj):
  """Return a dictionary or raises an exception."""
  if isinstance(obj, dict):
    return obj
  elif obj is None:
    return {}
  else:
    raise ValueError('Expecting a dictionary.')