Skip to content

Commit

Permalink
rollback escapechar standarize line terminators (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyn4 authored May 7, 2024
1 parent 6cbd334 commit 63273f9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions target_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,20 @@ def persist_messages(delimiter, quotechar, messages, destination_path, fixed_hea
else:
headers[o['stream']] = flattened_record.keys()

args = {}
if sys.version_info.major == 3 and sys.version_info.minor == 10:
args = {"escapechar": '\\'}
with open(filename, 'a') as csvfile:
writer = csv.DictWriter(csvfile,
headers[o['stream']],
extrasaction='ignore',
delimiter=delimiter,
quotechar=quotechar,
**args)
)
if file_is_empty:
writer.writeheader()

# We use simplejson to re-serialize the data to avoid formatting issues in the CSV
r = simplejson.dumps(flattened_record)
# if \\u0000 is being used as line terminator, replace with \n
r = r.replace("\\u0000", "\\n")
writer.writerow(simplejson.loads(r))

job_metrics_file_path = os.path.expanduser(os.path.join(destination_path, "job_metrics.json"))
Expand Down

0 comments on commit 63273f9

Please sign in to comment.