Public Types API
btpc.types
Shared immutable values for protocol modes, hashes, bytes, and paths.
UNCHANGED
HashValue
class HashValue(bytes: bytes)
Store a protocol hash as immutable raw bytes.
Attributes:
- bytes: Raw digest bytes.
bytes
bytes: bytes
hex
hex: str
Return lowercase hexadecimal text.
ParseOptions
class ParseOptions(max_total_input: int | None = None, max_owned_allocation: int | None = None, max_integer_digits: int | None = None)
Limit parser resource use before accepting owned metainfo.
None uses the core’s safe default for each limit. Limits apply equally to
Metainfo.from_bytes and Metainfo.read.
Attributes:
- max_total_input: Maximum encoded metainfo bytes accepted before parsing.
- max_owned_allocation: Maximum cumulative allocation for the owned parse.
- max_integer_digits: Maximum decimal digits in one bencoded integer.
Examples:
>>> from btpc import Metainfo, ParseOptions, ResourceLimitError
>>> options = ParseOptions(max_total_input=4)
>>> try:
... Metainfo.from_bytes(b"d4:infoe", options=options)
... except ResourceLimitError as error:
... assert error.limit == "total input"
max_total_input
max_total_input: int | None
max_owned_allocation
max_owned_allocation: int | None
max_integer_digits
max_integer_digits: int | None
TorrentBytes
class TorrentBytes(raw: bytes)
Preserve a torrent byte string without assuming text encoding.
Attributes:
- raw: Exact protocol bytes.
raw
raw: bytes
text
text: str | None
Return UTF-8 text only when decoding is lossless.
TorrentMode
class TorrentMode
Validated BitTorrent protocol representation.
V1
V2
HYBRID
TorrentPath
class TorrentPath(components: tuple[TorrentBytes, ...])
Preserve and validate a torrent path as raw byte components.
Attributes:
- components: Non-empty safe path components in torrent order.
components
components: tuple[TorrentBytes, ...]
text
text: tuple[str, ...] | None
Return decoded components only when every component is UTF-8.
to_path
to_path() -> Path | None
Return a platform path only when every component decodes safely.