Force blocklist to re-detect the format when a download is forced.

Move remove_zeros to common.py and simplify / speed up.
Change debug logging lines to be more uniform.
This commit is contained in:
John Garland 2009-11-09 01:52:58 +00:00
parent e73052df1c
commit 41353c9ae4
4 changed files with 24 additions and 29 deletions

View file

@ -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(".")])

View file

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

View file

@ -77,5 +77,4 @@ def create_reader(format, compression=""):
decompressor = DECOMPRESSERS.get(compression)
if decompressor:
reader = decompressor(reader)
return reader

View file

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