kennmarq 0.2.0__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.
kennmarq-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Neuramare
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,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: kennmarq
3
+ Version: 0.2.0
4
+ Summary: Mark AI pictures for the EU AI Act: an invisible watermark and signed, time-stamped C2PA Content Credentials.
5
+ Author: Neuramare
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://kennmarq.com
8
+ Project-URL: Documentation, https://kennmarq.com/docs/sdk/python
9
+ Project-URL: Repository, https://github.com/Kennmarq-com/kennmarq-python
10
+ Project-URL: Changelog, https://kennmarq.com/docs/changelog
11
+ Keywords: c2pa,content credentials,watermark,ai act,trustmark,provenance
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Topic :: Multimedia :: Graphics
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ License-File: THIRD_PARTY_NOTICES.md
19
+ Provides-Extra: local
20
+ Requires-Dist: c2pa-python==0.38.1; extra == "local"
21
+ Requires-Dist: trustmark==0.9.2; extra == "local"
22
+ Requires-Dist: torch>=2.4; extra == "local"
23
+ Requires-Dist: pillow>=10.0; extra == "local"
24
+ Requires-Dist: numpy>=1.26; extra == "local"
25
+ Requires-Dist: cryptography>=42; extra == "local"
26
+ Provides-Extra: safety
27
+ Requires-Dist: kennmarq[local]; extra == "safety"
28
+ Requires-Dist: transformers<6,>=4.57; extra == "safety"
29
+ Requires-Dist: onnxruntime>=1.20; extra == "safety"
30
+ Dynamic: license-file
31
+
32
+ # kennmarq
33
+
34
+ Mark AI pictures, songs and clips for the EU AI Act and California's AI Transparency Act in one call. Each gets an invisible watermark
35
+ (TrustMark for pictures, AudioSeal for sound, Video Seal for frames), and signed, time-stamped C2PA
36
+ Content Credentials that say it was made with AI. Kennmarq.com helps you
37
+ meet the Act's marking duty (Art. 50(2)) and the Code of Practice's two-layer measure; you stay
38
+ responsible for your system.
39
+
40
+ ```bash
41
+ pip install kennmarq # the cloud API: no dependencies
42
+ pip install "kennmarq[local]" # local mode: files never leave your machine
43
+ pip install "kennmarq[safety]" # the safety check on your machine too
44
+ ```
45
+
46
+ A free key marks 1,000 files a month, every feature included: [kennmarq.com](https://kennmarq.com).
47
+ The SDK reads it from `KENNMARQ_API_KEY`.
48
+
49
+ ## Cloud
50
+
51
+ ```python
52
+ from kennmarq import Kennmarq
53
+
54
+ k = Kennmarq()
55
+ result = k.mark("render.png", "render.marked.png", source="created", model="FLUX.1 schnell")
56
+ print(result.mark_id, result.watermark_id, result.marks_used)
57
+ ```
58
+
59
+ The picture goes to Kennmarq.com's servers in Zurich, which mark it in memory and keep nothing.
60
+
61
+ Add `label=True` to draw the EU's visible AI label ("AI GENERATED", or "AI MODIFIED" for edits) into a
62
+ picture or every frame of a clip, before the watermark; `deepfake=True` turns it on by itself, and
63
+ `label_language`, `label_position`, `label_size` and `label_style` shape it
64
+ ([docs](https://kennmarq.com/docs/api/mark#labels)). Labels are drawn in the cloud.
65
+
66
+ ## Songs and clips
67
+
68
+ ```python
69
+ song = k.mark("track.mp3", "track.marked.mp3", model="Song Model 2")
70
+ print(song.marks_counted, song.audio_watermark) # five marks per started minute; "claimed"
71
+
72
+ clip = k.mark("clip.mp4", "clip.marked.mp4", check="ai-act") # waits for the job, then downloads
73
+ print(clip.watermark_id, clip.marks_counted) # five marks per started second
74
+ ```
75
+
76
+ Songs (MP3, WAV, M4A, up to 15 minutes) carry Meta's AudioSeal in the sound, shaped so no one hears
77
+ it; clips (MP4 at up to 1080p, 4,500 frames: 2.5 minutes at 30 frames a second) carry Video Seal in every frame and AudioSeal in their
78
+ sound. Both are marked in the cloud. A clip is a job: `mark()` waits for it and downloads the marked
79
+ clip; `mark(..., wait=False)` returns at once, and `wait_for(mark_id, dest)` finishes later.
80
+
81
+ ## Local mode
82
+
83
+ ```python
84
+ result = k.mark_file("render.png", "render.marked.png", source="created", model="FLUX.1 schnell")
85
+ ```
86
+
87
+ The watermark and the Content Credentials are made on your machine. Only the manifest goes to
88
+ Kennmarq.com: about 13 KB of claim and assertions, never pixels. Kennmarq.com signs and time-stamps it, and
89
+ the SDK puts it back in your file. Before writing anything, the SDK checks the file reads as signed by
90
+ Kennmarq.com, with a validated time-stamp and the watermark in place; if not, it raises `InvalidSignedFile`
91
+ and writes nothing. Each file counts one mark.
92
+
93
+ - Credentials your file already carries (from an upstream model's API, say) are kept as an
94
+ ingredient, as the Code of Practice asks. They travel with the manifest, with any thumbnail their
95
+ signer put in them; `keep_input_credentials=False` keeps and sends none.
96
+ - The watermark's model (TrustMark Q, 65 MB) downloads once, to `~/.cache/kennmarq/models` or
97
+ `KENNMARQ_MODELS_DIR`, and is checked against its pinned SHA-256.
98
+ - Where c2pa-python has no build for your system (Windows, for now), `mark_file` makes the watermark
99
+ on your machine and sends the watermarked picture to the cloud for its manifest (`mode == "hybrid"`).
100
+ - Without a key, `watermark_file()` adds the watermark and the IPTC AI label alone, with no
101
+ Content Credentials.
102
+
103
+ ## The safety check
104
+
105
+ ```python
106
+ answer = k.check("render.png", policy="ai-act") # cloud: two marks
107
+ answer = k.check("render.png", policy="ai-act", local=True) # here: nothing sent, nothing counted
108
+ if answer["verdict"] == "block":
109
+ ...
110
+ ```
111
+
112
+ It screens a picture for what the AI Act's new bans are about (Art. 5(1)(ba) and (bb)): sexual content
113
+ with someone who appears to be a child, and with a realistic face, which needs the person's consent.
114
+ `ai-act` blocks the first and flags the second; `safe-only` also blocks anything explicit. It returns
115
+ a verdict and a reason, never an age or an identity. It's a risk signal with published error rates
116
+ ([docs](https://kennmarq.com/docs/api/check)), not a guarantee: you decide, and stay responsible.
117
+ Locally its models download once (about 2.3 GB). `mark()` and `mark_file()` take `check=` too: a block
118
+ raises `ContentBlocked` and nothing is marked.
119
+
120
+ ## Check a file
121
+
122
+ ```python
123
+ k.verify("render.marked.png") # free, no key needed
124
+ ```
125
+
126
+ What its Content Credentials and its watermark say, and the credential the watermark leads to when the
127
+ metadata was stripped.
128
+
129
+ ## Errors
130
+
131
+ API errors raise `KennmarqError` with the API's `code`, `status` and `request_id`
132
+ ([docs](https://kennmarq.com/docs/errors)). `ContentBlocked` carries the check's answer in `safety`.
133
+
134
+ MIT-licensed. The paid part is Kennmarq.com's signature, the time-stamps and the stored credentials.
135
+ The face model and the prompt embeddings bundled for the safety check carry their own licences:
136
+ [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
@@ -0,0 +1,105 @@
1
+ # kennmarq
2
+
3
+ Mark AI pictures, songs and clips for the EU AI Act and California's AI Transparency Act in one call. Each gets an invisible watermark
4
+ (TrustMark for pictures, AudioSeal for sound, Video Seal for frames), and signed, time-stamped C2PA
5
+ Content Credentials that say it was made with AI. Kennmarq.com helps you
6
+ meet the Act's marking duty (Art. 50(2)) and the Code of Practice's two-layer measure; you stay
7
+ responsible for your system.
8
+
9
+ ```bash
10
+ pip install kennmarq # the cloud API: no dependencies
11
+ pip install "kennmarq[local]" # local mode: files never leave your machine
12
+ pip install "kennmarq[safety]" # the safety check on your machine too
13
+ ```
14
+
15
+ A free key marks 1,000 files a month, every feature included: [kennmarq.com](https://kennmarq.com).
16
+ The SDK reads it from `KENNMARQ_API_KEY`.
17
+
18
+ ## Cloud
19
+
20
+ ```python
21
+ from kennmarq import Kennmarq
22
+
23
+ k = Kennmarq()
24
+ result = k.mark("render.png", "render.marked.png", source="created", model="FLUX.1 schnell")
25
+ print(result.mark_id, result.watermark_id, result.marks_used)
26
+ ```
27
+
28
+ The picture goes to Kennmarq.com's servers in Zurich, which mark it in memory and keep nothing.
29
+
30
+ Add `label=True` to draw the EU's visible AI label ("AI GENERATED", or "AI MODIFIED" for edits) into a
31
+ picture or every frame of a clip, before the watermark; `deepfake=True` turns it on by itself, and
32
+ `label_language`, `label_position`, `label_size` and `label_style` shape it
33
+ ([docs](https://kennmarq.com/docs/api/mark#labels)). Labels are drawn in the cloud.
34
+
35
+ ## Songs and clips
36
+
37
+ ```python
38
+ song = k.mark("track.mp3", "track.marked.mp3", model="Song Model 2")
39
+ print(song.marks_counted, song.audio_watermark) # five marks per started minute; "claimed"
40
+
41
+ clip = k.mark("clip.mp4", "clip.marked.mp4", check="ai-act") # waits for the job, then downloads
42
+ print(clip.watermark_id, clip.marks_counted) # five marks per started second
43
+ ```
44
+
45
+ Songs (MP3, WAV, M4A, up to 15 minutes) carry Meta's AudioSeal in the sound, shaped so no one hears
46
+ it; clips (MP4 at up to 1080p, 4,500 frames: 2.5 minutes at 30 frames a second) carry Video Seal in every frame and AudioSeal in their
47
+ sound. Both are marked in the cloud. A clip is a job: `mark()` waits for it and downloads the marked
48
+ clip; `mark(..., wait=False)` returns at once, and `wait_for(mark_id, dest)` finishes later.
49
+
50
+ ## Local mode
51
+
52
+ ```python
53
+ result = k.mark_file("render.png", "render.marked.png", source="created", model="FLUX.1 schnell")
54
+ ```
55
+
56
+ The watermark and the Content Credentials are made on your machine. Only the manifest goes to
57
+ Kennmarq.com: about 13 KB of claim and assertions, never pixels. Kennmarq.com signs and time-stamps it, and
58
+ the SDK puts it back in your file. Before writing anything, the SDK checks the file reads as signed by
59
+ Kennmarq.com, with a validated time-stamp and the watermark in place; if not, it raises `InvalidSignedFile`
60
+ and writes nothing. Each file counts one mark.
61
+
62
+ - Credentials your file already carries (from an upstream model's API, say) are kept as an
63
+ ingredient, as the Code of Practice asks. They travel with the manifest, with any thumbnail their
64
+ signer put in them; `keep_input_credentials=False` keeps and sends none.
65
+ - The watermark's model (TrustMark Q, 65 MB) downloads once, to `~/.cache/kennmarq/models` or
66
+ `KENNMARQ_MODELS_DIR`, and is checked against its pinned SHA-256.
67
+ - Where c2pa-python has no build for your system (Windows, for now), `mark_file` makes the watermark
68
+ on your machine and sends the watermarked picture to the cloud for its manifest (`mode == "hybrid"`).
69
+ - Without a key, `watermark_file()` adds the watermark and the IPTC AI label alone, with no
70
+ Content Credentials.
71
+
72
+ ## The safety check
73
+
74
+ ```python
75
+ answer = k.check("render.png", policy="ai-act") # cloud: two marks
76
+ answer = k.check("render.png", policy="ai-act", local=True) # here: nothing sent, nothing counted
77
+ if answer["verdict"] == "block":
78
+ ...
79
+ ```
80
+
81
+ It screens a picture for what the AI Act's new bans are about (Art. 5(1)(ba) and (bb)): sexual content
82
+ with someone who appears to be a child, and with a realistic face, which needs the person's consent.
83
+ `ai-act` blocks the first and flags the second; `safe-only` also blocks anything explicit. It returns
84
+ a verdict and a reason, never an age or an identity. It's a risk signal with published error rates
85
+ ([docs](https://kennmarq.com/docs/api/check)), not a guarantee: you decide, and stay responsible.
86
+ Locally its models download once (about 2.3 GB). `mark()` and `mark_file()` take `check=` too: a block
87
+ raises `ContentBlocked` and nothing is marked.
88
+
89
+ ## Check a file
90
+
91
+ ```python
92
+ k.verify("render.marked.png") # free, no key needed
93
+ ```
94
+
95
+ What its Content Credentials and its watermark say, and the credential the watermark leads to when the
96
+ metadata was stripped.
97
+
98
+ ## Errors
99
+
100
+ API errors raise `KennmarqError` with the API's `code`, `status` and `request_id`
101
+ ([docs](https://kennmarq.com/docs/errors)). `ContentBlocked` carries the check's answer in `safety`.
102
+
103
+ MIT-licensed. The paid part is Kennmarq.com's signature, the time-stamps and the stored credentials.
104
+ The face model and the prompt embeddings bundled for the safety check carry their own licences:
105
+ [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
@@ -0,0 +1,41 @@
1
+ # Third-party notices
2
+
3
+ The safety check (`kennmarq/local/safety/`) ships two small files made by others. Its larger models
4
+ aren't part of this package: `fetch()` downloads them from their publishers, each pinned to a commit and
5
+ checked against its SHA-256, under their own licences (listed in `kennmarq/local/safety/models.py`).
6
+
7
+ ## YuNet face detector
8
+
9
+ `kennmarq/local/safety/assets/face_detection_yunet_2023mar.onnx`, from OpenCV Zoo
10
+ (https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet), unchanged.
11
+
12
+ ```
13
+ MIT License
14
+
15
+ Copyright (c) 2020 Shiqi Yu <shiqi.yu@gmail.com>
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to deal
19
+ in the Software without restriction, including without limitation the rights
20
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in all
25
+ copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
34
+ ```
35
+
36
+ ## Prompt embeddings
37
+
38
+ `kennmarq/local/safety/assets/age_gate_prompts.npz` holds the embeddings of `age.py`'s photo and
39
+ drawing prompts, computed with the text half of google/siglip-base-patch16-224
40
+ (https://huggingface.co/google/siglip-base-patch16-224), licensed under the Apache License 2.0
41
+ (https://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,16 @@
1
+ """Kennmarq.com's Python SDK: mark AI pictures, songs and clips for the EU AI Act with an invisible
2
+ watermark and signed, time-stamped C2PA Content Credentials, in the cloud or (pictures) on your own machine.
3
+
4
+ from kennmarq import Kennmarq
5
+ k = Kennmarq() # reads KENNMARQ_API_KEY
6
+ k.mark("render.png", "render.marked.png") # cloud
7
+ k.mark("song.mp3", "song.marked.mp3") # a song, in the cloud
8
+ k.mark("clip.mp4", "clip.marked.mp4") # a clip: a job, waited for and downloaded
9
+ k.mark_file("render.png", "render.marked.png") # local: only the manifest leaves this machine
10
+ """
11
+ from ._version import __version__
12
+ from .client import Kennmarq, MarkResult
13
+ from .errors import ContentBlocked, InvalidSignedFile, KennmarqError, LocalModeUnavailable, MissingApiKey
14
+
15
+ __all__ = ["ContentBlocked", "InvalidSignedFile", "Kennmarq", "KennmarqError", "LocalModeUnavailable", "MarkResult",
16
+ "MissingApiKey", "__version__"]
@@ -0,0 +1,133 @@
1
+ """HTTP for the SDK, with the standard library only: the base install depends on nothing."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import secrets
6
+ import time
7
+ import urllib.error
8
+ import urllib.parse
9
+ import urllib.request
10
+ from dataclasses import dataclass
11
+ from typing import Any
12
+
13
+ from ._version import __version__
14
+ from .errors import ContentBlocked, KennmarqError
15
+
16
+ USER_AGENT = f"kennmarq-python/{__version__}"
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class Reply:
21
+ status: int
22
+ headers: dict[str, str]
23
+ body: bytes
24
+
25
+ def json(self) -> Any:
26
+ return json.loads(self.body)
27
+
28
+
29
+ def multipart(fields: dict[str, Any]) -> tuple[bytes, str]:
30
+ """multipart/form-data: a str value is a field, a (filename, bytes, content type) tuple a file."""
31
+ boundary = "kennmarq-" + secrets.token_hex(12)
32
+ parts: list[bytes] = []
33
+ for name, value in fields.items():
34
+ if value is None:
35
+ continue
36
+ if isinstance(value, tuple):
37
+ filename, data, content_type = value
38
+ head = (f'--{boundary}\r\nContent-Disposition: form-data; name="{name}"; filename="{filename}"\r\n'
39
+ f"Content-Type: {content_type}\r\n\r\n")
40
+ parts.append(head.encode() + data + b"\r\n")
41
+ else:
42
+ parts.append(f'--{boundary}\r\nContent-Disposition: form-data; name="{name}"\r\n\r\n{value}\r\n'.encode())
43
+ parts.append(f"--{boundary}--\r\n".encode())
44
+ return b"".join(parts), f"multipart/form-data; boundary={boundary}"
45
+
46
+
47
+ class _NoRedirect(urllib.request.HTTPRedirectHandler):
48
+ def redirect_request(self, *args, **kwargs): # an API call never follows a redirect elsewhere
49
+ return None
50
+
51
+
52
+ # A 429 that says to come back within a minute (the plan's calls a minute, for all of an organisation's keys
53
+ # together; a clip waiting for a free slot) is waited out, at most this many times. A longer wait (a day's
54
+ # cap) raises at once.
55
+ RETRIES_429 = 3
56
+ RETRY_429_MAX_S = 61
57
+
58
+
59
+ def _retry_after(reply: "Reply") -> int | None:
60
+ value = reply.headers.get("retry-after", "")
61
+ return int(value) if value.isdigit() else None
62
+
63
+
64
+ class Http:
65
+ def __init__(self, base_url: str, api_key: str | None, timeout: float):
66
+ self.base_url = base_url.rstrip("/")
67
+ self.api_key = api_key
68
+ self.timeout = timeout
69
+ self._opener = urllib.request.build_opener(_NoRedirect)
70
+
71
+ def request(self, method: str, path: str, *, body: bytes | None = None, content_type: str | None = None,
72
+ query: dict[str, str] | None = None, auth: bool = True) -> Reply:
73
+ url = self.base_url + path + ("?" + urllib.parse.urlencode(query) if query else "")
74
+ headers = {"User-Agent": USER_AGENT, "Accept": "application/json, */*"}
75
+ if content_type:
76
+ headers["Content-Type"] = content_type
77
+ if auth and self.api_key:
78
+ headers["Authorization"] = f"Bearer {self.api_key}"
79
+ for attempt in range(RETRIES_429 + 1):
80
+ request = urllib.request.Request(url, data=body, method=method, headers=headers)
81
+ try:
82
+ with self._opener.open(request, timeout=self.timeout) as response:
83
+ reply = Reply(response.status, {k.lower(): v for k, v in response.headers.items()}, response.read())
84
+ except urllib.error.HTTPError as error:
85
+ reply = Reply(error.code, {k.lower(): v for k, v in error.headers.items()}, error.read())
86
+ except (urllib.error.URLError, OSError) as error:
87
+ raise KennmarqError(f"couldn't reach {self.base_url}: {error}") from error
88
+ wait = _retry_after(reply) if reply.status == 429 else None
89
+ if wait is None or wait > RETRY_429_MAX_S or attempt == RETRIES_429:
90
+ break
91
+ time.sleep(wait)
92
+ if reply.status >= 400:
93
+ raise _error(reply)
94
+ return reply
95
+
96
+ def get_url(self, url: str) -> bytes:
97
+ """GET a download link (a clip's marked file, presigned). Never with our key: the link is the permission."""
98
+ request = urllib.request.Request(url, method="GET", headers={"User-Agent": USER_AGENT})
99
+ try:
100
+ with self._opener.open(request, timeout=self.timeout) as response:
101
+ return response.read()
102
+ except urllib.error.HTTPError as error:
103
+ raise KennmarqError(f"the download was refused (HTTP {error.code})", status=error.code) from error
104
+ except (urllib.error.URLError, OSError) as error:
105
+ raise KennmarqError(f"couldn't download the file: {error}") from error
106
+
107
+ def put_upload(self, url: str, body: bytes, headers: dict[str, str]) -> None:
108
+ """PUT a file to an upload's presigned URL (S3). Never with our key: the URL is the permission."""
109
+ request = urllib.request.Request(url, data=body, method="PUT", headers={"User-Agent": USER_AGENT, **headers})
110
+ try:
111
+ with self._opener.open(request, timeout=self.timeout) as response:
112
+ status = response.status
113
+ except urllib.error.HTTPError as error:
114
+ status = error.code
115
+ except (urllib.error.URLError, OSError) as error:
116
+ raise KennmarqError(f"couldn't upload the file: {error}") from error
117
+ if status >= 300:
118
+ raise KennmarqError(f"the upload was refused (HTTP {status})", status=status)
119
+
120
+
121
+ def _error(reply: Reply) -> KennmarqError:
122
+ try:
123
+ body = reply.json()
124
+ except ValueError:
125
+ body = None
126
+ detail = body.get("error") if isinstance(body, dict) else None
127
+ detail = detail if isinstance(detail, dict) else {}
128
+ message = str(detail.get("message") or f"HTTP {reply.status}")
129
+ kwargs = {"status": reply.status, "code": detail.get("code"), "request_id": detail.get("request_id") or reply.headers.get("x-request-id"),
130
+ "body": body}
131
+ if detail.get("code") == "content_blocked" and isinstance(body.get("safety"), dict):
132
+ return ContentBlocked(message, body["safety"], **kwargs)
133
+ return KennmarqError(message, **kwargs)
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"