@webauth.SecurityCheck
@renderers.ErrorHandler()
def RenderGenericRenderer(request):
  """Django handler for rendering registered GUI Elements."""
  try:
    action, renderer_name = request.path.split("/")[-2:]

    renderer_cls = renderers.Renderer.GetPlugin(name=renderer_name)
  except KeyError:
    stats.STATS.IncrementCounter("ui_unknown_renderer")
    return AccessDenied("Error: Renderer %s not found" % renderer_name)

  # Check that the action is valid
  ["Layout", "RenderAjax", "Download", "Validate"].index(action)
  renderer = renderer_cls()
  result = http.HttpResponse(content_type="text/html")

  # Pass the request only from POST parameters. It is much more convenient to
  # deal with normal dicts than Django's Query objects so we convert here.
  if flags.FLAGS.debug:
    # Allow both POST and GET for debugging
    request.REQ = request.POST.dict()
    request.REQ.update(request.GET.dict())
  else:
    # Only POST in production for CSRF protections.
    request.REQ = request.POST.dict()

  # Build the security token for this request
  request.token = BuildToken(request, renderer.max_execution_time)

  request.canary_mode = "canary_mode" in request.COOKIES

  # Allow the renderer to check its own ACLs.
  renderer.CheckAccess(request)

  try:
    # Does this renderer support this action?
    method = getattr(renderer, action)

    start_time = time.time()
    try:
      result = method(request, result) or result
    finally:
      total_time = time.time() - start_time
      stats.STATS.RecordEvent("ui_renderer_latency",
                              total_time, fields=[renderer_name])

  except access_control.UnauthorizedAccess, e:
    result = http.HttpResponse(content_type="text/html")
    result = renderers.Renderer.GetPlugin("UnauthorizedRenderer")().Layout(
        request, result, exception=e)

  except Exception:
    stats.STATS.IncrementCounter("ui_renderer_failure",
                                 fields=[renderer_name])

    if flags.FLAGS.debug:
      pdb.post_mortem()

    raise

  if not isinstance(result, (http.HttpResponse,
                             http.StreamingHttpResponse)):
    raise RuntimeError("Renderer returned invalid response %r" % result)

  return result
dataset/ETHPy150Open google/grr/grr/gui/views.py/RenderGenericRenderer/original