mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-03 15:08:40 +00:00
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:
parent
e73052df1c
commit
41353c9ae4
4 changed files with 24 additions and 29 deletions
|
@ -49,3 +49,18 @@ def raiseError(error):
|
||||||
raise error
|
raise error
|
||||||
return new
|
return new
|
||||||
return safer
|
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(".")])
|
||||||
|
|
|
@ -128,6 +128,8 @@ class Core(CorePluginBase):
|
||||||
self.use_cache = False
|
self.use_cache = False
|
||||||
self.failed_attempts = 0
|
self.failed_attempts = 0
|
||||||
self.auto_detected = False
|
self.auto_detected = False
|
||||||
|
if force:
|
||||||
|
self.reader = None
|
||||||
|
|
||||||
# Start callback chain
|
# Start callback chain
|
||||||
d = self.download_list()
|
d = self.download_list()
|
||||||
|
@ -218,8 +220,8 @@ class Core(CorePluginBase):
|
||||||
if self.config["last_update"] and not self.force_download:
|
if self.config["last_update"] and not self.force_download:
|
||||||
headers['If-Modified-Since'] = self.config["last_update"]
|
headers['If-Modified-Since'] = self.config["last_update"]
|
||||||
|
|
||||||
log.debug("Attempting to download blocklist %s" % url)
|
log.debug("Attempting to download blocklist %s", url)
|
||||||
log.debug("Sending headers: %s" % headers)
|
log.debug("Sending headers: %s", headers)
|
||||||
self.up_to_date = False
|
self.up_to_date = False
|
||||||
self.is_downloading = True
|
self.is_downloading = True
|
||||||
return download_file(url, deluge.configmanager.get_config_dir("blocklist.download"), on_retrieve_data, headers)
|
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
|
# Handle redirect errors
|
||||||
location = error_msg.split(" to ")[1]
|
location = error_msg.split(" to ")[1]
|
||||||
if "Moved Permanently" in error_msg:
|
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
|
self.config["url"] = location
|
||||||
f.trap(f.type)
|
f.trap(f.type)
|
||||||
d = self.download_list(url=location)
|
d = self.download_list(url=location)
|
||||||
|
@ -327,7 +329,7 @@ class Core(CorePluginBase):
|
||||||
elif os.path.exists(blocklist) and not self.use_cache:
|
elif os.path.exists(blocklist) and not self.use_cache:
|
||||||
# If we have a backup and we haven't already used it
|
# If we have a backup and we haven't already used it
|
||||||
e = f.trap(Exception)
|
e = f.trap(Exception)
|
||||||
log.warning("Error reading blocklist: ", e)
|
log.warning("Error reading blocklist: %s", e)
|
||||||
self.use_cache = True
|
self.use_cache = True
|
||||||
try_again = True
|
try_again = True
|
||||||
|
|
||||||
|
|
|
@ -77,5 +77,4 @@ def create_reader(format, compression=""):
|
||||||
decompressor = DECOMPRESSERS.get(compression)
|
decompressor = DECOMPRESSERS.get(compression)
|
||||||
if decompressor:
|
if decompressor:
|
||||||
reader = decompressor(reader)
|
reader = decompressor(reader)
|
||||||
|
|
||||||
return reader
|
return reader
|
||||||
|
|
|
@ -33,28 +33,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from common import raiseError, remove_zeros
|
||||||
from common import raiseError
|
|
||||||
|
|
||||||
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):
|
class ReaderParseError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue