comparison gpp/antispam/rate_limit.py @ 565:6a265b5768ca

For bitbucket issue #5, rework the duplicate email checking in the registration form logic. Added tests for registration.
author Brian Neal <bgneal@gmail.com>
date Sun, 04 Mar 2012 13:20:40 -0600
parents 6f5fff924877
children a18516692273
comparison
equal deleted inserted replaced
564:e5d3552d4ad0 565:6a265b5768ca
4 """ 4 """
5 import datetime 5 import datetime
6 import logging 6 import logging
7 7
8 import redis 8 import redis
9 from django.conf import settings
10 9
11 from core.services import get_redis_connection 10 from core.services import get_redis_connection
12 11
13 12
14 logger = logging.getLogger(__name__) 13 logger = logging.getLogger(__name__)
67 except redis.RedisError, e: 66 except redis.RedisError, e:
68 logger.error("rate limit (block_ip): %s" % e) 67 logger.error("rate limit (block_ip): %s" % e)
69 raise RateLimiterUnavailable 68 raise RateLimiterUnavailable
70 69
71 logger.info("Rate limiter blocked IP %s; %d / %s", ip, count, interval) 70 logger.info("Rate limiter blocked IP %s; %d / %s", ip, count, interval)
71
72
73 def unblock_ip(ip):
74 """
75 This function removes the block for the given IP address.
76
77 """
78 key = _make_key(ip)
79 conn = _get_connection()
80 try:
81 conn.delete(key)
82 except redis.RedisError, e:
83 logger.error("rate limit (unblock_ip): %s" % e)
84 raise RateLimiterUnavailable
85
86 logger.info("Rate limiter unblocked IP %s", ip)
72 87
73 88
74 class RateLimiter(object): 89 class RateLimiter(object):
75 """ 90 """
76 This class encapsulates the rate limiting logic for a given IP address. 91 This class encapsulates the rate limiting logic for a given IP address.