On Mar 15, 2009, at 05:02, Jeremy Dunck wrote: > 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
from IPy import IP class CIDRList(list): def __init__(self, seq=()): super(CIDRList, self).__init__(map(IP, seq)) def __contains__(self, other): return any(other in range for range in self) Of course, any only exists in recent Pythons, same for generator expressions. I also question the `except ImportError` in your __init__. :-) - Ludvig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---