2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
import appy
|
|
|
|
import os.path
|
|
|
|
|
2009-08-17 10:06:17 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
2009-06-29 07:06:01 -05:00
|
|
|
appyPath = os.path.realpath(os.path.dirname(appy.__file__))
|
2013-02-05 01:51:25 -06:00
|
|
|
od = 'application/vnd.oasis.opendocument'
|
2013-04-19 08:30:18 -05:00
|
|
|
ms = 'application/vnd.openxmlformats-officedocument'
|
|
|
|
|
2013-02-05 01:51:25 -06:00
|
|
|
mimeTypes = {'odt': '%s.text' % od,
|
|
|
|
'ods': '%s.spreadsheet' % od,
|
2009-06-29 07:06:01 -05:00
|
|
|
'doc': 'application/msword',
|
|
|
|
'rtf': 'text/rtf',
|
2010-03-25 10:34:37 -05:00
|
|
|
'pdf': 'application/pdf'
|
|
|
|
}
|
|
|
|
mimeTypesExts = {
|
2013-04-19 08:30:18 -05:00
|
|
|
'%s.text' % od: 'odt',
|
|
|
|
'%s.spreadsheet' % od: 'ods',
|
|
|
|
'application/msword': 'doc',
|
|
|
|
'text/rtf': 'rtf',
|
|
|
|
'application/pdf': 'pdf',
|
|
|
|
'image/png': 'png',
|
|
|
|
'image/jpeg': 'jpg',
|
|
|
|
'image/pjpeg': 'jpg',
|
|
|
|
'image/gif': 'gif',
|
|
|
|
'application/vnd.ms-excel': 'xls',
|
|
|
|
'application/vnd.ms-powerpoint': 'ppt',
|
|
|
|
'%s.wordprocessingml.document' % ms: 'docx',
|
|
|
|
'%s.spreadsheetml.sheet' % ms: 'xlsx',
|
|
|
|
'%s.presentationml.presentation' % ms: 'pptx',
|
|
|
|
}
|
2009-08-17 10:06:17 -05:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2009-08-28 08:14:26 -05:00
|
|
|
class UnmarshalledFile:
|
|
|
|
'''Used for producing file objects from a marshalled Python object.'''
|
|
|
|
def __init__(self):
|
|
|
|
self.name = '' # The name of the file on disk
|
|
|
|
self.mimeType = None # The MIME type of the file
|
|
|
|
self.content = '' # The binary content of the file of a file object
|
|
|
|
self.size = 0 # The length of the file in bytes.
|
|
|
|
|
2010-02-02 09:25:10 -06:00
|
|
|
class UnicodeBuffer:
|
|
|
|
'''With StringIO class, I have tons of encoding problems. So I define a
|
|
|
|
similar class here, that uses an internal unicode buffer.'''
|
|
|
|
def __init__(self):
|
2010-02-05 08:39:52 -06:00
|
|
|
self.buffer = []
|
2010-02-02 09:25:10 -06:00
|
|
|
def write(self, s):
|
|
|
|
if s == None: return
|
|
|
|
if isinstance(s, unicode):
|
2010-02-05 08:39:52 -06:00
|
|
|
self.buffer.append(s)
|
2010-02-02 09:25:10 -06:00
|
|
|
elif isinstance(s, str):
|
2010-02-05 08:39:52 -06:00
|
|
|
self.buffer.append(s.decode('utf-8'))
|
2010-02-02 09:25:10 -06:00
|
|
|
else:
|
2010-02-05 08:39:52 -06:00
|
|
|
self.buffer.append(unicode(s))
|
|
|
|
def getValue(self):
|
|
|
|
return u''.join(self.buffer)
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|