Skip to content

Commit 0d5939a

Browse files
_internal.py: Remove RGB, CMYK validators
Validators are outmoded by other validation Update tests Assisted-by: Codex
1 parent bd49bed commit 0d5939a

2 files changed

Lines changed: 5 additions & 47 deletions

File tree

src/pdfrest/models/_internal.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -588,48 +588,6 @@ class ExtractImagesPayload(BaseModel):
588588
CmykChannel = Annotated[int, Field(ge=0, le=100)]
589589

590590

591-
def _validate_rgb_values(value: Any) -> tuple[int, int, int] | None:
592-
normalized = _split_comma_string(value)
593-
if normalized is None:
594-
return None
595-
if len(normalized) != 3:
596-
msg = "text_color_rgb must have exactly 3 values."
597-
raise ValueError(msg)
598-
channels: list[int] = []
599-
for channel in normalized:
600-
try:
601-
numeric = int(channel)
602-
except (TypeError, ValueError) as exc:
603-
msg = "text_color_rgb values must be integers."
604-
raise ValueError(msg) from exc
605-
if not 0 <= numeric <= 255:
606-
msg = "text_color_rgb values must be between 0 and 255."
607-
raise ValueError(msg)
608-
channels.append(numeric)
609-
return (channels[0], channels[1], channels[2])
610-
611-
612-
def _validate_cmyk_values(value: Any) -> tuple[int, int, int, int] | None:
613-
normalized = _split_comma_string(value)
614-
if normalized is None:
615-
return None
616-
if len(normalized) != 4:
617-
msg = "text_color_cmyk must have exactly 4 values."
618-
raise ValueError(msg)
619-
channels: list[int] = []
620-
for channel in normalized:
621-
try:
622-
numeric = int(channel)
623-
except (TypeError, ValueError) as exc:
624-
msg = "text_color_cmyk values must be integers."
625-
raise ValueError(msg) from exc
626-
if not 0 <= numeric <= 100:
627-
msg = "text_color_cmyk values must be between 0 and 100."
628-
raise ValueError(msg)
629-
channels.append(numeric)
630-
return (channels[0], channels[1], channels[2], channels[3])
631-
632-
633591
class PdfLiteralRedactionModel(BaseModel):
634592
type: Literal["literal"]
635593
value: Annotated[str, Field(min_length=1)]
@@ -1107,13 +1065,13 @@ class PdfAddTextObjectModel(BaseModel):
11071065
text_color_rgb: Annotated[
11081066
tuple[RgbChannel, RgbChannel, RgbChannel] | None,
11091067
Field(serialization_alias="text_color_rgb", default=None),
1110-
BeforeValidator(_validate_rgb_values),
1068+
BeforeValidator(_split_comma_string),
11111069
PlainSerializer(_serialize_as_comma_separated_string),
11121070
] = None
11131071
text_color_cmyk: Annotated[
11141072
tuple[CmykChannel, CmykChannel, CmykChannel, CmykChannel] | None,
11151073
Field(serialization_alias="text_color_cmyk", default=None),
1116-
BeforeValidator(_validate_cmyk_values),
1074+
BeforeValidator(_split_comma_string),
11171075
PlainSerializer(_serialize_as_comma_separated_string),
11181076
] = None
11191077
text_size: Annotated[

tests/test_add_text_to_pdf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def handler(_: httpx.Request) -> httpx.Response:
284284
PdfRestClient(api_key=VALID_API_KEY, transport=transport) as client,
285285
pytest.raises(
286286
ValidationError,
287-
match=re.escape("text_color_rgb values must be between 0 and 255."),
287+
match="less than or equal to 255",
288288
),
289289
):
290290
client.add_text_to_pdf(
@@ -474,7 +474,7 @@ def handler(_: httpx.Request) -> httpx.Response:
474474
async with AsyncPdfRestClient(api_key=ASYNC_API_KEY, transport=transport) as client:
475475
with pytest.raises(
476476
ValidationError,
477-
match=re.escape("text_color_cmyk values must be between 0 and 100."),
477+
match="less than or equal to 100",
478478
):
479479
await client.add_text_to_pdf(
480480
make_pdf_file(PdfRestFileID.generate(1)),
@@ -582,7 +582,7 @@ def handler(_: httpx.Request) -> httpx.Response:
582582
async with AsyncPdfRestClient(api_key=ASYNC_API_KEY, transport=transport) as client:
583583
with pytest.raises(
584584
ValidationError,
585-
match=re.escape("text_color_rgb values must be between 0 and 255."),
585+
match="less than or equal to 255",
586586
):
587587
await client.add_text_to_pdf(
588588
make_pdf_file(PdfRestFileID.generate(1)),

0 commit comments

Comments
 (0)