diff --git a/deluge/plugins/blocklist/blocklist/core.py b/deluge/plugins/blocklist/blocklist/core.py index a5166f3a7..31b603100 100644 --- a/deluge/plugins/blocklist/blocklist/core.py +++ b/deluge/plugins/blocklist/blocklist/core.py @@ -86,10 +86,8 @@ READERS = { "PeerGuardian" : PeerGuardianReader } -# Libtorrent IP filter constants -START = 0 -END = 1 -BLOCK = 1 +# Constants +BLOCK_RANGE = 1 class Core(CorePluginBase): def enable(self): @@ -262,8 +260,9 @@ class Core(CorePluginBase): def import_list(self, force=False): """Imports the downloaded blocklist into the session""" - def on_read_ip_range(ip_range): - self.blocklist.add_rule(ip_range[START], ip_range[END], BLOCK) + def on_read_ip_range(start, end): + """Add ip range to blocklist""" + self.blocklist.add_rule(start, end, BLOCK_RANGE) self.num_blocked += 1 def on_finish_read(result): diff --git a/deluge/plugins/blocklist/blocklist/readers.py b/deluge/plugins/blocklist/blocklist/readers.py index 8a51008fc..7624a3539 100644 --- a/deluge/plugins/blocklist/blocklist/readers.py +++ b/deluge/plugins/blocklist/blocklist/readers.py @@ -53,17 +53,18 @@ class BaseReader(object): def read(self, callback): """Calls callback on each ip range in the file""" - for ip_range in self.readranges(): - callback(ip_range) + for start, end in self.readranges(): + callback(start, end) - def is_valid(self, line): - return not line.startswith('#') and line.strip() != "" + def is_ignored(self, line): + """Ignore commented lines and blank lines""" + return line.startswith('#') or not line.strip() def readranges(self): """Yields each ip range from the file""" blocklist = self.open() for line in blocklist: - if self.is_valid(line): + if not self.is_ignored(line): yield self.parse(line) blocklist.close()