Beispiel #1
0
def readZip(f, **kwargs):
	from mien.parsers.nmpml import elements as dialect
	f=ZipFile(f, 'r')
	xml=f.read('xml')
	xml=StringIO(xml)
	doc=xm.readTree(xml)
	xml.close()
	doc=xm.assignClasses(doc, dialect)	
	try:
		dat=f.read('data')
	except:
		print "No data archive in zip file"
		return doc
	from mien.parsers.datahash import readMD	
	dat=StringIO(dat)
	dat=readMD(dat, return_raw_hash=True)
	des=doc.getElements('Data')
	for de in des:
		try:
			d, h=dat[de.upath()]
		except:
			print "can't find data for element %s" % (de.upath(),)
			d, h=(zeros(0), {})
		de.datinit(d, h)
	f.close()	
	return doc		
Beispiel #2
0
	def readStore(self, fn):
		base=os.path.splitext(fn)[0]
		n=base+'.mdat'
		if not os.path.isfile(n):
			print "No data store for %s" % base
			return
		self.store=readMD(file(n, 'rb'), return_raw_hash=True)
		print "connected data store %s" % n
Beispiel #3
0
def deserialize(f, **kwargs):
	#st=time.time()
	if not type(f) in [str, unicode]:
		f=f.read()
	l=struct.unpack('<I', f[:4])[0]
	doc=zlib.decompress(f[4:l+4])
	doc=StringIO(doc)
	doc=xm.readTree(doc)
	from mien.parsers.nmpml import elements as dialect
	doc=xm.assignClasses(doc, dialect)	
	f=f[l+4:]
	try:
		if f:
			from mien.parsers.datahash import readMD	
			try:
				f2=StringIO(f)
				f=readMD(f2, return_raw_hash=True)
			except:
				f=zlib.decompress(f)		
				f2=StringIO(f)
				f=readMD(f2, return_raw_hash=True)
			del(f2)
			des=doc.getElements('Data')
			for de in des:
				try:
					d, h=f[de.upath()]
				except:
					print "can't find data for element %s" % (de.upath(),)
					d, h=(zeros(0), {})
				de.datinit(d, h)
	except:
		print "cant load data"
					
	#print time.time()-st;st=time.time()

	return doc