# HG changeset patch # Parent 5d2afb13dbe7beeabf791aa2d31955dbfb1f6ed6 diff -r 5d2afb13dbe7 spf.py --- a/spf.py Tue Sep 01 20:14:27 2015 -0600 +++ b/spf.py Tue Sep 01 21:03:10 2015 -0600 @@ -102,10 +102,7 @@ # Python standard libarary as of python3.3 import ipaddress except ImportError: - try: - import ipaddr as ipaddress - except ImportError: - print('ipaddr module required: http://code.google.com/p/ipaddr-py/') + print('ipaddress module required: https://github.com/phihag/ipaddress') import DNS # http://pydns.sourceforge.net if not hasattr(DNS.Type, 'SPF'): @@ -401,6 +398,9 @@ self.iplist = [] ip6 = True else: + if sys.version_info.major < 3: + if isinstance(i, str): + i = i.decode('ascii') try: self.ipaddr = ipaddress.ip_address(i) except AttributeError: @@ -1203,7 +1203,7 @@ 'No %s records found for'%A, domainname) if A == 'AAAA' and bytes is str: # work around pydns inconsistency plus python2 bytes/str ambiguity - return [ipaddress.Bytes(ip) for ip in r] + return [ipaddress.ip_address(ip) for ip in r] return r def validated_ptrs(self): @@ -1345,6 +1345,11 @@ True """ try: + if sys.version_info.major < 3: + for idx, ip in enumerate(ipaddrs): + if isinstance(ipaddrs[idx], str): + ipaddrs[idx] = ipaddrs[idx].decode('ascii') + for netwrk in [ipaddress.ip_network(ip) for ip in ipaddrs]: network = netwrk.supernet(new_prefix=n) if isinstance(self.iplist, bool):