docs: def extract(request, calc_id, what):
      """
      Wrapper over the `oq extract` command. If `setting.LOCKDOWN` is true
      only calculations owned by the current user can be retrieved.
      """
      job = logs.dbcmd('get_job', int(calc_id))
      if job is None:
          return HttpResponseNotFound()
      if not utils.user_has_permission(request, job.user_name):
          return HttpResponseForbidden()
  
      try:
          # read the data and save them on a temporary .npz file
          with datastore.read(job.ds_calc_dir + '.hdf5') as ds:
              fd, fname = tempfile.mkstemp(
                  prefix=what.replace('/', '-'), suffix='.npz')
              os.close(fd)
              n = len(request.path_info)
              query_string = unquote_plus(request.get_full_path()[n:])
              aw = _extract(ds, what + query_string)
              a = {}
              for key, val in vars(aw).items():
                  key = str(key)  # can be a numpy.bytes_
                  if isinstance(val, str):
                      # without this oq extract would fail
                      a[key] = numpy.array(val.encode('utf-8'))
                  elif isinstance(val, dict):
                      # this is hack: we are losing the values
                      a[key] = list(val)
                  else:
                      a[key] = val
              numpy.savez_compressed(fname, **a)
      except Exception as exc:
          tb = ''.join(traceback.format_tb(exc.__traceback__))
          return HttpResponse(
              content='%s: %s\n%s' % (exc.__class__.__name__, exc, tb),
              content_type='text/plain', status=500)
  
      # stream the data back
      stream = FileWrapper(open(fname, 'rb'))
      stream.close = lambda: (FileWrapper.close(stream), os.remove(fname))
      response = FileResponse(stream, content_type='application/octet-stream')
      response['Content-Disposition'] = (
          'attachment; filename=%s' % os.path.basename(fname))
      response['Content-Length'] = str(os.path.getsize(fname))
      return response