Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions abp_blocklist_parser/BlockListParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __init__(self, regex_file=None, regexes=None, shortcut_sizes=None,
all_shortcut_url_maps)
self.remaining_regex = self._convert_to_regex(remaining_lines)

def __repr__(self):
return f"BlockListParser with {len(self.regex_lines)} entries"

def get_num_classes(self):
# always supports only binary classification, blocked or not blocked
return 2
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file only contains development requirements the final library is freestanding
pytest
requests
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name='abp-blocklist-parser',
license='GPL v3',
url='https://github.com/englehardt/abp-blocklist-parser',
version='0.2',
version='0.3',
packages=['abp_blocklist_parser'],

# Dependencies
Expand Down
33 changes: 33 additions & 0 deletions test/test_blp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from abp_blocklist_parser.BlockListParser import BlockListParser
import requests
import pytest



@pytest.fixture(scope="module")
def block_list_parser():
# Download blocklists
raw_lists = {
'nocoin': 'https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/nocoin.txt',
'ublock-resource-abuse': 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt'
}
# Initialize parsers
blockers = [
BlockListParser(regexes=requests.get(raw_lists["nocoin"]).content.decode()),
BlockListParser(regexes=requests.get(raw_lists["ublock-resource-abuse"]).content.decode())
]
return blockers[0]


def test_should_block(block_list_parser: BlockListParser) -> None:
should_block_my_domain = block_list_parser.should_block("https://zabka.it")
assert not should_block_my_domain

def test_should_block_and_print(block_list_parser: BlockListParser)-> None:
should_block_my_domain = block_list_parser.should_block_and_print("https://zabka.it")
assert not should_block_my_domain

def test_should_block_with_items(block_list_parser: BlockListParser)-> None:
should_block_my_domain = block_list_parser.should_block_with_items("https://zabka.it")
assert not should_block_my_domain