<s> from __future__ import division <EOL> from datetime import date , datetime <EOL> from vistrails . core . system import strftime , time_strptime <EOL> class XMLDAO : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def hasAttribute ( self , node , attr ) : <EOL> return node . hasAttribute ( attr ) <EOL> def getAttribute ( self , node , attr ) : <EOL> try : <EOL> attribute = node . attributes . get ( attr ) <EOL> if attribute is not None : <EOL> return attribute . value <EOL> except KeyError : <EOL> pass <EOL> return None <EOL> def convertFromStr ( self , value , type ) : <EOL> if value is not None : <EOL> if type == '<STR_LIT:str>' : <EOL> return str ( value ) <EOL> elif value . strip ( ) != '<STR_LIT>' : <EOL> if type == '<STR_LIT>' : <EOL> return long ( value ) <EOL> elif type == '<STR_LIT:float>' : <EOL> return float ( value ) <EOL> elif type == '<STR_LIT:int>' : <EOL> return int ( value ) <EOL> elif type == '<STR_LIT:date>' : <EOL> return date ( * time_strptime ( value , '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:3> ] ) <EOL> elif type == '<STR_LIT>' : <EOL> return datetime ( * time_strptime ( value , <EOL> '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:6> ] ) <EOL> return None <EOL> def convertToStr ( self , value , type ) : <EOL> if value is not None : <EOL> if type == '<STR_LIT:date>' : <EOL> return value . isoformat ( ) <EOL> elif type == '<STR_LIT>' : <EOL> return strftime ( value , '<STR_LIT>' ) <EOL> else : <EOL> return str ( value ) <EOL> return '<STR_LIT>' </s>
