def _ratelimit(self, http_method, url, **kwargs):
def time_since_last_call():<EOL><INDENT>if self.callsafety['<STR_LIT>'] is not None:<EOL><INDENT>return int(time() - self.callsafety['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>lastlimitremaining = self.callsafety['<STR_LIT>']<EOL>if time_since_last_call() is None or time_since_last_call() >= self.ratelimit_request_interval orlastlimitremaining >= self.ratelimit:<EOL><INDENT>response = http_method(url, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>log.warning(<EOL>"<STR_LIT>"<EOL>% (self.ratelimit, self.ratelimit_request_interval)<EOL>)<EOL>while time_since_last_call() < self.ratelimit_request_interval:<EOL><INDENT>remaining_sleep = int(self.ratelimit_request_interval - time_since_last_call())<EOL>log.debug("<STR_LIT>" % remaining_sleep)<EOL>self.check_ratelimit_budget(<NUM_LIT:1>)<EOL>sleep(<NUM_LIT:1>)<EOL><DEDENT>response = http_method(url, **kwargs)<EOL><DEDENT>self.callsafety['<STR_LIT>'] = time()<EOL>self.callsafety['<STR_LIT>'] = int(response.headers.get('<STR_LIT>', <NUM_LIT:0>))<EOL>return response<EOL>
Ensure we do not hit the rate limit.