def times(filenames, tolerance=2):
    """For the given file(s), return the time ranges available.  Tolerance
    sets the number of seconds between time ranges.  Any gaps larger
    than tolerance seconds will result in a new time range.

    :param filenames: Single filename (string) or list of filenames
    :param tolerance: Maximum seconds between contiguous time ranges

    :returns: A dictionary keyed by filename, with each value a list
    of (start, stop) time ranges for that file.
    """
    times = { }
    delta = datetime.timedelta(seconds=tolerance)

    if isinstance(filenames, str):
        filenames = [ filenames ]

    for filename in filenames:
        with open(filename, 'r') as stream:
            times[filename] = list()
            header, packet  = stream.read()
            start , stop    = header.timestamp, header.timestamp

            for header, packet in stream:
                if header.timestamp - stop > delta:
                    times[filename].append((start, stop))
                    start = header.timestamp
                stop = header.timestamp

            times[filename].append((start, stop))

    return times