Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fix_dialect(dialect):
if not dialect.doublequote and dialect.escapechar is None:
dialect.doublequote = True
if dialect.quoting == unicodecsv.QUOTE_MINIMAL and dialect.quotechar == "'":
# Python csv's Sniffer seems to detect a wrong quotechar when
# quoting is minimal
dialect.quotechar = '"'
class excel_semicolon(unicodecsv.excel):
delimiter = ';'
unicodecsv.register_dialect("excel-semicolon", excel_semicolon)
if six.PY2:
def discover_dialect(sample, encoding=None, delimiters=(b",", b";", b"\t", b"|")):
"""Discover a CSV dialect based on a sample size.
`encoding` is not used (Python 2)
"""
try:
dialect = sniffer.sniff(sample, delimiters=delimiters)
except unicodecsv.Error: # Couldn't detect: fall back to 'excel'
dialect = unicodecsv.excel
fix_dialect(dialect)