MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / _download_pdf

Function _download_pdf

agents/reading-agent/main.py:1936–1952  ·  view source on GitHub ↗
(pdf_url: str, title: str, referer: Optional[str] = None)

Source from the content-addressed store, hash-verified

1934
1935def _download_pdf(pdf_url: str, title: str, referer: Optional[str] = None) -> str:
1936 response = _http_get(
1937 pdf_url,
1938 timeout=PDF_DOWNLOAD_TIMEOUT,
1939 referer=referer,
1940 accept_pdf=True,
1941 )
1942 content_type = str(response.headers.get("Content-Type") or "").lower()
1943 if "application/pdf" not in content_type and not response.content.startswith(b"%PDF"):
1944 raise ValueError(
1945 f"Resolved URL did not return a PDF (content-type={content_type or 'unknown'})"
1946 )
1947
1948 safe_prefix = re.sub(r"[^A-Za-z0-9]+", "_", title or "paper").strip("_")[:40] or "paper"
1949 with tempfile.NamedTemporaryFile(prefix=f"{safe_prefix}_", suffix=".pdf", delete=False) as temp_file:
1950 temp_file.write(response.content)
1951 return temp_file.name
1952
1953
1954def _persist_pdf_file(
1955 source_pdf_path: str,

Callers 1

Calls 2

getMethod · 0.80
_http_getFunction · 0.70

Tested by

no test coverage detected