Finished wri...
Content-type: text/plain

Author: johnnyg

Revision: 5728

Log:
        Detect now handles creating a reader.
Finished writing detect_format and hence auto_detect (could it really be?)
is_valid() doesn't need to take in a filename (already has it).

Diff:
Modified: trunk/deluge/plugins/blocklist/blocklist/core.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/core.py    2009-09-12 14:25:38 UTC 
(rev 5727)
+++ trunk/deluge/plugins/blocklist/blocklist/core.py    2009-09-13 13:51:00 UTC 
(rev 5728)
@@ -48,9 +48,7 @@
 import deluge.configmanager
 from deluge.core.rpcserver import export
 from deluge.httpdownloader import download_file
-from decompressers import Zipped, GZipped, BZipped2
-from readers import EmuleReader, SafePeerReader, PeerGuardianReader
-from detect import detect_compression, detect_format, UnknownFormatError
+from detect import detect_compression, detect_format, create_reader, 
UnknownFormatError
 
 # TODO: check return values for deferred callbacks
 # TODO: review class attributes for redundancy
@@ -67,18 +65,6 @@
     "try_times": 3,
 }
 
-DECOMPRESSERS = {
-    "Zip" : Zipped,
-    "GZip" : GZipped,
-    "BZip2" : BZipped2
-}
-
-READERS = {
-    "Emule" : EmuleReader,
-    "SafePeer" : SafePeerReader,
-    "PeerGuardian" : PeerGuardianReader
-}
-
 # Constants
 BLOCK_RANGE = 1
 
@@ -96,9 +82,7 @@
         self.core = component.get("Core")
         self.config = deluge.configmanager.ConfigManager("blocklist.conf", 
DEFAULT_PREFS)
 
-        self.reader = READERS.get(self.config["list_type"])
-        if self.config["list_compression"]:
-            self.reader = 
DECOMPRESSERS.get(self.config["list_compression"])(self.reader)
+        self.reader = create_reader(self.config["list_type"], 
self.config["list_compression"])
 
         update_now = False
         if self.config["load_on_start"]:

Modified: trunk/deluge/plugins/blocklist/blocklist/detect.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/detect.py  2009-09-12 14:25:38 UTC 
(rev 5727)
+++ trunk/deluge/plugins/blocklist/blocklist/detect.py  2009-09-13 13:51:00 UTC 
(rev 5728)
@@ -33,12 +33,27 @@
 #
 #
 
+from decompressers import Zipped, GZipped, BZipped2
+from readers import EmuleReader, SafePeerReader, PeerGuardianReader
+
 COMPRESSION_TYPES = {
     "PK" : "zip",
     "\x1f\x8b" : "gzip",
     "BZ" : "bzip2"
 }
 
+DECOMPRESSERS = {
+    "Zip" : Zipped,
+    "GZip" : GZipped,
+    "BZip2" : BZipped2
+}
+
+READERS = {
+    "Emule" : EmuleReader,
+    "SafePeer" : SafePeerReader,
+    "PeerGuardian" : PeerGuardianReader
+}
+
 class UnknownFormatError(Exception):
     pass
 
@@ -49,5 +64,15 @@
     return COMPRESSION_TYPES.get(magic_number, "")
 
 def detect_format(filename, compression=""):
-    # TODO: implement this function
-    return ""
+    format = ""
+    for reader in READERS:
+        if create_reader(reader, compression)(filename).is_valid():
+            format = reader
+            break
+    return format
+
+def create_reader(format, compression=""):
+    reader = READERS.get(format)
+    if compression:
+        reader = DECOMPRESSERS.get(compression)(reader)
+    return reader

Modified: trunk/deluge/plugins/blocklist/blocklist/readers.py
===================================================================
--- trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-09-12 14:25:38 UTC 
(rev 5727)
+++ trunk/deluge/plugins/blocklist/blocklist/readers.py 2009-09-13 13:51:00 UTC 
(rev 5728)
@@ -60,7 +60,7 @@
         """Ignore commented lines and blank lines"""
         return line.startswith('#') or not line.strip()
 
-    def is_valid(self, file):
+    def is_valid(self):
         """Determines whether file is valid for this reader"""
         blocklist = self.open()
         valid = True



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