From 95c98861daef57091347343f9238bdb25bfc5c4d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 29 Aug 2010 22:41:34 -0400 Subject: [PATCH] Object structure in place --- tablib/core.py | 116 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 3 deletions(-) diff --git a/tablib/core.py b/tablib/core.py index aa97ebc..8ba5c43 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -6,14 +6,124 @@ # / /_ / /_/ / _ /_/ /_ /_/ // __// /_/ / # \__/ \__,_/ /_.___/ /_.___/ \___/ \__,_/ + +import csv + + + __version__ = '0.0.2' __build__ = '0x000002' __author__ = 'Kenneth Reitz' __license__ = 'MIT' __copyright__ = 'Copyright 2010 Kenneth Reitz' +__all__ = ['Dataset', 'source'] -def cheese(): + + +class Dataset(object): + """Amazing Tabular Dataset object. """ + + def __init__(self, *args, **kwargs): + + self._data = [].append(args) + + try: + self.headers = kwargs['headers'] + except KeyError, why: + self.headers = None + + + def __len__(self): + return self.height + + + def __getitem__(self, key): + return self._data[key] + + + def __setitem__(self, key, value): + self.validate(value) + self._data[key] = value + + + def __delitem__(self, key): + del self._data[key] + + + def __repr__(self): + return '' + + + def validate(self, row=None, safety=False): + """Assures size of every row in dataset is of proper proportions.""" + if row: + is_valid = (len(row) == self.width) if self.width else True + else: + is_valid = all((len(x)== self.width for x in self._data)) + + if is_valid: + return True + + else: + if not safety: + raise InvalidDimensions + return False + + def digest(self): + """Retruns digest information of dataset in human-readable format.""" + pass + + + @property + def height(self): + """Returns the height of the Dataset.""" + return len(self._data) + + + @property + def width(self): + """Returns the width of the Dataset.""" + + try: + len(self._data[0]) + except Exception, why: + raise why + + + @property + def json(self): + pass + + + @property + def yaml(self): + pass + + + @property + def csv(self): + pass + + + @property + def xls(self): + pass + + + def add_row(self, index=None): + pass + + def del_row(self): + pass + + def save(self): + pass + +class InvalidDimensions(Exception): + "Invalid size" + + +def source(): """docstring for import""" - pass - + pass \ No newline at end of file