Skip to content

Commit

Permalink
Added newline kwarg to StringIO
Browse files Browse the repository at this point in the history
Fixes #517.
  • Loading branch information
matthewhegarty authored Feb 21, 2022
1 parent d9a4a97 commit 0fc3960
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Here is a list of passed and present much-appreciated contributors:
Mark Rogers
Mark Walling
Mathias Loesch
Matthew Hegarty
Mike Waldner
Peyman Salehi
Rabin Nankhwa
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# History

## 3.2.1 (unreleased)

### Bugfixes

- Support solo CR in text input imports (#518).

## 3.2.0 (2022-01-27)

### Changes
Expand Down
2 changes: 1 addition & 1 deletion src/tablib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def normalize_input(stream):
file-like object.
"""
if isinstance(stream, str):
return StringIO(stream)
return StringIO(stream, newline='')
elif isinstance(stream, bytes):
return BytesIO(stream)
return stream
8 changes: 8 additions & 0 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,14 @@ def test_csv_import_set_skip_lines(self):
dataset = tablib.import_set(csv_text, format="csv", skip_lines=2)
self.assertEqual(dataset.headers, ['id', 'name','description'])

def test_csv_import_mac_os_lf(self):
csv_text = (
'id,name,description\r'
'12,Smith,rounded\r'
)
dataset = tablib.import_set(csv_text, format="csv")
self.assertEqual('id,name,description\r\n12,Smith,rounded\r\n', dataset.csv)

def test_csv_export(self):
"""Verify exporting dataset object as CSV."""

Expand Down

0 comments on commit 0fc3960

Please sign in to comment.