def _normalize_entity(value):
  """Return an entity from an entity or model instance."""
  # TODO(user): Consider using datastore.NormalizeAndTypeCheck.
  if getattr(value, "_populate_internal_entity", None):
    return value._populate_internal_entity()
  return value
Return an entity from an entity or model instance.
mapreduce/context.py