[docs]
class MimeTypes:
"""
Contains MIME Types for commonly used data types and their extensions.
Example::
>>> MimeTypes.PDF
'application/pdf'
>>> MimeTypes.get_extension(MimeTypes.PDF)
'pdf'
"""
HTML = 'text/html'
JSON = 'application/json'
PDF = 'application/pdf'
TEXT = 'text/plain'
XML = 'application/xml'
_exts = {
HTML: 'html',
JSON: 'json',
PDF: 'pdf',
TEXT: 'txt',
XML: 'xml',
}
_DEFAULT_EXT = 'bin'
[docs]
@classmethod
def get_extension(cls, mime_type: str) -> str:
"""
:param mime_type: MIME Type, such as ``application/pdf``.
:return: Extension commonly used for this MIME Type.
"""
return cls._exts.get(mime_type, cls._DEFAULT_EXT)