diff options
Diffstat (limited to 'qutebrowser/browser/adblock.py')
-rw-r--r-- | qutebrowser/browser/adblock.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/qutebrowser/browser/adblock.py b/qutebrowser/browser/adblock.py index e38b44d5f..862ec18fa 100644 --- a/qutebrowser/browser/adblock.py +++ b/qutebrowser/browser/adblock.py @@ -173,15 +173,12 @@ class HostBlocker: for url in config.val.content.host_blocking.lists: if url.scheme() == 'file': filename = url.toLocalFile() - try: - fileobj = open(filename, 'rb') - except OSError as e: - message.error("adblock: Error while reading {}: {}".format( - filename, e.strerror)) - continue - download = _FakeDownload(fileobj) - self._in_progress.append(download) - self._on_download_finished(download) + if os.path.isdir(filename): + for filenames in os.scandir(filename): + if filenames.is_file(): + self._import_local(filenames.path) + else: + self._import_local(filename) else: fobj = io.BytesIO() fobj.name = 'adblock: ' + url.host() @@ -192,6 +189,22 @@ class HostBlocker: download.finished.connect( functools.partial(self._on_download_finished, download)) + def _import_local(self, filename): + """Adds the contents of a file to the blocklist. + + Args: + filename: path to a local file to import. + """ + try: + fileobj = open(filename, 'rb') + except OSError as e: + message.error("adblock: Error while reading {}: {}".format( + filename, e.strerror)) + return + download = _FakeDownload(fileobj) + self._in_progress.append(download) + self._on_download_finished(download) + def _parse_line(self, line): """Parse a line from a host file. |