@@ -20,9 +20,7 @@ def __init__(self, get_response=None):
2020
2121 ipinfo_token = getattr (settings , "IPINFO_TOKEN" , None )
2222 ipinfo_settings = getattr (settings , "IPINFO_SETTINGS" , {})
23- self .ip_selector = getattr (
24- settings , "IPINFO_IP_SELECTOR" , DefaultIPSelector ()
25- )
23+ self .ip_selector = getattr (settings , "IPINFO_IP_SELECTOR" , DefaultIPSelector ())
2624 self .ipinfo = ipinfo .getHandler (ipinfo_token , ** ipinfo_settings )
2725
2826 def __call__ (self , request ):
@@ -34,7 +32,7 @@ def __call__(self, request):
3432 request .ipinfo = self .ipinfo .getDetails (
3533 self .ip_selector .get_ip (request )
3634 )
37- except Exception as exc :
35+ except Exception :
3836 request .ipinfo = None
3937 LOGGER .error (traceback .format_exc ())
4038
@@ -57,9 +55,7 @@ def __init__(self, get_response):
5755
5856 ipinfo_token = getattr (settings , "IPINFO_TOKEN" , None )
5957 ipinfo_settings = getattr (settings , "IPINFO_SETTINGS" , {})
60- self .ip_selector = getattr (
61- settings , "IPINFO_IP_SELECTOR" , DefaultIPSelector ()
62- )
58+ self .ip_selector = getattr (settings , "IPINFO_IP_SELECTOR" , DefaultIPSelector ())
6359 self .ipinfo = ipinfo .getHandlerAsync (ipinfo_token , ** ipinfo_settings )
6460
6561 def __call__ (self , request ):
@@ -83,3 +79,23 @@ async def __acall__(self, request):
8379
8480 def is_bot (self , request ):
8581 return is_bot (request )
82+
83+
84+ class IPinfoLiteMiddleware (IPinfoMiddleware ):
85+ def __init__ (self , get_response ):
86+ super ().__init__ (get_response = get_response )
87+
88+ ipinfo_token = getattr (settings , "IPINFO_TOKEN" , None )
89+ ipinfo_settings = getattr (settings , "IPINFO_SETTINGS" , {})
90+ self .ipinfo = ipinfo .getHandlerLite (ipinfo_token , ** ipinfo_settings )
91+
92+
93+ class IPinfoAsyncLiteMiddleware (IPinfoAsyncMiddleware ):
94+ sync_capable = False
95+ async_capable = True
96+
97+ def __init__ (self , get_response ):
98+ super ().__init__ (get_response = get_response )
99+ ipinfo_token = getattr (settings , "IPINFO_TOKEN" , None )
100+ ipinfo_settings = getattr (settings , "IPINFO_SETTINGS" , {})
101+ self .ipinfo = ipinfo .getHandlerAsyncLite (ipinfo_token , ** ipinfo_settings )
0 commit comments