import os
import sys
+import socket
class BaseRateLimit(object):
api_method_caller = "unknown"
# excludes
- if api_method_source == None or api_method_source[0] == self.config.PLC_API_IP or api_method_source[0] in self.whitelist:
+ if api_method_source == None or api_method_source[0] == socket.gethostbyname(self.config.PLC_API_HOST) or api_method_source[0] in self.whitelist:
return
# sanity check
keys_to_check = ["%s_%s_%s_%s" % (self.prefix, api_method_caller, api_method_source[0], (now - timedelta(minutes = minute)).strftime("%Y%m%d%H%M")) for minute in range(self.minutes + 1)]
try:
- mc.incr(current_key)
+ value = mc.incr(current_key)
except ValueError:
+ value = None
+
+ if value == None:
mc.set(current_key, 1, time=self.expire_after)
results = mc.get_multi(keys_to_check)