Merge branch 'master' into develop

This commit is contained in:
Kenneth Reitz
2010-10-04 11:52:12 -04:00
4 changed files with 65 additions and 13 deletions
+27 -2
View File
@@ -20,6 +20,9 @@ class Dataset(object):
def __init__(self, *args, **kwargs):
self._data = list(args)
self.__headers = None
# ('title', index) tuples
self._separators = []
try:
self.headers = kwargs['headers']
@@ -33,6 +36,7 @@ class Dataset(object):
self._register_formats()
def __len__(self):
return self.height
@@ -203,7 +207,26 @@ class Dataset(object):
self._data = [tuple([row]) for row in col]
def insert(self, i, row=None, col=None):
def insert_separator(self, index, text='-'):
"""Adds a separator to Dataset at given index."""
sep = (index, text)
self._separators.append(sep)
def append_separator(self, text='-'):
"""Adds a separator to Dataset."""
# change offsets if headers are or aren't defined
if not self.headers:
index = self.height if self.height else 0
else:
index = (self.height + 1) if self.height else 1
self.insert_separator(index, text)
def insert(self, i, row=None):
"""Inserts a row at given position in Dataset"""
if row:
self._validate(row)
@@ -234,9 +257,11 @@ class Databook(object):
except AttributeError:
return '<databook object>'
def wipe(self):
"""Wipe book clean."""
self._datasets = []
@classmethod
def _register_formats(cls):
@@ -258,7 +283,7 @@ class Databook(object):
self._datasets.append(dataset)
else:
raise InvalidDatasetType
def _package(self):
"""Packages Databook for delivery."""