Skip to content

FileExtensionEnum

Bases: Enum

An enumeration that maps various file extensions to their corresponding MIME types.

This Enum provides a structured way to associate common file extensions with their respective MIME types, facilitating easy retrieval of file extensions based on content types. Each member of the enumeration is a tuple containing the file extension and its associated MIME type.

Members

TEXT_PLAIN : tuple Represents the MIME type "text/plain" with the file extension ".txt". TEXT_HTML : tuple Represents the MIME type "text/html" with the file extension ".html". TEXT_CSV : tuple Represents the MIME type "text/csv" with the file extension ".csv". TEXT_XML : tuple Represents the MIME type "text/xml" with the file extension ".xml". APPLICATION_MS_EXCEL : tuple Represents the MIME type "application/vnd.ms-excel" with the file extension ".xls". APPLICATION_ODS : tuple Represents the MIME type "application/vnd.oasis.opendocument.spreadsheet" with the file extension ".ods". APPLICATION_OPENXML_EXCEL : tuple Represents the MIME type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" with the file extension ".xlsx". APPLICATION_JSON : tuple Represents the MIME type "application/json" with the file extension ".json". APPLICATION_XML : tuple Represents the MIME type "application/xml" with the file extension ".xml". APPLICATION_PDF : tuple Represents the MIME type "application/pdf" with the file extension ".pdf". APPLICATION_PARQUET : tuple Represents the MIME type "application/parquet" with the file extension ".parquet". APPLICATION_VDN_PARQUET : tuple Represents the MIME type "application/vdn.apache.parquet" with the file extension ".parquet". APPLICATION_RAR_WINDOWS : tuple Represents the MIME type "application/x-rar-compressed" with the file extension ".rar". APPLICATION_RAR : tuple Represents the MIME type "application/vnd.rar" with the file extension ".rar". APPLICATION_ZIP : tuple Represents the MIME type "application/zip" with the file extension ".zip". APPLICATION_ZIP_WINDOWS : tuple Represents the MIME type "application/x-zip-compressed" with the file extension ".zip".

Methods:

Attributes:

APPLICATION_JSON class-attribute instance-attribute

APPLICATION_JSON = ('.json', 'application/json')

APPLICATION_MS_EXCEL class-attribute instance-attribute

APPLICATION_MS_EXCEL = ('.xls', 'application/vnd.ms-excel')

APPLICATION_ODS class-attribute instance-attribute

APPLICATION_ODS = ('.ods', 'application/vnd.oasis.opendocument.spreadsheet')

APPLICATION_OPENXML_EXCEL class-attribute instance-attribute

APPLICATION_OPENXML_EXCEL = ('.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')

APPLICATION_PARQUET class-attribute instance-attribute

APPLICATION_PARQUET = ('.parquet', 'application/parquet')

APPLICATION_PDF class-attribute instance-attribute

APPLICATION_PDF = ('.pdf', 'application/pdf')

APPLICATION_RAR class-attribute instance-attribute

APPLICATION_RAR = ('.rar', 'application/vnd.rar')

APPLICATION_RAR_WINDOWS class-attribute instance-attribute

APPLICATION_RAR_WINDOWS = ('.rar', 'application/x-rar-compressed')

APPLICATION_VDN_PARQUET class-attribute instance-attribute

APPLICATION_VDN_PARQUET = ('.parquet', 'application/vdn.apache.parquet')

APPLICATION_XML class-attribute instance-attribute

APPLICATION_XML = ('.xml', 'application/xml')

APPLICATION_ZIP class-attribute instance-attribute

APPLICATION_ZIP = ('.zip', 'application/zip')

APPLICATION_ZIP_WINDOWS class-attribute instance-attribute

APPLICATION_ZIP_WINDOWS = ('.zip', 'application/x-zip-compressed')

TEXT_CSV class-attribute instance-attribute

TEXT_CSV = ('.csv', 'text/csv')

TEXT_HTML class-attribute instance-attribute

TEXT_HTML = ('.html', 'text/html')

TEXT_PLAIN class-attribute instance-attribute

TEXT_PLAIN = ('.txt', 'text/plain')

TEXT_XML class-attribute instance-attribute

TEXT_XML = ('.xml', 'text/xml')

get_extension classmethod

get_extension(content_type: str) -> str | None

Retrieve the file extension associated with a given MIME type.

Parameters:

  • content_type (str) –

    The MIME type for which the corresponding file extension is to be retrieved.

Returns:

  • str | None

    The file extension associated with the given MIME type, or None if the MIME type is not supported.

Examples:

>>> FileExtensionEnum.get_extension("application/pdf")
>>> '.pdf'
>>> FileExtensionEnum.get_extension("application/unknown")
>>> None

search_file_extension_in_url classmethod

search_file_extension_in_url(url: str) -> str | None

Search for the file extension in a given URL.

Parameters:

  • url (str) –

    The URL to search for the file extension.

Returns:

  • str | None

    The file extension, or None if no match is found.

Examples:

>>> FileExtensionEnum.search_file_extension_in_url("https://example.com/file.pdf")
'.pdf'
>>> FileExtensionEnum.search_file_extension_in_url("https://example.com/file.unknown")
None