|
7 | 7 | * Author(s): Dan Halbert, Michał Pokusa |
8 | 8 | """ |
9 | 9 |
|
| 10 | + |
10 | 11 | class MIMEType: |
11 | 12 | """Common MIME types. |
12 | 13 | From https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types |
13 | 14 | """ |
14 | 15 |
|
15 | | - AAC = "audio/aac" |
16 | | - ABW = "application/x-abiword" |
17 | | - ARC = "application/x-freearc" |
18 | | - AVI = "video/x-msvideo" |
19 | | - AZW = "application/vnd.amazon.ebook" |
20 | | - BIN = "application/octet-stream" |
21 | | - BMP = "image/bmp" |
22 | | - BZ = "application/x-bzip" |
23 | | - BZ2 = "application/x-bzip2" |
24 | | - CSH = "application/x-csh" |
25 | | - CSS = "text/css" |
26 | | - CSV = "text/csv" |
27 | | - DOC = "application/msword" |
28 | | - DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" |
29 | | - EOT = "application/vnd.ms-fontobject" |
30 | | - EPUB = "application/epub+zip" |
31 | | - GZ = "application/gzip" |
32 | | - GIF = "image/gif" |
33 | | - HTML = "text/html" |
34 | | - HTM = "text/html" |
35 | | - ICO = "image/vnd.microsoft.icon" |
36 | | - ICS = "text/calendar" |
37 | | - JAR = "application/java-archive" |
38 | | - JPEG = "image/jpeg" |
39 | | - JPG = "image/jpeg" |
40 | | - JS = "text/javascript" |
41 | | - JSON = "application/json" |
42 | | - JSONLD = "application/ld+json" |
43 | | - MID = "audio/midi" |
44 | | - MIDI = "audio/midi" |
45 | | - MJS = "text/javascript" |
46 | | - MP3 = "audio/mpeg" |
47 | | - CDA = "application/x-cdf" |
48 | | - MP4 = "video/mp4" |
49 | | - MPEG = "video/mpeg" |
50 | | - MPKG = "application/vnd.apple.installer+xml" |
51 | | - ODP = "application/vnd.oasis.opendocument.presentation" |
52 | | - ODS = "application/vnd.oasis.opendocument.spreadsheet" |
53 | | - ODT = "application/vnd.oasis.opendocument.text" |
54 | | - OGA = "audio/ogg" |
55 | | - OGV = "video/ogg" |
56 | | - OGX = "application/ogg" |
57 | | - OPUS = "audio/opus" |
58 | | - OTF = "font/otf" |
59 | | - PNG = "image/png" |
60 | | - PDF = "application/pdf" |
61 | | - PHP = "application/x-httpd-php" |
62 | | - PPT = "application/vnd.ms-powerpoint" |
63 | | - PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation" |
64 | | - RAR = "application/vnd.rar" |
65 | | - RTF = "application/rtf" |
66 | | - SH = "application/x-sh" |
67 | | - SVG = "image/svg+xml" |
68 | | - SWF = "application/x-shockwave-flash" |
69 | | - TAR = "application/x-tar" |
70 | | - TIFF = "image/tiff" |
71 | | - TIF = "image/tiff" |
72 | | - TS = "video/mp2t" |
73 | | - TTF = "font/ttf" |
74 | | - TXT = "text/plain" |
75 | | - VSD = "application/vnd.visio" |
76 | | - WAV = "audio/wav" |
77 | | - WEBA = "audio/webm" |
78 | | - WEBM = "video/webm" |
79 | | - WEBP = "image/webp" |
80 | | - WOFF = "font/woff" |
81 | | - WOFF2 = "font/woff2" |
82 | | - XHTML = "application/xhtml+xml" |
83 | | - XLS = "application/vnd.ms-excel" |
84 | | - XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" |
85 | | - XML = "application/xml" |
86 | | - XUL = "application/vnd.mozilla.xul+xml" |
87 | | - ZIP = "application/zip" |
88 | | - _7Z = "application/x-7z-compressed" |
| 16 | + TYPE_AAC = "audio/aac" |
| 17 | + TYPE_ABW = "application/x-abiword" |
| 18 | + TYPE_ARC = "application/x-freearc" |
| 19 | + TYPE_AVI = "video/x-msvideo" |
| 20 | + TYPE_AZW = "application/vnd.amazon.ebook" |
| 21 | + TYPE_BIN = "application/octet-stream" |
| 22 | + TYPE_BMP = "image/bmp" |
| 23 | + TYPE_BZ = "application/x-bzip" |
| 24 | + TYPE_BZ2 = "application/x-bzip2" |
| 25 | + TYPE_CSH = "application/x-csh" |
| 26 | + TYPE_CSS = "text/css" |
| 27 | + TYPE_CSV = "text/csv" |
| 28 | + TYPE_DOC = "application/msword" |
| 29 | + TYPE_DOCX = ( |
| 30 | + "application/vnd.openxmlformats-officedocument.wordprocessingml.document" |
| 31 | + ) |
| 32 | + TYPE_EOT = "application/vnd.ms-fontobject" |
| 33 | + TYPE_EPUB = "application/epub+zip" |
| 34 | + TYPE_GZ = "application/gzip" |
| 35 | + TYPE_GIF = "image/gif" |
| 36 | + TYPE_HTML = "text/html" |
| 37 | + TYPE_HTM = "text/html" |
| 38 | + TYPE_ICO = "image/vnd.microsoft.icon" |
| 39 | + TYPE_ICS = "text/calendar" |
| 40 | + TYPE_JAR = "application/java-archive" |
| 41 | + TYPE_JPEG = "image/jpeg" |
| 42 | + TYPE_JPG = "image/jpeg" |
| 43 | + TYPE_JS = "text/javascript" |
| 44 | + TYPE_JSON = "application/json" |
| 45 | + TYPE_JSONLD = "application/ld+json" |
| 46 | + TYPE_MID = "audio/midi" |
| 47 | + TYPE_MIDI = "audio/midi" |
| 48 | + TYPE_MJS = "text/javascript" |
| 49 | + TYPE_MP3 = "audio/mpeg" |
| 50 | + TYPE_CDA = "application/x-cdf" |
| 51 | + TYPE_MP4 = "video/mp4" |
| 52 | + TYPE_MPEG = "video/mpeg" |
| 53 | + TYPE_MPKG = "application/vnd.apple.installer+xml" |
| 54 | + TYPE_ODP = "application/vnd.oasis.opendocument.presentation" |
| 55 | + TYPE_ODS = "application/vnd.oasis.opendocument.spreadsheet" |
| 56 | + TYPE_ODT = "application/vnd.oasis.opendocument.text" |
| 57 | + TYPE_OGA = "audio/ogg" |
| 58 | + TYPE_OGV = "video/ogg" |
| 59 | + TYPE_OGX = "application/ogg" |
| 60 | + TYPE_OPUS = "audio/opus" |
| 61 | + TYPE_OTF = "font/otf" |
| 62 | + TYPE_PNG = "image/png" |
| 63 | + TYPE_PDF = "application/pdf" |
| 64 | + TYPE_PHP = "application/x-httpd-php" |
| 65 | + TYPE_PPT = "application/vnd.ms-powerpoint" |
| 66 | + TYPE_PPTX = ( |
| 67 | + "application/vnd.openxmlformats-officedocument.presentationml.presentation" |
| 68 | + ) |
| 69 | + TYPE_RAR = "application/vnd.rar" |
| 70 | + TYPE_RTF = "application/rtf" |
| 71 | + TYPE_SH = "application/x-sh" |
| 72 | + TYPE_SVG = "image/svg+xml" |
| 73 | + TYPE_SWF = "application/x-shockwave-flash" |
| 74 | + TYPE_TAR = "application/x-tar" |
| 75 | + TYPE_TIFF = "image/tiff" |
| 76 | + TYPE_TIF = "image/tiff" |
| 77 | + TYPE_TS = "video/mp2t" |
| 78 | + TYPE_TTF = "font/ttf" |
| 79 | + TYPE_TXT = "text/plain" |
| 80 | + TYPE_VSD = "application/vnd.visio" |
| 81 | + TYPE_WAV = "audio/wav" |
| 82 | + TYPE_WEBA = "audio/webm" |
| 83 | + TYPE_WEBM = "video/webm" |
| 84 | + TYPE_WEBP = "image/webp" |
| 85 | + TYPE_WOFF = "font/woff" |
| 86 | + TYPE_WOFF2 = "font/woff2" |
| 87 | + TYPE_XHTML = "application/xhtml+xml" |
| 88 | + TYPE_XLS = "application/vnd.ms-excel" |
| 89 | + TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" |
| 90 | + TYPE_XML = "application/xml" |
| 91 | + TYPE_XUL = "application/vnd.mozilla.xul+xml" |
| 92 | + TYPE_ZIP = "application/zip" |
| 93 | + TYPE_7Z = "application/x-7z-compressed" |
89 | 94 |
|
90 | 95 | @staticmethod |
91 | 96 | def from_file_name(filename: str): |
92 | 97 | """Return the mime type for the given filename. If not known, return "text/plain".""" |
93 | | - attr_name = filename.split(".")[-1].upper() |
94 | | - |
95 | | - if attr_name[0].isdigit(): |
96 | | - attr_name = "_" + attr_name |
| 98 | + attr_name = "TYPE_" + filename.split(".")[-1].upper() |
97 | 99 |
|
98 | | - return getattr(MIMEType, attr_name, MIMEType.TXT) |
| 100 | + return getattr(MIMEType, attr_name, MIMEType.TYPE_TXT) |
0 commit comments