From ca8dbcf9bea46607d22fe205498b4c071c705860 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 4 Oct 2019 23:23:43 +0200 Subject: Refs #108 - Test and improve format autodetection Autodetection was added for the odf format. --- tablib/formats/_ods.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tablib/formats/_ods.py') diff --git a/tablib/formats/_ods.py b/tablib/formats/_ods.py index 5b900b5..dbf57c4 100644 --- a/tablib/formats/_ods.py +++ b/tablib/formats/_ods.py @@ -91,3 +91,14 @@ def dset_sheet(dataset, ws): cell = table.TableCell() cell.addElement(text.P(text=col)) odf_row.addElement(cell) + + +def detect(stream): + if isinstance(stream, bytes): + # load expects a file-like object. + stream = BytesIO(stream) + try: + opendocument.load(stream) + return True + except Exception: + return False -- cgit v1.2.1