Generic method import_book (similar to import_set) to import data into Databook model.

This commit is contained in:
xando 2012-05-16 16:56:53 +01:00
parent e8c923d712
commit eda9d5af03
2 changed files with 14 additions and 1 deletions

View File

@ -1,7 +1,7 @@
""" Tablib. """
from tablib.core import (
Databook, Dataset, detect, import_set,
Databook, Dataset, detect, import_set, import_book,
InvalidDatasetType, InvalidDimensions, UnsupportedFormat,
__version__
)

View File

@ -1008,6 +1008,19 @@ def import_set(stream):
return None
def import_book(stream):
"""Return dataset of given stream."""
(format, stream) = detect(stream)
try:
databook = Databook()
format.import_book(databook, stream)
return databook
except AttributeError:
return None
class InvalidDatasetType(Exception):
"Only Datasets can be added to a DataBook"