wsgi_tools.filtered_parser module

This module includes WSGI-apps, which parse content and call another WSGI-app.

Compared to wsgi_tools.parser this also includes a json-filter so that you can not pass any json you want to the parser, but only json that works for your app.

Do not use

environ['wsgi.input'].read()

except in this parser.

If you want the raw bytes content, you can use:

parser.raw_content
wsgi_tools.filtered_parser.Boolean(value)

A Filter, which checks if values are booleans.

Boolean is directly a filter.

class wsgi_tools.filtered_parser.FilteredJSONParser(app, filter)

Bases: object

A WSIG app, which parses json from the content.

Parameters
  • app – The WSGI-app, the parser will forward.

  • filter – The filter, which the json-content should match.

property json_content

the json content

property raw_content

the raw content of the body

Type

bytes

class wsgi_tools.filtered_parser.Float(min=None, max=None)

Bases: object

A filter class, which checks if values are floats and if they are in a specific range.

Float is not directly a filter, but has to be constructed.

Parameters
  • min (float, optional) – The minimum value.

  • max (float, optional) – The maximum value.

class wsgi_tools.filtered_parser.Int(min=None, max=None)

Bases: object

A filter class, which checks if values are ints and if they are in a specific range.

Int is not directly a filter, but has to be constructed.

Parameters
  • min (int, optional) – The minimum value.

  • max (int, optional) – The maximum value.

class wsgi_tools.filtered_parser.List(filter)

Bases: object

A filter class, which checks if values are lists and if their content is correct.

List is not directly a filter, but has to be constructed.

Parameters

filter – The filter, which filters the contents of the list.

class wsgi_tools.filtered_parser.Object(entries, ignore_more=False)

Bases: object

A filter class, which checks if values are objects and if their content is correct.

Object is not directly a filter, but has to be constructed.

Parameters
  • entries (dict) – a dict with the keys of the object as keys and the filters of the values of the object as values. If some entries are optional, the values should be a tuple with the filter and True.

  • ignore_more (bool, optional) – If False (default), objects do not match if they have more entries than the filter.

class wsgi_tools.filtered_parser.Options(*options)

Bases: object

A filter class, which checks if the content matches one of multiple filters

Options is not directly a filter, but has to be constructed.

Parameters

options – The filters, where one of them should match.

wsgi_tools.filtered_parser.String(value)

A Filter, which checks if values are strings.

String is directly a filter.