'Sleep if the download speed is over the rate limit.'

def slow_down(self, start_time, now, byte_counter):

    rate_limit = self.params.get(u'ratelimit')
    if ((rate_limit is None) or (byte_counter == 0)):
        return
    if (now is None):
        now = time.time()
    elapsed = (now - start_time)
    if (elapsed <= 0.0):
        return
    speed = (float(byte_counter) / elapsed)
    if (speed > rate_limit):
        time.sleep(max(((byte_counter // rate_limit) - elapsed), 0))
