Package etl :: Package component :: Package input :: Module data'
[hide private]
[frames] | no frames]

Source Code for Module etl.component.input.data'

 1  # -*- encoding: utf-8 -*- 
 2  ############################################################################## 
 3  # 
 4  #    ETL system- Extract Transfer Load system 
 5  #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved 
 6  #    $Id$ 
 7  # 
 8  #    This program is free software: you can redistribute it and/or modify 
 9  #    it under the terms of the GNU General Public License as published by 
10  #    the Free Software Foundation, either version 3 of the License, or 
11  #    (at your option) any later version. 
12  # 
13  #    This program is distributed in the hope that it will be useful, 
14  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  #    GNU General Public License for more details. 
17  # 
18  #    You should have received a copy of the GNU General Public License 
19  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
20  # 
21  ############################################################################## 
22  """ 
23   This component is used to read data. 
24   
25   Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). 
26   GNU General Public License 
27  """ 
28   
29   
30  from etl.component import component 
31   
32   
33 -class data(component):
34 """ 35 This is an ETL Component that return python data from a list of dictionary. 36 """ 37
38 - def __init__(self, datas, name='component.input.data', transformer=None, row_limit=0):
39 """ 40 Required Parameters 41 datas : Input data 42 43 Extra Parameters 44 name : Name of Component. 45 transformer : Transformer object to transform string data into particular object. 46 """ 47 super(data, self).__init__(name=name, transformer=transformer, row_limit=row_limit) 48 self._type = 'component.input.data' 49 self.datas = datas
50
51 - def __copy__(self):
52 res = data(self.datas, self.name, self.transformer, self.row_limit) 53 return res
54
55 - def process(self):
56 for d in self.datas: 57 yield d, 'main'
58 59 60
61 -def test():
62 from etl_test import etl_test 63 import etl 64 inp_data = etl.component.input.data([ 65 {'id': 1, 'name': 'Fabien', 'country_id': 3}, 66 {'id': 2, 'name': 'Luc', 'country_id': 3}, 67 {'id': 3, 'name': 'Henry', 'country_id': 1} 68 ]) 69 test = etl_test.etl_component_test(inp_data) 70 test.check_output([{'country_id': 3, 'id': 1, 'name': 'Fabien'}, {'country_id': 3, 'id': 2, 'name': 'Luc'}, {'country_id': 1, 'id': 3, 'name': 'Henry'}] ) 71 res = test.output() 72 print res
73 74 if __name__ == '__main__': 75 test() 76