Last active
April 23, 2020 16:32
-
-
Save englehardt/05c6be67d88e2450b091c417f92a1125 to your computer and use it in GitHub Desktop.
ABP blocklist parser options parsing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_option_dict(url, top_level_url, content_type=None): | |
"""Build an options dict for BlockListParser. | |
These options are checked here: | |
* https://github.com/englehardt/abp-blocklist-parser/blob/40f6bb5b91ea403b7b9852a16d6c57d5ec26cf7f/abp_blocklist_parser/RegexParser.py#L104-L117 | |
* https://github.com/englehardt/abp-blocklist-parser/blob/40f6bb5b91ea403b7b9852a16d6c57d5ec26cf7f/abp_blocklist_parser/RegexParser.py#L240-L248 | |
Parameters | |
---------- | |
url : string | |
The URL of the requested resource. | |
top_level_url : string | |
The URL of the top-level frame of the requested resource | |
content_type : string | |
WebExtensions resource type: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/ResourceType | |
Returns | |
------- | |
dict | |
An "options" dictionary for use with BlockListParser | |
""" | |
options = {} | |
# Add type option. Value doesn't matter. | |
if content_type: | |
options[content_type] = True | |
options["domain"] = urlparse(top_level_url).hostname | |
# Add third-party option if third party. Value doesn't matter. | |
if du.get_ps_plus_1(url) != du.get_ps_plus_1(top_level_url): | |
options["third-party"] = True | |
return options |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment