Blocklist reader's read() now calls callback with two arguments: start and end.

This will allow us to better detect when a blocklist reader fails to parse an entry.
Renamed is_valid to is_ignored to make the purpose of the function less ambigious.
This commit is contained in:
John Garland 2009-07-20 04:49:55 +00:00
parent 8fbe456410
commit e1ee5c3436
2 changed files with 11 additions and 11 deletions

View File

@ -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):

View File

@ -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()