def _prepare_data(data):
 if isinstance(data, dict):
  new_data = {}
  for (key, value) in data.iteritems():
   new_data[key] = _prepare_data(value)
  return new_data
 elif (isinstance(data, list) or isinstance(data, tuple) or isinstance(data, set)):
  return [_prepare_data(item) for item in data]
 elif isinstance(data, datetime.date):
  if ((data is NULL_DATETIME) or (data is NULL_DATE)):
   return None
  return str(data)
 else:
  return data

def _prepare_data ( data ) : if isinstance ( data , dict ) : new_data = { } for ( key , value ) in data . iteritems ( ) : new_data [ key ] = _prepare_data ( value ) return new_data elif ( isinstance ( data , list ) or isinstance ( data , tuple ) or isinstance ( data , set ) ) : return [ _prepare_data ( item ) for item in data ] elif isinstance ( data , datetime . date ) : if ( ( data is NULL_DATETIME ) or ( data is NULL_DATE ) ) : return None return str ( data ) else : return data
recursively process data structures .