webmentions.handlers package
Module contents
- class webmentions.handlers.WebmentionsHandler(storage: WebmentionsStorage, *, base_url: str | None = None, http_timeout: float = 10.0, user_agent: str = 'WebmentionSender', on_mention_processed: Callable[[Webmention], None] | None = None, on_mention_deleted: Callable[[Webmention], None] | None = None, initial_mention_status: WebmentionStatus = WebmentionStatus.CONFIRMED, **kwargs)[source]
Bases:
objectWebmentions handler.
- Parameters:
storage – The Webmentions storage backend
base_url – The base URL of the server, used to validate target URLs
http_timeout – The HTTP timeout for fetching source URLs
user_agent – The User-Agent header to use when fetching source URLs
on_mention_processed – A callback to call when a Webmention is processed
on_mention_deleted – A callback to call when a Webmention is deleted
initial_mention_status – The initial status of Webmentions (see
WebmentionStatus). If not specified, defaults toWebmentionStatus.CONFIRMED. If you set this toWebmentionStatus.PENDINGthen you will need to manually mark mentions as confirmed on your storage, or create your onon_mention_processedthat performs custom filtering or moderation and callshandler.storage.store_webmention(webmention)with the right status after processing.
- process_incoming_webmention(source_url: str | None, target_url: str | None) Any[source]
Process an incoming Webmention.
- Parameters:
source_url – The source URL of the Webmention
target_url – The target URL of the Webmention
- process_outgoing_webmentions(source_url: str, *, text: str | None = None, text_format: ContentTextFormat | None = None) Any[source]
Process an outgoing Webmention.
- Parameters:
source_url – The source URL of the Webmention. Ignored if text is provided.
text – The text of the Webmention. If not provided, the source URL will be fetched.
text_format – The text format of the Webmention. If not provided, it will be inferred from the source URL or text.
- render_webmention(webmention: Webmention, template: str | Path | Template | None = None) Markup[source]
Render a Webmention as a
Markupobject that can be imported as safe HTML snippets in your Jinja2 templates.- Parameters:
webmention – The Webmention to render
template – The template to use. It can be a path, a Jinja2 Template object or a template string. If not provided, the default template
webmentions/templates/webmention.htmlwill be used.
- Returns:
The rendered templates
- render_webmentions(webmentions: Collection[Webmention], template: str | Path | Template | None = None) Markup[source]
Render a list of Webmentions as a
Markupobject that can be imported as safe HTML snippets in your Jinja2 templates.- Parameters:
webmentions – The Webmentions to render
template – The template to use. It can be a path, a Jinja2 Template object or a template string. If not provided, the default template
webmentions/templates/webmention.htmlwill be used.
- Returns:
The rendered templates
- retrieve_stored_webmentions(resource: str, direction: WebmentionDirection) list[Webmention][source]
Retrieve stored Webmentions for a given URL.
- Parameters:
resource – The resource URL
direction – The direction of the Webmentions (inbound or outbound)
- Returns:
A list of Webmentions