diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2010-09-25 06:20:34 -0400 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2010-09-25 06:20:34 -0400 |
| commit | 80cb42e8dd787a2ceffb37fe7a2380a97d000f4e (patch) | |
| tree | fb3e68962053aa45837c42a251ba7236f3dfac29 /tablib/formats | |
| parent | 8d7e5732cd95c23cfa5947342312e7e519f8e311 (diff) | |
| download | tablib-80cb42e8dd787a2ceffb37fe7a2380a97d000f4e.tar.gz | |
Archaic imports in place!
Diffstat (limited to 'tablib/formats')
| -rw-r--r-- | tablib/formats/_csv.py | 2 | ||||
| -rw-r--r-- | tablib/formats/_json.py | 21 | ||||
| -rw-r--r-- | tablib/formats/_yaml.py | 15 |
3 files changed, 29 insertions, 9 deletions
diff --git a/tablib/formats/_csv.py b/tablib/formats/_csv.py index 0554976..a66f2e0 100644 --- a/tablib/formats/_csv.py +++ b/tablib/formats/_csv.py @@ -33,7 +33,7 @@ def import_set(in_stream, headers=True): rows = csv.reader(in_stream.split()) for i, row in enumerate(rows): - if (i == 1) and (headers): + if (i == 0) and (headers): data.headers = row else: data.append(row) diff --git a/tablib/formats/_json.py b/tablib/formats/_json.py index acbaf57..18885c7 100644 --- a/tablib/formats/_json.py +++ b/tablib/formats/_json.py @@ -14,19 +14,26 @@ def export_set(dataset): def export_book(databook): """Returns JSON representation of Databook.""" - return json.dumps(databook._package()) - - -def detect(contents): - """Return True if contets are JSON.""" - return False - + def import_set(in_stream): """Returns dataset from JSON stream.""" + data = tablib.core.Dataset() data.dict = json.loads(in_stream) return data + +def import_book(in_stream): + """Returns databook from JSON stream.""" + + book = tablib.core.Databook() + 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
\ No newline at end of file diff --git a/tablib/formats/_yaml.py b/tablib/formats/_yaml.py index 35c2bf2..d54e29a 100644 --- a/tablib/formats/_yaml.py +++ b/tablib/formats/_yaml.py @@ -24,4 +24,17 @@ def import_set(in_stream): data = tablib.core.Dataset() data.dict = yaml.load(in_stream) - return data
\ No newline at end of file + return data + + +def import_book(in_stream): + """Returns databook from YAML stream.""" + + book = tablib.core.Databook() + 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
\ No newline at end of file |
