summaryrefslogtreecommitdiff
path: root/tablib/formats
diff options
context:
space:
mode:
Diffstat (limited to 'tablib/formats')
-rw-r--r--tablib/formats/_csv.py2
-rw-r--r--tablib/formats/_dbf.py6
-rw-r--r--tablib/formats/_ods.py11
-rw-r--r--tablib/formats/_xls.py6
-rw-r--r--tablib/formats/_xlsx.py4
5 files changed, 18 insertions, 11 deletions
diff --git a/tablib/formats/_csv.py b/tablib/formats/_csv.py
index 9e8515a..5c03d6f 100644
--- a/tablib/formats/_csv.py
+++ b/tablib/formats/_csv.py
@@ -55,5 +55,5 @@ def detect(stream, delimiter=DEFAULT_DELIMITER):
try:
csv.Sniffer().sniff(stream, delimiters=delimiter)
return True
- except (csv.Error, TypeError):
+ except Exception:
return False
diff --git a/tablib/formats/_dbf.py b/tablib/formats/_dbf.py
index 710797d..0d1c87b 100644
--- a/tablib/formats/_dbf.py
+++ b/tablib/formats/_dbf.py
@@ -83,9 +83,5 @@ def detect(stream):
else:
_dbf = dbf.Dbf(StringIO(stream), readOnly=True)
return True
- except (ValueError, struct.error):
- # When we try to open up a file that's not a DBF, dbfpy raises a
- # ValueError.
- # When unpacking a string argument with less than 8 chars, struct.error is
- # raised.
+ except Exception:
return False
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
diff --git a/tablib/formats/_xls.py b/tablib/formats/_xls.py
index baa7904..88e8636 100644
--- a/tablib/formats/_xls.py
+++ b/tablib/formats/_xls.py
@@ -25,17 +25,17 @@ def detect(stream):
try:
xlrd.open_workbook(file_contents=stream)
return True
- except (TypeError, XLRDError):
+ except Exception:
pass
try:
xlrd.open_workbook(file_contents=stream.read())
return True
- except (AttributeError, XLRDError):
+ except Exception:
pass
try:
xlrd.open_workbook(filename=stream)
return True
- except:
+ except Exception:
return False
diff --git a/tablib/formats/_xlsx.py b/tablib/formats/_xlsx.py
index 516191c..f8f21c2 100644
--- a/tablib/formats/_xlsx.py
+++ b/tablib/formats/_xlsx.py
@@ -28,8 +28,8 @@ def detect(stream):
try:
openpyxl.reader.excel.load_workbook(stream, read_only=True)
return True
- except openpyxl.shared.exc.InvalidFileException:
- pass
+ except Exception:
+ return False
def export_set(dataset, freeze_panes=True):
"""Returns XLSX representation of Dataset."""