Package etl :: Package connector :: Module url_connector
[hide private]
[frames] | no frames]

Source Code for Module etl.connector.url_connector

 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 provide connectivity with URL Access like  http, ftp, https, gopher 
25   
26   Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). 
27   GNU General Public License. 
28  """ 
29  from etl.connector import connector 
30  import urllib 
31   
32 -class url_connector(connector):
33 """ 34 This is an ETL connector that is used to provide connectivity URL Access like http, ftp, https, gopher. 35 """
36 - def __init__(self, uri, bufsize=-1, encoding='utf-8', name='url_connector'):
37 """ 38 Required Parameters 39 uri : Path of file. 40 41 Extra Parameters 42 bufsize : Buffer size for reading data. 43 encoding : Encoding format. 44 name : Name of connector. 45 """ 46 super(url_connector, self).__init__(name) 47 self._type = 'connector.url_connector' 48 self.bufsize = bufsize 49 self.encoding = encoding 50 self.uri = uri
51
52 - def open(self):
53 """ 54 Opens the specified URL. 55 """ 56 # TODO : pass encoding in file 57 super(url_connector, self).open() 58 connector = urllib.URLopener().open(self.uri) 59 #self.file.encoding = self.encoding 60 return connector
61
62 - def close(self):
63 super(url_connector, self).close() 64 connector.close()
65
66 - def __copy__(self):
67 res = url_connector(self.uri, self.bufsize, self.encoding, self.name) 68 return res
69