-# 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
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:
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
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)
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():
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: