def RenderAFF4Object(obj, args=None):
  """Renders given AFF4 object into JSON-friendly data structure."""
  args = args or []

  cache_key = obj.__class__.__name__

  try:
    candidates = RENDERERS_CACHE[cache_key]
  except __HOLE__:
    candidates = []
    for candidate in ApiAFF4ObjectRendererBase.classes.values():
      if candidate.aff4_type:
        candidate_class = aff4.AFF4Object.classes[candidate.aff4_type]
      else:
        continue

      if aff4.issubclass(obj.__class__, candidate_class):
        candidates.append(candidate)

    if not candidates:
      raise RuntimeError("No renderer found for object %s." %
                         obj.__class__.__name__)

    # Ensure that the renderers order is stable.
    candidates = sorted(candidates, key=lambda cls: cls.__name__)

    RENDERERS_CACHE[cache_key] = candidates

  result = {}
  for candidate in candidates:
    api_renderer_args = None
    for arg in args:
      if candidate.args_type and isinstance(arg, candidate.args_type):
        api_renderer_args = arg

    if api_renderer_args is None and candidate.args_type is not None:
      api_renderer_args = candidate.args_type()

    api_renderer = candidate()
    renderer_output = api_renderer.RenderObject(obj, api_renderer_args)
    for k, v in renderer_output.items():
      result[k] = v

  return result
dataset/ETHPy150Open google/grr/grr/gui/api_aff4_object_renderers.py/RenderAFF4Object