diff --git a/iptools/__init__.py b/iptools/__init__.py index 181f845..8d21ce9 100644 --- a/iptools/__init__.py +++ b/iptools/__init__.py @@ -249,7 +249,7 @@ def _cast(self, item): if ipv4 == self._ipver and item > ipv4.MAX_IP: # casting an ipv6 in an ipv4 range # downcast to ipv4 iff address is in the IPv4 mapped block - if item in IpRange(ipv6.IPV4_MAPPED): + if item in _IPV6_MAPPED_IPV4: item = item & ipv4.MAX_IP # end if @@ -395,6 +395,9 @@ def __iter__(self): # end class IpRange +_IPV6_MAPPED_IPV4 = IpRange(ipv6.IPV4_MAPPED) + + class IpRangeList (object): """ List of IpRange objects. @@ -464,6 +467,11 @@ def __contains__(self, item): :type item: str :returns: ``True`` if address is in list, ``False`` otherwise. """ + if isinstance(item, basestring): + item = _address2long(item) + if type(item) not in (type(1), type(ipv4.MAX_IP), type(ipv6.MAX_IP)): + raise TypeError( + "expected ip address, 32-bit integer or 128-bit integer") for r in self.ips: if item in r: return True