summaryrefslogtreecommitdiff
path: root/tablib/core.py
blob: 8ba5c43686876253fe180f021a6d3a44a3fc175a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# -*- coding: utf-8 -*-

# _____         ______  ______        _________
# __  /_______ ____  /_ ___  /_ _____ ______  /
# _  __/_  __ `/__  __ \__  __ \_  _ \_  __  / 
# / /_  / /_/ / _  /_/ /_  /_/ //  __// /_/ /  
# \__/  \__,_/  /_.___/ /_.___/ \___/ \__,_/   


import csv



__version__ = '0.0.2'
__build__ = '0x000002'
__author__ = 'Kenneth Reitz'
__license__ = 'MIT'
__copyright__ = 'Copyright 2010 Kenneth Reitz'

__all__ = ['Dataset', 'source']



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