guess-file-mime-type 0.1.0a0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: guess-file-mime-type
3
+ Version: 0.1.0a0
4
+ Summary: A minimal, cross-platform, and cross-version utility to safely guess a file's MIME type.
5
+ Author-email: Jifeng Wu <jifengwu2k@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/jifengwu2k/guess-file-mime-type
8
+ Project-URL: Bug Tracker, https://github.com/jifengwu2k/guess-file-mime-type/issues
9
+ Classifier: Programming Language :: Python :: 2
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=2
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: posix-or-nt
16
+ Dynamic: license-file
17
+
18
+ # guess-file-mime-type
19
+
20
+ A minimal, cross-platform, and cross-version utility to safely guess a file's MIME type.
21
+
22
+ ## Features
23
+
24
+ - ✅ **NT & POSIX** filesystem support
25
+ - ✅ **Uniform API** for different Python versions (2+ and 3.0 - 3.13+)
26
+ - *Standard library* functions like `mimetypes.guess_type()` and `mimetypes.guess_file_type()` **change signature and location** in Python 3.13.
27
+ - ✅ Returns sensible default (`application/octet-stream`) for unknown types
28
+
29
+ ## Why?
30
+
31
+ - Write portable code that works everywhere, forever.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install guess-file-mime-type
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ # coding=utf-8
43
+ from __future__ import print_function
44
+ from guess_file_mime_type import guess_file_mime_type
45
+
46
+ mime_type = guess_file_mime_type('/path/to/image.png')
47
+ print(mime_type) # 'image/png'
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
53
+
54
+ ## License
55
+
56
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,6 @@
1
+ guess_file_mime_type.py,sha256=dczYLa0eMvEkxanZPbL65kuyNcl812-NfE3rkpSVLlI,744
2
+ guess_file_mime_type-0.1.0a0.dist-info/licenses/LICENSE,sha256=FZ9XWedK_wQ4wfqVanrQVQpArRHDkxwxic2rgii1pZg,1066
3
+ guess_file_mime_type-0.1.0a0.dist-info/METADATA,sha256=hMWbBFjM9t51qUpU659FpsmQGTlZCS6gRsbLpNfFFV4,1667
4
+ guess_file_mime_type-0.1.0a0.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
5
+ guess_file_mime_type-0.1.0a0.dist-info/top_level.txt,sha256=MBq_R_Nvwu7G0N8KsP3lJfVxmhGVKAX5i7lT-BaxHZY,21
6
+ guess_file_mime_type-0.1.0a0.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jifeng Wu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ guess_file_mime_type
@@ -0,0 +1,22 @@
1
+ # coding=utf-8
2
+ # Copyright (c) 2025 Jifeng Wu
3
+ # Licensed under the MIT License. See LICENSE file in the project root for full license information.
4
+ import mimetypes
5
+ import sys
6
+
7
+ from posix_or_nt import posix_or_nt
8
+ if posix_or_nt() == 'nt':
9
+ import ntpath as os_path
10
+ else:
11
+ import posixpath as os_path
12
+
13
+ if sys.version_info >= (3, 13):
14
+ def guess_file_mime_type(file_path):
15
+ # type: (str) -> str
16
+ mime_type, _ = mimetypes.guess_file_type(os_path.basename(file_path))
17
+ return mime_type or 'application/octet-stream'
18
+ else:
19
+ def guess_file_mime_type(file_path):
20
+ # type: (str) -> str
21
+ mime_type, _ = mimetypes.guess_type(os_path.basename(file_path))
22
+ return mime_type or 'application/octet-stream'