MCPcopy
hub / github.com/OpenHands/OpenHands / encode_page_id

Function encode_page_id

openhands/app_server/utils/paging_utils.py:12–26  ·  view source on GitHub ↗

Encode an integer page identifier as an opaque base64 string. This function exists to ensure that page IDs are opaque tokens that do not reveal the underlying pagination strategy to API consumers. The encoding format may change in the future, so consumers should treat page_id as an

(value: int)

Source from the content-addressed store, hash-verified

10
11
12def encode_page_id(value: int) -> str:
13 """Encode an integer page identifier as an opaque base64 string.
14
15 This function exists to ensure that page IDs are opaque tokens that do not
16 reveal the underlying pagination strategy to API consumers. The encoding
17 format may change in the future, so consumers should treat page_id as an
18 opaque string and not attempt to parse or construct it themselves.
19
20 Args:
21 value: The integer value to encode.
22
23 Returns:
24 Base64-encoded string (URL-safe, without padding).
25 """
26 return base64.urlsafe_b64encode(str(value).encode()).decode().rstrip('=')
27
28
29def decode_page_id(page_id: str | None) -> int | None:

Calls

no outgoing calls