updated FOP.py
This commit is contained in:
parent
c4e87e27fa
commit
2622a85fca
14
FOP.py
14
FOP.py
|
@ -54,7 +54,8 @@ COMMITPATTERN = re.compile(r"^(A|M|P)\:\s(\((.+)\)\s)?(.*)$")
|
||||||
|
|
||||||
# List the files that should not be sorted, either because they have a special sorting system or because they are not filter files
|
# List the files that should not be sorted, either because they have a special sorting system or because they are not filter files
|
||||||
IGNORE = ("CC-BY-SA.txt", "easytest.txt", "GPL.txt", "MPL.txt",
|
IGNORE = ("CC-BY-SA.txt", "easytest.txt", "GPL.txt", "MPL.txt",
|
||||||
"enhancedstats-addon.txt", "fanboy-tracking", "firefox-regional", "other")
|
"enhancedstats-addon.txt", "fanboy-tracking", "firefox-regional", "other",
|
||||||
|
"easylist_cookie_specific_uBO.txt", "fanboy_annoyance_specific_uBO.txt", "fanboy_notifications_specific_uBO.txt", "fanboy_social_specific_uBO.txt")
|
||||||
|
|
||||||
# List all Adblock Plus options (excepting domain, which is handled separately), as of version 1.3.9
|
# List all Adblock Plus options (excepting domain, which is handled separately), as of version 1.3.9
|
||||||
KNOWNOPTIONS = ("collapse", "csp", "document", "elemhide",
|
KNOWNOPTIONS = ("collapse", "csp", "document", "elemhide",
|
||||||
|
@ -215,6 +216,9 @@ def fopsort (filename):
|
||||||
filterlines = elementlines = 0
|
filterlines = elementlines = 0
|
||||||
outputfile.write("{line}\n".format(line = line))
|
outputfile.write("{line}\n".format(line = line))
|
||||||
else:
|
else:
|
||||||
|
# Skip filters containing less than three characters
|
||||||
|
if len(line) < 3:
|
||||||
|
continue
|
||||||
# Neaten up filters and, if necessary, check their type for the sorting algorithm
|
# Neaten up filters and, if necessary, check their type for the sorting algorithm
|
||||||
elementparts = re.match(ELEMENTPATTERN, line)
|
elementparts = re.match(ELEMENTPATTERN, line)
|
||||||
if elementparts:
|
if elementparts:
|
||||||
|
@ -271,7 +275,7 @@ def filtertidy (filterin):
|
||||||
optionlist = sorted(set(filter(lambda option: option not in removeentries, optionlist)), key = lambda option: (option[1:] + "~") if option[0] == "~" else option)
|
optionlist = sorted(set(filter(lambda option: option not in removeentries, optionlist)), key = lambda option: (option[1:] + "~") if option[0] == "~" else option)
|
||||||
# If applicable, sort domain restrictions and append them to the list of options
|
# If applicable, sort domain restrictions and append them to the list of options
|
||||||
if domainlist:
|
if domainlist:
|
||||||
optionlist.append("domain={domainlist}".format(domainlist = "|".join(sorted(set(domainlist), key = lambda domain: domain.strip("~")))))
|
optionlist.append("domain={domainlist}".format(domainlist = "|".join(sorted(set(filter(lambda domain: domain != "", domainlist)), key = lambda domain: domain.strip("~")))))
|
||||||
|
|
||||||
# Return the full filter
|
# Return the full filter
|
||||||
return "{filtertext}${options}".format(filtertext = filtertext, options = ",".join(optionlist))
|
return "{filtertext}${options}".format(filtertext = filtertext, options = ",".join(optionlist))
|
||||||
|
@ -379,10 +383,10 @@ def isglobalelement (domains):
|
||||||
def removeunnecessarywildcards (filtertext):
|
def removeunnecessarywildcards (filtertext):
|
||||||
""" Where possible, remove unnecessary wildcards from the beginnings
|
""" Where possible, remove unnecessary wildcards from the beginnings
|
||||||
and ends of blocking filters."""
|
and ends of blocking filters."""
|
||||||
whitelist = False
|
allowlist = False
|
||||||
hadStar = False
|
hadStar = False
|
||||||
if filtertext[0:2] == "@@":
|
if filtertext[0:2] == "@@":
|
||||||
whitelist = True
|
allowlist = True
|
||||||
filtertext = filtertext[2:]
|
filtertext = filtertext[2:]
|
||||||
while len(filtertext) > 1 and filtertext[0] == "*" and not filtertext[1] == "|" and not filtertext[1] == "!":
|
while len(filtertext) > 1 and filtertext[0] == "*" and not filtertext[1] == "|" and not filtertext[1] == "!":
|
||||||
filtertext = filtertext[1:]
|
filtertext = filtertext[1:]
|
||||||
|
@ -394,7 +398,7 @@ def removeunnecessarywildcards (filtertext):
|
||||||
filtertext = "{filtertext}*".format(filtertext = filtertext)
|
filtertext = "{filtertext}*".format(filtertext = filtertext)
|
||||||
if filtertext == "*":
|
if filtertext == "*":
|
||||||
filtertext = ""
|
filtertext = ""
|
||||||
if whitelist:
|
if allowlist:
|
||||||
filtertext = "@@{filtertext}".format(filtertext = filtertext)
|
filtertext = "@@{filtertext}".format(filtertext = filtertext)
|
||||||
return filtertext
|
return filtertext
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue