Mercurial > p > roundup > code
diff roundup/rate_limit.py @ 7587:8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
Replace calls with equivalent that produces timezone aware dates
rather than naive dates.
Also some flake8 fixes for test/rest_common.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 25 Jul 2023 16:30:10 -0400 |
| parents | 69a35d164a69 |
| children | 5fbd3af526bd |
line wrap: on
line diff
--- a/roundup/rate_limit.py Mon Jul 24 21:24:07 2023 -0400 +++ b/roundup/rate_limit.py Tue Jul 25 16:30:10 2023 -0400 @@ -6,6 +6,8 @@ from datetime import timedelta, datetime +from roundup.anypy.datetime_ import utcnow + class RateLimit: # pylint: disable=too-few-public-methods def __init__(self, count, period): @@ -50,7 +52,7 @@ '''Determine if the item associated with the key should be rejected given the RateLimit limit. ''' - now = datetime.utcnow() + now = utcnow() tat = max(self.get_tat(key), now) separation = (tat - now).total_seconds() max_interval = limit.period.total_seconds() - limit.inverse @@ -88,7 +90,7 @@ ) # status of current limit as of now - now = datetime.utcnow() + now = utcnow() current_count = int((limit.period - (tat - now)).total_seconds() / limit.inverse)
