示例#1
0
def test_blocklist_dl(qtbot, pretend_blocklists):
    total_expected = 10
    num_single_dl_called = 0

    def on_single_download(download: IO[bytes]) -> None:
        nonlocal num_single_dl_called
        num_single_dl_called += 1

        num_lines = 0
        with io.TextIOWrapper(download, encoding="utf-8") as dl_io:
            for line in dl_io:
                assert line.split(".")[-1].strip() in ("com", "net", "is")
                num_lines += 1
        assert num_lines >= 1

    list_qurls = [QUrl(blocklist) for blocklist in pretend_blocklists[0]]

    dl = blockutils.BlocklistDownloads(list_qurls)
    dl.single_download_finished.connect(on_single_download)

    with qtbot.waitSignal(dl.all_downloads_finished) as blocker:
        dl.initiate()
        assert blocker.args == [total_expected]

    assert num_single_dl_called == total_expected
示例#2
0
    def adblock_update(self) -> blockutils.BlocklistDownloads:
        """Update the adblock block lists."""
        self._read_hosts_file(self._config_hosts_file, self._config_blocked_hosts)
        self._blocked_hosts = set()

        blocklists = config.val.content.blocking.hosts.lists
        dl = blockutils.BlocklistDownloads(blocklists)
        dl.single_download_finished.connect(self._merge_file)
        dl.all_downloads_finished.connect(self._on_lists_downloaded)
        dl.initiate()
        return dl
示例#3
0
    def adblock_update(self) -> blockutils.BlocklistDownloads:
        """Update the adblock block lists."""
        logger.info("Downloading adblock filter lists...")

        filter_set = adblock.FilterSet()
        dl = blockutils.BlocklistDownloads(config.val.content.blocking.adblock.lists)
        dl.single_download_finished.connect(
            functools.partial(self._on_download_finished, filter_set=filter_set)
        )
        dl.all_downloads_finished.connect(
            functools.partial(self._on_lists_downloaded, filter_set=filter_set)
        )
        dl.initiate()
        return dl