fixed: encodes boolean and double type values for the requests
[plcapi.git] / aspects / ratelimitaspects.py
index e95764f..836b2ba 100644 (file)
@@ -18,6 +18,7 @@ import memcache
 
 import os
 import sys
+import socket
 
 class BaseRateLimit(object):
 
@@ -105,7 +106,7 @@ Subject: %(subject)s
             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
@@ -123,8 +124,11 @@ Subject: %(subject)s
         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)