Skip to content

Commit f7e3381

Browse files
committed
generate-domains-blocklist: parse names prefixed with *.
1 parent 7a8bd35 commit f7e3381

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

utils/generate-domains-blocklist/generate-domains-blocklist.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def parse_list(content, trusted=False):
6565
r"^@*\|\|([a-z0-9][a-z0-9.-]*[.][a-z]{2,})\^?(\$(popup|third-party))?$"
6666
)
6767
rx_l = re.compile(r"^([a-z0-9][a-z0-9.-]*[.][a-z]{2,})$")
68+
rx_lw = re.compile(r"^[*][.]([a-z0-9][a-z0-9.-]*[.][a-z]{2,})$")
6869
rx_h = re.compile(
6970
r"^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}\s+([a-z0-9][a-z0-9.-]*[.][a-z]{2,})$"
7071
)
@@ -75,7 +76,7 @@ def parse_list(content, trusted=False):
7576
names = set()
7677
time_restrictions = {}
7778
globs = set()
78-
rx_set = [rx_u, rx_l, rx_h, rx_mdl, rx_b, rx_dq]
79+
rx_set = [rx_u, rx_l, rx_lw, rx_h, rx_mdl, rx_b, rx_dq]
7980
for line in content.splitlines():
8081
line = str.lower(str.strip(line))
8182
if rx_comment.match(line):
@@ -92,7 +93,8 @@ def parse_list(content, trusted=False):
9293

9394
def print_restricted_name(output_fd, name, time_restrictions):
9495
if name in time_restrictions:
95-
print("{}\t{}".format(name, time_restrictions[name]), file=output_fd, end="\n")
96+
print("{}\t{}".format(
97+
name, time_restrictions[name]), file=output_fd, end="\n")
9698
else:
9799
print(
98100
"# ignored: [{}] was in the time-restricted list, "
@@ -120,7 +122,8 @@ def load_from_url(url):
120122
except urllib.URLError as err:
121123
raise Exception("[{}] could not be loaded: {}\n".format(url, err))
122124
if trusted is False and response.getcode() != 200:
123-
raise Exception("[{}] returned HTTP code {}\n".format(url, response.getcode()))
125+
raise Exception("[{}] returned HTTP code {}\n".format(
126+
url, response.getcode()))
124127
content = response.read()
125128
if URLLIB_NEW:
126129
content = content.decode("utf-8", errors="replace")
@@ -262,10 +265,12 @@ def blocklists_from_config_file(
262265

263266
list_names.sort(key=name_cmp)
264267
if ignored:
265-
print("# Ignored duplicates: {}".format(ignored), file=output_fd, end="\n")
268+
print("# Ignored duplicates: {}".format(
269+
ignored), file=output_fd, end="\n")
266270
if glob_ignored:
267271
print(
268-
"# Ignored due to overlapping local patterns: {}".format(glob_ignored),
272+
"# Ignored due to overlapping local patterns: {}".format(
273+
glob_ignored),
269274
file=output_fd,
270275
end="\n",
271276
)

0 commit comments

Comments
 (0)