'Called during WSGI pipeline creation. Modifies the WSGI pipeline
context to ensure that mandatory middleware is present in the pipeline.
:param pipe: A PipelineWrapper object'

def modify_wsgi_pipeline(self, pipe):

    pipeline_was_modified = False
    for filter_spec in reversed(required_filters):
        filter_name = filter_spec['name']
        if (filter_name not in pipe):
            afters = filter_spec.get('after_fn', (lambda _junk: []))(pipe)
            insert_at = 0
            for after in afters:
                try:
                    insert_at = max(insert_at, (pipe.index(after) + 1))
                except ValueError:
                    pass
            self.logger.info(_('Adding    required    filter    %(filter_name)s    to    pipeline    at    position    %(insert_at)d'), {'filter_name': filter_name, 'insert_at': insert_at})
            ctx = pipe.create_filter(filter_name)
            pipe.insert_filter(ctx, index=insert_at)
            pipeline_was_modified = True
    if pipeline_was_modified:
        self.logger.info(_('Pipeline    was    modified.    New    pipeline    is    "%s".'), pipe)
    else:
        self.logger.debug(_('Pipeline    is    "%s"'), pipe)
