Package wsgitools :: Module filters :: Class BaseWSGIFilter
[hide private]
[frames] | no frames]

Class BaseWSGIFilter

source code


Generic WSGI filter class to be used with WSGIFilterMiddleware.

For each request a filter object gets created. The environment is then passed through filter_environ. Possible exceptions are filtered by filter_exc_info. After that for each (header, value) tuple filter_header is used. The resulting list is filtered through filter_headers. Any data is filtered through filter_data. In order to possibly append data the append_data method is invoked. When the request has finished handle_close is invoked.

All methods do not modify the passed data by default. Passing the BaseWSGIFilter class to a WSGIFilterMiddleware will result in not modifying requests at all.

Instance Methods [hide private]
 
__init__(self)
This constructor does nothing and can safely be overwritten.
source code
{str: str}
filter_environ(self, environ)
Receives a dict with the environment passed to the wsgi application and a dict must be returned.
source code
 
filter_exc_info(self, exc_info)
Receives either None or a tuple passed as third argument to start_response from the wrapped wsgi application.
source code
str
filter_status(self, status)
Receives a status string passed as first argument to start_response from the wrapped wsgi application.
source code
(str, str)
filter_header(self, headername, headervalue)
This function is invoked for each (headername, headervalue) tuple in the second argument to the start_response from the wrapped wsgi application.
source code
[(str, str)]
filter_headers(self, headers)
A list of headers passed as the second argument to the start_response from the wrapped wsgi application is passed to this function and such a list must also be returned.
source code
bytes
filter_data(self, data)
For each string that is either written by the write callable or returned from the wrapped wsgi application this method is invoked.
source code
gen([bytes])
append_data(self)
This function can be used to append data to the response.
source code
 
handle_close(self)
This method is invoked after the request has finished.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

This constructor does nothing and can safely be overwritten. It is only listed here to document that it must be callable without additional parameters.

Overrides: object.__init__

filter_environ(self, environ)

source code 

Receives a dict with the environment passed to the wsgi application and a dict must be returned. The default is to return the same dict.

Parameters:
  • environ ({str: str})
Returns: {str: str}

filter_exc_info(self, exc_info)

source code 

Receives either None or a tuple passed as third argument to start_response from the wrapped wsgi application. Either None or such a tuple must be returned.

filter_status(self, status)

source code 

Receives a status string passed as first argument to start_response from the wrapped wsgi application. A valid HTTP status string must be returned.

Parameters:
  • status (str)
Returns: str

filter_header(self, headername, headervalue)

source code 

This function is invoked for each (headername, headervalue) tuple in the second argument to the start_response from the wrapped wsgi application. Such a value or None for discarding the header must be returned.

Parameters:
  • headervalue (str)
  • headername (str)
Returns: (str, str)

filter_headers(self, headers)

source code 

A list of headers passed as the second argument to the start_response from the wrapped wsgi application is passed to this function and such a list must also be returned.

Parameters:
  • headers ([(str, str)])
Returns: [(str, str)]

filter_data(self, data)

source code 

For each string that is either written by the write callable or returned from the wrapped wsgi application this method is invoked. It must return a string.

Parameters:
  • data (bytes)
Returns: bytes

append_data(self)

source code 

This function can be used to append data to the response. A list of strings or some kind of iterable yielding strings has to be returned. The default is to return an empty list.

Returns: gen([bytes])