PyXWF.Message – Response messages

In PyXWF, we call all content we send over the wire a Message. Messages thus contain information about their mime type, encoding and of course their payload.

They represent it internally however they like, but must be able to serialize the payload to a properly encoded bytes object for conversion in a MessageInfo instance.

class PyXWF.Message.EmptyMessage(**kwargs)[source]

Represent a message without a body.

class PyXWF.Message.HTMLMessage(doctree, version='HTML5', pretty_print=False, **kwargs)[source]

Represent an HTML message. doctree must be a valid HTML document tree (the same as the XHTML tree, but without namespaces) as lxml.etree node. Conversion to bytes payload is handled by this class automatically.

You can specify the HTML version via version, which is currently restricted to HTML5.

classmethod from_xhtml_tree(doctree, version='HTML5', **kwargs)[source]

Return an HTMLMessage instance from the given XHTML doctree. This performs automatic conversion by removing the XHTML namespace from all elements. Raises ValueError if a non-xhtml namespace is encountered.

class PyXWF.Message.Message(mimetype, status=<class 'PyXWF.Errors.HTTP.HTTP200'>, encoding=None)[source]

Baseclass for any message. For proper function, messages must implement the get_encoded_body() method.

It handles sending the message in a given transaction context if all properties and methods are set up properly.

mimetype is the MIME type according to RFC 2046.

Encoding None[source]

Encoding (charset in the Content Type context) of the message.

MIMEType None[source]

The internet media type (aka content type) of the Message.

get_encoded_body()[source]

Return the bytes object resembling the contents encoded in the encoding set up in Encoding.

Derived classes must implement this method.

class PyXWF.Message.TextMessage(contents, **kwargs)[source]

Represent a plain-text message. contents must be either a string (which must be convertible into unicode using the default encoding) or a unicode instance.

Contents None[source]

Contents of the plain text message. Assigning to this property will convert the assigned value to unicode if neccessary and fail for anything which does not inherit from str or unicode.

class PyXWF.Message.XHTMLMessage(doctree, minify_namespaces=True, **kwargs)[source]

Represent an XHTML message. doctree must be a valid XHTML document tree as lxml.etree node. Conversion to bytes payload is handled by this class automatically.

class PyXWF.Message.XMLMessage(doctree, content_type, cleanup_namespaces=False, pretty_print=False, force_namespaces={}, **kwargs)[source]

Represent a generic XML message. doctree must be a valid lxml Element or ElementTree. content_type must specify the MIME type of the document.

If cleanup_namespaces is True, lxml.etree.cleanup_namespaces() will be called on the tree.

Previous topic

PyXWF.Site — A whole Website

Next topic

PyXWF.Templates – XSL transformation based templating

This Page