def safestr(value):
    '''Ensure type to string serialization'''
    if not value or isinstance(value, (int, float, bool, long)):
        return value
    elif isinstance(value, (date, datetime)):
        return value.isoformat()
    else:
        return unicode(value)
def safestr ( value ) : if not value or isinstance ( value , ( int , float , bool , long ) ) : return value elif isinstance ( value , ( date , datetime ) ) : return value . isoformat ( ) else : return unicode ( value )
Ensure type to string serialization