@webauth.SecurityCheck
def RenderBinaryDownload(request):
  """Basic handler to allow downloads of aff4:/config/executables files."""
  path, filename = request.path.split("/", 2)[-1].rsplit("/", 1)
  if not path or not filename:
    return AccessDenied("Error: Invalid path.")
  request.REQ = request.REQUEST

  def Generator():
    with aff4.FACTORY.Open(aff4_path, aff4_type="GRRSignedBlob",
                           token=BuildToken(request, 60)) as fd:
      while True:
        data = fd.Read(1000000)
        if not data: break
        yield data

  base_path = rdfvalue.RDFURN("aff4:/config/executables")
  aff4_path = base_path.Add(path).Add(filename)
  if not aff4_path.RelativeName(base_path):
    # Check for path traversals.
    return AccessDenied("Error: Invalid path.")
  filename = aff4_path.Basename()
  response = http.StreamingHttpResponse(
      streaming_content=Generator(),
      content_type="binary/octet-stream")
  response["Content-Disposition"] = ("attachment; filename=%s" % filename)
  return response
dataset/ETHPy150Open google/grr/grr/gui/views.py/RenderBinaryDownload/original