Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python 

2# cardinal_pythonlib/httpconst.py 

3 

4""" 

5=============================================================================== 

6 

7 Original code copyright (C) 2009-2021 Rudolf Cardinal (rudolf@pobox.com). 

8 

9 This file is part of cardinal_pythonlib. 

10 

11 Licensed under the Apache License, Version 2.0 (the "License"); 

12 you may not use this file except in compliance with the License. 

13 You may obtain a copy of the License at 

14 

15 https://www.apache.org/licenses/LICENSE-2.0 

16 

17 Unless required by applicable law or agreed to in writing, software 

18 distributed under the License is distributed on an "AS IS" BASIS, 

19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

20 See the License for the specific language governing permissions and 

21 limitations under the License. 

22 

23=============================================================================== 

24 

25**Constants for use with HTTP.** 

26 

27Many of these can be extracted: 

28 

29.. code-block:: python 

30 

31 import mimetypes 

32 mimetypes.types_map['.zip'] # application/zip -- this is built in 

33 mimetypes.types_map['.xlsx'] # fails 

34 mimetypes.init() 

35 mimetypes.types_map['.xlsx'] # application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 

36 # ... must read some local thing... 

37  

38Something's changed -- in Python 3.6.8, there's no need for the init() call. 

39There is also a guessing function, :func:`mimetypes.guess_type`; see 

40https://docs.python.org/3.6/library/mimetypes.html. 

41 

42.. code-block:: python 

43 

44 >>> import mimetypes 

45 >>> print(mimetypes.guess_type("thing.html")) 

46 ('text/html', None) 

47 >>> print(mimetypes.guess_type("thing.xls")) 

48 ('application/vnd.ms-excel', None) 

49 >>> print(mimetypes.guess_type("thing.xlsx")) 

50 ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', None) 

51 

52""" # noqa 

53 

54 

55class MimeType(object): 

56 """ 

57 Some MIME type constants. 

58 See also the Python standard library ``mimetypes``; e.g. 

59 

60 .. code-block:: python 

61 

62 import mimetypes 

63 mimetypes.types_map['.pdf'] # 'application/pdf' 

64  

65 See: 

66 

67 - Binary: 

68 

69 - https://stackoverflow.com/questions/6783921/which-mime-type-to-use-for-a-binary-file-thats-specific-to-my-program 

70 

71 - CSV 

72  

73 - https://stackoverflow.com/questions/264256/what-is-the-best-mime-type-and-extension-to-use-when-exporting-tab-delimited 

74 - https://www.iana.org/assignments/media-types/text/tab-separated-values 

75  

76 - ZIP 

77  

78 - https://stackoverflow.com/questions/4411757/zip-mime-types-when-to-pick-which-one 

79  

80 - Microsoft Office 

81  

82 - https://filext.com/faq/office_mime_types.html 

83  

84 - OpenOffice 

85  

86 - https://www.openoffice.org/framework/documentation/mimetypes/mimetypes.html 

87 - https://stackoverflow.com/questions/31489757/what-is-correct-mimetype-with-apache-openoffice-files-like-odt-ods-odp 

88 

89 """ # noqa 

90 BINARY = "application/octet-stream" 

91 CSV = "text/csv" 

92 DOC = "application/msword" 

93 DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" # noqa 

94 DOT = DOC 

95 DOTX = "application/vnd.openxmlformats-officedocument.wordprocessingml.template" # noqa 

96 FORCE_DOWNLOAD = "application/force-download" 

97 ODP = "application/vnd.oasis.opendocument.presentation" 

98 ODS = "application/vnd.oasis.opendocument.spreadsheet" 

99 ODT = "application/vnd.oasis.opendocument.text" 

100 PDF = "application/pdf" 

101 PNG = "image/png" 

102 PPT = "application/vnd.ms-powerpoint" 

103 SQLITE3 = "application/x-sqlite3" 

104 TEXT = "text/plain" 

105 TSV = "text/tab-separated-values" 

106 TXT = TEXT 

107 XLS = "application/vnd.ms-excel" 

108 XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 

109 XML = "text/xml" 

110 ZIP = "application/zip" 

111 

112 

113ContentType = MimeType