docs: def _result_object(result):
      """
      Return the JSON payload in the HTTP response as a Python dict.
  
      Parameters:
          result (requests.Response): HTTP response object.
  
      Raises:
          zhmcclient.ParseError: Error parsing the returned JSON.
      """
      content_type = result.headers.get('content-type', None)
  
      if content_type is None or content_type.startswith('application/json'):
          # This function is only called when there is content expected.
          # Therefore, a response without content will result in a ParseError.
          try:
              return result.json(object_pairs_hook=OrderedDict)
          except ValueError as exc:
              raise ParseError(
                  "JSON parse error in HTTP response: {}. "
                  "HTTP request: {} {}. "
                  "Response status {}. "
                  "Response content-type: {!r}. "
                  "Content (max.1000, decoded using {}): {}".
                  format(exc.args[0],
                         result.request.method, result.request.url,
                         result.status_code, content_type, result.encoding,
                         _text_repr(result.text, 1000)))
      elif content_type.startswith('text/html'):
          # We are in some error situation. The HMC returns HTML content
          # for some 5xx status codes. We try to deal with it somehow,
          # but we are not going as far as real HTML parsing.
          m = re.search(r'charset=([^;,]+)', content_type)
          if m:
              encoding = m.group(1)  # e.g. RFC "ISO-8859-1"
          else:
              encoding = 'utf-8'
          try:
              html_uni = result.content.decode(encoding)
          except LookupError:
              html_uni = result.content.decode()
  
          # We convert to one line to be regexp-friendly.
          html_oneline = html_uni.replace('\r\n', '\\n').replace('\r', '\\n').\
              replace('\n', '\\n')
  
          # Check for some well-known errors:
          if re.search(r'javax\.servlet\.ServletException: '
                       r'Web Services are not enabled\.', html_oneline):
              html_title = "Console Configuration Error"
              html_details = "Web Services API is not enabled on the HMC."
              html_reason = HTML_REASON_WEB_SERVICES_DISABLED
          else:
              m = re.search(
                  r'<title>([^<]*)</title>.*'
                  r'<h2>Details:</h2>(.*)(<hr size="1" noshade>)?</body>',
                  html_oneline)
              if m:
                  html_title = m.group(1)
                  # Spend a reasonable effort to make the HTML readable:
                  html_details = m.group(2).replace('<p>', '\\n').\
                      replace('<br>', '\\n').replace('\\n\\n', '\\n').strip()
              else:
                  html_title = "Console Internal Error"
                  html_details = "Response body: {!r}".format(html_uni)
              html_reason = HTML_REASON_OTHER
          message = "{}: {}".format(html_title, html_details)
  
          # We create a minimal JSON error object (to the extent we use it
          # when processing it):
          result_obj = {
              'http-status': result.status_code,
              'reason': html_reason,
              'message': message,
              'request-uri': result.request.url,
              'request-method': result.request.method,
          }
          return result_obj
      elif content_type.startswith('application/vnd.ibm-z-zmanager-metrics'):
          content_bytes = result.content
          assert isinstance(content_bytes, six.binary_type)
          return content_bytes.decode('utf-8')  # as a unicode object
      else:
          raise ParseError(
              "Unknown content type in HTTP response: {}. "
              "HTTP request: {} {}. "
              "Response status {}. "
              "Response content-type: {!r}. "
              "Content (max.1000, decoded using {}): {}".
              format(content_type,
                     result.request.method, result.request.url,
                     result.status_code, content_type, result.encoding,
                     _text_repr(result.text, 1000)))