detect_format no...
Content-type: text/plain

Author: johnnyg

Revision: 5727

Log:
        Added is_valid method to readers.
detect_format now takes in optional compression type.

Diff:
Modified: trunk/deluge/plugins/blocklist/blocklist/core.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/core.py    2009-09-10 14:26:14 UTC 
(rev 5726)
+++ trunk/deluge/plugins/blocklist/blocklist/core.py    2009-09-12 14:25:38 UTC 
(rev 5727)
@@ -344,7 +344,7 @@
         :raises UnknownFormatError: if the format cannot be detected
         """
         self.config["list_compression"] = detect_compression(blocklist)
-        self.config["list_type"] = detect_format(blocklist)
+        self.config["list_type"] = detect_format(blocklist, 
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-09-10 14:26:14 UTC 
(rev 5726)
+++ trunk/deluge/plugins/blocklist/blocklist/detect.py  2009-09-12 14:25:38 UTC 
(rev 5727)
@@ -48,6 +48,6 @@
     f.close()
     return COMPRESSION_TYPES.get(magic_number, "")
 
-def detect_format(filename):
+def detect_format(filename, compression=""):
     # TODO: implement this function
     return ""

Modified: trunk/deluge/plugins/blocklist/blocklist/readers.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-09-10 14:26:14 UTC 
(rev 5726)
+++ trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-09-12 14:25:38 UTC 
(rev 5727)
@@ -60,6 +60,21 @@
         """Ignore commented lines and blank lines"""
         return line.startswith('#') or not line.strip()
 
+    def is_valid(self, file):
+        """Determines whether file is valid for this reader"""
+        blocklist = self.open()
+        valid = True
+        for line in blocklist:
+            if not self.is_ignored(line):
+                try:
+                    (start, end) = self.parse(line)
+                except:
+                    valid = False
+                finally:
+                    break
+        blocklist.close()
+        return valid
+
     def readranges(self):
         """Yields each ip range from the file"""
         blocklist = self.open()



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