From 4fc70957ac4fc796f27e199e12cc54cc2115b374 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 20 Sep 2010 21:33:48 -0400 Subject: [PATCH 1/5] Reverted methods back to properties. --- tablib/core.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/tablib/core.py b/tablib/core.py index 730f673..1cdfeb2 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 @@ -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.""" From 31e4c39762d9ddab781c55b1c23fc6a21a4c6a31 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 20 Sep 2010 21:34:01 -0400 Subject: [PATCH 2/5] Updated tests for reverted methods. --- test_tablib.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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__': From dd13744c9223ec34a0ad9df44f70a95cd8d21b31 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 20 Sep 2010 21:37:08 -0400 Subject: [PATCH 3/5] Documentation update for properties. --- README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 4fe26bd..6ef9c22 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. From 3407170b99772c6155498372ac41ca663c1961ec Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 20 Sep 2010 21:37:32 -0400 Subject: [PATCH 4/5] Updated TODO. --- README.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 6ef9c22..c0333e7 100644 --- a/README.rst +++ b/README.rst @@ -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 From 7364995eaabf49d35652754158151a232af08a22 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 20 Sep 2010 21:39:27 -0400 Subject: [PATCH 5/5] Version bump (v0.7.1) --- HISTORY.rst | 7 +++++++ setup.py | 2 +- tablib/core.py | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) 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/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 1cdfeb2..0167c34 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -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'