Skip to content

Commit d25fd46

Browse files
datalogics-cgreendatalogics-kam
authored andcommitted
client.py: Streamline payload dicts
Assisted-by: Codex
1 parent d03b36a commit d25fd46

1 file changed

Lines changed: 104 additions & 124 deletions

File tree

src/pdfrest/client.py

Lines changed: 104 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,25 +3207,19 @@ def convert_office_to_pdf(
32073207
) -> PdfRestFileBasedResponse:
32083208
"""Convert a Microsoft Office file (Word, Excel, PowerPoint) to PDF."""
32093209

3210-
payload: dict[str, Any] = {"files": file}
3211-
if output is not None:
3212-
payload["output"] = output
3213-
if compression is not None:
3214-
payload["compression"] = compression
3215-
if downsample is not None:
3216-
payload["downsample"] = downsample
3217-
if tagged_pdf is not None:
3218-
payload["tagged_pdf"] = tagged_pdf
3219-
if locale is not None:
3220-
payload["locale"] = locale
3221-
if page_size is not None:
3222-
payload["page_size"] = page_size
3223-
if page_margin is not None:
3224-
payload["page_margin"] = page_margin
3225-
if page_orientation is not None:
3226-
payload["page_orientation"] = page_orientation
3227-
if web_layout is not None:
3228-
payload["web_layout"] = web_layout
3210+
payload: dict[str, Any] = {
3211+
"files": file,
3212+
"output": output,
3213+
"compression": compression,
3214+
"downsample": downsample,
3215+
"tagged_pdf": tagged_pdf,
3216+
"locale": locale,
3217+
"page_size": page_size,
3218+
"page_margin": page_margin,
3219+
"page_orientation": page_orientation,
3220+
"web_layout": web_layout,
3221+
}
3222+
payload = {key: value for key, value in payload.items() if value is not None}
32293223

