def stringify(value, encoding_default='<STR_LIT:utf-8>', encoding=None):
if value is None:<EOL><INDENT>return None<EOL><DEDENT>if not isinstance(value, six.text_type):<EOL><INDENT>if isinstance(value, (date, datetime)):<EOL><INDENT>return value.isoformat()<EOL><DEDENT>elif isinstance(value, (float, Decimal)):<EOL><INDENT>return Decimal(value).to_eng_string()<EOL><DEDENT>elif isinstance(value, six.binary_type):<EOL><INDENT>if encoding is None:<EOL><INDENT>encoding = guess_encoding(value, default=encoding_default)<EOL><DEDENT>value = value.decode(encoding, '<STR_LIT:replace>')<EOL>value = remove_byte_order_mark(value)<EOL>value = remove_unsafe_chars(value)<EOL><DEDENT>else:<EOL><INDENT>value = six.text_type(value)<EOL><DEDENT><DEDENT>value = value.strip()<EOL>if not len(value):<EOL><INDENT>return None<EOL><DEDENT>return value<EOL>
Brute-force convert a given object to a string.

    This will attempt an increasingly mean set of conversions to make a given
    object into a unicode string. It is guaranteed to either return unicode or
    None, if all conversions failed (or the value is indeed empty).