Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ezodf/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

MIMETYPES = {
'odt': "application/vnd.oasis.opendocument.text",
'fodt': "application/xml",
'ott': "application/vnd.oasis.opendocument.text-template",
'odg': "application/vnd.oasis.opendocument.graphics",
'otg': "application/vnd.oasis.opendocument.graphics-template",
'odp': "application/vnd.oasis.opendocument.presentation",
'otp': "application/vnd.oasis.opendocument.presentation-template",
'ods': "application/vnd.oasis.opendocument.spreadsheet",
'fods': "application/xml",
'ots': "application/vnd.oasis.opendocument.spreadsheet-template",
'odc': "application/vnd.oasis.opendocument.chart",
'otc': "application/vnd.oasis.opendocument.chart-template",
Expand Down
14 changes: 7 additions & 7 deletions ezodf/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ def is_valid_stream(buffer):
def opendoc(filename):
if is_stream(filename):
fm = ByteStreamManager(filename)
elif filename is not None:
fm = FileManager(filename)
else:
fm = FileManager(filename)

mime_type = __detect_mime_type(fm)
if (mime_type == "application/xml"):
try:
xmlnode = etree.parse(filename).getroot()
return FlatXMLDocument(filename=filename, xmlnode=xmlnode)
except etree.ParseError:
raise IOError("File '%s' is neither a zip-package nor a flat "
"XML OpenDocumentFormat file." % filename)

mime_type = __detect_mime_type(fm)
raise IOError("File '%s' is detected as a flat "
"XML OpenDocumentFormat file but failed to be parsed." % filename)
return PackagedDocument(filemanager=fm, mimetype=mime_type)


Expand All @@ -64,7 +64,7 @@ def __detect_mime_type(file_manager):
else:
# use file ext name
ext = os.path.splitext(file_manager.zipname)[1]
mime_type = MIMETYPES[ext]
mime_type = MIMETYPES[ext[1:]]
return mime_type


Expand Down