Skip to content

Commit 20d6f5b

Browse files
committed
fix
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 321c7a2 commit 20d6f5b

9 files changed

+143
-21
lines changed

cyclonedx_py/_internal/utils/mimetypes.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,40 @@
1919
from os.path import splitext
2020
from typing import Optional
2121

22+
_MIME_TEXT_PLAIN = 'text/plain'
23+
2224
_MAP_EXT_MIME = {
2325
# https://www.iana.org/assignments/media-types/media-types.xhtml
26+
'.csv': 'text/csv',
27+
'.htm': 'text/html',
28+
'.html': 'text/html',
2429
'.md': 'text/markdown',
2530
'.txt': 'text/plain',
2631
'.rst': 'text/prs.fallenstein.rst',
32+
'.xml': 'text/xml', # not `application/xml` -- our scope is text!
33+
# license-specific files
34+
'.license': _MIME_TEXT_PLAIN,
35+
'.licence': _MIME_TEXT_PLAIN,
2736
# add more mime types. pull-requests welcome!
2837
}
2938

39+
_LICENSE_FNAME_BASE = ('licence', 'license')
40+
_LICENSE_FNAME_EXT = (
41+
'.apache',
42+
'.bsd',
43+
'.gpl',
44+
'.mit',
45+
)
46+
3047

3148
def guess_type(file_name: str) -> Optional[str]:
3249
"""
3350
The stdlib `mimetypes.guess_type()` is inconsistent, as it depends heavily on type registry in the env/os.
3451
Therefore, this polyfill exists.
3552
"""
36-
ext = splitext(file_name)[1].lower()
37-
return _MAP_EXT_MIME.get(
38-
ext,
39-
_stdlib_guess_type(file_name)[0]
40-
)
53+
file_name_l = file_name.lower()
54+
base, ext = splitext(file_name_l)
55+
if base in _LICENSE_FNAME_BASE and ext in _LICENSE_FNAME_EXT:
56+
return _MIME_TEXT_PLAIN
57+
return _MAP_EXT_MIME.get(ext) \
58+
or _stdlib_guess_type(file_name_l)[0]

tests/_data/snapshots/environment/pep639-texts_with-license-pep639_1.3.json.bin

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/environment/pep639-texts_with-license-pep639_1.3.xml.bin

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/environment/pep639-texts_with-license-pep639_1.4.json.bin

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/environment/pep639-texts_with-license-pep639_1.4.xml.bin

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)