guess-file-mime-type 0.1.0a0__tar.gz
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.
- guess_file_mime_type-0.1.0a0/LICENSE +21 -0
- guess_file_mime_type-0.1.0a0/PKG-INFO +56 -0
- guess_file_mime_type-0.1.0a0/README.md +39 -0
- guess_file_mime_type-0.1.0a0/guess_file_mime_type.egg-info/PKG-INFO +56 -0
- guess_file_mime_type-0.1.0a0/guess_file_mime_type.egg-info/SOURCES.txt +10 -0
- guess_file_mime_type-0.1.0a0/guess_file_mime_type.egg-info/dependency_links.txt +1 -0
- guess_file_mime_type-0.1.0a0/guess_file_mime_type.egg-info/requires.txt +1 -0
- guess_file_mime_type-0.1.0a0/guess_file_mime_type.egg-info/top_level.txt +1 -0
- guess_file_mime_type-0.1.0a0/guess_file_mime_type.py +22 -0
- guess_file_mime_type-0.1.0a0/pyproject.toml +26 -0
- guess_file_mime_type-0.1.0a0/setup.cfg +7 -0
@@ -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,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,39 @@
|
|
1
|
+
# guess-file-mime-type
|
2
|
+
|
3
|
+
A minimal, cross-platform, and cross-version utility to safely guess a file's MIME type.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- ✅ **NT & POSIX** filesystem support
|
8
|
+
- ✅ **Uniform API** for different Python versions (2+ and 3.0 - 3.13+)
|
9
|
+
- *Standard library* functions like `mimetypes.guess_type()` and `mimetypes.guess_file_type()` **change signature and location** in Python 3.13.
|
10
|
+
- ✅ Returns sensible default (`application/octet-stream`) for unknown types
|
11
|
+
|
12
|
+
## Why?
|
13
|
+
|
14
|
+
- Write portable code that works everywhere, forever.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
```bash
|
19
|
+
pip install guess-file-mime-type
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```python
|
25
|
+
# coding=utf-8
|
26
|
+
from __future__ import print_function
|
27
|
+
from guess_file_mime_type import guess_file_mime_type
|
28
|
+
|
29
|
+
mime_type = guess_file_mime_type('/path/to/image.png')
|
30
|
+
print(mime_type) # 'image/png'
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
This project is licensed under the [MIT License](LICENSE).
|
@@ -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,10 @@
|
|
1
|
+
LICENSE
|
2
|
+
README.md
|
3
|
+
guess_file_mime_type.py
|
4
|
+
pyproject.toml
|
5
|
+
setup.cfg
|
6
|
+
guess_file_mime_type.egg-info/PKG-INFO
|
7
|
+
guess_file_mime_type.egg-info/SOURCES.txt
|
8
|
+
guess_file_mime_type.egg-info/dependency_links.txt
|
9
|
+
guess_file_mime_type.egg-info/requires.txt
|
10
|
+
guess_file_mime_type.egg-info/top_level.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
posix-or-nt
|
@@ -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'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "guess-file-mime-type"
|
7
|
+
version = "0.1.0a0"
|
8
|
+
description = "A minimal, cross-platform, and cross-version utility to safely guess a file's MIME type."
|
9
|
+
readme = "README.md"
|
10
|
+
requires-python = ">=2"
|
11
|
+
license = "MIT"
|
12
|
+
authors = [
|
13
|
+
{ name="Jifeng Wu", email="jifengwu2k@gmail.com" }
|
14
|
+
]
|
15
|
+
classifiers = [
|
16
|
+
"Programming Language :: Python :: 2",
|
17
|
+
"Programming Language :: Python :: 3",
|
18
|
+
"Operating System :: OS Independent",
|
19
|
+
]
|
20
|
+
dependencies = [
|
21
|
+
"posix-or-nt"
|
22
|
+
]
|
23
|
+
|
24
|
+
[project.urls]
|
25
|
+
"Homepage" = "https://github.com/jifengwu2k/guess-file-mime-type"
|
26
|
+
"Bug Tracker" = "https://github.com/jifengwu2k/guess-file-mime-type/issues"
|