Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion loopx/extensions/public_source_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
from pathlib import Path
import re
import runpy
import socket
import ssl
import subprocess
Expand All @@ -23,6 +24,12 @@
from html.parser import HTMLParser
from urllib.parse import urljoin, urlsplit, urlunsplit

# Reuse the generated binding without adding this release to the isolated
# worker's module search path or requiring a site-installed LoopX package.
_BARE_SHA256_PATTERN = runpy.run_path(
str(Path(__file__).resolve().parents[1] / "control_plane" / "content_digest.py")
)["BARE_SHA256_PATTERN"]

MAX_BYTES = 4_000_000
MAX_TEXT = 100_000
MAX_IMAGES = 128
Expand Down Expand Up @@ -223,7 +230,7 @@ def _text_page_parameters(offset: int, expected_sha256: str | None) -> None:
if type(offset) is not int or not 0 <= offset <= MAX_BYTES:
raise ValueError("invalid text offset")
if ((expected_sha256 is not None and (not isinstance(expected_sha256, str)
or re.fullmatch(r"[0-9a-f]{64}", expected_sha256) is None))
or _BARE_SHA256_PATTERN.fullmatch(expected_sha256) is None))
or (offset > 0 and expected_sha256 is None)):
raise ValueError("text continuation requires the original source digest")

Expand Down
Loading