fix UserAgent import error with newer versions of gevent
fix port conflict in tests with postgresql
python c ext compat fix Py_TYPE fixes #41
refactor python 3 compat