Close various files when finished writing to them; fixes ResourceWarnings and some PyPy uses.

This avoids ResourceWarnings on Python 3, but the main motivation for this was to support doctests in other projects run under PyPy. Because PyPy doesn't use a reference-counting GC like CPython, these files are not closed and flushed to disk until some indeterminate time in the future, or when the process exits. A buildout-based doctest doesn't exit the process, unlike normal buildout usage, and so mysterious failures can arise due to the data on disk not being what's expected at subsequent parts of the test. (I encountered this working on `collective.recipe.supervisor`.)  There may be other ResourceWarnings out there, but fixing the ones in these two files was enough to make the doctests work for me.

I get one test error and one failure both before and after these changes; it's in the log handler code and seems unrelated. I only ran the full test suite under Python 2.7, and to make that work I had to change `dev.py` to use a newer setuptools version (otherwise installation simply failed). I did not include that change here.