import time
import logging
from random import randint

logger = logging.getLogger('grab.tools.control')

def sleep(lower_limit, upper_limit):
    """
    Sleep for random number of seconds in interval
    between `lower_limit` and `upper_limit`
    """

    # Doing this math calculations
    # to call randint function with integer arugments
    # There is no random function which accepts float arguments
    lower_limit_float = int(lower_limit * 1000)
    upper_limit_float = int(upper_limit * 1000)
    sleep_time = randint(lower_limit_float, upper_limit_float) / 1000.0
    logger.debug('Sleeping for %f seconds' % sleep_time)
    time.sleep(sleep_time)

@@ -640,20 +640,698 @@
 e.sleep(sleep_time)%0A
+%0A%0Adef repeat(func, limit=3, args=None, kwargs=None, fatal_exceptions=()):%0A    for x in xrange(limit):%0A        ok = False%0A        try:%0A            if args is not None and kwargs is not None:%0A                res = func(*args, **kwargs)%0A            elif args is not None:%0A                res = func(*args)%0A            elif kwargs is not None:%0A                res = func(**kwargs)%0A            else:%0A                res = func()%0A            return res%0A        except Exception, ex:%0A            if isinstance(ex, fatal_exceptions):%0A                raise%0A            logging.error('', exc_info=ex)%0A            if x == (limit - 1):%0A                raise%0A        else:%0A            break%0A

Add repeat function to grab.tools.control