Added tablib.import_set() and tested accordingly.

This commit is contained in:
Kenneth Reitz
2010-09-25 18:35:10 -04:00
parent 7f2f925ddb
commit a310ab7a09
4 changed files with 25 additions and 10 deletions
+2 -2
View File
@@ -2,7 +2,7 @@
"""
from tablib.core import (
Databook, Dataset, detect, InvalidDatasetType,
InvalidDimensions, UnsupportedFormat
Databook, Dataset, detect, import_set,
InvalidDatasetType, InvalidDimensions, UnsupportedFormat
)
+10 -7
View File
@@ -14,7 +14,7 @@ from helpers import Struct, piped
FORMATS = ('json', 'yaml', 'xls', 'csv')
FORMATS = [fmt.title for fmt in tablib.formats.FORMATS]
opts = []
@@ -32,13 +32,16 @@ def start(in_file=None, out_file=None, **opts):
opts = Struct(**opts)
if opts.version:
print('Tabbed, Ver. %s' % tabbed.core.__version__)
sys.sys.exit(0)
print('Tabbed, Ver. %s' % tablib.core.__version__)
sys.exit(0)
stdin = piped()
if stdin:
print stdin
data = tablib.import_set(stdin)
print data.json
# test = tablib.Dataset()
# print test.yaml
elif in_file:
@@ -81,6 +84,6 @@ def start(in_file=None, out_file=None, **opts):
# look for filename
print opts.__dict__
print in_file
print out_file
# print opts.__dict__
# print in_file
# print out_file
+13
View File
@@ -277,7 +277,20 @@ def detect(stream):
except AttributeError:
pass
return (None, stream)
def import_set(stream):
"""Return dataset of given stream."""
(format, stream) = detect(stream)
try:
data = Dataset()
format.import_set(data, stream)
return data
except AttributeError, e:
return None
class InvalidDatasetType(Exception):
"Only Datasets can be added to a DataBook"
-1
View File
@@ -314,7 +314,6 @@ class TablibTestCase(unittest.TestCase):
self.assertEqual(tablib.detect(_bunk)[0], None)
def test_wipe(self):
"""Purge a dataset."""