more python3, esp. in shebangs and doc
[plcapi.git] / aspects / ratelimitaspects.py
index 5aeaa86..a290079 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/python
 #-*- coding: utf-8 -*-
 #
 # S.Çağlar Onur <caglar@cs.princeton.edu>
@@ -18,6 +17,7 @@ import memcache
 
 import os
 import sys
+import socket
 
 class BaseRateLimit(object):
 
@@ -105,7 +105,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
@@ -144,13 +144,12 @@ Subject: %(subject)s
                 if (api_method == "session" and api_method_caller.__contains__("@")) or (api_method == "password" or api_method == "capability"):
                     self.mail(api_method_caller)
 
-            raise PLCPermissionDenied, "Maximum allowed number of API calls exceeded"
+            raise PLCPermissionDenied("Maximum allowed number of API calls exceeded")
 
     def after(self, wobj, data, *args, **kwargs):
         return
 
-class RateLimitAspect_class(BaseRateLimit):
-    __metaclass__ = MetaAspect
+class RateLimitAspect_class(BaseRateLimit, metaclass=MetaAspect):
     name = "ratelimitaspect_class"
 
     def __init__(self):