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() parts = line.split()
if len(parts) == 1: if len(parts) == 1:
# "one host per line" format # "one host per line" format
host = parts[0] hosts = [parts[0]]
elif len(parts) == 2:
# /etc/hosts format
host = parts[1]
else: else:
log.misc.error("Failed to parse: {!r}".format(line)) hosts = parts[1:]
return False
if '.' in host and not host.endswith('.localdomain'): for host in hosts:
self._blocked_hosts.add(host) if '.' in host and not host.endswith('.localdomain'):
self._blocked_hosts.add(host)
return True return True