def truncate(message, from_start, from_end=None):
  """
  Truncate the string *message* until at max *from_start* characters and
  insert an ellipsis (`...`) in place of the additional content. If *from_end*
  is specified, the same will be applied to the end of the string.
  """

  if len(message) <= (from_start + (from_end or 0) + 3):
    return message
  part1, part2 = message[:from_start], ''
  if from_end and len(message) > from_end:
    if len(message) - from_start < from_end:
      from_end -= len(message) - from_start
    part2 = message[-from_end:]
  return part1 + '...' + part2