Author: johnnyg

Revision: 5926

Log:
        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.

Diff:
Modified: branches/1.2_RC/ChangeLog
===================================================================
--- branches/1.2_RC/ChangeLog   2009-11-08 17:22:57 UTC (rev 5925)
+++ branches/1.2_RC/ChangeLog   2009-11-09 01:52:58 UTC (rev 5926)
@@ -18,6 +18,9 @@
        * Allow commands that are .pyc files to be used
        * Fix printing info, help, etc.. on the command line
 
+==== Blocklist ====
+       * Force blocklist to auto-detect format when a download / import is 
forced
+
 === Deluge 1.2.0_rc3 (01 November 2009) ===
 ==== Core ====
        * Fix #1047 move completed does not work if saving to non default path

Modified: branches/1.2_RC/deluge/plugins/blocklist/blocklist/common.py
===================================================================
--- branches/1.2_RC/deluge/plugins/blocklist/blocklist/common.py        
2009-11-08 17:22:57 UTC (rev 5925)
+++ branches/1.2_RC/deluge/plugins/blocklist/blocklist/common.py        
2009-11-09 01:52:58 UTC (rev 5926)
@@ -49,3 +49,18 @@
                 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(".")])

Modified: branches/1.2_RC/deluge/plugins/blocklist/blocklist/core.py
===================================================================
--- branches/1.2_RC/deluge/plugins/blocklist/blocklist/core.py  2009-11-08 
17:22:57 UTC (rev 5925)
+++ branches/1.2_RC/deluge/plugins/blocklist/blocklist/core.py  2009-11-09 
01:52:58 UTC (rev 5926)
@@ -128,6 +128,8 @@
         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 @@
         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 @@
             # 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 @@
             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 @@
         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 @@
         """
         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

Modified: branches/1.2_RC/deluge/plugins/blocklist/blocklist/detect.py
===================================================================
--- branches/1.2_RC/deluge/plugins/blocklist/blocklist/detect.py        
2009-11-08 17:22:57 UTC (rev 5925)
+++ branches/1.2_RC/deluge/plugins/blocklist/blocklist/detect.py        
2009-11-09 01:52:58 UTC (rev 5926)
@@ -77,5 +77,4 @@
         decompressor = DECOMPRESSERS.get(compression)
         if decompressor:
             reader = decompressor(reader)
-            
     return reader

Modified: branches/1.2_RC/deluge/plugins/blocklist/blocklist/readers.py
===================================================================
--- branches/1.2_RC/deluge/plugins/blocklist/blocklist/readers.py       
2009-11-08 17:22:57 UTC (rev 5925)
+++ branches/1.2_RC/deluge/plugins/blocklist/blocklist/readers.py       
2009-11-09 01:52:58 UTC (rev 5926)
@@ -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
 

Modified: trunk/deluge/plugins/blocklist/blocklist/common.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/common.py  2009-11-08 17:22:57 UTC 
(rev 5925)
+++ trunk/deluge/plugins/blocklist/blocklist/common.py  2009-11-09 01:52:58 UTC 
(rev 5926)
@@ -49,3 +49,18 @@
                 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(".")])

Modified: trunk/deluge/plugins/blocklist/blocklist/core.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/core.py    2009-11-08 17:22:57 UTC 
(rev 5925)
+++ trunk/deluge/plugins/blocklist/blocklist/core.py    2009-11-09 01:52:58 UTC 
(rev 5926)
@@ -128,6 +128,8 @@
         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 @@
         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 @@
             # 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 @@
             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 @@
         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 @@
         """
         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

Modified: trunk/deluge/plugins/blocklist/blocklist/detect.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/detect.py  2009-11-08 17:22:57 UTC 
(rev 5925)
+++ trunk/deluge/plugins/blocklist/blocklist/detect.py  2009-11-09 01:52:58 UTC 
(rev 5926)
@@ -77,5 +77,4 @@
         decompressor = DECOMPRESSERS.get(compression)
         if decompressor:
             reader = decompressor(reader)
-            
     return reader

Modified: trunk/deluge/plugins/blocklist/blocklist/readers.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-11-08 17:22:57 UTC 
(rev 5925)
+++ trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-11-09 01:52:58 UTC 
(rev 5926)
@@ -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
 



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

Reply via email to