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

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

 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  """ 
24   To import data from vcard. 
25   
26   Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). 
27   GNU General Public License. 
28  """ 
29   
30  from etl.component import component 
31   
32 -class vcard_in(component):
33
34 - def __init__(self,fileconnector, name='component.input.csv_in', transformer=None, row_limit=0):
35 """ 36 Required Parameters 37 fileconnector : Local file connector to connect with file. 38 39 Extra Parameters 40 name : Name of Component. 41 """ 42 super(vcard_in, self).__init__(name=name, connector=fileconnector, transformer=transformer, row_limit=row_limit) 43 self._type = 'component.input.vcard_in'
44 45
46 - def __copy__(self):
47 res = vcard_in(self.connector, self.name, self.transformer, self.row_limit) 48 return res
49
50 - def end(self):
51 super(vcard_in, self).end() 52 if self.fp: 53 self.connector.close(self.fp) 54 self.fp = False
55 56
57 - def process(self):
58 import vobject 59 self.fp = self.connector.open('r') 60 s = "".join(self.fp.readlines()) 61 reader = vobject.readComponents(s) 62 while True: 63 row = {} 64 data = reader.next() 65 for d in data.contents: 66 row[unicode(d)] = eval('data.' + unicode(d) + '.value') 67 yield row, 'main' 68
69 -def test():
70 from etl_test import etl_test 71 import etl 72 file_conn = etl.connector.localfile('../../../demo/input/input1.vcf') 73 test = etl_test.etl_component_test(vcard_in(file_conn, name='vcf test')) 74 test.check_output([{u'tel': u'(111) 555-1212', u'title': u'Shrimp Man', u'rev': u'20080424T195243Z', u'version': u'3.0', u'org': [u'BubbaGumpShrimp'], u'label': u'100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America', u'email': u'forrestgump@example.com', u'fn': u'ForrestGump'}], 'main') 75 res = test.output() 76 print res
77 78 if __name__ == '__main__': 79 test() 80