From d8a7d9fcaa8e7f5f8e3935d1f78b004f6812c766 Mon Sep 17 00:00:00 2001 From: Micha Glave Date: Thu, 1 Oct 2015 12:03:21 +0200 Subject: [PATCH 1/2] fixing incompatibility with ipadress-lib. Probably introduced by https://github.com/phihag/ipaddress/commit/3c5883496177b654a81e98b5c77007455d8ee4a6 --- tumgreyspf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tumgreyspf b/tumgreyspf index 90f05df..8e6baac 100755 --- a/tumgreyspf +++ b/tumgreyspf @@ -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 @@ -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): @@ -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 From 6419df73d926f06c6f13628d32d2acaed99c5b55 Mon Sep 17 00:00:00 2001 From: Micha Glave Date: Thu, 1 Oct 2015 14:09:44 +0200 Subject: [PATCH 2/2] converting str into utf-8-string. --- tumgreyspf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tumgreyspf b/tumgreyspf index 8e6baac..9a1b977 100755 --- a/tumgreyspf +++ b/tumgreyspf @@ -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', ''))) - ip = data.get('client_address') + ip = data.get('client_address').decode('latin1') if ip == None: if debugLevel: syslog.syslog('spfcheck: No client address, exiting')