]> code.delx.au - pymsnt/blobdiff - src/xdb.py
Fixed jid.internJID that somehow slipped through
[pymsnt] / src / xdb.py
index 1e3e33e64c91a3a93f3a454a52a75809a998b674..a3e3b5d0adefd90dc431064394f97d731d0ff6f5 100644 (file)
@@ -1,11 +1,12 @@
-# Copyright 2004-2005 James Bunton <james@delx.cjb.net>
+# Copyright 2004-2006 James Bunton <james@delx.cjb.net>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
-from tlib import xmlw
+from twisted.words.xish.domish import parseFile, Element
 from debug import LogEvent, INFO, WARN
 import os
 import os.path
 import shutil
+import md5
 import config
 
 X = os.path.sep
@@ -18,8 +19,11 @@ def unmangle(file):
        file = "%s@%s" % ("%".join(chunks), end)
        return file
 
-def mangle(jid):
-       return jid.replace("@", "%")
+def mangle(file):
+       return file.replace("@", "%")
+
+def makeHash(file):
+       return md5.md5(file).hexdigest()[0:3]
 
 
 class XDB:
@@ -40,8 +44,8 @@ class XDB:
                if(self.mangle):
                        file = mangle(file)
                
-               hash = file[0:2]
-               document = xmlw.parseFile(self.name + X + hash + X + file + ".xml")
+               hash = makeHash(file)
+               document = parseFile(self.name + X + hash + X + file + ".xml")
                
                return document
        
@@ -50,7 +54,7 @@ class XDB:
                        file = mangle(file)
                
                prev_umask = os.umask(SPOOL_UMASK)
-               hash = file[0:2]
+               hash = makeHash(file)
                pre = self.name + X + hash + X
                if not os.path.exists(pre):
                        os.makedirs(pre)
@@ -100,7 +104,7 @@ class XDB:
                        except IOError:
                                pass
                        if(not document):
-                               document = xmlw.Element((None, "xdb"))
+                               document = Element((None, "xdb"))
                        
                        # Remove the existing node (if any)
                        for child in document.elements():
@@ -116,9 +120,10 @@ class XDB:
        
        def remove(self, file):
                """ Removes an XDB file """
-               file = self.name + X + file[0:2] + X + file + ".xml"
-               if(self.mangle):
+               if self.mangle:
                        file = mangle(file)
+               hash = makeHash(file)
+               file = self.name + X + hash + X + file + ".xml"
                try:
                        os.remove(file)
                except IOError, e: