def _make_ping(self, key):

        # shortcut if no configured conditions 
        if not self.conditions:
            return True, 0.0

        # short cut if we are limiting to 0 requests
        min_requests, min_request_seconds = self.conditions[0]
        if min_requests == 0:
            self.log.warn('(%s) hit block all limit (%s/%s)', key, min_requests, min_request_seconds)
            return False, min_request_seconds


        log_key = ':'.join((self.namespace, key, 'log'))
        block_key = ':'.join((self.namespace, key, 'block'))
        lock_key = ':'.join((self.namespace, key, 'lock'))

        try:
            with self.redis.lock(lock_key, timeout=10):
                with self.redis.pipeline() as pipe:
                    for requests, _ in self.conditions:
                        pipe.lindex(log_key, 1-requests) # subtract 1 as 0 indexed

                    # check manual block keys
                    pipe.ttl(block_key)
                    pipe.get(block_key)
                    boundry_timestamps = pipe.execute()

                blocked = boundry_timestamps.pop()
                block_ttl = boundry_timestamps.pop()

                if blocked is not None:
                    # block_ttl is None for last second of a keys life. set min of 0.5
                    if block_ttl is None:
                        block_ttl = 0.5
                    self.log.warn('(%s) hit manual block. %ss remaining', key, block_ttl)
                    return False, block_ttl

                timestamp = time.time()

                for boundry_timestamp, (requests, seconds) in izip(boundry_timestamps, self.conditions):
                    # if we dont yet have n number of requests boundry_timestamp will be None and this condition wont be limiting
                    if boundry_timestamp is not None:
                        boundry_timestamp = float(boundry_timestamp)
                        if boundry_timestamp + seconds > timestamp:
                            self.log.warn('(%s) hit limit (%s/%s) time to allow %.1fs',
                                    key, requests, seconds, boundry_timestamp + seconds - timestamp)
                            return False, boundry_timestamp + seconds - timestamp

                # record our success
                with self.redis.pipeline() as pipe:
                        pipe.lpush(log_key, timestamp)
                        max_requests, _ = self.conditions[-1]
                        pipe.ltrim(log_key, 0, max_requests-1) # 0 indexed so subtract 1
                        # if we never use this key again, let it fall out of the DB after max seconds has past
                        pipe.expire(log_key, self.list_ttl)
                        pipe.execute()
        except redis.exceptions.LockError:
            self.log.exception("lock error in _make_ping")

        return True, 0.0
dataset/ETHPy150Open Impactstory/total-impact-core/rate_limit.py/RateLimiter._make_ping/swapped operands of `-`