Skip to content

Commit d9e210b

Browse files
committed
ci: Merge remote-tracking branch 'refs/remotes/origin/mathern/version-bump' into mathern/version-bump
2 parents b7454ed + b68e2bc commit d9e210b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/c2pa/c2pa.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
'c2pa_reader_from_manifest_data_and_stream',
4242
'c2pa_reader_free',
4343
'c2pa_reader_json',
44+
'c2pa_reader_detailed_json',
4445
'c2pa_reader_resource_to_stream',
4546
'c2pa_builder_from_json',
4647
'c2pa_builder_from_archive',
@@ -379,6 +380,9 @@ def _setup_function(func, argtypes, restype=None):
379380
_setup_function(
380381
_lib.c2pa_reader_json, [
381382
ctypes.POINTER(C2paReader)], ctypes.c_void_p)
383+
_setup_function(
384+
_lib.c2pa_reader_detailed_json, [
385+
ctypes.POINTER(C2paReader)], ctypes.c_void_p)
382386
_setup_function(_lib.c2pa_reader_resource_to_stream, [ctypes.POINTER(
383387
C2paReader), ctypes.c_char_p, ctypes.POINTER(C2paStream)], ctypes.c_int64)
384388
_setup_function(
@@ -1737,6 +1741,34 @@ def json(self) -> str:
17371741
self._manifest_json_str_cache = _convert_to_py_string(result)
17381742
return self._manifest_json_str_cache
17391743

1744+
def detailed_json(self) -> str:
1745+
"""Get the detailed JSON representation of the C2PA manifest store.
1746+
1747+
This method returns a more detailed JSON string than Reader.json(),
1748+
providing additional information about the manifest structure.
1749+
Note that the returned JSON by this method has a slightly different
1750+
structure than the one returned by Reader.json().
1751+
1752+
Returns:
1753+
A JSON string containing the detailed manifest store data.
1754+
1755+
Raises:
1756+
C2paError: If there is an error reading the manifest data or if
1757+
the Reader has been closed.
1758+
"""
1759+
1760+
self._ensure_valid_state()
1761+
1762+
result = _lib.c2pa_reader_detailed_json(self._reader)
1763+
1764+
if result is None:
1765+
error = _parse_operation_result_for_error(_lib.c2pa_error())
1766+
if error:
1767+
raise C2paError(error)
1768+
raise C2paError("Error during detailed manifest parsing in Reader")
1769+
1770+
return _convert_to_py_string(result)
1771+
17401772
def get_active_manifest(self) -> Optional[dict]:
17411773
"""Get the active manifest from the manifest store.
17421774

tests/test_unit_tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ def test_stream_read(self):
114114
json_data = reader.json()
115115
self.assertIn(DEFAULT_TEST_FILE_NAME, json_data)
116116

117+
def test_stream_read_detailed(self):
118+
with open(self.testPath, "rb") as file:
119+
reader = Reader("image/jpeg", file)
120+
json_data = reader.detailed_json()
121+
self.assertIn(DEFAULT_TEST_FILE_NAME, json_data)
122+
117123
def test_get_active_manifest(self):
118124
with open(self.testPath, "rb") as file:
119125
reader = Reader("image/jpeg", file)
@@ -265,6 +271,13 @@ def test_stream_read_and_parse(self):
265271
title = manifest_store["manifests"][manifest_store["active_manifest"]]["title"]
266272
self.assertEqual(title, DEFAULT_TEST_FILE_NAME)
267273

274+
def test_stream_read_detailed_and_parse(self):
275+
with open(self.testPath, "rb") as file:
276+
reader = Reader("image/jpeg", file)
277+
manifest_store = json.loads(reader.detailed_json())
278+
title = manifest_store["manifests"][manifest_store["active_manifest"]]["claim"]["dc:title"]
279+
self.assertEqual(title, DEFAULT_TEST_FILE_NAME)
280+
268281
def test_stream_read_string_stream(self):
269282
with Reader(self.testPath) as reader:
270283
json_data = reader.json()

0 commit comments

Comments
 (0)