Repository navigation
PDFCLOUD-6573 Add TDM reservation policy support #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
datalogics-tsmith
wants to merge
4
commits into
main
Choose a base branch
from
pdfcloud-6573-add-tdm-reservation-policy-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02db388
client: Add TDM reservation policy support
datalogics-tsmith 1006dfb
tests: Verify TDM reservation live
datalogics-tsmith 77186be
docs: Document TDM reservation workflow
datalogics-tsmith f6d9d71
pyproject: Bump package version to 1.7.0
datalogics-tsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
examples/apply_tdm_reservation/apply_tdm_reservation_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # /// script | ||
| # requires-python = ">=3.10" | ||
| # dependencies = ["pdfrest", "python-dotenv"] | ||
| # /// | ||
| """Apply a text-and-data-mining reservation policy to a PDF. | ||
|
|
||
| This sample demonstrates how to: | ||
|
|
||
| 1. Load ``PDFREST_API_KEY`` from the environment or a local ``.env`` file. | ||
| 2. Upload the checked-in ``examples/resources/report.pdf`` input. | ||
| 3. Embed a URL for hosted TDM terms or a machine-readable policy document. | ||
| 4. Print the generated PDF metadata. | ||
|
|
||
| Replace ``POLICY_URL`` with the URL of your hosted policy in a real integration. | ||
| Set ``PDFREST_BASE_URL`` only for a self-hosted deployment. pdfRest stores the | ||
| URL without fetching or inspecting its destination. Run from the repository root with | ||
| ``uv run examples/apply_tdm_reservation/apply_tdm_reservation_example.py``. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| from pdfrest import PdfRestClient | ||
|
|
||
| RESOURCE_DIRECTORY = Path(__file__).resolve().parents[1] / "resources" | ||
| INPUT_PATH = RESOURCE_DIRECTORY / "report.pdf" | ||
| POLICY_URL = "https://example.com/terms/tdm-policy" | ||
|
|
||
|
|
||
| def apply_tdm_reservation() -> None: | ||
| """Upload a PDF and add a URL-based TDM reservation policy.""" | ||
| load_dotenv() | ||
| base_url = os.getenv("PDFREST_BASE_URL") | ||
|
|
||
| with PdfRestClient(base_url=base_url) as client: | ||
| uploaded_pdf = client.files.create_from_paths(INPUT_PATH)[0] | ||
| response = client.apply_tdm_reservation( | ||
| uploaded_pdf, | ||
| policy=POLICY_URL, | ||
| output="report-with-tdm-reservation", | ||
| ) | ||
|
|
||
| print(f"Input ID: {response.input_id}") | ||
| print(f"Output file: {response.output_file.name}") | ||
| print(f"Output MIME type: {response.output_file.type}") | ||
| print(f"Output URL: {response.output_file.url}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": # pragma: no cover - manual example | ||
| apply_tdm_reservation() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Reject malformed URLs with strict parsing
validate_python(value)acceptshttps:/example.com/policy,https:example.com/policy, andhttps:///example.com/policyby repairing the separators internally. Because the validator returns the original string, those malformed values still reach the API unchanged. Please callvalidate_python(value, strict=True)and continue returning the original value so valid policy URLs are never rewritten.Please add parametrized regression tests for all three malformed forms through distinct sync and async client tests, using a fail-if-called transport to prove rejection before any HTTP request. Also test that valid URLs (including a bare origin and an encoded path/query/fragment) serialize exactly as supplied. Retain the existing whitespace, backslash, and malformed-percent checks.