Refactored wsgi compatibility layer