Python 2 compatibility

@gulopine

The meat here is in 994d031, which fixes up the `__metaclass__` usage and inheritance to make this module compatible with Python 2.