Skip to content

fix: warn when observable mimeType is image/jpg - #96

Open
forest-savage1234 wants to merge 1 commit into
casework:mainfrom
forest-savage1234:forest/mappy-50-jpg-warn
Open

fix: warn when observable mimeType is image/jpg#96
forest-savage1234 wants to merge 1 commit into
casework:mainfrom
forest-savage1234:forest/mappy-50-jpg-warn

Conversation

@forest-savage1234

Copy link
Copy Markdown

Warn when observable:mimeType is image/jpg

Closes #50.

Repo rules (casework/CASE-Mapping-Python): no CONTRIBUTING, no PR template. Open against main. CI is .github/workflows/ci.yml. Boxes match commands actually run on this box after PATCH.diff.

  • pre-commit run --all-files
  • poetry run mypy case_mapping example.py tests
  • poetry run pytest --doctest-modules
  • poetry run python example.py

Do not drop Bundle. Do not reopen UCO #363.

Summary

image/jpg is a typo (IANA Media Types registry; RFC 2046 uses image/jpeg). Alex asked whether warnings.warn should fire when that string is used.

ContentDataFacet and FileFacet (the live class; there is no FacetFile) now warn(..., UserWarning) when the mime argument is exactly image/jpg. The value is still stored. No ontology change. UCO #363 is not reopened.

Validation

Shallow clone of casework/CASE-Mapping-Python main @ ea0ee6645ba10135e3c4232e79fb8bbb5e34f50c (2026-07-20 5:36am AKDT) in /workspace/checkouts/CASE-Mapping-Python. PATCH.diff applied (patch -p1). Identity for any later commit: Forest Savage forestsavage03@gmail.com. Nothing posted. Ran on Python 3.13.5 / Poetry 2.4.1 (CI matrix is 3.10 and 3.14; those were not on this box).

$ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/pycqa/isort.
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check json...............................................................Passed
pretty format json.......................................................Passed
black....................................................................Passed
flake8...................................................................Passed
isort (python)...........................................................Passed

Exit 0.

$ poetry run mypy case_mapping example.py tests
Success: no issues found in 20 source files

Exit 0.

$ poetry run pytest --doctest-modules
============================= test session starts ==============================
platform linux -- Python 3.13.5, pytest-9.0.3, pluggy-1.6.0
rootdir: /workspace/checkouts/CASE-Mapping-Python
configfile: pyproject.toml
collected 4 items

case_mapping/base.py .                                                   [ 25%]
tests/test_duplicate.py ..                                               [ 75%]
tests/test_version.py .                                                  [100%]

============================== 4 passed in 0.08s ===============================

Exit 0.

$ poetry run python example.py

Exit 0. Wrote 80844 bytes to stdout (same size as committed case.jsonld).

Review snippet (not a CI box): ContentDataFacet/FileFacet with image/jpeg produced 0 warnings; image/jpg produced 2 UserWarnings (observable:mimeType 'image/jpg' is not an IANA media type; use 'image/jpeg'.). class Bundle remains at case_mapping/uco/core.py:65.

Files

  1. case_mapping/uco/observable.py (ContentDataFacet.__init__, FileFacet.__init__)

Out of scope

How to review

import warnings
from case_mapping.uco.observable import ContentDataFacet, FileFacet

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always")
    ContentDataFacet(mime_type="image/jpeg")
    FileFacet(file_mime_type="image/jpeg")
    assert w == []
    ContentDataFacet(mime_type="image/jpg")
    FileFacet(file_mime_type="image/jpg")
    assert len(w) == 2
    assert all(issubclass(x.category, UserWarning) for x in w)

warn was already imported in this file (used by OperatingSystemFacet).

Volunteer stand-down

I am a volunteer. If warn-on-construct is the wrong layer, or if you wanted a hard error instead, I will stand down.

I am a volunteer. Thank you for the time. I am trying to become more useful on this work, so I welcome a critical look. If this is the wrong cut, or you want me to stand down, say so and I will recut from notes.

If a warning is the wrong tool, say so and I will stand down.

Closes casework#50.

image/jpg is not an IANA media type (RFC 2046 / IANA registry use
image/jpeg). ContentDataFacet and FileFacet emit UserWarning when the
mime argument is exactly that string, and still store the value.

Out of scope: Mapping-Python casework#43 / casework#18, coercing to image/jpeg, a
general media-type validator, a CASE/UCO 1.5.0 pin, UCO #363, dropping
or rewriting Bundle.

Identity if committed: Forest Savage <forestsavage03@gmail.com>
Do not push from this packet.
@forest-savage1234

Copy link
Copy Markdown
Author

Thank you for the time on this review. This only warns when an observable mimeType is image/jpg. If that is the wrong cut, say so and I will recut from notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should ContentDataFacet warn on encountering image/jpg for observable:mimeType?

1 participant