def truncate(x, maxlen=1000):
    """
    >>> truncate('1234567890', 8)
    '1234 ...'
    >>> truncate('1234567890', 10)
    '1234567890'
    """
    if len(x) > maxlen:
        suffix = ' ...'
        return '%s%s' % (x[:maxlen - len(suffix)], suffix)
    else:
        return x