Generic method import_book (similar to import_set) to import data into Databook model.
This commit is contained in:
parent
e8c923d712
commit
eda9d5af03
|
@ -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__
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue