<s> from __future__ import division <EOL> from xml . auto_gen import XMLDAOListBase <EOL> from sql . auto_gen import SQLDAOListBase <EOL> from vistrails . core . system import get_elementtree_library <EOL> from vistrails . db import VistrailsDBException <EOL> from vistrails . db . versions . v0_9_0 import version as my_version <EOL> ElementTree = get_elementtree_library ( ) <EOL> class DAOList ( dict ) : <EOL> def __init__ ( self ) : <EOL> self [ '<STR_LIT>' ] = XMLDAOListBase ( ) <EOL> self [ '<STR_LIT>' ] = SQLDAOListBase ( ) <EOL> def parse_xml_file ( self , filename ) : <EOL> return ElementTree . parse ( filename ) <EOL> def write_xml_file ( self , filename , tree ) : <EOL> tree . write ( filename ) <EOL> def read_xml_object ( self , vtType , node ) : <EOL> return self [ '<STR_LIT>' ] [ vtType ] . fromXML ( node ) <EOL> def write_xml_object ( self , obj , node = None ) : <EOL> res_node = self [ '<STR_LIT>' ] [ obj . vtType ] . toXML ( obj , node ) <EOL> return res_node <EOL> def open_from_xml ( self , filename , vtType , tree = None ) : <EOL> """<STR_LIT>""" <EOL> if tree is None : <EOL> tree = self . parse_xml_file ( filename ) <EOL> vistrail = self . read_xml_object ( vtType , tree . getroot ( ) ) <EOL> return vistrail <EOL> def save_to_xml ( self , obj , filename , tags ) : <EOL> """<STR_LIT>""" <EOL> root = self . write_xml_object ( obj ) <EOL> root . set ( '<STR_LIT:version>' , my_version ) <EOL> for k , v in tags . iteritems ( ) : <EOL> root . set ( k , v ) <EOL> tree = ElementTree . ElementTree ( root ) <EOL> self . write_xml_file ( filename , tree ) <EOL> def open_from_db ( self , db_connection , vtType , id , lock = False ) : <EOL> pass <EOL> def save_to_db ( self , db_connection , obj , doCopy = False ) : <EOL> pass <EOL> def serialize ( self , object ) : <EOL> root = self . write_xml_object ( object ) <EOL> return ElementTree . tostring ( root ) <EOL> def unserialize ( self , str , obj_type ) : <EOL> try : <EOL> root = ElementTree . fromstring ( str ) <EOL> return self . read_xml_object ( obj_type , root ) <EOL> except SyntaxError , e : <EOL> msg = "<STR_LIT>" % str <EOL> raise VistrailsDBException ( msg ) <EOL> return None </s>
