Process a buffer for human-readable display.

  This function performs the following operation on each of the buffers in `s`.
    1. Truncate input buffer if the length of the buffer is greater than
       `limit`, to prevent large strings from overloading the frontend.
    2. Apply `binascii.b2a_qp` on the truncated buffer to make the buffer
       printable and convertible to JSON.
    3. If truncation happened (in step 1), append a string at the end
       describing the original length and the truncation.

  Args:
    s: The buffer to be processed, either a single buffer or a nested array of
      them.
    limit: Length limit for each buffer, beyond which truncation will occur.

  Return:
    A single processed buffer or a nested array of processed buffers.

def process_buffers_for_display(s, limit=40):
  """Process a buffer for human-readable display.

  This function performs the following operation on each of the buffers in `s`.
    1. Truncate input buffer if the length of the buffer is greater than
       `limit`, to prevent large strings from overloading the frontend.
    2. Apply `binascii.b2a_qp` on the truncated buffer to make the buffer
       printable and convertible to JSON.
    3. If truncation happened (in step 1), append a string at the end
       describing the original length and the truncation.

  Args:
    s: The buffer to be processed, either a single buffer or a nested array of
      them.
    limit: Length limit for each buffer, beyond which truncation will occur.

  Return:
    A single processed buffer or a nested array of processed buffers.
  """
  if isinstance(s, (list, tuple)):
    return [process_buffers_for_display(elem, limit=limit) for elem in s]
  else:
    length = len(s)
    if length > limit:
      return (binascii.b2a_qp(s[:limit]) +
              b' (length-%d truncated at %d bytes)' % (length, limit))
    else:
      return binascii.b2a_qp(s)