mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Object structure in place
This commit is contained in:
+113
-3
@@ -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 '<dataset object>'
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user