From 93ec3e3fad0db08dc5464a4f9312626c7519db5a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 18 Sep 2018 20:27:58 +0200 Subject: [PATCH] Make some stuff in adblock.py private --- qutebrowser/browser/adblock.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/qutebrowser/browser/adblock.py b/qutebrowser/browser/adblock.py index 03f0f87a7..e38b44d5f 100644 --- a/qutebrowser/browser/adblock.py +++ b/qutebrowser/browser/adblock.py @@ -31,7 +31,7 @@ from qutebrowser.utils import objreg, standarddir, log, message from qutebrowser.commands import cmdutils -def guess_zip_filename(zf): +def _guess_zip_filename(zf): """Guess which file to use inside a zip file. Args: @@ -53,14 +53,14 @@ def get_fileobj(byte_io): 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) + 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_url(url): +def _is_whitelisted_url(url): """Check if the given URL is on the adblock whitelist. Args: @@ -72,7 +72,7 @@ def is_whitelisted_url(url): return False -class FakeDownload: +class _FakeDownload: """A download stub to use on_download_finished with local files.""" @@ -117,7 +117,7 @@ class HostBlocker: host = url.host() return ((host in self._blocked_hosts or host in self._config_blocked_hosts) and - not is_whitelisted_url(url)) + not _is_whitelisted_url(url)) def _read_hosts_file(self, filename, target): """Read hosts from the given filename. @@ -179,9 +179,9 @@ class HostBlocker: message.error("adblock: Error while reading {}: {}".format( filename, e.strerror)) continue - download = FakeDownload(fileobj) + download = _FakeDownload(fileobj) self._in_progress.append(download) - self.on_download_finished(download) + self._on_download_finished(download) else: fobj = io.BytesIO() fobj.name = 'adblock: ' + url.host() @@ -190,7 +190,7 @@ class HostBlocker: auto_remove=True) self._in_progress.append(download) download.finished.connect( - functools.partial(self.on_download_finished, download)) + functools.partial(self._on_download_finished, download)) def _parse_line(self, line): """Parse a line from a host file. @@ -270,7 +270,7 @@ class HostBlocker: message.error("adblock: {} read errors for {}".format( error_count, byte_io.name)) - def on_lists_downloaded(self): + def _on_lists_downloaded(self): """Install block lists after files have been downloaded.""" with open(self._local_hosts_file, 'w', encoding='utf-8') as f: for host in sorted(self._blocked_hosts): @@ -289,7 +289,7 @@ class HostBlocker: except OSError as e: log.misc.exception("Failed to delete hosts file: {}".format(e)) - def on_download_finished(self, download): + def _on_download_finished(self, download): """Check if all downloads are finished and if so, trigger reading. Arguments: @@ -304,6 +304,6 @@ class HostBlocker: download.fileobj.close() if not self._in_progress: try: - self.on_lists_downloaded() + self._on_lists_downloaded() except OSError: log.misc.exception("Failed to write host block list!")