"""
Parse the domain from the AdBlockPlus format
"""
- if line.startswith("||"):
- # Remove the leading ||
- line = line.removeprefix("||")
+ # Skip any comments
+ if line.startswith("!") or line.startswith("@@"):
+ return
+
+ # Remove the leading ||
+ # Some files actually don't always use this
+ line = line.removeprefix("||")
+
+ # Split off any options
+ line, __, options = line.partition("$")
+
+ # Parse the options
+ if options:
+ # Split options by comma and strip any whitespace
+ options = [option.strip() for option in options.split(",")]
+
+ # Remove some options that we know and will ignore
+ for option in ("all", "important"):
+ try:
+ options.remove(option)
+ except ValueError:
+ pass
+
+ # Cut off everything after ^
+ line, __, rest = line.partition("^")
- # Cut off everything after ^
- domain, _, rest = line.partition("^")
+ # The line now should only contain the domain
+ domain = line
- return domain
+ # Ignore any domains that have unknown/unsupported options
+ if options:
+ log.warning(_("Cannot parse domain %s with unknown options: %s") \
+ % (domain, ",".join(options)))
+ return
+
+ return domain
def _process_hosts(self, line):
"""