<s> '''<STR_LIT>''' <EOL> from string import Template <EOL> class Conversion : <EOL> def __init__ ( self , field , default , format_template , typ , evaluate = None ) : <EOL> self . field = field <EOL> self . evaluate = evaluate <EOL> self . type = typ <EOL> self . format_template = Template ( format_template ) <EOL> self . default = default <EOL> def value ( self , node , type_fns ) : <EOL> if not self . field in node . __dict__ : <EOL> return self . default <EOL> value = node . __dict__ [ self . field ] <EOL> if value == None : <EOL> return self . default <EOL> if self . evaluate != None : <EOL> value = eval ( self . evaluate ) <EOL> if value == None : <EOL> return self . default <EOL> value = type_fns [ self . type ] ( value ) <EOL> if value == None : <EOL> return self . default <EOL> return self . format_template . safe_substitute ( value = value ) <EOL> class AttribMapBuilder : <EOL> def __init__ ( self ) : <EOL> self . type_fns = { } <EOL> self . type_fns [ '<STR_LIT:string>' ] = lambda x : x <EOL> self . type_fns [ '<STR_LIT:date>' ] = lambda x : x . strftime ( self . date_format ) <EOL> self . type_fns [ '<STR_LIT>' ] = lambda x : str ( x ) <EOL> self . type_fns [ '<STR_LIT:int>' ] = lambda x : int ( x ) <EOL> self . type_fns [ '<STR_LIT>' ] = lambda x : x . get_note ( ) <EOL> self . attrib_conversions = { } <EOL> self . set_conversion ( Conversion ( "<STR_LIT:id>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT:type>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT:status>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" , "<STR_LIT>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" , "<STR_LIT>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:date>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:date>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:date>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:int>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:date>" ) ) <EOL> self . set_conversion ( Conversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . date_format = "<STR_LIT>" <EOL> def set_conversion ( self , attrib ) : <EOL> self . attrib_conversions [ attrib . field ] = attrib <EOL> def get_values ( self , x ) : <EOL> result = { } <EOL> for conversion in self . attrib_conversions . values ( ) : <EOL> key = conversion . field <EOL> value = conversion . value ( x , self . type_fns ) <EOL> result [ key ] = value <EOL> return result </s>
