On Sat, Mar 14, 2009 at 6:33 PM, Rodrigo Guzman <rodg...@gmail.com> wrote:
...
> So, it seems like it'd be a straight forward change to
> django.core.context_processors.debug to implement it.  However, it
> seems that this functionality would be better placed in the settings
> module.

Django only uses INTERNAL_IPS using "in", so just __contains__ is needed.

I've been doing something like this in my project settings for some
time; unless I'm missing something, there's no need to change Django:

class CIDR_LIST(list):
    def __init__(self, cidrs):
        from IPy import IP
        self.cidrs = []
        try:
            for cidr in cidrs:
                self.cidrs.append(IP(cidr))
        except ImportError:
            pass
    def __contains__(self, ip):
        try:
            for cidr in self.cidrs:
                if ip in cidr:
                    return True
        except:
            pass
        return False

INTERNAL_IPS = CIDR_LIST([
    '127.0.0.1/32',
    '10.0.0.0/24'
    ])

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to