def stringify(obj, trimmable=False):
    """
    Convert an object to a stringified version of this object where the
    initial object's attribute values have been stringified when these
    values are not native Python types.

    This function differs from the standard Python ``str`` as the latter
    returns a string version of object, while this function returns an
    object which attributes have native Python types.


    @param obj: an instance to return its stringified version.


    @param trimmable: indicate whether null attributes of this object
        need to be stripped out.


    @return: an object which attributes values are either a native Python
        types, either a string.
    """
    if obj is None:
        return None
    elif isinstance(obj, (basestring, bool, int, long, float, complex)):
        return obj
    elif isinstance(obj, (list, set, tuple)):
        return [stringify(item, trimmable=trimmable) for item in obj]
    elif isinstance(obj, dict):
        return dict([(unicode(key), stringify(value, trimmable=trimmable))
                for (key, value) in obj.iteritems() if not trimmable or value is not None])
    elif isinstance(obj, (uuid.UUID, EnumValue, ISO8601DateTime, Locale)):
        return unicode(obj)
    elif isinstance(obj, datetime.datetime):
        return str(ISO8601DateTime.from_datetime(obj)) if obj.tzinfo else str(obj)
    elif hasattr(obj, '__dict__'): # '__dict__' in dir(obj):
        return dict([(key, stringify(value, trimmable=trimmable))
                for (key, value) in obj.__dict__.iteritems() if not trimmable or value is not None])
    else:
        return unicode(obj)
def stringify ( obj , trimmable = False ) : if obj is None : return None elif isinstance ( obj , ( basestring , bool , int , long , float , complex ) ) : return obj elif isinstance ( obj , ( list , set , tuple ) ) : return [ stringify ( item , trimmable = trimmable ) for item in obj ] elif isinstance ( obj , dict ) : return dict ( [ ( unicode ( key ) , stringify ( value , trimmable = trimmable ) ) for ( key , value ) in obj . iteritems ( ) if not trimmable or value is not None ] ) elif isinstance ( obj , ( uuid . UUID , EnumValue , ISO8601DateTime , Locale ) ) : return unicode ( obj ) elif isinstance ( obj , datetime . datetime ) : return str ( ISO8601DateTime . from_datetime ( obj ) ) if obj . tzinfo else str ( obj ) elif hasattr ( obj , '__dict__' ) : return dict ( [ ( key , stringify ( value , trimmable = trimmable ) ) for ( key , value ) in obj . __dict__ . iteritems ( ) if not trimmable or value is not None ] ) else : return unicode ( obj )
Convert an object to a stringified version of this object where the
    initial object's attribute values have been stringified when these
    values are not native Python types.

    This function differs from the standard Python ``str`` as the latter
    returns a string version of object, while this function returns an
    object which attributes have native Python types.


    @param obj: an instance to return its stringified version.


    @param trimmable: indicate whether null attributes of this object
        need to be stripped out.


    @return: an object which attributes values are either a native Python
        types, either a string.