httk.serve.web.widgets¶
Static, safe widget authoring contracts and discovery helpers.
Submodules¶
Attributes¶
Largest individual trusted widget asset accepted by |
|
The deliberately small content-type vocabulary for internal widget assets. |
Exceptions¶
A declared OPTIMADE table shell cannot meet the browser protocol. |
Classes¶
Adapt a module-level |
|
Define the advanced immutable widget protocol. |
|
Declare an immutable, deployment-relative asset from trusted widget code. |
|
Provide immutable request and page information to a widget. |
|
Register built-in widgets whose aliases do not resolve site widgets. |
|
Return explicitly trusted HTML and its declared widget assets. |
|
Load site widgets without allowing paths to escape their directory. |
Functions¶
|
Wrap a callable as a |
|
Mark a widget's reviewed HTML output as trusted. |
Return the registered-compatible built-in OPTIMADE protocol module. |
|
|
Return the protocol module URL for a page. |
Package Contents¶
- httk.serve.web.widgets.MAX_WIDGET_ASSET_BYTES = 1000000[source]¶
Largest individual trusted widget asset accepted by
WidgetAsset.
- httk.serve.web.widgets.SUPPORTED_WIDGET_ASSET_CONTENT_TYPES[source]¶
The deliberately small content-type vocabulary for internal widget assets.
- class httk.serve.web.widgets.FunctionWidget[source]¶
Adapt a module-level
renderfacade to the widget protocol.- Parameters:
name – Canonical widget name.
render_function – Function used to render the widget.
source – Source identifier for diagnostics and discovery.
- render_function: WidgetRenderer¶
- render(context, **props)[source]¶
Render the widget through its wrapped callable.
- Parameters:
context (WidgetContext) – Immutable widget invocation context.
**props (object) – Literal widget properties.
- Returns:
HTML string or explicitly trusted render result.
- Return type:
- class httk.serve.web.widgets.Widget[source]¶
Bases:
ProtocolDefine the advanced immutable widget protocol.
- class httk.serve.web.widgets.WidgetAsset[source]¶
Declare an immutable, deployment-relative asset from trusted widget code.
pathis relative to/_httk/serve/assets/and is never interpreted as a filesystem path. The engine serves only assets it has registered while rendering this site instance.- Parameters:
path – Safe path below
/_httk/serve/assets/.content – Immutable asset bytes.
content_type – Supported asset content type.
- class httk.serve.web.widgets.WidgetContext[source]¶
Provide immutable request and page information to a widget.
- Parameters:
route – Route containing the widget.
render_mode –
servefor live rendering orpublishfor static output.widget_id – Stable identifier for this widget placement.
query – Request query values.
postvars – Parsed request body values.
page – Page metadata and context.
source_path – Source file containing the widget invocation.
url_for – Builder for site-relative URLs.
absolute_url_for – Builder for absolute site URLs.
table_runtime – Engine-local table runtime when available.
- query: collections.abc.Mapping[str, str]¶
- postvars: collections.abc.Mapping[str, str]¶
- page: collections.abc.Mapping[str, object]¶
- source_path: pathlib.Path¶
- url_for: collections.abc.Callable[[str], str]¶
- absolute_url_for: collections.abc.Callable[[str], str]¶
- class httk.serve.web.widgets.WidgetRegistry[source]¶
Register built-in widgets whose aliases do not resolve site widgets.
- register(widget, *, alias=None)[source]¶
Register one built-in widget and optional display alias.
- Parameters:
- Raises:
ValueError – If the name or alias is already registered.
- class httk.serve.web.widgets.WidgetRenderResult[source]¶
Return explicitly trusted HTML and its declared widget assets.
- Parameters:
html – Trusted HTML output.
assets – Immutable assets used by the output.
- assets: tuple[WidgetAsset, Ellipsis] = ()¶
- httk.serve.web.widgets.function_widget(render, *, name='', source='')[source]¶
Wrap a callable as a
FunctionWidget.Site-local modules normally need no wrapper: a module-level
renderis discovered automatically. The helper is useful for explicit definitions.- Parameters:
render (WidgetRenderer) – Function used to render the widget.
name (str) – Canonical widget name.
source (str) – Source identifier for diagnostics and discovery.
- Returns:
Immutable function-backed widget.
- Return type:
- httk.serve.web.widgets.trusted_html(value)[source]¶
Mark a widget’s reviewed HTML output as trusted.
- Parameters:
value (str) – HTML reviewed by the widget author.
- Returns:
Trusted widget render result.
- Return type:
- class httk.serve.web.widgets.SiteWidgetLoader(widgets_dir)[source]¶
Load site widgets without allowing paths to escape their directory.
- Parameters:
widgets_dir (pathlib.Path) – Directory containing trusted site widget modules.
- widgets_dir¶
- resolve(name)[source]¶
Resolve and load one site-local widget.
- Parameters:
name (str) – Site widget name beginning with
site..- Returns:
Loaded widget, or
Nonewhen the name or file is absent.- Raises:
ValueError – If the widget module or definition is invalid.
- Return type:
- httk.serve.web.widgets.optimade_protocol_asset()[source]¶
Return the registered-compatible built-in OPTIMADE protocol module.
- Returns:
The protocol module asset used by
optimade_table.- Return type:
- httk.serve.web.widgets.optimade_protocol_href(context)[source]¶
Return the protocol module URL for a page.
- Parameters:
context (httk.serve.web.widgets.core.WidgetContext) – Widget invocation context.
- Returns:
Deployment-relative protocol module URL.
- Return type:
- exception httk.serve.web.widgets.OptimadeTableProtocolError[source]¶
Bases:
ValueErrorA declared OPTIMADE table shell cannot meet the browser protocol.