summaryrefslogtreecommitdiff
path: root/tablib/formats/_ods.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2019-10-04 23:23:43 +0200
committerClaude Paroz <claude@2xlibre.net>2019-10-04 23:40:24 +0200
commitca8dbcf9bea46607d22fe205498b4c071c705860 (patch)
treedd685c19557a42b7655898b2bcf11603f653dbea /tablib/formats/_ods.py
parent44185350306c1cbc9a85b5682b4cb5d69a663494 (diff)
downloadtablib-ca8dbcf9bea46607d22fe205498b4c071c705860.tar.gz
Refs #108 - Test and improve format autodetection
Autodetection was added for the odf format.
Diffstat (limited to 'tablib/formats/_ods.py')
-rw-r--r--tablib/formats/_ods.py11
1 files changed, 11 insertions, 0 deletions
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