for line in f:
line = line.rstrip()
+ # Strip any comments
+ line, hashtag, comment = line.partition("#")
+
+ # Skip the line if it is empty
+ if not line:
+ continue
+
# Detect the format if still unknown
if format is None:
format = self._detect_format(line)
"""
Parses a line of a hosts file.
"""
- # Strip any comments
- line, _, comment = line.partition("#")
-
for prefix in HOST_PREFIXES:
if line.startswith(prefix):
return line.removeprefix(prefix)
"""
Parses a plain list of domains
"""
- domain, _, comment = line.partition("#")
-
- return domain
+ return line
def add_domains(self, _domains):
"""