qutebrowser/qutebrowser/browser/adblock.py

309 lines
10 KiB
Python
Raw Normal View History

Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2018-02-05 12:19:50 +01:00
# Copyright 2014-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
2015-03-31 20:49:29 +02:00
"""Functions related to ad blocking."""
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
import io
import os.path
import functools
import posixpath
import zipfile
import fnmatch
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
from qutebrowser.browser import downloads
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
from qutebrowser.config import config
2016-11-09 14:29:06 +01:00
from qutebrowser.utils import objreg, standarddir, log, message
from qutebrowser.commands import cmdutils
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
def guess_zip_filename(zf):
"""Guess which file to use inside a zip file.
Args:
zf: A ZipFile instance.
"""
files = zf.namelist()
if len(files) == 1:
return files[0]
else:
for e in files:
if posixpath.splitext(e)[0].lower() == 'hosts':
return e
raise FileNotFoundError("No hosts file found in zip")
2014-12-04 21:35:32 +01:00
def get_fileobj(byte_io):
"""Get a usable file object to read the hosts file from."""
byte_io.seek(0) # rewind downloaded file
if zipfile.is_zipfile(byte_io):
byte_io.seek(0) # rewind what zipfile.is_zipfile did
zf = zipfile.ZipFile(byte_io)
filename = guess_zip_filename(zf)
byte_io = zf.open(filename, mode='r')
else:
byte_io.seek(0) # rewind what zipfile.is_zipfile did
return byte_io
def is_whitelisted_host(host):
"""Check if the given host is on the adblock whitelist.
Args:
host: The host of the request as string.
"""
for pattern in config.val.content.host_blocking.whitelist:
if fnmatch.fnmatch(host, pattern.lower()):
return True
return False
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
class FakeDownload:
"""A download stub to use on_download_finished with local files."""
def __init__(self, fileobj):
self.basename = os.path.basename(fileobj.name)
self.fileobj = fileobj
self.successful = True
class HostBlocker:
"""Manage blocked hosts based from /etc/hosts-like files.
Attributes:
_blocked_hosts: A set of blocked hosts.
2016-03-29 06:59:23 +02:00
_config_blocked_hosts: A set of blocked hosts from ~/.config.
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
_in_progress: The DownloadItems which are currently downloading.
_done_count: How many files have been read successfully.
2016-03-29 06:59:23 +02:00
_local_hosts_file: The path to the blocked-hosts file.
_config_hosts_file: The path to a blocked-hosts in ~/.config
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
"""
def __init__(self):
self._blocked_hosts = set()
2016-03-29 06:59:23 +02:00
self._config_blocked_hosts = set()
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
self._in_progress = []
self._done_count = 0
2016-03-29 06:59:23 +02:00
data_dir = standarddir.data()
self._local_hosts_file = os.path.join(data_dir, 'blocked-hosts')
2017-06-14 21:42:36 +02:00
self._update_files()
2016-03-29 06:59:23 +02:00
config_dir = standarddir.config()
self._config_hosts_file = os.path.join(config_dir, 'blocked-hosts')
2016-03-29 06:59:23 +02:00
2017-06-14 21:42:36 +02:00
config.instance.changed.connect(self._update_files)
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
def is_blocked(self, url):
"""Check if the given URL (as QUrl) is blocked."""
2017-06-13 13:54:56 +02:00
if not config.val.content.host_blocking.enabled:
return False
host = url.host()
2016-03-29 06:59:23 +02:00
return ((host in self._blocked_hosts or
host in self._config_blocked_hosts) and
not is_whitelisted_host(host))
def _read_hosts_file(self, filename, target):
"""Read hosts from the given filename.
Args:
filename: The file to read.
target: The set to store the hosts in.
Return:
True if a read was attempted, False otherwise
"""
if not os.path.exists(filename):
2016-03-29 06:59:23 +02:00
return False
try:
with open(filename, 'r', encoding='utf-8') as f:
for line in f:
target.add(line.strip())
except (OSError, UnicodeDecodeError):
2016-03-29 06:59:23 +02:00
log.misc.exception("Failed to read host blocklist!")
return True
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
def read_hosts(self):
"""Read hosts from the existing blocked-hosts file."""
self._blocked_hosts = set()
2016-03-29 06:59:23 +02:00
self._read_hosts_file(self._config_hosts_file,
self._config_blocked_hosts)
found = self._read_hosts_file(self._local_hosts_file,
self._blocked_hosts)
if not found:
args = objreg.get('args')
if (config.val.content.host_blocking.lists and
2017-03-04 17:16:52 +01:00
args.basedir is None and
2017-06-13 13:54:56 +02:00
config.val.content.host_blocking.enabled):
2016-09-14 20:52:32 +02:00
message.info("Run :adblock-update to get adblock lists.")
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
@cmdutils.register(instance='host-blocker')
2016-09-14 20:52:32 +02:00
def adblock_update(self):
2016-03-29 06:59:23 +02:00
"""Update the adblock block lists.
This updates `~/.local/share/qutebrowser/blocked-hosts` with downloaded
host lists and re-reads `~/.config/qutebrowser/blocked-hosts`.
2016-03-29 06:59:23 +02:00
"""
self._read_hosts_file(self._config_hosts_file,
self._config_blocked_hosts)
self._blocked_hosts = set()
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
self._done_count = 0
download_manager = objreg.get('qtnetwork-download-manager')
for url in config.val.content.host_blocking.lists:
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
if url.scheme() == 'file':
filename = url.toLocalFile()
try:
fileobj = open(filename, 'rb')
except OSError as e:
2016-09-14 20:52:32 +02:00
message.error("adblock: Error while reading {}: {}".format(
filename, e.strerror))
continue
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
download = FakeDownload(fileobj)
self._in_progress.append(download)
2016-09-14 20:52:32 +02:00
self.on_download_finished(download)
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
else:
fobj = io.BytesIO()
fobj.name = 'adblock: ' + url.host()
target = downloads.FileObjDownloadTarget(fobj)
download = download_manager.get(url, target=target,
auto_remove=True)
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
self._in_progress.append(download)
download.finished.connect(
2016-09-14 20:52:32 +02:00
functools.partial(self.on_download_finished, download))
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
2017-03-07 21:44:32 +01:00
def _parse_line(self, line):
"""Parse a line from a host file.
Args:
line: The bytes object to parse.
Returns:
True if parsing succeeded, False otherwise.
"""
if line.startswith(b'#'):
# Ignoring comments early so we don't have to care about
# encoding errors in them.
return True
try:
line = line.decode('utf-8')
except UnicodeDecodeError:
log.misc.error("Failed to decode: {!r}".format(line))
return False
# Remove comments
try:
hash_idx = line.index('#')
line = line[:hash_idx]
except ValueError:
pass
line = line.strip()
# Skip empty lines
if not line:
return True
parts = line.split()
if len(parts) == 1:
# "one host per line" format
hosts = [parts[0]]
2017-03-07 21:44:32 +01:00
else:
# /etc/hosts format
hosts = parts[1:]
2017-03-07 21:44:32 +01:00
for host in hosts:
if '.' in host and not host.endswith('.localdomain'):
self._blocked_hosts.add(host)
2017-03-07 21:44:32 +01:00
return True
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
def _merge_file(self, byte_io):
"""Read and merge host files.
Args:
byte_io: The BytesIO object of the completed download.
Return:
A set of the merged hosts.
"""
error_count = 0
line_count = 0
try:
f = get_fileobj(byte_io)
except (OSError, zipfile.BadZipFile, zipfile.LargeZipFile,
LookupError) as e:
2016-09-14 20:52:32 +02:00
message.error("adblock: Error while reading {}: {} - {}".format(
byte_io.name, e.__class__.__name__, e))
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
return
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
for line in f:
line_count += 1
2017-03-07 21:44:32 +01:00
ok = self._parse_line(line)
if not ok:
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
error_count += 1
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
log.misc.debug("{}: read {} lines".format(byte_io.name, line_count))
if error_count > 0:
2016-09-15 13:56:27 +02:00
message.error("adblock: {} read errors for {}".format(
error_count, byte_io.name))
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
2016-09-14 20:52:32 +02:00
def on_lists_downloaded(self):
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
"""Install block lists after files have been downloaded."""
2016-03-29 06:59:23 +02:00
with open(self._local_hosts_file, 'w', encoding='utf-8') as f:
for host in sorted(self._blocked_hosts):
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
f.write(host + '\n')
2016-09-14 20:52:32 +02:00
message.info("adblock: Read {} hosts from {} sources.".format(
len(self._blocked_hosts), self._done_count))
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
2017-06-13 12:22:04 +02:00
@config.change_filter('content.host_blocking.lists')
2017-06-14 21:42:36 +02:00
def _update_files(self):
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
"""Update files when the config changed."""
if not config.val.content.host_blocking.lists:
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
try:
2016-03-29 06:59:23 +02:00
os.remove(self._local_hosts_file)
except FileNotFoundError:
pass
except OSError as e:
log.misc.exception("Failed to delete hosts file: {}".format(e))
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
2016-09-14 20:52:32 +02:00
def on_download_finished(self, download):
Basic host blocker implementation. Squashed commit of the following: commit 8d38e9c2f13778fe21cc2c1d61c5d26907b469ef Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:30 2014 +0100 Fix default adblock lists. commit a734b87e753daec28fa0c6643af8de088041179a Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 21:04:14 2014 +0100 Fix error output on adblock errors. commit 15bc10f605ebb86c12523bb81b55d1440fcacdbf Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:47 2014 +0100 Update adblock docks commit 475d530ee50f52295c2171208c6a0278750cf4b4 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:38:39 2014 +0100 Remove adblock ram calculation commit 0e52cc3ec93912fd3fa3ecf6de833aef0c540a60 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 07:03:11 2014 +0100 Adjust docs for hosts-file. commit 941df242d38300d7e42a26f2e67cfd668c6f8590 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 06:55:40 2014 +0100 Add logging for host blocking. commit 4ca1561ccf32affb8439113f4f1c222d7dee1e14 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 24 00:11:59 2014 +0100 Don't do adblock updates automatically after changing config. commit 26d4e86ca393d4a1a5fd8fac7729ce9c2e7cd240 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:32 2014 +0100 adblock: Don't delete blocked hosts between files. commit c7af08c68adf3c135d5a2fc746eb6d3c715b0711 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:58:22 2014 +0100 adblock: Add comments for rewinding. commit 9af87313088cd79ab8c022bcee9308511d6328f0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:56:39 2014 +0100 adblock: Rewind files properly. commit 7f3dadc04ba68c92d6789ecf5822f7b2dfc367a0 Author: Florian Bruhin <git@the-compiler.org> Date: Thu Nov 20 19:40:18 2014 +0100 Add untested file support. commit 334c01867d510b599d94c9397097a1d789c0c64c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:33:25 2014 +0100 adblock: Handle download errors correctly commit 3a9af4cd4a903386dc323640f1d52e03383b3aa7 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:23:04 2014 +0100 adblock: Add error handling for invalid input. commit 5934c3c027ff9205adb512aab396ca913b31e50d Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 22:22:47 2014 +0100 adblock: Handle done_count correctly. commit 3ba5e83fda9b7d764bfcf1e4b1aa479daae39791 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 21:18:10 2014 +0100 Read adblock files when they finished downloading. commit 86a5ecf194445e2ebe0cf22b59e24223387880c5 Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:25 2014 +0100 Add hosts-file.net to host-block-lists. commit 121f0bff953497449c32e45e671b71d954beed4c Author: Florian Bruhin <git@the-compiler.org> Date: Wed Nov 19 20:51:13 2014 +0100 Add zip-file support to adblock.py. commit f1c0e67cb9d890a44a1d1f545ace997f0a453f91 Author: Florian Bruhin <git@the-compiler.org> Date: Mon Nov 17 07:41:14 2014 +0100 print line counts for debugging commit 75dbb8964fd44862abc378ef26fb47f8cda6061e Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 19:22:20 2014 +0100 Use statusbar messages for adblock commit 74d9142d831496e02c5baae72c2723e320af1778 Author: Florian Bruhin <git@the-compiler.org> Date: Fri Nov 14 08:34:46 2014 +0100 Add basic adblock functionality.
2014-11-24 21:05:09 +01:00
"""Check if all downloads are finished and if so, trigger reading.
Arguments:
download: The finished DownloadItem.
"""
self._in_progress.remove(download)
if download.successful:
self._done_count += 1
try:
self._merge_file(download.fileobj)
finally:
download.fileobj.close()
if not self._in_progress:
try:
2016-09-14 20:52:32 +02:00
self.on_lists_downloaded()
except OSError:
log.misc.exception("Failed to write host block list!")