diff --git a/deluge/plugins/blocklist/blocklist/common.py b/deluge/plugins/blocklist/blocklist/common.py index a8d6d93b9..d1181ddf5 100644 --- a/deluge/plugins/blocklist/blocklist/common.py +++ b/deluge/plugins/blocklist/blocklist/common.py @@ -49,3 +49,18 @@ def raiseError(error): raise error return new return safer + +def remove_zeros(ip): + """ + Removes unneeded zeros from ip addresses. + + Example: 000.000.000.003 -> 0.0.0.3 + + :param ip: the ip address + :type ip: string + + :returns: the ip address without the unneeded zeros + :rtype: string + + """ + return ".".join([part.lstrip("0").zfill(1) for part in ip.split(".")]) diff --git a/deluge/plugins/blocklist/blocklist/core.py b/deluge/plugins/blocklist/blocklist/core.py index c734ca0fc..0d772a2ad 100644 --- a/deluge/plugins/blocklist/blocklist/core.py +++ b/deluge/plugins/blocklist/blocklist/core.py @@ -128,6 +128,8 @@ class Core(CorePluginBase): self.use_cache = False self.failed_attempts = 0 self.auto_detected = False + if force: + self.reader = None # Start callback chain d = self.download_list() @@ -218,8 +220,8 @@ class Core(CorePluginBase): if self.config["last_update"] and not self.force_download: headers['If-Modified-Since'] = self.config["last_update"] - log.debug("Attempting to download blocklist %s" % url) - log.debug("Sending headers: %s" % headers) + log.debug("Attempting to download blocklist %s", url) + log.debug("Sending headers: %s", headers) self.up_to_date = False self.is_downloading = True return download_file(url, deluge.configmanager.get_config_dir("blocklist.download"), on_retrieve_data, headers) @@ -239,7 +241,7 @@ class Core(CorePluginBase): # Handle redirect errors location = error_msg.split(" to ")[1] if "Moved Permanently" in error_msg: - log.debug("Setting blocklist url to %s" % location) + log.debug("Setting blocklist url to %s", location) self.config["url"] = location f.trap(f.type) d = self.download_list(url=location) @@ -291,7 +293,7 @@ class Core(CorePluginBase): self.auto_detect(blocklist) self.auto_detected = True - log.debug("Importing using reader: %s",self.reader) + log.debug("Importing using reader: %s", self.reader) log.debug("Reader type: %s compression: %s", self.config["list_type"], self.config["list_compression"]) d = threads.deferToThread(self.reader(blocklist).read, on_read_ip_range) d.addCallback(on_finish_read) @@ -327,7 +329,7 @@ class Core(CorePluginBase): elif os.path.exists(blocklist) and not self.use_cache: # If we have a backup and we haven't already used it e = f.trap(Exception) - log.warning("Error reading blocklist: ", e) + log.warning("Error reading blocklist: %s", e) self.use_cache = True try_again = True @@ -347,7 +349,7 @@ class Core(CorePluginBase): """ self.config["list_compression"] = detect_compression(blocklist) self.config["list_type"] = detect_format(blocklist, self.config["list_compression"]) - log.debug("Auto-detected type: %s compression: %s", self.config["list_type"], self.config["list_compression"]) + log.debug("Auto-detected type: %s compression: %s", self.config["list_type"], self.config["list_compression"]) if not self.config["list_type"]: self.config["list_compression"] = "" raise UnknownFormatError diff --git a/deluge/plugins/blocklist/blocklist/detect.py b/deluge/plugins/blocklist/blocklist/detect.py index af1450424..f429e1e9f 100644 --- a/deluge/plugins/blocklist/blocklist/detect.py +++ b/deluge/plugins/blocklist/blocklist/detect.py @@ -77,5 +77,4 @@ def create_reader(format, compression=""): decompressor = DECOMPRESSERS.get(compression) if decompressor: reader = decompressor(reader) - return reader diff --git a/deluge/plugins/blocklist/blocklist/readers.py b/deluge/plugins/blocklist/blocklist/readers.py index ddfea004c..89ebd1559 100644 --- a/deluge/plugins/blocklist/blocklist/readers.py +++ b/deluge/plugins/blocklist/blocklist/readers.py @@ -33,29 +33,8 @@ # # -from deluge.log import LOG as log -from common import raiseError +from common import raiseError, remove_zeros -def remove_zeros(ip): - """ - Removes unneeded zeros from ip addresses. - - Example: 000.000.000.003 -> 0.0.0.3 - - :param ip: the ip address - :type ip: string - - :returns: the ip address without the unneeded zeros - :rtype: string - - """ - new_ip = [] - for part in ip.split("."): - while part[0] == "0" and len(part) > 1: - part = part[1:] - new_ip.append(part) - return ".".join(new_ip) - class ReaderParseError(Exception): pass