mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Added tablib.import_set() and tested accordingly.
This commit is contained in:
+2
-2
@@ -2,7 +2,7 @@
|
||||
"""
|
||||
|
||||
from tablib.core import (
|
||||
Databook, Dataset, detect, InvalidDatasetType,
|
||||
InvalidDimensions, UnsupportedFormat
|
||||
Databook, Dataset, detect, import_set,
|
||||
InvalidDatasetType, InvalidDimensions, UnsupportedFormat
|
||||
)
|
||||
|
||||
|
||||
+10
-7
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -314,7 +314,6 @@ class TablibTestCase(unittest.TestCase):
|
||||
self.assertEqual(tablib.detect(_bunk)[0], None)
|
||||
|
||||
|
||||
|
||||
def test_wipe(self):
|
||||
"""Purge a dataset."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user