py3k compatibility

This should make all test pass in python 2.7 and 3.3.

I rebased @wolever's work, however there are some commits there regarding "open atomic" which are irrelevant to the python 3 compatibility. I could do an interactive rebase and remove them but that would rewrite the history and so I chose not to do so.

Also please review before merge, hopefully nothing went bad during the conflict resolution :pray:

This closes #15 and closes #16.