def load(self, filename, clobber=1): """Combine this TreeDict with the TreeDict previously save()d to a file. If clobber=1, this tree will be clear()ed before combining (this is the default).""" newprefs = pickle.load(file(filename)) if clobber: self.clear() self.tree_update(newprefs) return self
def xmlLoad(fileName) : import gnosis.xml.pickle as xml_pickle if not os.path.exists(fileName) : raise ValueError, "file does not exist at %s" % fileName file = open(fileName) return xml_pickle.load(file)
def doit(deepcopy=1): f = mk_foo() xml_pickle.setDeepCopy(deepcopy) print("CREATE XML") t1 = time() fh = open('aaa.xml','w') x = xml_pickle.dump(f,fh) fh.close() print("TIME = %f"%(time()-t1)) print("Pickle len = ",os.stat('aaa.xml')[ST_SIZE]) print("minidom pure parse") t1 = time() fh = open('aaa.xml','r') #minidom.parse(fh) fh.close() print("TIME = %f"%(time()-t1)) print("DOM load") t1 = time() fh = open('aaa.xml','r') xml_pickle.setParser("DOM") # default, but just to be sure #o = xml_pickle.load(fh) fh.close() print("TIME = %f"%(time()-t1)) #del o print("SAX load") t1 = time() fh = open('aaa.xml','r') xml_pickle.setParser("SAX") m = xml_pickle.load(fh) fh.close() print("TIME = %f"%(time()-t1)) del m print("cEXPAT load") t1 = time() fh = open('aaa.xml','r') xml_pickle.setParser("cEXPAT") #m = xml_pickle.load(fh) fh.close() print("TIME = %f"%(time()-t1))
def doit(deepcopy=1): f = mk_foo() xml_pickle.setDeepCopy(deepcopy) print "CREATE XML" t1 = time() fh = open('aaa.xml','w') x = xml_pickle.dump(f,fh) fh.close() print "TIME = %f"%(time()-t1) print "Pickle len = ",os.stat('aaa.xml')[ST_SIZE] print "minidom pure parse" t1 = time() fh = open('aaa.xml','r') #minidom.parse(fh) fh.close() print "TIME = %f"%(time()-t1) print "DOM load" t1 = time() fh = open('aaa.xml','r') xml_pickle.setParser("DOM") # default, but just to be sure #o = xml_pickle.load(fh) fh.close() print "TIME = %f"%(time()-t1) #del o print "SAX load" t1 = time() fh = open('aaa.xml','r') xml_pickle.setParser("SAX") m = xml_pickle.load(fh) fh.close() print "TIME = %f"%(time()-t1) del m print "cEXPAT load" t1 = time() fh = open('aaa.xml','r') xml_pickle.setParser("cEXPAT") #m = xml_pickle.load(fh) fh.close() print "TIME = %f"%(time()-t1)
xml_pickle.dump(f,fh) fh.close() # check header + contents fh = open('aaa','rb') line = fh.read(5) if line == '<?xml': print "OK" else: print "ERROR" sys.exit(1) fh.close() fh = open('aaa','rb') g = xml_pickle.load(fh) if g.a == (1,2,3): print "OK" else: print "ERROR" sys.exit(1) fh.close() # method 4 -- StreamWriter is a compressed file fh = open('aaa','wb') xml_pickle.dump(f,fh,1) fh.close() # check header + contents fh = open('aaa','rb') line = fh.read(2)
xml_pickle.dump(f, fh) fh.close() # check header + contents fh = open('aaa', 'rb') line = fh.read(5) if line == '<?xml': print("OK") else: print("ERROR") sys.exit(1) fh.close() fh = open('aaa', 'rb') g = xml_pickle.load(fh) if g.a == (1, 2, 3): print("OK") else: print("ERROR") sys.exit(1) fh.close() # method 4 -- StreamWriter is a compressed file fh = open('aaa', 'wb') xml_pickle.dump(f, fh, 1) fh.close() # check header + contents fh = open('aaa', 'rb') line = fh.read(2)