support Python 3

These changes enable the extension to be used with Python 3 while keeping it backwards compatible with Python 2.7 (see also #5).