summaryrefslogtreecommitdiff
path: root/tablib/formats/_yaml.py
diff options
context:
space:
mode:
Diffstat (limited to 'tablib/formats/_yaml.py')
-rw-r--r--tablib/formats/_yaml.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tablib/formats/_yaml.py b/tablib/formats/_yaml.py
index 4cac8aa..57d63d7 100644
--- a/tablib/formats/_yaml.py
+++ b/tablib/formats/_yaml.py
@@ -39,4 +39,15 @@ def import_book(dbook, in_stream):
data = tablib.core.Dataset()
data.title = sheet['title']
data.dict = sheet['data']
- dbook.add_sheet(data) \ No newline at end of file
+ dbook.add_sheet(data)
+
+def detect(stream):
+ """Returns True if given stream is valid YAML."""
+ try:
+ _yaml = yaml.load(stream)
+ if isinstance(_yaml, (list, tuple, dict)):
+ return True
+ else:
+ return False
+ except yaml.parser.ParserError:
+ return False \ No newline at end of file