meantime commit: code review, simplification, pythonization, etc. (test cases passed)

pull/1414/head
sebres 2016-05-04 14:02:03 +02:00
parent a757037671
commit 07c9f38e45
2 changed files with 8 additions and 5 deletions

View File

@ -375,7 +375,7 @@ class Filter(JailThread):
# @return True if IP address is in ignore list
def inIgnoreIPList(self, ip, log_ignore=False):
if isinstance(ip, basestring):
if not isinstance(ip, IPAddr):
ip = IPAddr(ip)
for net in self.__ignoreIpList:
# if it isn't a valid IP address, try DNS resolution
@ -1037,6 +1037,9 @@ class DNSUtils:
return v
# retrieve name
try:
if not isinstance(ip, IPAddr):
v = socket.gethostbyaddr(ip)[0]
else:
v = socket.gethostbyaddr(ip.ntoa())[0]
except socket.error, e:
logSys.debug("Unable to find a name for the IP %s: %s", ip, e)

View File

@ -1314,9 +1314,9 @@ class DNSUtilsNetworkTests(unittest.TestCase):
res = DNSUtils.textToIp('www.example.com', 'no')
self.assertEqual(res, [])
res = DNSUtils.textToIp('www.example.com', 'warn')
self.assertEqual(res, ['93.184.216.34'])
self.assertEqual(res, ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'])
res = DNSUtils.textToIp('www.example.com', 'yes')
self.assertEqual(res, ['93.184.216.34'])
self.assertEqual(res, ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'])
def testTextToIp(self):
# Test hostnames
@ -1328,7 +1328,7 @@ class DNSUtilsNetworkTests(unittest.TestCase):
for s in hostnames:
res = DNSUtils.textToIp(s, 'yes')
if s == 'www.example.com':
self.assertEqual(res, ['93.184.216.34'])
self.assertEqual(res, ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'])
else:
self.assertEqual(res, [])