Add a method to get all the extensions associated to a mime type

This is needed to solve problems with mismanaged extensions in the journal.
This commit is contained in:
Gonzalo Odiard 2014-04-25 15:11:37 -03:00 committed by Martin Abente Lahaye
parent 568e0254d7
commit 4a565dacac

View File

@ -210,7 +210,7 @@ def _get_mime_data_directories():
return dirs return dirs
def get_primary_extension(mime_type): def _init_mime_information():
global _extensions global _extensions
global _globs_timestamps global _globs_timestamps
@ -230,8 +230,8 @@ def get_primary_extension(mime_type):
_extensions = {} _extensions = {}
# FIXME Properly support these types in the system. (#4855) # FIXME Properly support these types in the system. (#4855)
_extensions['audio/ogg'] = 'ogg' _extensions['audio/ogg'] = ['ogg']
_extensions['video/ogg'] = 'ogg' _extensions['video/ogg'] = ['ogg']
for globs_path in globs_path_list: for globs_path in globs_path_list:
globs_file = open(globs_path) globs_file = open(globs_path)
@ -240,14 +240,28 @@ def get_primary_extension(mime_type):
if not line.startswith('#'): if not line.startswith('#'):
line_type, glob = line.split(':') line_type, glob = line.split(':')
if glob.startswith('*.'): if glob.startswith('*.'):
_extensions[line_type] = glob[2:] if line_type in _extensions:
_extensions[line_type].append(glob[2:])
else:
_extensions[line_type] = [glob[2:]]
_globs_timestamps = timestamps _globs_timestamps = timestamps
def get_primary_extension(mime_type):
_init_mime_information()
if mime_type in _extensions:
return _extensions[mime_type][0]
else:
return None
def get_extensions_by_mimetype(mime_type):
_init_mime_information()
if mime_type in _extensions: if mime_type in _extensions:
return _extensions[mime_type] return _extensions[mime_type]
else: else:
return None return []
_MIME_TYPE_BLACK_LIST = [ _MIME_TYPE_BLACK_LIST = [