Skip to content

Commit 4ea97a3

Browse files
committed
Rename Store class in rate_limit.py to Gcra. The name Store makes no
sense since the class implements a Gcra, I'll call it Gcra....
1 parent 2981428 commit 4ea97a3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

roundup/cgi/actions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from roundup.i18n import _
66
from roundup.cgi import exceptions, templating
77
from roundup.mailgw import uidFromAddress
8-
from roundup.rate_limit import Store, RateLimit
8+
from roundup.rate_limit import Gcra, RateLimit
99
from roundup.exceptions import Reject, RejectRaw
1010
from roundup.anypy import urllib_
1111
from roundup.anypy.strings import StringIO
@@ -1235,27 +1235,27 @@ def handle(self):
12351235
# Use prefix to prevent key collisions maybe??
12361236
rlkey="LOGIN-" + self.client.user
12371237
limit=self.loginLimit
1238-
s=Store()
1238+
gcra=Gcra()
12391239
otk=self.client.db.Otk
12401240
try:
12411241
val=otk.getall(rlkey)
1242-
s.set_tat_as_string(rlkey, val['tat'])
1242+
gcra.set_tat_as_string(rlkey, val['tat'])
12431243
except KeyError:
12441244
# ignore if tat not set, it's 1970-1-1 by default.
12451245
pass
12461246
# see if rate limit exceeded and we need to reject the attempt
1247-
reject=s.update(rlkey, limit)
1247+
reject=gcra.update(rlkey, limit)
12481248

12491249
# Calculate a timestamp that will make OTK expire the
12501250
# unused entry 1 hour in the future
12511251
ts = time.time() - (60 * 60 * 24 * 7) + 3600
1252-
otk.set(rlkey, tat=s.get_tat_as_string(rlkey),
1252+
otk.set(rlkey, tat=gcra.get_tat_as_string(rlkey),
12531253
__timestamp=ts)
12541254
otk.commit()
12551255

12561256
if reject:
12571257
# User exceeded limits: find out how long to wait
1258-
status=s.status(rlkey, limit)
1258+
status=gcra.status(rlkey, limit)
12591259
raise Reject(_("Logins occurring too fast. Please wait: %d seconds.")%status['Retry-After'])
12601260
else:
12611261
self.verifyLogin(self.client.user, password)

roundup/rate_limit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def inverse(self):
1616
return self.period.total_seconds() / self.count
1717

1818

19-
class Store:
19+
class Gcra:
2020

2121
memory = {}
2222

@@ -82,7 +82,7 @@ def status(self, key, limit):
8282

8383
# static defined headers according to limit
8484
ret['X-RateLimit-Limit'] = limit.count
85-
ret['X-RateLimit-Limit-Period'] = limit.period.total_seconds()
85+
ret['X-RateLimit-Limit-Period'] = int(limit.period.total_seconds())
8686

8787
# status of current limit as of now
8888
now = datetime.utcnow()

0 commit comments

Comments
 (0)