From 8d13bdc6cac0e20c43c6f909fc0208774b9c5c84 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 21:47:39 +0200 Subject: Adding upstream version 2020.10.7. Signed-off-by: Daniel Baumann --- scripts/convertpsl.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 scripts/convertpsl.py (limited to 'scripts/convertpsl.py') diff --git a/scripts/convertpsl.py b/scripts/convertpsl.py new file mode 100755 index 0000000..3cd78be --- /dev/null +++ b/scripts/convertpsl.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +# script based on +# https://github.com/adblockplus/buildtools/blob/d090e00610a58cebc78478ae33e896e6b949fc12/publicSuffixListUpdater.py + +from __future__ import print_function + +import json +import sys + +def convert(psl_text): + suffixes = {} + + for line in psl_text: + line = line.rstrip() + if line.startswith('//') or '.' not in line: + continue + if line.startswith('*.'): + suffixes[line[2:]] = 2 + elif line.startswith('!'): + suffixes[line[1:]] = 0 + else: + suffixes[line] = 1 + + return suffixes + + +if __name__ == '__main__': + with open(sys.argv[1], 'r+') as f: + psl = convert(f) + f.seek(0) + text = 'window.publicSuffixes = %s;' % ( + json.dumps(psl, sort_keys=True, indent=2, separators=(',', ': ')) + ) + print(text, file=f) + f.truncate() -- cgit v1.2.3