Refactor for more reliable compiling

First of all, apologies for a slightly large pull request.  If you would prefer I can probably do some rebasing to neaten it up.

This incorporates the changes from @mociepka to add python3 support and a couple of tests.  My changes add casting from strings to utf-8 bytestrings (important for python3) and clean up the setup.py file, forcing installation of cython.  I have also added a tox file for running tests locally.

I believe that the only non backwards-compatible change is in c04aac3: switching from integer constants to strings for output type.  This probably doesn't need to be included.