| 310 | _handle_429 = util.false |
| 311 | |
| 312 | def wait(self, seconds=None, until=None, adjust=1.0, |
| 313 | reason="rate limit"): |
| 314 | now = time.time() |
| 315 | |
| 316 | if seconds: |
| 317 | seconds = float(seconds) |
| 318 | until = now + seconds |
| 319 | elif until: |
| 320 | if isinstance(until, dt.datetime): |
| 321 | # convert to UTC timestamp |
| 322 | until = dt.to_ts(until) |
| 323 | else: |
| 324 | until = float(until) |
| 325 | seconds = until - now |
| 326 | else: |
| 327 | raise ValueError("Either 'seconds' or 'until' is required") |
| 328 | |
| 329 | seconds += adjust |
| 330 | if seconds <= 0.0: |
| 331 | return |
| 332 | |
| 333 | if reason: |
| 334 | if seconds >= 3600.0: |
| 335 | h, m = divmod(seconds, 3600.0) |
| 336 | dur = f"{int(h)}h {int(m/60.0)}min" |
| 337 | elif seconds >= 60.0: |
| 338 | dur = str(int(seconds/60.0)) + " minutes" |
| 339 | else: |
| 340 | dur = str(int(seconds)) + " seconds" |
| 341 | t = time.localtime(until) |
| 342 | iso = f"{t.tm_hour:02}:{t.tm_min:02}:{t.tm_sec:02}" |
| 343 | self.log.info("Waiting for %s until %s (%s)", dur, iso, reason) |
| 344 | time.sleep(seconds) |
| 345 | |
| 346 | def sleep(self, seconds, reason): |
| 347 | self.log.debug("Sleeping %.2f seconds (%s)", |