Elegant databook importers.

This commit is contained in:
Kenneth Reitz
2010-09-25 15:56:20 -04:00
parent f1bdf43aab
commit a73bbe1645
2 changed files with 7 additions and 10 deletions
+3 -5
View File
@@ -24,14 +24,12 @@ def import_set(dset, in_stream):
dset.dict = json.loads(in_stream)
def import_book(in_stream):
def import_book(dbook, in_stream):
"""Returns databook from JSON stream."""
book = tablib.core.Databook()
dbook.wipe()
for sheet in json.loads(in_stream):
data = tablib.core.Dataset()
data.title = sheet['title']
data.dict = sheet['data']
book.add_sheet(data)
return book
dbook.add_sheet(data)
+4 -5
View File
@@ -25,14 +25,13 @@ def import_set(dset, in_stream):
dset.dict = yaml.load(in_stream)
def import_book(in_stream):
def import_book(dbook, in_stream):
"""Returns databook from YAML stream."""
book = tablib.core.Databook()
dbook.wipe()
for sheet in yaml.load(in_stream):
data = tablib.core.Dataset()
data.title = sheet['title']
data.dict = sheet['data']
book.add_sheet(data)
return book
dbook.add_sheet(data)