Python3 port of the important bits of wsgi-intercept