Skip to content

Commit 0f0b4bb

Browse files
committed
fix: refactor
1 parent 427b3d0 commit 0f0b4bb

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

src/c2pa/c2pa.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,27 @@
3232

3333
# Define required function names
3434
_REQUIRED_FUNCTIONS = [
35+
# Version
3536
'c2pa_version',
37+
# Error retriever and parser
3638
'c2pa_error',
37-
'c2pa_string_free',
39+
# Legacy APIs, deprecated
3840
'c2pa_load_settings',
3941
'c2pa_read_file',
4042
'c2pa_read_ingredient_file',
43+
# Reader bindings
4144
'c2pa_reader_from_stream',
4245
'c2pa_reader_from_manifest_data_and_stream',
4346
'c2pa_reader_json',
4447
'c2pa_reader_detailed_json',
4548
'c2pa_reader_resource_to_stream',
49+
'c2pa_reader_from_context',
50+
'c2pa_reader_with_stream',
51+
'c2pa_reader_with_fragment',
52+
'c2pa_reader_is_embedded',
53+
'c2pa_reader_remote_url',
54+
'c2pa_reader_supported_mime_types',
55+
# Builder bindings
4656
'c2pa_builder_from_json',
4757
'c2pa_builder_from_archive',
4858
'c2pa_builder_set_no_embed',
@@ -54,32 +64,31 @@
5464
'c2pa_builder_to_archive',
5565
'c2pa_builder_sign',
5666
'c2pa_builder_sign_context',
57-
'c2pa_manifest_bytes_free',
67+
'c2pa_builder_from_context',
68+
'c2pa_builder_with_definition',
69+
'c2pa_builder_with_archive',
70+
'c2pa_builder_supported_mime_types',
5871
'c2pa_format_embeddable',
72+
# Signer bindings
5973
'c2pa_signer_create',
6074
'c2pa_signer_from_info',
6175
'c2pa_signer_reserve_size',
6276
'c2pa_ed25519_sign',
6377
'c2pa_signature_free',
64-
'c2pa_free_string_array',
65-
'c2pa_reader_supported_mime_types',
66-
'c2pa_builder_supported_mime_types',
67-
'c2pa_reader_is_embedded',
68-
'c2pa_reader_remote_url',
78+
# Settings bindings
6979
'c2pa_settings_new',
7080
'c2pa_settings_set_value',
7181
'c2pa_settings_update_from_string',
82+
# Context bindings
7283
'c2pa_context_builder_new',
7384
'c2pa_context_builder_set_settings',
7485
'c2pa_context_builder_build',
7586
'c2pa_context_builder_set_signer',
7687
'c2pa_context_new',
77-
'c2pa_reader_from_context',
78-
'c2pa_reader_with_stream',
79-
'c2pa_reader_with_fragment',
80-
'c2pa_builder_from_context',
81-
'c2pa_builder_with_definition',
82-
'c2pa_builder_with_archive',
88+
# Free bindings
89+
'c2pa_string_free',
90+
'c2pa_free_string_array',
91+
'c2pa_manifest_bytes_free',
8392
'c2pa_free',
8493
]
8594

@@ -1373,7 +1382,7 @@ def execution_context(self): ...
13731382

13741383

13751384
class Settings(ManagedResource):
1376-
"""Per-instance configuration for C2PA operations.
1385+
"""Configuration for C2PA operations.
13771386
13781387
Settings configure SDK behavior. Use with Context class to
13791388
apply settings to Reader/Builder operations.
@@ -1392,7 +1401,7 @@ def __init__(self):
13921401

13931402
@classmethod
13941403
def from_json(cls, json_str: str) -> 'Settings':
1395-
"""Create Settings from a JSON configuration string.
1404+
"""Create Settings from a serialized JSON configuration string.
13961405
13971406
Args:
13981407
json_str: JSON string with settings configuration.
@@ -1406,7 +1415,7 @@ def from_json(cls, json_str: str) -> 'Settings':
14061415

14071416
@classmethod
14081417
def from_dict(cls, config: dict) -> 'Settings':
1409-
"""Create Settings from a dictionary.
1418+
"""Create Settings from a (JSON-based)dictionary.
14101419
14111420
Args:
14121421
config: Dictionary with settings configuration.
@@ -1420,8 +1429,7 @@ def set(self, path: str, value: str) -> 'Settings':
14201429
"""Set a configuration value by dot-notation path.
14211430
14221431
Args:
1423-
path: Dot-notation path (e.g.
1424-
"builder.thumbnail.enabled").
1432+
path: Dot-notation path (e.g. "builder.thumbnail.enabled").
14251433
value: The value to set.
14261434
14271435
Returns:
@@ -1443,11 +1451,10 @@ def set(self, path: str, value: str) -> 'Settings':
14431451
def update(
14441452
self, data: Union[str, dict],
14451453
) -> 'Settings':
1446-
"""Merge configuration from a JSON string or dict.
1454+
"""Update current configuration from a JSON string or dict.
14471455
14481456
Args:
1449-
data: A JSON string or dict with configuration
1450-
to merge.
1457+
data: A JSON string or dict with configuration to merge.
14511458
14521459
Returns:
14531460
self, for method chaining.
@@ -1475,7 +1482,6 @@ def _c_settings(self):
14751482
class ContextBuilder:
14761483
"""Fluent builder for Context.
14771484
1478-
Matches the c2pa-rs ContextBuilder pattern.
14791485
Use Context.builder() to create an instance.
14801486
"""
14811487

@@ -1486,7 +1492,7 @@ def __init__(self):
14861492
def with_settings(
14871493
self, settings: 'Settings',
14881494
) -> 'ContextBuilder':
1489-
"""Attach Settings to the context being built."""
1495+
"""Attach Settings to the Context being built."""
14901496
self._settings = settings
14911497
return self
14921498

@@ -1508,7 +1514,7 @@ def build(self) -> 'Context':
15081514
class Context(ManagedResource, ContextProvider):
15091515
"""Per-instance context for C2PA operations.
15101516
1511-
A Context may carry Settings and a Signer,
1517+
A Context may carry Settings and a Signer,
15121518
and is passed to Reader or Builder to control their behavior,
15131519
thus propagating settings and configurations by passing
15141520
object as parameter.

0 commit comments

Comments
 (0)