mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-26 18:10:43 +00:00
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:
parent
8fbe456410
commit
e1ee5c3436
@ -86,10 +86,8 @@ READERS = {
|
|||||||
"PeerGuardian" : PeerGuardianReader
|
"PeerGuardian" : PeerGuardianReader
|
||||||
}
|
}
|
||||||
|
|
||||||
# Libtorrent IP filter constants
|
# Constants
|
||||||
START = 0
|
BLOCK_RANGE = 1
|
||||||
END = 1
|
|
||||||
BLOCK = 1
|
|
||||||
|
|
||||||
class Core(CorePluginBase):
|
class Core(CorePluginBase):
|
||||||
def enable(self):
|
def enable(self):
|
||||||
@ -262,8 +260,9 @@ class Core(CorePluginBase):
|
|||||||
|
|
||||||
def import_list(self, force=False):
|
def import_list(self, force=False):
|
||||||
"""Imports the downloaded blocklist into the session"""
|
"""Imports the downloaded blocklist into the session"""
|
||||||
def on_read_ip_range(ip_range):
|
def on_read_ip_range(start, end):
|
||||||
self.blocklist.add_rule(ip_range[START], ip_range[END], BLOCK)
|
"""Add ip range to blocklist"""
|
||||||
|
self.blocklist.add_rule(start, end, BLOCK_RANGE)
|
||||||
self.num_blocked += 1
|
self.num_blocked += 1
|
||||||
|
|
||||||
def on_finish_read(result):
|
def on_finish_read(result):
|
||||||
|
@ -53,17 +53,18 @@ class BaseReader(object):
|
|||||||
|
|
||||||
def read(self, callback):
|
def read(self, callback):
|
||||||
"""Calls callback on each ip range in the file"""
|
"""Calls callback on each ip range in the file"""
|
||||||
for ip_range in self.readranges():
|
for start, end in self.readranges():
|
||||||
callback(ip_range)
|
callback(start, end)
|
||||||
|
|
||||||
def is_valid(self, line):
|
def is_ignored(self, line):
|
||||||
return not line.startswith('#') and line.strip() != ""
|
"""Ignore commented lines and blank lines"""
|
||||||
|
return line.startswith('#') or not line.strip()
|
||||||
|
|
||||||
def readranges(self):
|
def readranges(self):
|
||||||
"""Yields each ip range from the file"""
|
"""Yields each ip range from the file"""
|
||||||
blocklist = self.open()
|
blocklist = self.open()
|
||||||
for line in blocklist:
|
for line in blocklist:
|
||||||
if self.is_valid(line):
|
if not self.is_ignored(line):
|
||||||
yield self.parse(line)
|
yield self.parse(line)
|
||||||
blocklist.close()
|
blocklist.close()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user