Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing incompatibility with ipadress-lib. #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions tumgreyspf
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ tumgreyspfsupp.setExceptHook()
def is_loopback(address):
'''Return true if address is a loopback IP.'''
if (
address in ['127.0.0.1', '::1']
or address.startswith('127.0.0.')
address in [u'127.0.0.1', u'::1']
or address.startswith(u'127.0.0.')
):
return True

Expand All @@ -37,7 +37,7 @@ def is_loopback(address):
except ImportError:
return False

loopback_cidrs = ['127.0.0.0/8', '::ffff:127.0.0.0/104', '::1/128']
loopback_cidrs = [u'127.0.0.0/8', u'::ffff:127.0.0.0/104', u'::1/128']
compare = ipaddress.ip_interface(address).network.overlaps
for cidr in loopback_cidrs:
if compare(ipaddress.ip_interface(cidr).network):
Expand All @@ -50,7 +50,7 @@ def is_loopback(address):
def spfcheck(data, configData, configGlobal):
debugLevel = configGlobal.get('debugLevel', 0)
queue_id = ('QUEUE_ID="%s"' % (data.get('queue_id', '<UNKNOWN>')))
ip = data.get('client_address')
ip = data.get('client_address').decode('latin1')
if ip == None:
if debugLevel:
syslog.syslog('spfcheck: No client address, exiting')
Expand Down Expand Up @@ -327,14 +327,14 @@ def run_tests():

class Tests(unittest.TestCase):
def test_is_loopback(self):
self.assertEqual(is_loopback('10.1.1.1'), False)
self.assertEqual(is_loopback('127.0.0.1'), True)
self.assertEqual(is_loopback('::1'), True)
self.assertEqual(is_loopback(u'10.1.1.1'), False)
self.assertEqual(is_loopback(u'127.0.0.1'), True)
self.assertEqual(is_loopback(u'::1'), True)

try:
import ipaddress
# tests using ipaddress module (if available)
self.assertEqual(is_loopback('127.0.1.1'), True)
self.assertEqual(is_loopback(u'127.0.1.1'), True)
except ImportError:
pass

Expand Down