class Format(enum.Enum):
PLAIN = 1
- ADBLOCKPLUS = 2
+ HOSTS = 2
+ ADBLOCKPLUS = 3
class Sources(object):
case Format.ADBLOCKPLUS:
domain = self._process_adblockplus(line)
+ case Format.HOSTS:
+ domain = self._process_hosts(line)
+
case Format.PLAIN:
domain = line
if line == "[Adblock Plus]":
return Format.ADBLOCKPLUS
+ # Is this a hosts file?
+ elif line.startswith("0.0.0.0 "):
+ return Format.HOSTS
+
# Check for a plain FQDN
elif util.is_fqdn(line):
return Format.PLAIN
return domain
+ def _process_hosts(self, line):
+ """
+ Parses a line of a hosts file.
+ """
+ return line.removeprefix("0.0.0.0 ")
+
def add_domain(self, name):
"""
Adds or updates a domain.