def _Shorten(s, prefixofs, suffixofs, maxlen):
  """Shorten the given string if its length is >= maxlen.

  Note: maxlen should generally be considerably bigger than
  prefixofs + suffixofs.  It's disconcerting to a reader when
  you have a "..." to replace 10 bytes, but it feels fine when the
  "..." replaces 500 bytes.

  Args:
    s: the string to shorten.
    prefixofs: the number of chars to keep at the beginning of s.
    suffixofs: the number of chars to keep at the end of s.
    maxlen: if the string is longer than this, shorten it.
  Returns:
    A shortened version of the string.
  """
  s = str(s)
  if len(s) >= maxlen:
    # When the string exceeds the limit, we deliberately shorten it to
    # considerably less than the limit, because it's disconcerting when
    # you have a "..." to replace 10 bytes, but it feels right when the
    # "..." replaces 500 bytes.
    s = s[0:prefixofs] + '.....' + s[-suffixofs:]
  return s