This is allowed by the pep but the code was written such that if it
received an empty string it would not get the rest of the iterator.
This change fixes it so only None will cause the stop.
With this change an unrelated test wsgi app which was returning an
empty string needed to be fixed to return a bytestring.
Fixes #46
Should probably consider changing it to kwargs, but this way it is
explicit about what args are being dropped. Add a note to the docs
to indicate this is the case (it's always been true).
With the addition of six to __init__.py the import of wsgi_intercept
in setup.py to get version and long description information no longer
works. Now we keep that information externally:
* version is static in setup.py
* the __doc__ from __init__.py is written to README.rst by a tox
target, and that is loaded by setup.py
This has an added benefit of keeping the github visible readme,
the pypi info, and the main docs all in sync, at the cost of a
little magic. The __doc__ rarely changes, so the magic isn't
that bad.
Note that the bug in this code (the use of bytestrings) is not
yet fixed, but I'm making this change on that branch because it
makes the test usable.
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
This is basic flake8 testing without any 'hacking' extensions. We
may wish to add those later, but for the time being this code is
so much of its own particular style that that would be painful.
In any case, the hacking rules aren't that great.
In the process some documentation adjustments were made while fixing
line lenghts. A dead link was removed.
This allows easier testing of multiple versions of Python in a more
automated fashion. This is needed if we're ever going to make some
of the planned extensive refactorings.
This change:
* adds tox.ini
* updates Makefile and .travis.yml to point to tox
* fixes a doctest typo found while make sure the Makefile targets
work
* adds a [docs] extras_require so that the deps in tox are managed
cleanly
The pep8 target is currently commented out because it fails (and
has done for a long time). Will fix asap. This commit is to ensure
that travis is working. Followups will tune it up.
PEP 3333 requires that values in the environ that come from
header be native str objects decoded from ISO-8859-1 bytes.
This means that in Python 2 and 3 they are effectively
different things, but oh well, these are the rules.
One area where this causes a real issue is in the
SimpleCookie.load() method which checks for the type of the
string associated with HTTP_COOKIE.
Fixes #39
Otherwise monkeypatching get confused and will not work
and the tests will fail. An effort was made to use the
six http_client always (both in tests and the interceptor)
but this led to infinite recursion, so going for the lame
fix here.
The functionality has always worked (as long as six wasn't
involved) this is just getting things working in tests.
requests vendorizes urllib3 which makes monkey patching it while also
wanting to monkey patch proper urllib3 a bit hairy. Here we use a
factory to do the overrides for us. Hat tip to @FND for helping
with the thinking through of this.
This is relatively straightforward but presents a problem.
The monkeypatching is identical as that for requests, but on
different modules, because of the vendorization of urllib3
that requests does.
It would be better if there was some way to have just one
set of code that removes the duplication and does the right
but maintains the semantics of intercepting the desired thing
by name.
requests and urllib will get upset of socks proxy settings are
present in the environment. In those interceptors, an exception
will now be raised if $http_proxy or $https_proxy are set.
Tests are added to cover the variable being set for all four
of the interceptor types.
This is the quick and dirty solution to the problem. The way this
has been done shows some clear opportunities for refactoring down
the road.
Fixes #30