66
77from datetime import timedelta , datetime
88
9- class RateLimit :
9+ class RateLimit : # pylint: disable=too-few-public-methods
1010 def __init__ (self , count , period ):
1111 self .count = count
1212 self .period = period
@@ -17,8 +17,8 @@ def inverse(self):
1717
1818
1919class Gcra :
20-
21- memory = {}
20+ def __init__ ( self ):
21+ self . memory = {}
2222
2323 def get_tat (self , key ):
2424 # This should return a previous tat for the key or the current time.
@@ -47,7 +47,7 @@ def set_tat_as_string(self, key, tat):
4747 self .memory [key ] = datetime .strptime (tat ,"%Y-%m-%dT%H:%M:%S.%f" )
4848
4949 def update (self , key , limit , testonly = False ):
50- '''Determine if the item assocaited with the key should be
50+ '''Determine if the item associated with the key should be
5151 rejected given the RateLimit limit.
5252 '''
5353 now = datetime .utcnow ()
@@ -91,7 +91,7 @@ def status(self, key, limit):
9191 (limit .period - (tat - now )).total_seconds () \
9292 / limit .inverse ),ret ['X-RateLimit-Limit' ])
9393
94- tat_epochsec = (tat - datetime (1970 , 1 , 1 )).total_seconds ()
94+ # tat_in_epochsec = (tat - datetime(1970, 1, 1)).total_seconds()
9595 seconds_to_tat = (tat - now ).total_seconds ()
9696 ret ['X-RateLimit-Reset' ] = max (seconds_to_tat , 0 )
9797 ret ['X-RateLimit-Reset-date' ] = "%s" % tat
0 commit comments