summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.com>2010-08-30 01:01:32 -0400
committerKenneth Reitz <me@kennethreitz.com>2010-08-30 01:01:32 -0400
commit6405ec3bafcfca3ec33a7f533a8fee53afa2cd19 (patch)
treebc173130fd30108438f912b3f96f48896e1246fc
parentea64e4cfacc7b640b65a4b23a7b18606aba8f138 (diff)
downloadtablib-6405ec3bafcfca3ec33a7f533a8fee53afa2cd19.tar.gz
General improvments
-rw-r--r--tablib/core.py44
-rw-r--r--tablib/tests/tests.py2
2 files changed, 40 insertions, 6 deletions
diff --git a/tablib/core.py b/tablib/core.py
index ae19740..530551d 100644
--- a/tablib/core.py
+++ b/tablib/core.py
@@ -13,9 +13,13 @@ import os
from helpers import *
from packages import simplejson as json
from packages import xlwt
-from packages import yaml
+try:
+ import yaml
+except ImportError, why:
+ from packages import yaml
+
__all__ = ['Dataset', 'source']
@@ -26,13 +30,18 @@ __license__ = 'MIT'
__copyright__ = 'Copyright 2010 Kenneth Reitz'
+FILE_EXTENTIONS = ('csv', 'json', 'xls', 'yaml')
+
+
class Dataset(object):
"""Amazing Tabular Dataset object. """
def __init__(self, *args, **kwargs):
self._data = None
- self._filename = None
+ self._saved_file = None
+ self._saved_format = None
+
self._data = list(args)
@@ -94,7 +103,18 @@ class Dataset(object):
def digest(self):
"""Retruns digest information of dataset in human-readable format."""
- 'Height: Width: '
+
+ digest_text = ''
+
+ if self.title:
+ digest_text += 'Title: %s \n' % (self.title)
+ if self.headers:
+ digest_text += 'Headers: %s\n' % [self.headers]
+
+ digest_text += 'Height: %s\nWidth: %s\n' % (self.height, self.width)
+
+
+ return digest_text
@property
@@ -149,16 +169,30 @@ class Dataset(object):
pass
- def save(self):
- pass
+ def save(self, filename=None, format=None):
+
+ if not format:
+ # set format from filename
+# format = filename
+ pass
+
+ if format not in FILE_EXTENTIONS:
+ raise UnsupportedFormat
+
# note export format
# open file, save the bitch
+
class InvalidDimensions(Exception):
"Invalid size"
+class UnsupportedFormat(NotImplemented):
+ "Format is not supported"
+
+
+
def source(io_string=None, filename=None):
"""docstring for import"""
#open by filename
diff --git a/tablib/tests/tests.py b/tablib/tests/tests.py
index f457dfb..9a8c417 100644
--- a/tablib/tests/tests.py
+++ b/tablib/tests/tests.py
@@ -14,4 +14,4 @@ print data[1]
data.append(['kenneth' ,'reitz', 4.3])
-print data._data \ No newline at end of file
+print data.digest() \ No newline at end of file