Charlie,
This is how I fixed the problem.
The function openpyxl/packaging looks as follows:
def _register_mimetypes(self, filenames):
"""
Make sure that the mime type for all file extensions is registered
"""
for fn in filenames:
ext = os.path.splitext(fn)[-1]
if not ext:
continue
mime = mimetypes.types_map[ext]
fe = FileExtension(ext[1:], mime)
self.Default.append(fe)
This contains no protection against duplicated extensions in the default list.
In my case the duplicate is created when 'FileExtension("xml", "text/xml")' and 'FileExtension("xml", "application/xml")' are both added to the list.
My modified version of the function avoids such duplicates:
def _register_mimetypes(self, filenames):
"""
Make sure that the mime type for all file extensions is registered
"""
defaults = [t.Extension for t in self.Default] # <<< NEW
for fn in filenames:
ext = os.path.splitext(fn)[-1]
if not ext:
continue
mime = mimetypes.types_map[ext]
if ext[1:] not in defaults: # <<< NEW
fe = FileExtension(ext[1:], mime) # <<< NEW
self.Default.append(fe) # <<< NEW
defaults.append(ext[1:]) # <<< NEW
Is this a fix that makes sense to you and can be added to the standard openpyxl?
Regards,
Johan
Op donderdag 16 november 2017 15:11:15 UTC+1 schreef Charlie Clark: