Add support for more than 1 host on a given line

This commit is contained in:
George Edward Bulmer 2018-03-24 20:20:16 +00:00
parent 3f37fcf8fa
commit 8809ef02a1

View File

@ -228,16 +228,13 @@ class HostBlocker:
parts = line.split()
if len(parts) == 1:
# "one host per line" format
host = parts[0]
elif len(parts) == 2:
# /etc/hosts format
host = parts[1]
hosts = [parts[0]]
else:
log.misc.error("Failed to parse: {!r}".format(line))
return False
hosts = parts[1:]
if '.' in host and not host.endswith('.localdomain'):
self._blocked_hosts.add(host)
for host in hosts:
if '.' in host and not host.endswith('.localdomain'):
self._blocked_hosts.add(host)
return True