From 23f654052a9807e6b66917d86a9b829b2d66b590 Mon Sep 17 00:00:00 2001 From: jonadem Date: Wed, 26 Jul 2017 11:49:56 +0200 Subject: [PATCH] Reenable support for Flat XML OpenDocumentFormat files (i.e. .fodt and .fods) --- ezodf/const.py | 2 ++ ezodf/document.py | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ezodf/const.py b/ezodf/const.py index 86b6fc4..5ded5e8 100644 --- a/ezodf/const.py +++ b/ezodf/const.py @@ -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", diff --git a/ezodf/document.py b/ezodf/document.py index 27552df..ca6afab 100644 --- a/ezodf/document.py +++ b/ezodf/document.py @@ -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) @@ -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