Esempio n. 1
0
def xfrange(start, stop, step=1, maxSize=-1):
    """
    Returns a generator that yields the frames from start to stop, inclusive.
    In other words it adds or subtracts a frame, as necessary, to return the
    stop value as well, if the stepped range would touch that value.

    :type start: int
    :type stop: int
    :type step: int
    :param step: Note that the sign will be ignored
    :type maxSize: int
    :param maxSize: If >= raise a :class:`fileseq.exceptions.MaxSizeException` 
                    if size is exceeded
    :rtype: generator
    """
    if start <= stop:
        stop, step = stop + 1, abs(step)
    else:
        stop, step = stop - 1, -abs(step)
        
    if maxSize >= 0:
        size = lenRange(start, stop, step)
        if size > maxSize:
            raise exceptions.MaxSizeException(
                "Size %d > %s (MAX_FRAME_SIZE)" % (size, maxSize))
        
    # because an xrange is an odd object all its own, we wrap it in a
    # generator expression to get a proper Generator
    return (f for f in xrange(start, stop, step))
Esempio n. 2
0
def xfrange(start, stop, step=1, maxSize=-1):
    """
    Returns a generator that yields the frames from start to stop, inclusive.
    In other words it adds or subtracts a frame, as necessary, to return the
    stop value as well, if the stepped range would touch that value.

    Args:
        start (int):
        stop (int):
        step (int): Note that the sign will be ignored
        maxSize (int):

    Returns:
        generator:

    Raises:
        :class:`fileseq.exceptions.MaxSizeException`: if size is exceeded
    """
    if not step:
        raise ValueError('xfrange() step argument must not be zero')

    start, stop, step = normalizeFrames([start, stop, step])

    if start <= stop:
        step = abs(step)
    else:
        step = -abs(step)

    if isinstance(start, futils.integer_types):
        size = (stop - start) // step + 1
    else:
        size = int((stop - start) / step) + 1

    if maxSize >= 0 and size > maxSize:
        raise exceptions.MaxSizeException("Size %d > %s (MAX_FRAME_SIZE)" %
                                          (size, maxSize))

    # because an xrange is an odd object all its own, we wrap it in a
    # generator expression to get a proper Generator
    if isinstance(start, futils.integer_types):
        offset = step // abs(step)
        return (f for f in range(start, stop + offset, step))
    else:
        return (start + i * step for i in range(size))