class_docstr: Subprocess communication protocol base class for `run_async_cmd`
  
  This class implements basic subprocess output handling. Derived classes
  like `StdOutCapture` should be used for subprocess communication that need
  to capture and return output. In particular, the `pipe_data_received()`
  method can be overwritten to implement "online" processing of process
  output.
  
  This class defines a default return value setup that causes
  `run_async_cmd()` to return a 2-tuple with the subprocess's exit code
  and a list with bytestrings of all captured output streams.
docstr: Prepares the final result to be returned to the runner
  
  Note for derived classes overwriting this method:
  
  The result must be a dict with keys that do not unintentionally
  conflict with the API of CommandError, as the result dict is passed to
  this exception class as kwargs on error. The Runner will overwrite
  'cmd' and 'cwd' on error, if they are present in the result.
docstr_tok: ["Prepares","the","final","result","to","be","returned","to","the","runner","Note","for","derived","classes","overwriting","this","method",":","The","result","must","be","a","dict","with","keys","that","do","not","unintentionally","conflict","with","the","API","of","CommandError",",","as","the","result","dict","is","passed","to","this","exception","class","as","kwargs","on","error",".","The","Runner","will","overwrite","'cmd","'","and","'cwd","'","on","error",",","if","they","are","present","in","the","result","."]
code: def _prepare_result(self) -> dict:
      """Prepares the final result to be returned to the runner
  
      Note for derived classes overwriting this method:
  
      The result must be a dict with keys that do not unintentionally
      conflict with the API of CommandError, as the result dict is passed to
      this exception class as kwargs on error. The Runner will overwrite
      'cmd' and 'cwd' on error, if they are present in the result.
      """
      assert self.process is not None
      return_code = self.process.poll()
      if return_code is None:
          raise CommandError(
              msg=f"Got None as a return_code for the process {self.process.pid}"
          )
      lgr.log(
          8,
          "Process %i exited with return code %i",
          self.process.pid,
          return_code,
      )
      # give captured process output back to the runner as string(s)
      results: dict[str, Any] = {
          name: (
              bytes(byt).decode(self.encoding)
              if byt is not None
              else ""
          )
          for name, byt in self.fd_infos.values()
      }
      results["code"] = return_code
      return results
  
imports: from __future__ import annotations
  import logging
  import subprocess
  import warnings
  from collections import deque
  from locale import getpreferredencoding
  from typing import Any, Optional
  from datalad.utils import ensure_unicode
  from .exception import CommandError
label_desc: Use image node_id 9 for calling the WitlessProtocol obj's underlying member method code with example usage: obj._prepare_result() and returns: results