# Path: iprestrict/models.py
# class ReloadRulesRequest(models.Model):
#     at = models.DateTimeField(auto_now_add=True)
# 
#     @classmethod
#     def request_reload(cls):
#         rrs = ReloadRulesRequest.objects.all()
#         if len(rrs) > 0:
#             obj = rrs[0]
#             obj.at = timezone.now()
#             obj.save()
#         else:
#             cls.objects.create()
# 
#     @staticmethod
#     def last_request():
#         result = None
#         rrs = ReloadRulesRequest.objects.all()
#         if len(rrs) > 0:
#             result = rrs[0].at
#         return result
# 
# Path: iprestrict/restrictor.py
# class IPRestrictor(object):
#     rules = None
#     last_reload = None
# 
#     def __init__(self):
#         self.load_rules()
# 
#     def is_restricted(self, url, ip):
#         for rule in self.rules:
#             if rule.matches_url(url) and rule.matches_ip(ip):
#                 return rule.is_restricted()
#         return False
# 
#     def load_rules(self):
#         # We are caching the rules, to avoid DB lookup on each request
#         from .models import Rule
#         self.rules = list(Rule.objects.all())
#         self.last_reload = timezone.now()
# 
#     reload_rules = load_rules


from django.core import exceptions
from django.conf import settings
from .models import ReloadRulesRequest
from .restrictor import IPRestrictor
    from django.utils.deprecation import MiddlewareMixin
import logging
import warnings
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

try:
except ImportError:
    class MiddlewareMixin(object):
        def __init__(self, *args, **kwargs):
            pass


logger = logging.getLogger(__name__)


class IPRestrictMiddleware(MiddlewareMixin):
    restrictor = None
    trusted_proxies = None
    allow_proxies = None
    reload_rules = None

    def __init__(self, *args, **kwargs):
        super(IPRestrictMiddleware, self).__init__(*args, **kwargs)

# Path: iprestrict/models.py
# class ReloadRulesRequest(models.Model):
#     at = models.DateTimeField(auto_now_add=True)
# 
#     @classmethod
#     def request_reload(cls):
#         rrs = ReloadRulesRequest.objects.all()
#         if len(rrs) > 0:
#             obj = rrs[0]
#             obj.at = timezone.now()
#             obj.save()
#         else:
#             cls.objects.create()
# 
#     @staticmethod
#     def last_request():
#         result = None
#         rrs = ReloadRulesRequest.objects.all()
#         if len(rrs) > 0:
#             result = rrs[0].at
#         return result
# 
# Path: iprestrict/restrictor.py
# class IPRestrictor(object):
#     rules = None
#     last_reload = None
# 
#     def __init__(self):
#         self.load_rules()
# 
#     def is_restricted(self, url, ip):
#         for rule in self.rules:
#             if rule.matches_url(url) and rule.matches_ip(ip):
#                 return rule.is_restricted()
#         return False
# 
#     def load_rules(self):
#         # We are caching the rules, to avoid DB lookup on each request
#         from .models import Rule
#         self.rules = list(Rule.objects.all())
#         self.last_reload = timezone.now()
# 
#     reload_rules = load_rules


# Path: iprestrict/middleware.py
from django.core import exceptions
from django.conf import settings
from .models import ReloadRulesRequest
from .restrictor import IPRestrictor
    from django.utils.deprecation import MiddlewareMixin
import logging
import warnings

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

try:
except ImportError:
    class MiddlewareMixin(object):
        def __init__(self, *args, **kwargs):
            pass


logger = logging.getLogger(__name__)


class IPRestrictMiddleware(MiddlewareMixin):
    restrictor = None
    trusted_proxies = None
    allow_proxies = None
    reload_rules = None

    def __init__(self, *args, **kwargs):
        super(IPRestrictMiddleware, self).__init__(*args, **kwargs)

        self.restrictor = IPRestrictor()