Package nsi :: Package granulate :: Module FileUtils
[hide private]
[frames] | no frames]

Source Code for Module nsi.granulate.FileUtils

 1  ############################################################################## 
 2  # 
 3  # Copyright (c) 2007 ISrg (NSI, CEFETCAMPOS, BRAZIL) and Contributors.  
 4  #                                                         All Rights Reserved. 
 5  # 
 6  # WARNING: This program as such is intended to be used by professional 
 7  # programmers who take the whole responsability of assessing all potential 
 8  # consequences resulting from its eventual inadequacies and bugs 
 9  # End users who are looking for a ready-to-use solution with commercial 
10  # garantees and support are strongly adviced to contract a Free Software 
11  # Service Company 
12  # 
13  # This program is Free Software; you can redistribute it and/or 
14  # modify it under the terms of the GNU General Public License 
15  # as published by the Free Software Foundation; either version 2 
16  # of the License, or (at your option) any later version. 
17  # 
18  # This program is distributed in the hope that it will be useful, 
19  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
21  # GNU General Public License for more details. 
22  # 
23  # You should have received a copy of the GNU General Public License 
24  # along with this program; if not, write to the Free Software 
25  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
26  # 
27  ############################################################################## 
28   
29  import mimetypes 
30  from StringIO import StringIO 
31   
32 -class File(object):
33 """ 34 This class is used for file handling 35 """
36 - def __init__(self, filename=None, data=None):
37 """ 38 Sets the filename and the file content 39 """ 40 self.setFilename(filename) 41 self.setData(data)
42
43 - def __call__(self):
44 """ 45 Should be used getData instead of __call___ 46 For this object, call is useless. 47 """ 48 return self.getData()
49
50 - def getFilename(self):
51 return self.filename
52
53 - def setFilename(self, filename=None):
54 """ 55 Set Filename and extract MimeType document 56 """ 57 self.filename = filename 58 self.mimetype = mimetypes.guess_type(filename)[0]
59 60
61 - def getData(self):
62 return self.data
63
64 - def setData(self,data=None):
65 """ 66 Set Data as a StringIO 67 """ 68 if isinstance(data,StringIO): 69 self.data = data 70 else: 71 self.data = StringIO(str(data))
72
73 - def getContentType(self):
74 return self.mimetype
75
76 - def setContentType(self, mimetype=None):
77 self.mimetype = mimetype
78