summaryrefslogtreecommitdiff
path: root/tablib/formats/_yaml.py
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.com>2010-09-25 18:03:03 -0400
committerKenneth Reitz <me@kennethreitz.com>2010-10-01 17:52:08 -0400
commiteaa4de779391d9cbfc970cd418ccb36efdde122e (patch)
treedc58128651c5ce4c43a6df37b96fb08b38698cc8 /tablib/formats/_yaml.py
parentd479c5735ad5875fc2a953abd1c20654ddc83aef (diff)
downloadtablib-eaa4de779391d9cbfc970cd418ccb36efdde122e.tar.gz
Auto-detectors operational.
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