import PySablot

FP='file://'

class Sablot:

	def __init__(self):
		self.handle = PySablot.CreateProcessor()

	def __del__(self):
		PySablot.DestroyProcessor(self.handle)


	def File2File(self,xsl,xml,out):

		xsl = 'file://' + xsl
		xml = 'file://' + xml
		out = 'file://' + out

		PySablot.RunProcessor(self.handle,xsl,xml,out)


	def String2String(self,xsl,xml):
		import tempfile,os

		f_xsl = tempfile.mktemp()
		f_xml = tempfile.mktemp()
		f_out = tempfile.mktemp()

		open(f_xsl,'w').write(xsl)
		open(f_xml,'w').write(xml)

		PySablot.RunProcessor(self.handle,FP+f_xsl,FP+f_xml,FP+f_out)
		res = open(f_out , 'r').read()
		
		os.unlink(f_xsl)
		os.unlink(f_xml)
		os.unlink(f_out)
	
		return res


if __name__=='__main__':

	P = Sablot()
#	P.File2File('/tmp/test.xsl','/tmp/test.xml','out.sux')
	print P.String2String(open('test.xsl','r').read(),open('test.xml','r').read())

