def _format_csv_value(self, value):
"""Takes a single CSV value string and formats it in compliance with RFC4180.
Multiple values can be joined together by putting them in a list and using ",".join(the_list).
http://tools.ietf.org/html/rfc4180#page-3
:param value: A single value destined to be output among multiple in a CSV row
:return: The escaped and/or quoted string if necessary, otherwise simply returns <value>.
"""
for x in [",", '"', "\n", "\r\n"]:
if x in value:
# Must replace double quotes '"' with two double quotes '""'
value = value.replace('"', '""')
# and contain all fields in double quotes if they contain commas or double quotes
value = '"%s"' % value
break
return value