<s> from __future__ import print_function <EOL> from datetime import datetime <EOL> from dateutil import parser <EOL> import six <EOL> class OutputMapper ( object ) : <EOL> def __init__ ( self , date_strings ) : <EOL> self . date_strings = date_strings <EOL> self . output_map = { <EOL> "<STR_LIT>" : '<STR_LIT:date>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:start>" : '<STR_LIT:date>' , <EOL> "<STR_LIT:end>" : '<STR_LIT:date>' , <EOL> "<STR_LIT>" : '<STR_LIT:date>' , <EOL> "<STR_LIT>" : '<STR_LIT:date>' , <EOL> "<STR_LIT>" : '<STR_LIT:date>' , <EOL> "<STR_LIT>" : '<STR_LIT:date>' <EOL> } <EOL> def float_handler ( self , d ) : <EOL> return float ( d ) <EOL> def date ( self , d ) : <EOL> if isinstance ( d , list ) : <EOL> return list ( map ( self . date , d ) ) <EOL> if isinstance ( d , six . string_types ) : <EOL> if d . isdigit ( ) : <EOL> d = int ( d ) <EOL> else : <EOL> if self . date_strings : <EOL> return str ( parser . parse ( d ) ) <EOL> return parser . parse ( d ) <EOL> if isinstance ( d , six . integer_types ) : <EOL> if self . date_strings : <EOL> return str ( datetime . fromtimestamp ( d ) ) <EOL> return datetime . fromtimestamp ( d ) <EOL> return d <EOL> def outputmap ( self , data ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( data , list ) : <EOL> for item in data : <EOL> self . outputmap ( item ) <EOL> elif isinstance ( data , dict ) : <EOL> for map_target in self . output_map : <EOL> if map_target in data : <EOL> data [ map_target ] = getattr ( self , self . output_map [ map_target ] ) ( data [ map_target ] ) <EOL> for item in data . values ( ) : <EOL> self . outputmap ( item ) </s>
