Author: johnnyg
Revision: 5499
Log:
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.
Diff:
Modified: trunk/deluge/plugins/blocklist/blocklist/core.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/core.py 2009-07-20 00:46:57 UTC
(rev 5498)
+++ trunk/deluge/plugins/blocklist/blocklist/core.py 2009-07-20 04:49:55 UTC
(rev 5499)
@@ -86,10 +86,8 @@
"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 @@
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):
Modified: trunk/deluge/plugins/blocklist/blocklist/readers.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-07-20 00:46:57 UTC
(rev 5498)
+++ trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-07-20 04:49:55 UTC
(rev 5499)
@@ -53,17 +53,18 @@
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()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---