According to pep 3333 response headers are supposed to be bytestrings. In Python 2 that means a str, and in Python 3, bytes. Some wsgi servers, notably mod_wsgi, check that the values of headers are correct, and make an error if they are not. In at least some testing situations wsgi-intercept should replicate this behavior so that an application can know that it is not sending bad headers. This is something that needs to be done in wsgi_intercept itself, and not external tests, because many http client libraries will transform response header values to native strings before providing them to the caller. However, many existing tools (for example selector) do not obey this constraint, so we cannot simply turn this check on by default. Instead we need to be able to declare that for a given context we want it to be done. The easiest way to do this is to set a module level global, as done in wsgi_intercept/tests/__init__.py. In practical terms what this code does, is disallow * in py2, sending responses with unicode values * in py3, sending responses with str values if wsgi_intercept.STRICT_RESPONSE_HEADERS == True. Because this change introduced some six into wsgi_intercept/__init__.py, additional changes to use six were made. Note that since Python 2.7 io.BytesIO has been available so we no longer need to do a conditional import. Interestingly, some testing suggests that six.BytesIO in 2.7 is _not_ the same as io.BytesIO. Fixes: #43
11 lines
230 B
Python
11 lines
230 B
Python
import os
|
|
import wsgi_intercept
|
|
|
|
# Ensure that our test apps are sending strict headers.
|
|
wsgi_intercept.STRICT_RESPONSE_HEADERS = True
|
|
|
|
|
|
if os.environ.get('USER') == 'cdent':
|
|
import warnings
|
|
warnings.simplefilter('error')
|