diff --git a/HISTORY.rst b/HISTORY.rst index ca0470f..d4b58d4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,13 @@ History ======= +0.7.1 (2010-09-20) +------------------ + +* Reverting methods back to properties. +* Windows bug compenated in documentation. + + 0.7.0 (2010-09-20) ------------------ diff --git a/README.rst b/README.rst index 4fe26bd..c0333e7 100644 --- a/README.rst +++ b/README.rst @@ -70,7 +70,7 @@ JSON! +++++ :: - >>> print data.json() + >>> print data.json [ { "last_name": "Adams", @@ -89,7 +89,7 @@ YAML! +++++ :: - >>> print data.yaml() + >>> print data.yaml - {age: 90, first_name: John, last_name: Adams} - {age: 83, first_name: Henry, last_name: Ford} @@ -97,7 +97,7 @@ CSV... ++++++ :: - >>> print data.csv() + >>> print data.csv first_name,last_name,age John,Adams,90 Henry,Ford,83 @@ -106,7 +106,7 @@ EXCEL! ++++++ :: - >>> data.xls('people.xls') + >>> open('people.xls', 'wb').write(data.xls) It's that easy. @@ -131,7 +131,6 @@ If you'd like to contribute, simply fork `the repository`_, commit your changes Roadmap ------- -- Add ability to add/remove full columns - Import datasets from CSV, JSON, YAML - Release CLI Interface - Auto-detect import format @@ -141,4 +140,4 @@ Roadmap - Plugin support .. _`the repository`: http://github.com/kennethreitz/tablib -.. _AUTHORS: http://github.com/kennethreitz/tablib/blob/master/AUTHORS \ No newline at end of file +.. _AUTHORS: http://github.com/kennethreitz/tablib/blob/master/AUTHORS diff --git a/setup.py b/setup.py index c853439..8816512 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ if sys.argv[-1] == "publish": setup( name='tablib', - version='0.7.0', + version='0.7.1', description='Format agnostic tabular data library (XLS, JSON, YAML, CSV)', long_description=open('README.rst').read() + '\n\n' + open('HISTORY.rst').read(), diff --git a/tablib/core.py b/tablib/core.py index 730f673..0167c34 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -8,7 +8,7 @@ import csv -import StringIO +import cStringIO import random import simplejson as json @@ -21,8 +21,8 @@ from helpers import * # __all__ = ['Dataset', 'DataBook'] __name__ = 'tablib' -__version__ = '0.7.0' -__build__ = 0x000700 +__version__ = '0.7.1' +__build__ = 0x000701 __author__ = 'Kenneth Reitz' __license__ = 'MIT' __copyright__ = 'Copyright 2010 Kenneth Reitz' @@ -155,19 +155,20 @@ class Dataset(object): return self._package() + @property def json(self): """Returns JSON representation of Dataset.""" return json.dumps(self.dict) - + @property def yaml(self): """Returns YAML representation of Dataset.""" return yaml.dump(self.dict) - + @property def csv(self): """Returns CSV representation of Dataset.""" - stream = StringIO.StringIO() + stream = cStringIO.StringIO() _csv = csv.writer(stream) for row in self._package(dicts=False): @@ -175,8 +176,8 @@ class Dataset(object): return stream.getvalue() - - def xls(self, path=None): + @property + def xls(self): """Returns XLS representation of Dataset.""" wb = xlwt.Workbook(encoding='utf8') @@ -186,13 +187,9 @@ class Dataset(object): for j, col in enumerate(row): ws.write(i, j, col) - if path: - wb.save(path) - return True - else: - stream = StringIO.StringIO() - wb.save(stream) - return stream.getvalue() + stream = cStringIO.StringIO() + wb.save(stream) + return stream.getvalue() def append(self, row=None, col=None): @@ -266,8 +263,8 @@ class Databook(object): """The number of the Datasets within DataBook.""" return len(self._datasets) - - def xls(self, path=None): + @property + def xls(self): """Returns XLS representation of DataBook.""" @@ -282,22 +279,19 @@ class Databook(object): ws.write(i, j, col) - - if path: - wb.save(path) - return True - else: - stream = cStringIO.StringIO() - wb.save(stream) - return stream.getvalue() + stream = cStringIO.StringIO() + wb.save(stream) + return stream.getvalue() + @property def json(self): """Returns JSON representation of Databook.""" return json.dumps(self._package()) + @property def yaml(self): """Returns YAML representation of Databook.""" diff --git a/test_tablib.py b/test_tablib.py index fc8cb7d..959a01c 100755 --- a/test_tablib.py +++ b/test_tablib.py @@ -167,7 +167,7 @@ class TablibTestCase(unittest.TestCase): csv += str(col) + ',' csv = csv.strip(',') + '\r\n' - self.assertEqual(csv, self.founders.csv()) + self.assertEqual(csv, self.founders.csv) def test_unicode_append(self): @@ -176,10 +176,10 @@ class TablibTestCase(unittest.TestCase): new_row = ('å', 'é') data.append(new_row) - data.json() - data.yaml() - data.csv() - data.xls() + data.json + data.yaml + data.csv + data.xls if __name__ == '__main__':