document_url
langroid/parsing/document_url.py
Bounded HTTP document retrieval and text decoding.
is_http_url(source)
¶
url_extension_source(source)
¶
Return the URL path or local source used for extension detection.
Source code in langroid/parsing/document_url.py
fetch_url_bytes(url, *, connect_timeout=DEFAULT_CONNECT_TIMEOUT, read_timeout=DEFAULT_READ_TIMEOUT, max_size=DEFAULT_MAX_SIZE, sample_size=None)
¶
Fetch a URL with timeouts and bounded streamed consumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP(S) document URL. |
required |
connect_timeout
|
float
|
Maximum seconds allowed to establish a connection. |
DEFAULT_CONNECT_TIMEOUT
|
read_timeout
|
float
|
Maximum seconds allowed between response bytes. |
DEFAULT_READ_TIMEOUT
|
max_size
|
int
|
Maximum complete response size in bytes. |
DEFAULT_MAX_SIZE
|
sample_size
|
int | None
|
Optional byte count after which sampling may stop early. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[bytes, Mapping[str, str]]
|
The response bytes and headers. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a complete response exceeds |
RequestException
|
If the request fails or times out. |
Source code in langroid/parsing/document_url.py
fetch_configured_url(url, config)
¶
Fetch a complete URL using document parsing configuration.
Source code in langroid/parsing/document_url.py
fetch_url_sample(url, config=None)
¶
Fetch at most 1 KiB using optional parsing configuration.
Source code in langroid/parsing/document_url.py
decode_document_text(content, headers=None, *, html)
¶
Decode document bytes using BOM, HTTP, and HTML declarations.
BOMs take precedence, followed by a valid charset in the HTTP
Content-Type header and, for HTML, encoding detected from its meta
declarations. If none applies, UTF-8 is used with replacement so malformed
or legacy undeclared documents remain ingestible.