32303224
return self._post_file_operation(
32313225
endpoint="/pdf",
@@ -3251,13 +3245,13 @@ def convert_postscript_to_pdf(
32513245
) -> PdfRestFileBasedResponse:
32523246
"""Convert a PostScript or EPS file to PDF."""
32533247

3254-
payload: dict[str, Any] = {"files": file}
3255-
if output is not None:
3256-
payload["output"] = output
3257-
if compression is not None:
3258-
payload["compression"] = compression
3259-
if downsample is not None:
3260-
payload["downsample"] = downsample
3248+
payload: dict[str, Any] = {
3249+
"files": file,
3250+
"output": output,
3251+
"compression": compression,
3252+
"downsample": downsample,
3253+
}
3254+
payload = {key: value for key, value in payload.items() if value is not None}
32613255

32623256
return self._post_file_operation(
32633257
endpoint="/pdf",
@@ -3281,9 +3275,11 @@ def convert_email_to_pdf(
32813275
) -> PdfRestFileBasedResponse:
32823276
"""Convert an RFC822 email file to PDF."""
32833277

3284-
payload: dict[str, Any] = {"files": file}
3285-
if output is not None:
3286-
payload["output"] = output
3278+
payload: dict[str, Any] = {
3279+
"files": file,
3280+
"output": output,
3281+
}
3282+
payload = {key: value for key, value in payload.items() if value is not None}
32873283

32883284
return self._post_file_operation(
32893285
endpoint="/pdf",
@@ -3307,9 +3303,11 @@ def convert_image_to_pdf(
33073303
) -> PdfRestFileBasedResponse:
33083304
"""Convert a supported image file to PDF."""
33093305

3310-
payload: dict[str, Any] = {"files": file}
3311-
if output is not None:
3312-
payload["output"] = output
3306+
payload: dict[str, Any] = {
3307+
"files": file,
3308+
"output": output,
3309+
}
3310+
payload = {key: value for key, value in payload.items() if value is not None}
33133311

33143312
return self._post_file_operation(
33153313
endpoint="/pdf",
@@ -3339,21 +3337,17 @@ def convert_html_to_pdf(
33393337
) -> PdfRestFileBasedResponse:
33403338
"""Convert an uploaded HTML file to PDF."""
33413339

3342-
payload: dict[str, Any] = {"files": file}
3343-
if output is not None:
3344-
payload["output"] = output
3345-
if compression is not None:
3346-
payload["compression"] = compression
3347-
if downsample is not None:
3348-
payload["downsample"] = downsample
3349-
if page_size is not None:
3350-
payload["page_size"] = page_size
3351-
if page_margin is not None:
3352-
payload["page_margin"] = page_margin
3353-
if page_orientation is not None:
3354-
payload["page_orientation"] = page_orientation
3355-
if web_layout is not None:
3356-
payload["web_layout"] = web_layout
3340+
payload: dict[str, Any] = {
3341+
"files": file,
3342+
"output": output,
3343+
"compression": compression,
3344+
"downsample": downsample,
3345+
"page_size": page_size,
3346+
"page_margin": page_margin,
3347+
"page_orientation": page_orientation,
3348+
"web_layout": web_layout,
3349+
}
3350+
payload = {key: value for key, value in payload.items() if value is not None}
33573351

33583352
return self._post_file_operation(
33593353
endpoint="/pdf",
@@ -3383,21 +3377,17 @@ def convert_urls_to_pdf(
33833377
) -> PdfRestFileBasedResponse:
33843378
"""Convert HTML content from one or more URLs to PDF."""
33853379

3386-
payload: dict[str, Any] = {"url": urls}
3387-
if output is not None:
3388-
payload["output"] = output
3389-
if compression is not None:
3390-
payload["compression"] = compression
3391-
if downsample is not None:
3392-
payload["downsample"] = downsample
3393-
if page_size is not None:
3394-
payload["page_size"] = page_size
3395-
if page_margin is not None:
3396-
payload["page_margin"] = page_margin
3397-
if page_orientation is not None:
3398-
payload["page_orientation"] = page_orientation
3399-
if web_layout is not None:
3400-
payload["web_layout"] = web_layout
3380+
payload: dict[str, Any] = {
3381+
"url": urls,
3382+
"output": output,
3383+
"compression": compression,
3384+
"downsample": downsample,
3385+
"page_size": page_size,
3386+
"page_margin": page_margin,
3387+
"page_orientation": page_orientation,
3388+
"web_layout": web_layout,
3389+
}
3390+
payload = {key: value for key, value in payload.items() if value is not None}
34013391

34023392
return self._post_file_operation(
34033393
endpoint="/pdf",
@@ -4809,25 +4799,19 @@ async def convert_office_to_pdf(
48094799
) -> PdfRestFileBasedResponse:
48104800
"""Asynchronously convert a Microsoft Office file to PDF."""
48114801

4812-
payload: dict[str, Any] = {"files": file}
4813-
if output is not None:
4814-
payload["output"] = output
4815-
if compression is not None:
4816-
payload["compression"] = compression
4817-
if downsample is not None:
4818-
payload["downsample"] = downsample
4819-
if tagged_pdf is not None:
4820-
payload["tagged_pdf"] = tagged_pdf
4821-
if locale is not None:
4822-
payload["locale"] = locale
4823-
if page_size is not None:
4824-
payload["page_size"] = page_size
4825-
if page_margin is not None:
4826-
payload["page_margin"] = page_margin
4827-
if page_orientation is not None:
4828-
payload["page_orientation"] = page_orientation
4829-
if web_layout is not None:
4830-
payload["web_layout"] = web_layout
4802+
payload: dict[str, Any] = {
4803+
"files": file,
4804+
"output": output,
4805+
"compression": compression,
4806+
"downsample": downsample,
4807+
"tagged_pdf": tagged_pdf,
4808+
"locale": locale,
4809+
"page_size": page_size,
4810+
"page_margin": page_margin,
4811+
"page_orientation": page_orientation,
4812+
"web_layout": web_layout,
4813+
}
4814+
payload = {key: value for key, value in payload.items() if value is not None}
48314815

48324816
return await self._post_file_operation(
48334817
endpoint="/pdf",
@@ -4853,13 +4837,13 @@ async def convert_postscript_to_pdf(
48534837
) -> PdfRestFileBasedResponse:
48544838
"""Asynchronously convert a PostScript or EPS file to PDF."""
48554839

4856-
payload: dict[str, Any] = {"files": file}
4857-
if output is not None:
4858-
payload["output"] = output
4859-
if compression is not None:
4860-
payload["compression"] = compression
4861-
if downsample is not None:
4862-
payload["downsample"] = downsample
4840+
payload: dict[str, Any] = {
4841+
"files": file,
4842+
"output": output,
4843+
"compression": compression,
4844+
"downsample": downsample,
4845+
}
4846+
payload = {key: value for key, value in payload.items() if value is not None}
48634847

48644848
return await self._post_file_operation(
48654849
endpoint="/pdf",
@@ -4883,9 +4867,11 @@ async def convert_email_to_pdf(
48834867
) -> PdfRestFileBasedResponse:
48844868
"""Asynchronously convert an RFC822 email file to PDF."""
48854869

4886-
payload: dict[str, Any] = {"files": file}
4887-
if output is not None:
4888-
payload["output"] = output
4870+
payload: dict[str, Any] = {
4871+
"files": file,
4872+
"output": output,
4873+
}
4874+
payload = {key: value for key, value in payload.items() if value is not None}
48894875

48904876
return await self._post_file_operation(
48914877
endpoint="/pdf",
@@ -4909,9 +4895,11 @@ async def convert_image_to_pdf(
49094895
) -> PdfRestFileBasedResponse:
49104896
"""Asynchronously convert a supported image file to PDF."""
49114897

4912-
payload: dict[str, Any] = {"files": file}
4913-
if output is not None:
4914-
payload["output"] = output
4898+
payload: dict[str, Any] = {
4899+
"files": file,
4900+
"output": output,
4901+
}
4902+
payload = {key: value for key, value in payload.items() if value is not None}
49154903

49164904
return await self._post_file_operation(
49174905
endpoint="/pdf",
@@ -4941,21 +4929,17 @@ async def convert_html_to_pdf(
49414929
) -> PdfRestFileBasedResponse:
49424930
"""Asynchronously convert an uploaded HTML file to PDF."""
49434931

4944-
payload: dict[str, Any] = {"files": file}
4945-
if output is not None:
4946-
payload["output"] = output
4947-
if compression is not None:
4948-
payload["compression"] = compression
4949-
if downsample is not None:
4950-
payload["downsample"] = downsample
4951-
if page_size is not None:
4952-
payload["page_size"] = page_size
4953-
if page_margin is not None:
4954-
payload["page_margin"] = page_margin
4955-
if page_orientation is not None:
4956-
payload["page_orientation"] = page_orientation
4957-
if web_layout is not None:
4958-
payload["web_layout"] = web_layout
4932+
payload: dict[str, Any] = {
4933+
"files": file,
4934+
"output": output,
4935+
"compression": compression,
4936+
"downsample": downsample,
4937+
"page_size": page_size,
4938+
"page_margin": page_margin,
4939+
"page_orientation": page_orientation,
4940+
"web_layout": web_layout,
4941+
}
4942+
payload = {key: value for key, value in payload.items() if value is not None}
49594943

49604944
return await self._post_file_operation(
49614945
endpoint="/pdf",
@@ -4985,21 +4969,17 @@ async def convert_urls_to_pdf(
49854969
) -> PdfRestFileBasedResponse:
49864970
"""Asynchronously convert HTML content from one or more URLs to PDF."""
49874971

4988-
payload: dict[str, Any] = {"url": urls}
4989-
if output is not None:
4990-
payload["output"] = output
4991-
if compression is not None:
4992-
payload["compression"] = compression
4993-
if downsample is not None:
4994-
payload["downsample"] = downsample
4995-
if page_size is not None:
4996-
payload["page_size"] = page_size
4997-
if page_margin is not None:
4998-
payload["page_margin"] = page_margin
4999-
if page_orientation is not None:
5000-
payload["page_orientation"] = page_orientation
5001-
if web_layout is not None:
5002-
payload["web_layout"] = web_layout
4972+
payload: dict[str, Any] = {
4973+
"url": urls,
4974+
"output": output,
4975+
"compression": compression,
4976+
"downsample": downsample,
4977+
"page_size": page_size,
4978+
"page_margin": page_margin,
4979+
"page_orientation": page_orientation,
4980+
"web_layout": web_layout,
4981+
}
4982+
payload = {key: value for key, value in payload.items() if value is not None}
50034983

50044984
return await self._post_file_operation(
50054985
endpoint="/pdf",

0 commit comments

Comments
 (0)