Python 3 compatibility

This code now runs on Python2 and Python3. Many of the edits were done by the 2to3 utility. 

I had to add a bunch of "with" statements to get the Python3 interpreter to stop throwing warnings about unclosed files.

And I had to add a dynamic import for the url quote and unquote methods since these are in different places for Python3.

It now passes test in both python 2.7 and 3.4. However, pip complains on install because the setup file references namaste which is not python3 compatible. @mjgiarlo accepted my pull request for python3 changes to namaste, but we didn't update the version number and push the changes to pypi. So we will need to take care of that and do the same for dflat.