Commit 6c083b59 authored by Boris Kocherov's avatar Boris Kocherov

x2t: use OOHandler.getMetadata if need generate baseformat

parent e0068547
...@@ -72,12 +72,6 @@ yformat_map = { ...@@ -72,12 +72,6 @@ yformat_map = {
'ppty': 'pptx', 'ppty': 'pptx',
} }
yformat2opendocument_map = {
'docy': 'odt',
'xlsy': 'ods',
'ppty': 'odp',
}
yformat_tuple = ( yformat_tuple = (
"docy", "application/x-asc-text", "docy", "application/x-asc-text",
"xlsy", "application/x-asc-spreadsheet", "xlsy", "application/x-asc-spreadsheet",
...@@ -239,19 +233,19 @@ class Handler(object): ...@@ -239,19 +233,19 @@ class Handler(object):
r"""Returns a dictionary with all metadata of document. r"""Returns a dictionary with all metadata of document.
""" """
if self._source_format in yformat_tuple and self._data.startswith("PK\x03\x04"): if self._source_format in yformat_tuple and self._data.startswith("PK\x03\x04"):
with io.BytesIO(self._data) as memfile, ZipFile(memfile) as zipfile: if base_document:
try: openxml_format = yformat_map[self._source_format]
metadata = zipfile.read("metadata.json") data = self.convert(yformat_map[self._source_format])
except KeyError: return OOoHandler(self.base_folder_url, data, openxml_format, **self._init_kw).getMetadata(base_document)
metadata = '{}' else:
metadata = json.loads(metadata) with io.BytesIO(self._data) as memfile, ZipFile(memfile) as zipfile:
metadata['MIMEType'] = self._getContentType() try:
if base_document: metadata = zipfile.read("metadata.json")
opendocument_format = yformat2opendocument_map[self._source_format] except KeyError:
metadata['MIMEType'] = guess_type('a.' + opendocument_format)[0] metadata = '{}'
metadata['Data'] = self.convert(opendocument_format) metadata = json.loads(metadata)
metadata['MIMEType'] = self._getContentType()
return metadata return metadata
else: else:
return OOoHandler(self.base_folder_url, self._data, self._source_format, **self._init_kw).getMetadata(base_document) return OOoHandler(self.base_folder_url, self._data, self._source_format, **self._init_kw).getMetadata(base_document)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment