Documentation for pulsar 0.9.2. For development docs, go here.

Utilities

HTTP Parsers

Pulsar ships with its own HTTP parser used by both server and the HTTP client. Headers are collected using the Headers data structure which exposes a list/dictionary-type interface.

Authentication

Handle basic and digest authentication on the server.

HttpAuthenticate

class pulsar.apps.wsgi.auth.HttpAuthenticate(type, realm=None, **options)[source]

Exception when basic or digest authentication is required.

This HttpException is raised with status code 401 and the extra WWW_Authenticate header if type is either basic or digest.

Authorization header parser

pulsar.apps.wsgi.auth.parse_authorization_header(value, charset='utf-8')[source]

Parse an HTTP basic/digest authorisation header.

Parameters:value – the authorisation header to parse.
Returns:either None if the header was invalid or not given, otherwise an Auth object.

Structures

class pulsar.apps.wsgi.structures.Accept[source]

An Accept object is a tuple subclass for tuples of (value, quality) tuples. It is automatically sorted by quality.

All Accept objects work similar to a list but provide extra functionality for working with the data. Containment checks are normalised to the rules of that header:

>>> a = CharsetAccept([('ISO-8859-1', 1), ('utf-8', 0.7)])
>>> a.best
'ISO-8859-1'
>>> 'iso-8859-1' in a
True
>>> 'UTF8' in a
True
>>> 'utf7' in a
False

To get the quality for an item you can use normal item lookup:

>>> print(a['utf-8'])
0.7
>>> a(['utf7'])
0
best

The best match as value.

best_match(matches, default=None)[source]

Returns the best match from a list of possible matches based on the quality of the client. If two items have the same quality, the one is returned that comes first.

Parameters:
  • matches – a list of matches to check for
  • default – the value that is returned if none match
find(key)[source]

Get the position of an entry or return -1.

Parameters:key – The key to be looked up.
index(key)[source]

Get the position of an entry or raise ValueError.

Parameters:key – The key to be looked up.

Changed in version 0.5: This used to raise IndexError, which was inconsistent with the list API.

itervalues()[source]

Iterate over all values.

quality(key)[source]

Returns the quality of the key.

New in version 0.6: In previous versions you had to use the item-lookup syntax (eg: obj[key] instead of obj.quality(key))

to_header()[source]

Convert the header set into an HTTP header string.

values()[source]

Return a list of the values, not the qualities.

class pulsar.apps.wsgi.structures.CharsetAccept[source]

Like Accept but with normalisation for charsets.

class pulsar.apps.wsgi.structures.ContentAccept[source]

Like Accept but with special methods and behaviour for content types.

accept_html

True if this object accepts HTML.

accept_json

True if this object accepts JSON.

accept_xhtml

True if this object accepts XHTML.

class pulsar.apps.wsgi.structures.LanguageAccept[source]

Like Accept but with normalisation for languages.

Miscellaneous

The pulsar.apps.wsgi.utils module include several utilities used by various components in the wsgi application

pulsar.apps.wsgi.utils.handle_wsgi_error(environ, exc)[source]

The default error handler while serving a WSGI request.

Parameters:
  • environ – The WSGI environment.
  • exc – the exception
Returns:

a WsgiResponse

pulsar.apps.wsgi.utils.render_error_debug(request, exception, is_html)[source]

Render the exception traceback



Table Of Contents

Previous topic

Asynchronous Content

Next topic

JSON-RPC

This Page