<s> from __future__ import division <EOL> from xml . parsers . expat import ExpatError <EOL> import xml . dom . minidom <EOL> from vistrails . db import VistrailsDBException <EOL> from vistrails . db . versions . v0_3_0 import version as my_version <EOL> def parse_xml_file ( filename ) : <EOL> try : <EOL> return xml . dom . minidom . parse ( filename ) <EOL> except xml . parsers . expat . ExpatError , e : <EOL> msg = '<STR_LIT>' % ( e . lineno , e . offset , e . code ) <EOL> raise VistrailsDBException ( msg ) <EOL> def write_xml_file ( filename , dom , prettyprint = True ) : <EOL> output = open ( filename , '<STR_LIT:w>' ) <EOL> if prettyprint : <EOL> dom . writexml ( output , '<STR_LIT>' , '<STR_LIT:U+0020>' , '<STR_LIT:\n>' ) <EOL> else : <EOL> dom . writexml ( output ) <EOL> output . close ( ) <EOL> def read_xml_object ( vtType , node , dao_list ) : <EOL> return dao_list [ vtType ] . fromXML ( node ) <EOL> def write_xml_object ( obj , dom , dao_list , node = None ) : <EOL> res_node = dao_list [ obj . vtType ] . toXML ( obj , dom , node ) <EOL> return res_node <EOL> def open_from_xml ( filename , vtType , dao_list ) : <EOL> """<STR_LIT>""" <EOL> dom = parse_xml_file ( filename ) <EOL> vistrail = read_xml_object ( vtType , dom . documentElement , dao_list ) <EOL> dom . unlink ( ) <EOL> return vistrail <EOL> def save_to_xml ( obj , filename , dao_list ) : <EOL> dom = xml . dom . minidom . getDOMImplementation ( ) . createDocument ( None , None , <EOL> None ) <EOL> root = write_xml_object ( obj , dom , dao_list ) <EOL> dom . appendChild ( root ) <EOL> if obj . vtType == '<STR_LIT>' : <EOL> root . setAttribute ( '<STR_LIT:version>' , my_version ) <EOL> root . setAttribute ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> root . setAttribute ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> write_xml_file ( filename , dom ) <EOL> dom . unlink ( ) <EOL> def serialize ( object , dao_list ) : <EOL> dom = xml . dom . minidom . getDOMImplementation ( ) . createDocument ( None , None , <EOL> None ) <EOL> root = write_xml_object ( object , dom , dao_list ) <EOL> dom . appendChild ( root ) <EOL> return dom . toxml ( ) <EOL> def unserialize ( str , obj_type ) : <EOL> dom = xml . dom . minidom . parseString ( str ) <EOL> return read_xml_object ( obj_type , dom . documentElement , dao_list ) </s>
