PyXWF.Site — A whole Website

The heart of PyXWF is beating in the Site instance. It accepts requests and passes them through the tree defined in the sitemap xml.

class PyXWF.Site.Site(sitemap_file, default_url_root=None, **kwargs)[source]

Represent and maintain a complete PyXWF framework instance. The sitemap is loaded from sitemap_file. Optionally, one can specify a default_url_root which is used if no URL root is specified in the sitemap XML.

parser_registry

An instance of ParserRegistry local to the current site. This is the preferred method to access parsers.

hooks

An instance of HookRegistry for this site. See Hooks available on Site objects for a reference of existing hooks.

add_crumb(crumb)[source]

Add the given crumb to the Sites crumb registry. May throw a ValueError if the ID is invalied or duplicated with an already existing registry entry.

get_message(ctx)[source]

Handle a request in the given Context ctx.

get_node(ID)[source]

Retrieve the node which has the ID ID.

handle_not_found(ctx, resource_name)[source]

Handle a NotFound exception if it occurs while traversing the sitetree in the search for a node to handle the current request.

load_sitemap(sitemap_file)[source]

Load the whole sitemap XML from sitemap_file.

register_node_id(ID, node)[source]

Nodes may have IDs under which they can be referred using the Site. This method is used to register the node under a given ID. This will raise a ValueError if the ID is duplicated.

transform_href(ctx, node, attrname=u'href', make_global=False)[source]

Transform the attribute attrname on the ETree node node as if it was a possibly local url. If it is local and relative, it gets transformed so that it points to the same location independent of the current URL.

transform_py_namespace(ctx, body, crumbs=True)[source]

Do PyXWF specific transformations on the XHTML tree body. This includes transforming local a tags, local img tags and placing crumbs.

Note that the tree body is not bound to be an actual XHTML body. This method will iterate over all matching elements, so it can also be a whole XHTML html document or just a snippet or something completely outside the XHTML namespace.

See <py-namespace> for documentation on what can be done with in that XML namespace.

transform_references(ctx, tree)[source]

Transform all <py:author /> elements in tree which have an @id attribute by copying all relevant attributes of the Author object referred to by the @id to the element. This overrides existing attributes.

If the @id is not known to the site, the text of the element is replaced with a easy-to-recognize placeholder and the element is converted to a <h:span /> element.

update()[source]

If neccessary, reload the whole sitemap. This works as long as the new sitemap does not depend on any python code changes.

Hooks available on Site objects

The following hooks are available on every Site instance. They’re called with the specified arguments and their return value is ignored. See PyXWF.Registry.HookRegistry for more information on hooking.

tweaks-loaded()

All nodes in <site:tweaks /> have been processed. This is useful to do something smart with the configuration you received.

tree-loaded()

The tree root has been found in the sitemap and is completely loaded. This implies that all node IDs are accessible by the time this hook is called.

crumbs-loaded()

The whole <site:crumbs /> has been processed.

loading-finished()

The whole sitemap was successfully processed.

handle.pre-lookup(ctx)

getMessage() has just been called, no lookup has been done yet. This is useful to place site-wide redirects.

ctx is the Context instance of the request.

Table Of Contents

Previous topic

PyXWF.Context – One HTTP transaction context

Next topic

PyXWF.Message – Response messages

This Page